source: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl @ 1102

Revision 1102, 1.8 KB checked in by szirmay, 18 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        //return 1;     
27}
28
29///////////////Shadow
30
31struct VS_OUT_SHADOW
32{
33        float4 hPosition        : POSITION;
34        float4 Position         : TEXCOORD0;
35        float4 cPosition        : TEXCOORD1;
36};
37
38VS_OUT_SHADOW depthShadowVS(float4 position : POSITION,
39                uniform float4x4 world,
40                uniform float4x4 worldView,
41                uniform float4x4 worldViewProj)
42{
43  VS_OUT_SHADOW OUT;
44  OUT.hPosition = mul(worldViewProj, position);
45  OUT.Position = mul(world, position);
46  OUT.cPosition = mul(worldView, position);
47  return OUT;
48}
49
50
51float4 depthShadowPS(VS_OUT_SHADOW IN,
52                                        uniform float4x4 lightView,
53                                        uniform float4x4 lightViewProj,
54                                        uniform float4x4 lightView2,
55                                        uniform float4x4 lightViewProj2,
56                                        uniform sampler2D depthShadowMap : register(s0),
57                                        uniform sampler2D depthShadowMap2 : register(s1)):COLOR
58{                                       
59        float bias = 0.06;
60        float4 shadowColor = float4(0.6, 0.6, 0.6, 1.0);
61
62        float4 light1 = float4(1,1,1,1);
63       
64        float4 lightCamPos1 = mul(lightView, IN.Position);
65        float d1 = length(lightCamPos1.xyz);   
66        float4 lightScreenPos1 = mul(lightViewProj, IN.Position);
67        lightScreenPos1 = lightScreenPos1 / lightScreenPos1.w ;
68        lightScreenPos1 = ( lightScreenPos1 + 1.0 ) / 2.0;
69        lightScreenPos1.y = 1.0 - lightScreenPos1.y;
70        float4 storedDepth1 = tex2D(depthShadowMap, lightScreenPos1.xy);
71                if(storedDepth1.r + bias < d1)
72                        light1 = shadowColor;   
73       
74       
75        return light1; 
76}
77
Note: See TracBrowser for help on using the repository browser.