Multiple Point Lights

This commit is contained in:
Mamitiana RASOLOJAONA
2024-03-27 10:40:17 +01:00
parent 8d56c159c6
commit ee4564560d
13 changed files with 286 additions and 63 deletions

View File

@@ -3,6 +3,12 @@
////////////////////////////////////////////////////////////////////////////////
/////////////
// DEFINES //
/////////////
#define NUM_LIGHTS 4
/////////////
// GLOBALS //
/////////////
@@ -13,6 +19,11 @@ cbuffer MatrixBuffer
matrix projectionMatrix;
};
cbuffer LightPositionBuffer
{
float4 lightPosition[NUM_LIGHTS];
};
//////////////
// TYPEDEFS //
@@ -29,7 +40,8 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
float3 lightPos[NUM_LIGHTS] : TEXCOORD1;
};
////////////////////////////////////////////////////////////////////////////////
@@ -38,7 +50,9 @@ struct PixelInputType
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;
@@ -57,5 +71,17 @@ 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);
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;
}