- Timestamp:
- 03/01/07 18:04:37 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl
r2024 r2179 15 15 #define DEPTH_BIAS_VSM 0.001 16 16 #define DEPTH_EPSILON 0.001 17 #define DIST_BIAS 0. 00117 #define DIST_BIAS 0.1 18 18 #define DIST_BIAS_VSM 0.001 19 19 #define DIST_EPSILON 0.001 20 20 21 const float4 shadowColor = float4(0.85,0.85,0.85,1); 21 #define shadowColor float4(0.85,0.85,0.85,1) 22 22 23 23 float4 shadowMapDepth(LightVPos_OUT IN, … … 25 25 { 26 26 float4 light = shadowColor; 27 float4 pos = (IN.LightVPos / IN.LightVPos.w); 28 if( pos.z > 0.0) 27 if( IN.LightVPos.z > 0.0) 29 28 { 30 pos.xy = (pos.xy + 1.0) / 2.0; 29 float4 pos = (IN.LightVPos / IN.LightVPos.w); 30 pos.xy = (pos.xy + 1.0) / 2.0; 31 31 pos.y = 1.0 - pos.y; 32 32 float storedDepth = tex2D(shadowMap, pos.xy).r; 33 34 if(pos.z - DEPTH_BIAS <= storedDepth.r) 35 light = 1; 33 pos.z -= DIST_BIAS; 34 light = max(pos.z <= storedDepth.r, shadowColor); 36 35 } 37 38 36 return light; 39 37 } … … 74 72 } 75 73 76 float4 shadowMapDist(LightCPos_OUT IN, 77 uniform sampler2D shadowMap) : COLOR 74 float4 shadowMapDist(LightCPos_OUT IN, 75 //uniform float lightFarPlane, 76 uniform sampler2D shadowMap) : COLOR 78 77 { 79 float4 light = shadowColor; 80 float4 pos = (IN.LightVPos / IN.LightVPos.w); 78 float4 light = shadowColor; 81 79 82 if( pos.z > 0.0)80 if( IN.LightVPos.z > 0.0) 83 81 { 84 //float d = length(pos.xy); 82 float4 pos = (IN.LightVPos / IN.LightVPos.w); 83 //float d = length(pos.xy); 85 84 //light = saturate((1.0 - d)/0.05); 86 85 //if(d <= 1.0) 87 { 88 float dist = length(IN.LightCPos.xyz); 89 pos.xy = (pos.xy + 1.0) / 2.0; 90 pos.y = 1.0 - pos.y; 91 float storedDist = tex2D(shadowMap, pos.xy).r; 92 dist -= DIST_BIAS; 93 94 if(dist <= storedDist); 95 light = 1; 96 } 97 } 98 86 //{ 87 float dist = length(IN.LightCPos.xyz) ; 88 pos.xy = (pos.xy + 1.0) / 2.0; 89 pos.y = 1.0 - pos.y; 90 float4 storedDist = tex2D(shadowMap, pos.xy); 91 dist -= DIST_BIAS; 92 light = max(dist <= storedDist.r, shadowColor); 93 //} 94 } 95 99 96 return light; 100 97 } … … 105 102 { 106 103 float4 light = float4(1,1,1,1); 107 108 float4 pos = (IN.LightVPos / IN.LightVPos.w);109 104 110 if( pos.z > 0.0)105 if( IN.LightVPos.z > 0.0) 111 106 { 112 //float d = length(pos.xy); 113 //light = saturate((1.0 - d)/0.05); 114 //if(d <= 1.0) 107 float4 pos = (IN.LightVPos / IN.LightVPos.w); 108 float d = length(pos.xy); 109 light = saturate((1.0 - d)/0.05); 110 if(d <= 1.0) 115 111 { 116 float dist = length(IN.LightCPos.xyz) / lightFarPlane;117 pos.xy = (pos.xy + 1.0) / 2.0;118 pos.y = 1.0 - pos.y;119 float4 storedDist = tex2D(shadowMap, pos.xy);120 dist -= DIST_BIAS_VSM;121 float lit_factor = light * (dist <= storedDist.r);112 float dist = length(IN.LightCPos.xyz) / lightFarPlane; 113 pos.xy = (pos.xy + 1.0) / 2.0; 114 pos.y = 1.0 - pos.y; 115 float4 storedDist = tex2D(shadowMap, pos.xy); 116 dist -= DIST_BIAS_VSM; 117 float lit_factor = light * (dist <= storedDist.r); 122 118 123 float M1 = storedDist.r;124 float M2 = storedDist.g;125 float v2 = min(max(M2 - M1 * M1, 0.0) + DIST_EPSILON, 1.0);126 float m_d = M1 - dist;119 float M1 = storedDist.r; 120 float M2 = storedDist.g; 121 float v2 = min(max(M2 - M1 * M1, 0.0) + DIST_EPSILON, 1.0); 122 float m_d = M1 - dist; 127 123 float pmax = v2 / (v2 + m_d * m_d); 128 124 129 125 // Adjust the light color based on the shadow attenuation 130 light = max(lit_factor, pmax); 131 132 } 126 light = max(lit_factor, pmax); 127 } 133 128 } 134 129 else
Note: See TracChangeset
for help on using the changeset viewer.