rendered paste body// Camera settings.
float4x4 World;
float4x4 View;
float4x4 Projection;
// The light direction is shared between the Lambert and Toon lighting techniques.
float3 LightDirection = normalize(float3(1, 0.4, 0.8));
float3 WorldNormal = normalize(float3(0, 0, 1));
// Settings controlling the Lambert lighting technique.
float3 DiffuseLight = 0.5;
float3 AmbientLight = 0.7;
// Is texturing enabled?
bool TextureEnabled;
// The main texture applied to the object, and a sampler for reading it.
texture Texture;
sampler Sampler = sampler_state
{
Texture = (Texture);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
struct LightingVertexShaderInput
{
float4 Position : POSITION0;
float3 Normal : NORMAL0;
float2 TextureCoordinate : TEXCOORD0;
};
struct LightingVertexShaderOutput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
float LightAmount : TEXCOORD1;
};
struct LightingPixelShaderInput
{
float2 TextureCoordinate : TEXCOORD0;
float LightAmount : TEXCOORD1;
};
LightingVertexShaderOutput LightingVertexShader(LightingVertexShaderInput input)
{
LightingVertexShaderOutput output;
// Apply camera matrices to the input position.
output.Position = mul(mul(mul(input.Position, World), View), Projection);
output.TextureCoordinate = input.TextureCoordinate;
output.LightAmount = dot(input.Normal, WorldNormal);
return output;
}
float4 LightingPixelShader(LightingPixelShaderInput input) : COLOR0
{
float4 color = TextureEnabled ? tex2D(Sampler, input.TextureCoordinate) : 0;
color.rgb *= saturate(input.LightAmount) * DiffuseLight + AmbientLight;
return color;
}
technique Lighting
{
pass P0
{
VertexShader = compile vs_2_0 LightingVertexShader();
PixelShader = compile ps_2_0 LightingPixelShader();
}
}