struct PSInput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
Texture2D g_txDiffuse; // : register(t0);
SamplerState g_sampler; // : register(s0);
float4 PSMain(PSInput input) : SV_TARGET
{
//return g_txDiffuse.Sample(g_sampler, input.uv);
float4 textureColor;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = g_txDiffuse.Sample(g_sampler, input.uv);
//We set the output color value to the base ambient color. All pixels will now be illuminated by a minimum of the ambient color value.
// Set the default output color to the ambient light value for all pixels.
float4 color = float4(0.05f,0.05f,0.05f,1.0f);
// Invert the light direction for calculations.
float3 lightDir = float3(1.0f,1.0f,1.0f);
float3 lightDir2 = float3(-1.0f,-1.0f,0.0f);
// Calculate the amount of light on this pixel.
float lightIntensity = saturate(dot(input.normal, lightDir));
float lightIntensity2 = saturate(dot(input.normal, lightDir2));
color += 0.6f * (float4(0.6f,0.6f,0.6f,1.0f) * lightIntensity) + 0.5f * (float4(0.6f,0.6f,0.6f,1.0f) * lightIntensity2);
// Make sure to saturate the final output light color since the combination of ambient and diffuse could have been greater than 1.
// 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;
return color;
}