Changeset 2944 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 09/15/08 00:07:01 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2943 r2944 13 13 }; 14 14 15 #define NUM_SAMPLES 16 16 17 18 float2 myreflect(float2 pt, float2 n) 19 { 20 // distance to plane 21 float d = dot(n, pt); 22 // reflect around plane 23 float2 rpt = pt - d * 2.0f * n; 24 25 return rpt; 26 } 15 27 16 28 … … 73 85 } 74 86 87 88 float CalcShadowTerm(fragment IN, 89 uniform sampler2D shadowMap, 90 uniform float w, 91 uniform float2 lightSpacePos, 92 float depth, 93 uniform float2 samples[NUM_SAMPLES], 94 uniform sampler2D noiseTexture 95 ) 96 { 97 float s; 98 99 float total_d = 0.0; 100 //float total_d = tex2D(shadowMap, lightSpacePos).x; 101 102 for (int i = 0; i < NUM_SAMPLES; ++ i) 103 { 104 const float2 offset = samples[i]; 105 106 #if 1 107 //////////////////// 108 //-- add random noise: reflect around random normal vector (warning: slow!) 109 110 float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy; 111 const float2 offsetTransformed = myreflect(offset, mynoise); 112 #else 113 const float2 offsetTransformed = offset; 114 #endif 115 // weight with projected coordinate to reach similar kernel size for near and far 116 float2 texcoord = lightSpacePos + offsetTransformed * w; 117 118 float shadowDepth = tex2D(shadowMap, texcoord).x; 119 120 total_d += step(shadowDepth, depth); 121 //total_d += length(offsetTransformed); 122 } 123 124 total_d /= (float)NUM_SAMPLES; 125 126 return total_d; 127 } 128 129 130 #if 0 75 131 /** The mrt shader for standard rendering 76 132 */ … … 114 170 115 171 shadowDepth[1] = tex2D(shadowMap, lightSpacePos.xy + float2( w, w)).x; 116 shadowDepth[2] = tex2D(shadowMap, lightSpacePos.xy -float2( w, -w)).x;117 shadowDepth[3] = tex2D(shadowMap, lightSpacePos.xy -float2(-w, -w)).x;118 shadowDepth[4] = tex2D(shadowMap, lightSpacePos.xy -float2(-w, w)).x;119 120 shadowDepth[5] = tex2D(shadowMap, lightSpacePos.xy -float2( w, 0)).x;121 shadowDepth[6] = tex2D(shadowMap, lightSpacePos.xy -float2( 0, w)).x;122 shadowDepth[7] = tex2D(shadowMap, lightSpacePos.xy -float2(-w, 0)).x;123 shadowDepth[8] = tex2D(shadowMap, lightSpacePos.xy -float2( 0, -w)).x;172 shadowDepth[2] = tex2D(shadowMap, lightSpacePos.xy + float2( w, -w)).x; 173 shadowDepth[3] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, -w)).x; 174 shadowDepth[4] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, w)).x; 175 176 shadowDepth[5] = tex2D(shadowMap, lightSpacePos.xy + float2( w, 0)).x; 177 shadowDepth[6] = tex2D(shadowMap, lightSpacePos.xy + float2( 0, w)).x; 178 shadowDepth[7] = tex2D(shadowMap, lightSpacePos.xy + float2(-w, 0)).x; 179 shadowDepth[8] = tex2D(shadowMap, lightSpacePos.xy + float2( 0, -w)).x; 124 180 125 181 … … 156 212 return OUT; 157 213 } 158 159 160 /** The mrt shader for standard rendering 161 */ 162 pixel main_shadow_debug(fragment IN, 163 uniform sampler2D shadowMap, 164 uniform sampler2D colorTex, 165 uniform float4x4 shadowMatrix) 214 #else 215 216 pixel main_shadow(fragment IN, 217 uniform sampler2D colors, 218 uniform sampler2D positions, 219 uniform sampler2D normals, 220 uniform sampler2D shadowMap, 221 uniform float4x4 shadowMatrix, 222 uniform float maxDepth, 223 uniform float sampleWidth, 224 uniform sampler2D noiseTexture, 225 uniform float2 samples[NUM_SAMPLES] 226 ) 166 227 { 167 228 pixel OUT; 168 #if 0 169 // visualize depth 170 OUT.color = tex2Dlod(colorTex, float4(IN.texCoord.xy, 0, 0)); 171 #else 172 float4 col; 173 col = tex2Dlod(shadowMap, float4(IN.texCoord.xy, 0, 0)); 174 OUT.color = float4(col.z / col.w, 0, 0, 1); 229 230 float4 norm = tex2D(normals, IN.texCoord.xy); 231 float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 232 float4 position = tex2D(positions, IN.texCoord.xy); 233 234 235 // an ambient color term 236 float amb = norm.w; 237 238 float3 normal = normalize(norm.xyz); 239 float4 col = shade(IN, color, position, normal, amb); 240 241 position *= maxDepth; 242 position.w = 1.0f; 243 244 float4 lightSpacePos = mul(shadowMatrix, position); 245 lightSpacePos /= lightSpacePos.w; 246 247 OUT.color = col; 248 249 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture); 250 251 if (amb < 0.9f) // hack: prevent shadowing the sky 252 { 253 // base lighting 254 const float baseLighting = 0.3f; 255 OUT.color *= baseLighting + (1.0f - baseLighting) * (1.0f - shadowTerm); 256 } 257 258 // also write out depth component 259 OUT.color.w = color.w; 260 261 return OUT; 262 } 263 175 264 #endif 176 return OUT;177 }
Note: See TracChangeset
for help on using the changeset viewer.