source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreGames/CarGame/Media/materials/programs/GameTools_DepthShadow.hlsl @ 3255

Revision 3255, 2.5 KB checked in by szirmay, 15 years ago (diff)
Line 
1///////depth map
2struct VS_OUT
3{
4        float4 hPosition        : POSITION;
5        float4 Position : TEXCOORD0;
6};
7
8VS_OUT hDepthVS(float4 position : POSITION,     
9                uniform float4x4 worldView,
10                uniform float4x4 worldViewProj)
11{
12 
13  VS_OUT OUT;
14  OUT.hPosition = mul(worldViewProj, position);
15  OUT.Position = mul(worldView, position);
16  OUT.Position.z *= -1.0;
17  return OUT;
18}
19
20
21
22float4 DepthPS(VS_OUT IN ):COLOR
23{
24        float dist = length(IN.Position.xyz);
25        return float4(dist, dist, dist, 1);     
26}
27
28///////////////Shadow
29
30struct VS_OUT_SHADOW
31{
32        float4 hPosition        : POSITION;
33        float4 Position         : TEXCOORD0;
34        float4 cPosition        : TEXCOORD1;
35};
36
37VS_OUT_SHADOW depthShadowVS(float4 position : POSITION,
38                uniform float4x4 world,
39                uniform float4x4 worldView,
40                uniform float4x4 worldViewProj)
41{
42  VS_OUT_SHADOW OUT;
43  OUT.hPosition = mul(worldViewProj, position);
44  OUT.Position = mul(world, position);
45  OUT.cPosition = mul(worldView, position);
46  return OUT;
47}
48
49
50float4 depthShadowPS(VS_OUT_SHADOW IN,
51                                        uniform float4x4 lightView,
52                                        uniform float4x4 lightViewProj,
53                                        uniform float4x4 lightView2,
54                                        uniform float4x4 lightViewProj2,
55                                        uniform sampler2D depthShadowMap : register(s0),
56                                        uniform sampler2D depthShadowMap2 : register(s1)):COLOR
57{                                       
58        float bias = 0.06;
59        float4 shadowColor = float4(0.6, 0.6, 0.6, 1.0);
60
61        float4 light1 = 1;
62        float4 light2 = 1;
63        float weight1 = 1;
64        float weight2 = 1;
65       
66        float4 lightCamPos1 = mul(lightView, IN.Position);
67        float d1 = length(lightCamPos1.xyz);   
68        float4 lightScreenPos1 = mul(lightViewProj, IN.Position);
69        lightScreenPos1 = lightScreenPos1 / lightScreenPos1.w ;
70        lightScreenPos1 = ( lightScreenPos1 + 1.0 ) / 2.0;
71        lightScreenPos1.y = 1.0 - lightScreenPos1.y;
72        float4 storedDepth1 = tex2D(depthShadowMap, lightScreenPos1.xy);
73                if(storedDepth1.r + bias < d1)
74                        light1=0;
75       
76       
77        float4 lightCamPos2 = mul(lightView2, IN.Position);
78        float d2 = length(lightCamPos2.xyz);
79       
80                       
81        float4 lightScreenPos2 = mul(lightViewProj2, IN.Position);
82        lightScreenPos2 = lightScreenPos2 / lightScreenPos2.w ;
83
84        if(abs(lightScreenPos2.x) < 0.99 && abs(lightScreenPos2.y) < 0.99 )
85        {
86                lightScreenPos2 = ( lightScreenPos2 + 1.0 ) / 2.0;
87                lightScreenPos2.y = 1.0 - lightScreenPos2.y;
88                float4 storedDepth2 = tex2D(depthShadowMap2, lightScreenPos2.xy);
89                        if(storedDepth2.r + bias < d2)
90                                light2=0;       
91        }
92        else
93                weight2 = 0;
94               
95        weight1 = 1 - weight2; 
96               
97        return saturate((light1*weight1 + light2*weight2) + shadowColor);       
98}
99
Note: See TracBrowser for help on using the repository browser.