//------------------------------------------------------------------- // GLOBAL VARIABLES float4x4 WorldViewProj : WorldViewProj; float3 LightVector; //in object space; must be normalized float Ambient; texture TextureMap; sampler TextureMapSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; //------------------------------------------------------------------- // I/O STRUCTURES struct VS_INPUT { float4 Position : POSITION; //in object space float3 Normal : NORMAL; //in object space float2 TexCoord : TEXCOORD0; }; struct VS_OUTPUT_DIFFUSE { float4 Position : POSITION; //in projection space float2 TexCoord0 : TEXCOORD0; float3 Normal : TEXCOORD2; //in tangent space float3 LightVector : TEXCOORD3; //in tangent space }; //------------------------------------------------------------------- // VERTEX SHADERS VS_OUTPUT_DIFFUSE Simple_VS(VS_INPUT IN) { VS_OUTPUT_DIFFUSE OUT; // pass texture coordinates for fetching the diffuse map OUT.TexCoord0 = IN.TexCoord.xy; // transform position to projection space OUT.Position = mul(IN.Position, WorldViewProj); OUT.LightVector = float3(-0.707,0.707,0.0); OUT.Normal = IN.Normal; return OUT; } float4 Simple_PS(VS_OUTPUT_DIFFUSE IN) : COLOR { //fetch base color float4 color = tex2D(TextureMapSampler, IN.TexCoord0.xy); //compute self-shadowing term float shadow = saturate(4 * dot(IN.Normal.xyz , IN.LightVector.xyz )); //compute final color return color* shadow; } Technique Simple { Pass P0 { VertexShader = compile vs_1_1 Simple_VS(); PixelShader = compile ps_1_1 Simple_PS(); AlphaBlendEnable = False; } }