Minor update - Sunlight shader

This commit is contained in:
2025-01-23 17:29:29 +01:00
parent d8552d3f91
commit 51b29f77aa
7 changed files with 62 additions and 156 deletions

View File

@@ -6,10 +6,8 @@ SamplerState SampleType : register(s0);
cbuffer SunLightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
float padding;
float specularPower;
float4 specularColor;
};
cbuffer SunLightColorBuffer
@@ -17,7 +15,6 @@ cbuffer SunLightColorBuffer
float4 sunColor;
};
//////////////
// TYPEDEFS //
//////////////
@@ -26,10 +23,9 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 sunPos : TEXCOORD1;
float3 lightDir : TEXCOORD1;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
@@ -38,32 +34,29 @@ float4 SunLightPixelShader(PixelInputType input) : SV_TARGET
float4 textureColor;
float3 lightDir;
float4 color;
float3 reflection;
float4 specular;
float lightIntensity;
float4 colorArray;
float4 colorSum;
int i;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// Calculate the different amounts of light on this pixel based on the positions of the lights.
lightIntensity = saturate(dot(input.normal, input.sunPos));
// Calculate the different amounts of light on this pixel based on the direction of the light.
lightIntensity = saturate(dot(input.normal, input.lightDir));
// Determine the diffuse color amount of each of the four lights.
colorArray = sunColor * lightIntensity;
// Determine the diffuse color amount of the light.
colorArray = diffuseColor * lightIntensity;
// Initialize the sum of colors.
colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f);
// Add all of the light colors up.
// Add the light color.
colorSum.r += colorArray.r;
colorSum.g += colorArray.g;
colorSum.b += colorArray.b;
// Multiply the texture pixel by the combination of all four light colors to get the final result.
// Multiply the texture pixel by the light color to get the final result.
color = saturate(colorSum) * textureColor;
return color;
}
}