63 lines
1.6 KiB
PostScript
63 lines
1.6 KiB
PostScript
/////////////
|
|
// GLOBALS //
|
|
/////////////
|
|
Texture2D shaderTexture : register(t0);
|
|
SamplerState SampleType : register(s0);
|
|
cbuffer SunLightBuffer
|
|
{
|
|
float4 ambientColor;
|
|
float4 diffuseColor;
|
|
float3 lightDirection;
|
|
};
|
|
|
|
cbuffer SunLightColorBuffer
|
|
{
|
|
float4 sunColor;
|
|
};
|
|
|
|
//////////////
|
|
// TYPEDEFS //
|
|
//////////////
|
|
struct PixelInputType
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float2 tex : TEXCOORD0;
|
|
float3 normal : NORMAL;
|
|
float3 lightDir : TEXCOORD1;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Pixel Shader
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
float4 SunLightPixelShader(PixelInputType input) : SV_TARGET
|
|
{
|
|
float4 textureColor;
|
|
float3 lightDir;
|
|
float4 color;
|
|
float lightIntensity;
|
|
float4 colorArray;
|
|
float4 colorSum;
|
|
|
|
// 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 direction of the light.
|
|
lightIntensity = saturate(dot(input.normal, input.lightDir));
|
|
|
|
// 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 the light color.
|
|
colorSum.r += colorArray.r;
|
|
colorSum.g += colorArray.g;
|
|
colorSum.b += colorArray.b;
|
|
|
|
// Multiply the texture pixel by the light color to get the final result.
|
|
color = saturate(colorSum) * textureColor;
|
|
|
|
return color;
|
|
}
|