69 lines
1.8 KiB
PostScript

/////////////
// GLOBALS //
/////////////
Texture2D shaderTexture : register(t0);
SamplerState SampleType : register(s0);
cbuffer SunLightBuffer
{
float4 ambientColor;
float3 lightDirection;
float padding;
float specularPower;
float4 specularColor;
};
cbuffer SunLightColorBuffer
{
float4 sunColor;
};
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 sunPos : TEXCOORD1;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
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));
// Determine the diffuse color amount of each of the four lights.
colorArray = sunColor * lightIntensity;
// Initialize the sum of colors.
colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f);
// Add all of the light colors up.
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.
color = saturate(colorSum) * textureColor;
return color;
}