0001:
0002:
0003:
0004:
0005:
0006:
0007:
0008:
0009:
0010: float4x4 mWVP;
0011: float4x4 mWLP;
0012: float4x4 mWLPB;
0013: float4 vCol;
0014: float4 vLightDir;
0015:
0016:
0017:
0018:
0019: texture ShadowMap;
0020: sampler ShadowMapSamp = sampler_state
0021: {
0022: Texture = <ShadowMap>;
0023: MinFilter = LINEAR;
0024: MagFilter = LINEAR;
0025: MipFilter = NONE;
0026:
0027: AddressU = Clamp;
0028: AddressV = Clamp;
0029: };
0030:
0031:
0032:
0033: struct VS_OUTPUT
0034: {
0035: float4 Pos : POSITION;
0036: float4 Diffuse : COLOR0;
0037: float4 Ambient : COLOR1;
0038: float4 ShadowMapUV : TEXCOORD0;
0039: float4 Depth : TEXCOORD1;
0040: };
0041:
0042:
0043:
0044:
0045: VS_OUTPUT VS_pass0(
0046: float4 Pos : POSITION,
0047: float3 Normal : NORMAL
0048: ){
0049: VS_OUTPUT Out = (VS_OUTPUT)0;
0050:
0051:
0052: float4 pos = mul( Pos, mWLP );
0053:
0054:
0055: Out.Pos = pos;
0056:
0057:
0058: Out.ShadowMapUV = pos.z / pos.w;
0059:
0060: return Out;
0061: }
0062:
0063:
0064:
0065: PIXELSHADER PS_pass0 =
0066: asm
0067: {
0068: ps.1.1
0069:
0070: texcoord t0
0071:
0072: mov r0, t0
0073: };
0074:
0075:
0076:
0077: VS_OUTPUT VS_pass1(
0078: float4 Pos : POSITION,
0079: float3 Normal : NORMAL
0080: ){
0081: VS_OUTPUT Out = (VS_OUTPUT)0;
0082: float4 uv;
0083:
0084:
0085: Out.Pos = mul(Pos, mWVP);
0086:
0087: Out.Diffuse = vCol * max( dot(vLightDir, Normal), 0);
0088: Out.Ambient = vCol * 0.3f;
0089:
0090:
0091: uv = mul(Pos, mWLPB);
0092: Out.ShadowMapUV = uv;
0093: uv = mul(Pos, mWLP);
0094: Out.Depth = uv.z / uv.w-0.003;
0095:
0096: return Out;
0097: }
0098:
0099:
0100:
0101: float4 PS_pass1(VS_OUTPUT In) : COLOR
0102: {
0103: float4 Color = In.Ambient;
0104: float4 zero = {0,0,0,0};
0105:
0106: float shadow_map = tex2Dproj( ShadowMapSamp, In.ShadowMapUV ).x;
0107:
0108: Color += (shadow_map < In.Depth.z) ? zero : In.Diffuse;
0109:
0110: return Color;
0111: }
0112:
0113:
0114:
0115: technique TShader
0116: {
0117: pass P0
0118: {
0119:
0120: VertexShader = compile vs_1_1 VS_pass0();
0121: PixelShader = <PS_pass0>;
0122: }
0123: pass P1
0124: {
0125:
0126: VertexShader = compile vs_1_1 VS_pass1();
0127: PixelShader = compile ps_2_0 PS_pass1();
0128:
0129: Sampler[0] = (ShadowMapSamp);
0130: }
0131: }
0132: