1 / 16

Cg Programming

Cg Programming. Mikkel Adamsen Anders Vaaben Andersen Jacob Atzen Oliver Due Billing Peter Bruun-Rasmussen Micky Kelager Christensen Anders Fleron Dennis Franck Sune Gamsby Frederik Gottlieb. Adam Hasselbalch Hansen Anders Starcke Henriksen Joakim Hovard Stig Frank Irming-Pedersen

royce
Télécharger la présentation

Cg Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cg Programming Mikkel Adamsen Anders Vaaben Andersen Jacob Atzen Oliver Due Billing Peter Bruun-Rasmussen Micky Kelager Christensen Anders Fleron Dennis Franck Sune Gamsby Frederik Gottlieb Adam Hasselbalch Hansen Anders Starcke Henriksen Joakim Hovard Stig Frank Irming-Pedersen Sune Gustav Nielsen Martin Lehnsbo Parm Emil Støvring Thomas Szymanski Erik Larsen Underbjerg Participants:

  2. Plan for today • Administrative details • Overview of GPU pipeline • Programming model • Cg language overview • Examples • Intro to Image Lab

  3. Lecture Plan

  4. Seminar Details • Groups of 3. • 3 seminars each to pass. • Aim at 30 minutes presentation • Theory. • Implementation details. • Demonstration. • Schema at imagelab to assign presentation time and subject.

  5. Available subjects • Natural Effects: • Water, skin, animation, noise, fire, grass, diffraction. • Lighting and shadows: • Lots of different shadowing techniques. • Materials: • Subsurface scattering, ambient occlusion, spatial BRDFs Image-based lighting, texture bombing. • Image Processing: • Glow, color, dof, filtering, hdr, ip. • Performance: • Occlusion culling, Renderman to realtime. • Beyond Triangles: • Computations on GPU, Fluid Dynamics, Stereograms, Volume Rendering, 3d ultrasound, Deformers.

  6. GPU Pipeline Historical data: • Pre-GPU Graphics Acceleration • SGI, Evans & Sutherland. Introduced concepts like vertex transformation and texture mapping. Very expensive! • First-Generation GPU (-1998) • Nvidia TNT2, ATI Rage, Voodoo3. Vertex transformation on CPU, limited set of math operations. • Second-Generation GPU (1999-2000) • GeForce 256, Geforce2, Radeon 7500, Savage3D. Transformation & Lighting. More configurable, still not programmable. • Third-Generation GPU (2001) • Geforce3, Geforce4 Ti, Xbox, Radeon 8500. Vertex Programmability, pixel-level configurability. • Fourth-Generation GPU (2002-) • Geforce FX series, Radeon 9700 and on. Vertex-level and pixel-level programmability. CPU GPU Graphics State Application Transform Rasterizer Shade VideoMemory(Textures) Vertices(3D) Xformed,LitVertices(2D) Fragments(pre-pixels) Finalpixels(Color, Depth) Render-to-texture

  7. GPU Pipeline: Transform • Vertex Processor (multiple operate in parallel) • Transform from “world space” to “image space” • Compute per-vertex lighting

  8. GPU Pipeline: Rasterizer • Rasterizer • Convert geometric rep. (vertex) to image rep. (fragment) • Fragment = image fragment • Pixel + associated data: color, depth, stencil, etc. • Interpolate per-vertex quantities across pixels

  9. GPU Pipeline: Shader • Fragment Processors (multiple in parallel) • Compute a color for each pixel • Optionally read colors from textures (images)

  10. Switch to PDF • Cg language introduction coming up...

  11. Datatypes • float 32-bit IEEE floating point • half 16-bit IEEE-like floating point • fixed 12-bit fixed [-2,2) clamping • bool Boolean • sampler Handle to a texture sampler • struct Structure as in C/C++ • No pointers... Yet.

  12. Different kinds of variables • Uniform • same for each vertex (in a vertex program) • same for each fragment (in a fragment program) • examples: reflectivity, light, color • Varying • different for each vertex (in a vertex program) • different for each fragment (in a fragment program) • examples: position, normal, texture coordinates • Local • used for intermediate computations within a vertex or fragment program

  13. Example } void introShaderFP(float2 texCoord : TEXCOORD0, float3 R : TEXCOORD1, float3 diffuse : TEXCOORD2, float3 specular : TEXCOORD3, out float3 color : COLOR, uniform float reflectivity, uniform sampler2D decalMap, uniform samplerCUBE environmentMap) { float3 lighting; lighting = diffuse + specular; color = lighting; } varying parameters } uniform parameters } local variable

  14. Array/Vector/Matrix declarations • Native support for vectors (up to length 4) and matrices (up to size 4x4): float4 mycolor; float3x3 mymatrix; • Declare more general array exactly as in C: float lightpower[8]; • But, arrays are first-class types, not pointers: float v[4] != float4 v

  15. Function Overloading • Examples: float myFuncA(float3 x); float myFuncA(half3 x); float myFuncA(float2 a, float2 b); float myFuncA(float3 a, float3 b); float myFuncA(float4 a, float4 b); Very useful with so many data types.

  16. Change to Constant-Typing Rules • In C, it’s easy to accidently use high precision half x, y; x = y * 2.0; // multiply is at // float precision! • Not in Cg x = y * 2.0; // multiply is at half // precision (from y) • Unless you want to x = y * 2.0f; // multiply is at // float precision

More Related