Oh, I am extremely sorry. Here is the edited version
Code:
void VertSceneAmbient( float4 vPos : POSITION,
float2 vTex0 : TEXCOORD0,
out float4 oPos : POSITION,
out float2 oTex0 : TEXCOORD0 )
{
// Transform the position from object space to homogeneous projection space
oPos = mul( vPos, g_mWorldViewProjection );
// Just copy the texture coordinate through
oTex0 = vTex0;
}
float4 PixSceneAmbient( float2 Tex0 : TEXCOORD0 ) : COLOR0
{
// Lookup mesh texture and modulate it with material and ambient amount
return g_vAmbient * tex2D( g_samScene, Tex0 ) * g_vMatColor;
}
void VertScene( float4 vPos : POSITION,
float3 vNormal : NORMAL,
float2 vTex0 : TEXCOORD0,
out float4 oPos : POSITION,
out float4 ViewPos : TEXCOORD0,
out float3 ViewNormal : TEXCOORD1,
out float2 oTex0 : TEXCOORD2,
out float4 oDiffuse : TEXCOORD3 )
{
// Transform the position from view space to homogeneous projection space
oPos = mul( vPos, g_mWorldViewProjection );
// Compute view space position
ViewPos = mul( vPos, g_mWorldView );
// Compute world space normal
ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
// Modulate material with light to obtain diffuse
oDiffuse = g_vMatColor * g_vLightColor;
// Just copy the texture coordinate through
oTex0 = vTex0;
}
float4 PixScene( float4 ViewPos : TEXCOORD0,
float3 ViewNormal : TEXCOORD1,
float2 Tex0 : TEXCOORD2,
float4 Diffuse : TEXCOORD3 ) : COLOR0
{
// Pixel to light vector
float3 L = g_vLightView - ViewPos;
float LenSq = dot( L, L );
L = normalize( L );
// Compute lighting amount
float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse *
(LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq;
// Lookup mesh texture and modulate it with diffuse
// return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I;
float4 returnColor = tex2D( g_samScene, Tex0 );
returnColor.rgb *= I;
return returnColor;
}
technique RenderScene
{
pass P0
{
VertexShader = compile vs_2_0 VertScene();
PixelShader = compile ps_2_0 PixScene();
ZEnable = true;
ZFunc = LessEqual;
StencilEnable = true;
AlphaBlendEnable = true;
BlendOp = Add;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
StencilRef = 1;
StencilFunc = Greater;
StencilPass = Keep;
}
}