난반사광을 단계적으로 감소시켜 표현한다.
Vertex Shader
struct VS_INPUT
{
float4 mPosition : POSITION;
float3 mNormal : NORMAL;
};
struct VS_OUTPUT
{
float4 mPosition : POSITION;
float3 mDiffuse : TEXCOORD1;
};
float4x4 gWorldViewProjectionMatrix;
float4x4 gInvWorldMatrix;
float4 gWorldLightPosition;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.mPosition = mul(Input.mPosition, gWorldViewProjectionMatrix);
float3 objectLightPosition = mul(gWorldLightPosition, gInvWorldMatrix);
float3 lightDir = normalize(Input.mPosition.xyz - objectLightPosition);
Output.mDiffuse = dot(-lightDir, normalize(Input.mNormal));
return (Output);
}
Pixel Shader
float3 gSurfaceColor;
struct PS_INPUT
{
float3 mDiffuse : TEXCOORD1;
};
float4 ps_main(PS_INPUT Input) : COLOR
{
float3 diffuse = saturate(Input.mDiffuse);
diffuse = ceil(diffuse * 5)/5.0f;
return float4(gSurfaceColor * diffuse.xyz, 1);
}