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

Revision 1629, 2.4 KB checked in by szirmay, 18 years ago (diff)
RevLine 
[777]1///////depth map
2struct VS_OUT
3{
4        float4 hPosition        : POSITION;
[1118]5        float4 Position         : TEXCOORD0;   
[777]6};
7
[1118]8VS_OUT DepthVS(float4 position : POSITION,     
[1131]9                                uniform float4x4 worldViewProj)
[777]10{
11 
12  VS_OUT OUT;
[1118]13 
[777]14  OUT.hPosition = mul(worldViewProj, position);
[1131]15  OUT.Position = mul(worldViewProj, position);
[1118]16 
[777]17  return OUT;
18}
19
[1118]20//for directional light
[777]21float4 DepthPS(VS_OUT IN ):COLOR
22{
[1629]23//return 1;
[1118]24        float4 pos = (IN.Position / IN.Position.w);
[1629]25        //pos = (pos +1.0 ) / 2.0;
[1131]26        return float4(pos.z, pos.z * pos.z, 1, 1);     
[777]27}
28
29///////////////Shadow
30
31struct VS_OUT_SHADOW
32{
33        float4 hPosition        : POSITION;
34        float4 Position         : TEXCOORD0;
[1118]35        float4 lPosition        : TEXCOORD1;
[777]36};
37
38VS_OUT_SHADOW depthShadowVS(float4 position : POSITION,
[1118]39                                                        uniform float4x4 worldViewProj,
[1131]40                                                        uniform float4x4 world,
[1118]41                                                        uniform float4x4 lightViewProj)
[777]42{
43  VS_OUT_SHADOW OUT;
44  OUT.hPosition = mul(worldViewProj, position);
[1131]45  float4 wPos = mul(world, position);
46  OUT.lPosition = mul(lightViewProj, wPos); 
[1118]47  OUT.Position = position; 
[777]48  return OUT;
49}
50
[1629]51/*
[777]52float4 depthShadowPS(VS_OUT_SHADOW IN,
53                                        uniform float4x4 lightViewProj,
[1118]54                                        uniform sampler2D depthShadowMap : register(s0)
55                                        ):COLOR
56{       
[1629]57        float bias = 0.0001;
[1118]58        float4 light = float4(1,1,1,1);
[1629]59        float4 shadow = float4(0.6,0.6,0.6,1);
[777]60       
[1118]61        float4 pos = (IN.lPosition / IN.lPosition.w);
[1131]62        pos.xy = (pos.xy +1.0 ) / 2.0;
[1118]63        pos.y = 1.0 - pos.y;
64        float4 storedDepth = tex2D(depthShadowMap, pos.xy);
[1131]65       
[1629]66        if(storedDepth.r + bias < pos.z)
[1131]67        {
68                float M1 = storedDepth.r;
69                float M2 = storedDepth.g;
70                float v2 = M2 - M1 * M1;
71                float pmax = v2 / (v2 + pow(M1 - pos.z, 2));
72                light = shadow + (1 - shadow) * pmax;
73               
74                //light = shadow;
75        }
[1118]76        //return abs( pos.z - storedDepth.z ); 
77        return light;   
[777]78}
[1629]79*/
[777]80
[1629]81
82float4 depthShadowPS(VS_OUT_SHADOW IN,
83                                        uniform float4x4 lightViewProj,
84                                        uniform sampler2D depthShadowMap : register(s0)
85                                        ):COLOR
86{       
87        float bias = 0.0001;
88        float4 light = float4(1,1,1,1);
89        float4 shadow = float4(0.65,0.65,0.65,1);
90        //float4 shadow = float4(0,0,0,1);
91       
92        if(IN.lPosition.z > 0.0)
93        {
94                float4 pos = (IN.lPosition / IN.lPosition.w);
95                pos.xy = (pos.xy + 1.0) / 2.0;
96       
97       
98                pos.y = 1.0 - pos.y;
99                float4 storedDepth = tex2D(depthShadowMap, pos.xy);
100       
101                if(storedDepth.r + bias < pos.z)
102                {               
103                        light = shadow;
104                }
105                //if(length(pos.xy)>1)
106                //              light = shadow;
107        }
108       
109       
110        return light;   
111}
Note: See TracBrowser for help on using the repository browser.