1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- cbuffer MatrixBuffer
- {
- matrix worldMatrix;
- matrix viewMatrix;
- matrix projectionMatrix;
- };
- cbuffer CameraBuffer
- {
- float3 cameraPosition;
- float padding;
- };
- struct VertexInputType
- {
- float4 position : POSITION;
- float2 tex : TEXCOORD0;
- float3 normal : NORMAL;
- };
- struct PixelInputType
- {
- float4 position : SV_POSITION;
- float2 tex : TEXCOORD0;
- float3 normal : NORMAL;
- float3 viewDirection : TEXCOORD1;
- };
- PixelInputType LightVertexShader(VertexInputType input)
- {
- PixelInputType output;
- float4 worldPosition;
- // Change the position vector to be 4 units for proper matrix calculations
- input.position.w = 1.0f;
- // Calculate the position of the vertex against the world, view, and projection matracies
- output.position = mul(input.position, worldMatrix);
- output.position = mul(output.position, viewMatrix);
- output.position = mul(output.position, projectionMatrix);
- // Store the input color for the pixel shader to use.
- output.tex = input.tex;
- // Calculate the normal vector against the world matrix only
- output.normal = mul(input.normal, (float3x3)worldMatrix);
- // Normalize the normal vector
- output.normal = normalize(output.normal);
- // Calculate the position of the vertex in the world
- worldPosition = mul(input.position, worldMatrix);
- // Determine the viewing direction
- output.viewDirection = cameraPosition.xyz - worldPosition.xyz;
- // Normalize the viewing direction vector
- output.viewDirection = normalize(output.viewDirection);
- return output;
- }
|