Geometric Objects and Transformations

24
Geometric Objects and Transformations

description

Geometric Objects and Transformations. Coordinate systems. http://alt.pluralsight.com/wiki/default.aspx/Craig.DirectX/CoordinateSystemsTutorial.html. Clockwise = Front Face. http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx. The DirectX 10 Pipeline. - PowerPoint PPT Presentation

Transcript of Geometric Objects and Transformations

Page 1: Geometric Objects and Transformations

Geometric Objects and Transformations

Page 2: Geometric Objects and Transformations

Coordinate systems

http://alt.pluralsight.com/wiki/default.aspx/Craig.DirectX/CoordinateSystemsTutorial.html

Page 3: Geometric Objects and Transformations

Clockwise = Front Face

Page 4: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 1: Model Space -> World Space

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 5: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 2: World Space -> Camera Space(Not done in OpenGL 2.x)

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 6: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 3: Camera Space -> Projection Space

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 7: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 4: Change the Clipping Matrix(If you are not using the std Projection Matrix)

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 8: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 5: Clipping (Not a Matrix!)

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 9: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 6: Projected Space -> Clipping Space(Flips the Y-Axis)

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 10: Geometric Objects and Transformations

The DirectX 10 Pipeline

Stage 7: Projected Space -> Screen Space(Coordinates passed to the rasterizer)

http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

Page 11: Geometric Objects and Transformations

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)

Page 12: Geometric Objects and Transformations

HLSL

• High Level Shader Language, the Dx only solution.

• Cg, the Nvidia Dx / GL solution• GLSL, the GL only solution

Page 13: Geometric Objects and Transformations

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;

}

Page 14: Geometric Objects and Transformations

Our Super Cheap Vertex Shader

float4 VS( float4 Pos : POSITION ) : SV_POSITION{ return Pos;}The Colon: sets the semantics of the data

(metadata)

Page 15: Geometric Objects and Transformations

Geometry Shaders WTF?

• Grass• Water• Fur+ve

Less Bus DataLess CPU + Memory usage

-veMore GPU LoadNo Dx9 or below compatibility (Who cares!)

Page 16: Geometric Objects and Transformations

Vertex Shader

• Base Functions:– World– View– Projection Transformation

• Extensions:– Water Movement– Plant movements– Object Morphing

Page 17: Geometric Objects and Transformations

Pixel (Fragment) Shader

• Colouring• Simple texturing• Cell shading• Normal mapping• Particle effects• Alpha blending• Etc!

Page 18: Geometric Objects and Transformations

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

Page 19: Geometric Objects and Transformations

Semantics

• What about:float4x4 wvp : WORLDVIEWPROJ...

Page 20: Geometric Objects and Transformations

float4 PS( float4 Pos : SV_POSITION ) : SV_Target { return float4( 1.0f, 1.0f, 0.0f, 1.0f ); // BGRA}

Page 21: Geometric Objects and Transformations

• In both OpenGL and Direct3D Z is the depth of the viewport!!!!hence the Z-buffer (Depth Buffer)

Page 22: Geometric Objects and Transformations

• 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

Page 23: Geometric Objects and Transformations

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

Page 24: Geometric Objects and Transformations

References

• http://knol.google.com/k/hlsl-shaders#