minor update - préparation sunlight
This commit is contained in:
78
enginecustom/sunlight.vs
Normal file
78
enginecustom/sunlight.vs
Normal file
@@ -0,0 +1,78 @@
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
cbuffer MatrixBuffer
|
||||
{
|
||||
matrix worldMatrix;
|
||||
matrix viewMatrix;
|
||||
matrix projectionMatrix;
|
||||
};
|
||||
|
||||
cbuffer CameraBuffer
|
||||
{
|
||||
float3 cameraPosition;
|
||||
float padding;
|
||||
};
|
||||
|
||||
cbuffer SunLightPositionBuffer
|
||||
{
|
||||
float4 sunPosition;
|
||||
};
|
||||
|
||||
//////////////
|
||||
// TYPEDEFS //
|
||||
//////////////
|
||||
struct VertexInputType
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct PixelInputType
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
float3 lightPos : TEXCOORD1;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Vertex Shader
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
PixelInputType SunLightVertexShader(VertexInputType input)
|
||||
{
|
||||
PixelInputType output;
|
||||
float4 worldPosition;
|
||||
int i;
|
||||
|
||||
// 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 matrices.
|
||||
output.position = mul(input.position, worldMatrix);
|
||||
output.position = mul(output.position, viewMatrix);
|
||||
output.position = mul(output.position, projectionMatrix);
|
||||
|
||||
// Store the texture coordinates for the pixel shader.
|
||||
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 light positions based on the position of the lights and the position of the vertex in the world.
|
||||
output.lightPos = sunPosition.xyz - worldPosition.xyz;
|
||||
|
||||
// Normalize the light position vectors.
|
||||
output.lightPos = normalize(output.lightPos);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user