Multiple point lights

This commit is contained in:
StratiX0
2024-03-28 10:56:57 +01:00
parent 16db21608a
commit e5c88797b0
17 changed files with 4143 additions and 208 deletions

View File

@@ -2,6 +2,10 @@
// Filename: light.vs
////////////////////////////////////////////////////////////////////////////////
/////////////
// DEFINES //
/////////////
#define NUM_LIGHTS 4
/////////////
// GLOBALS //
@@ -19,6 +23,11 @@ cbuffer CameraBuffer
float padding;
};
cbuffer LightPositionBuffer
{
float4 lightPosition[NUM_LIGHTS];
};
//////////////
// TYPEDEFS //
//////////////
@@ -34,7 +43,7 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 viewDirection : TEXCOORD1;
float3 lightPos[NUM_LIGHTS] : TEXCOORD1;
};
@@ -45,7 +54,7 @@ PixelInputType LightVertexShader(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;
@@ -67,11 +76,14 @@ PixelInputType LightVertexShader(VertexInputType input)
// 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);
for(i=0; i<NUM_LIGHTS; i++)
{
// Determine the light positions based on the position of the lights and the position of the vertex in the world.
output.lightPos[i] = lightPosition[i].xyz - worldPosition.xyz;
// Normalize the light position vectors.
output.lightPos[i] = normalize(output.lightPos[i]);
}
return output;
}