[777] | 1 | ///////depth map
|
---|
| 2 | struct VS_OUT
|
---|
| 3 | {
|
---|
| 4 | float4 hPosition : POSITION;
|
---|
| 5 | float4 Position : TEXCOORD0;
|
---|
| 6 | };
|
---|
| 7 |
|
---|
| 8 | VS_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 |
|
---|
| 22 | float4 DepthPS(VS_OUT IN ):COLOR
|
---|
| 23 | {
|
---|
| 24 | float dist = length(IN.Position.xyz);
|
---|
[1102] | 25 | return float4(dist, dist, dist, 1);
|
---|
| 26 | //return 1;
|
---|
[777] | 27 | }
|
---|
| 28 |
|
---|
| 29 | ///////////////Shadow
|
---|
| 30 |
|
---|
| 31 | struct VS_OUT_SHADOW
|
---|
| 32 | {
|
---|
| 33 | float4 hPosition : POSITION;
|
---|
| 34 | float4 Position : TEXCOORD0;
|
---|
[1060] | 35 | float4 cPosition : TEXCOORD1;
|
---|
[777] | 36 | };
|
---|
| 37 |
|
---|
| 38 | VS_OUT_SHADOW depthShadowVS(float4 position : POSITION,
|
---|
| 39 | uniform float4x4 world,
|
---|
[1060] | 40 | uniform float4x4 worldView,
|
---|
[777] | 41 | uniform float4x4 worldViewProj)
|
---|
| 42 | {
|
---|
| 43 | VS_OUT_SHADOW OUT;
|
---|
| 44 | OUT.hPosition = mul(worldViewProj, position);
|
---|
| 45 | OUT.Position = mul(world, position);
|
---|
[1060] | 46 | OUT.cPosition = mul(worldView, position);
|
---|
[777] | 47 | return OUT;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | float4 depthShadowPS(VS_OUT_SHADOW IN,
|
---|
| 52 | uniform float4x4 lightView,
|
---|
| 53 | uniform float4x4 lightViewProj,
|
---|
[1060] | 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);
|
---|
[777] | 61 |
|
---|
[1102] | 62 | float4 light1 = float4(1,1,1,1);
|
---|
[777] | 63 |
|
---|
[1060] | 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)
|
---|
[1102] | 72 | light1 = shadowColor;
|
---|
[777] | 73 |
|
---|
| 74 |
|
---|
[1102] | 75 | return light1;
|
---|
[777] | 76 | }
|
---|
| 77 |
|
---|