Specular Lighting

This commit is contained in:
StratiX0
2024-03-28 10:14:25 +01:00
parent e0c875187b
commit 16db21608a
15 changed files with 14989 additions and 57 deletions

View File

@@ -13,6 +13,12 @@ cbuffer MatrixBuffer
matrix projectionMatrix;
};
cbuffer CameraBuffer
{
float3 cameraPosition;
float padding;
};
//////////////
// TYPEDEFS //
//////////////
@@ -28,6 +34,7 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
};
@@ -37,7 +44,8 @@ struct PixelInputType
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;
@@ -56,5 +64,14 @@ PixelInputType LightVertexShader(VertexInputType input)
// 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 based on the position of the camera and the position of the vertex in the world.
output.viewDirection = cameraPosition.xyz - worldPosition.xyz;
// Normalize the viewing direction vector.
output.viewDirection = normalize(output.viewDirection);
return output;
}