Geometric Objects and Transformations
Coordinate systems rial.html
Clockwise = Front Face
The DirectX 10 Pipeline Stage 1: Model Space -> World Space
The DirectX 10 Pipeline Stage 2: World Space -> Camera Space (Not done in OpenGL 2.x)
The DirectX 10 Pipeline Stage 3: Camera Space -> Projection Space
The DirectX 10 Pipeline Stage 4: Change the Clipping Matrix (If you are not using the std Projection Matrix)
The DirectX 10 Pipeline Stage 5: Clipping (Not a Matrix!)
The DirectX 10 Pipeline Stage 6: Projected Space -> Clipping Space (Flips the Y-Axis)
The DirectX 10 Pipeline Stage 7: Projected Space -> Screen Space (Coordinates passed to the rasterizer)
Up till Dx9 this was all done for us... With the new approach to Rendering, NOTHING is default Need to write our own: – Geometry Shader (Optional) – Vertex Shader – Pixel Shader – Code to run the Combined Vertex Shader + Pixel Shader on the GPU (Effect)
HLSL High Level Shader Language, the Dx only solution. Cg, the Nvidia Dx / GL solution GLSL, the GL only solution
What about a real Vertex Shader? matrix World; matrix View; matrix Projection; VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR ) { VS_OUTPUT output = (VS_OUTPUT)0; output.Pos = mul( Pos, World ); output.Pos = mul( output.Pos, View ); output.Pos = mul( output.Pos, Projection ); output.Color = Color; return output; }
Our Super Cheap Vertex Shader float4 VS( float4 Pos : POSITION ) : SV_POSITION { return Pos; } The Colon: sets the semantics of the data (metadata)
Geometry Shaders WTF? Grass Water Fur +ve Less Bus Data Less CPU + Memory usage -ve More GPU Load No Dx9 or below compatibility (Who cares!)
Vertex Shader Base Functions: – World – View – Projection Transformation Extensions: – Water Movement – Plant movements – Object Morphing
Pixel (Fragment) Shader Colouring Simple texturing Cell shading Normal mapping Particle effects Alpha blending Etc!
Semantics (metadata) There are so few data types in GPU programming (Typically just a load of floats) Using Semantics we can specify the intended purpose of the variables What does this do: float3 pos : POSITION; Creates 3x floats to store the xyz + tells HLSL the floats are used as a position
Semantics What about: float4x4 wvp : WORLDVIEWPROJ...
float4 PS( float4 Pos : SV_POSITION ) : SV_Target { return float4( 1.0f, 1.0f, 0.0f, 1.0f ); // BGRA }
In both OpenGL and Direct3D Z is the depth of the viewport!!!! hence the Z-buffer (Depth Buffer)
Z Buffer Depth – Due to the scalar nature of the Pyramid Viewport – Depth precision drops as the distance between the Near and Far planes are moved apart – This will result in more artefacts and visual errors
Viewport types Orthogonal – No depth perception (scaling) Projected – This is the typical 3D viewport Objects \ Vertices are scaled and rotated based on the ‘virtual’ distance from the screen
References