Ambient lightning + Multitexture (Les shaders ne se superposent pas)

This commit is contained in:
GolfOcean334
2024-03-27 11:19:34 +01:00
parent 35876a05a5
commit 6f08684972
18 changed files with 675 additions and 63 deletions

View File

@@ -11,6 +11,7 @@ SamplerState SampleType : register(s0);
cbuffer LightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
float padding;
@@ -42,17 +43,23 @@ float4 LightPixelShader(PixelInputType input) : SV_TARGET
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// Set the default output color to the ambient light value for all pixels.
color = ambientColor;
// Invert the light direction for calculations.
lightDir = -lightDirection;
// Calculate the amount of light on this pixel.
lightIntensity = saturate(dot(input.normal, lightDir));
// Change the diffuse color to red (0, 1, 0)
float3 greenDiffuseColor = float3(1, 0, 0);
if(lightIntensity > 0.0f)
{
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color += (diffuseColor * lightIntensity);
}
// Determine the final amount of diffuse color based on the diffuse color combined with the light intensity.
color = saturate(diffuseColor * lightIntensity);
// Saturate the final light color.
color = saturate(color);
// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
color = color * textureColor;