Ambient lightning + Multitexture (Les shaders ne se superposent pas)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user