- Timestamp:
- 09/15/08 01:43:13 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2944 r2945 35 35 uniform float amb) 36 36 { 37 float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 38 //float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f); 37 const float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 38 const float3 light = normalize(lightDir.xyz); 39 const float diffuseLight = saturate(dot(normal, light)); 40 41 /* 39 42 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 43 float3 light2 = normalize(lightDir2.xyz); 44 float diffuseLight2 = saturate(dot(normal, light2)); 45 */ 46 float diffuse = diffuseLight;// + diffuseLight2; 40 47 41 48 // global ambient 42 49 const float4 ambient = 0.25f; 43 44 // float3 L = normalize(lightPosition - position); 45 float3 light = normalize(lightDir.xyz); 46 float3 light2 = normalize(lightDir2.xyz); 47 48 float diffuseLight = saturate(dot(normal, light)); 49 float diffuseLight2 = saturate(dot(normal, light2)); 50 51 float diffuse = diffuseLight + diffuseLight2; 50 //const float4 ambient = 0.0f; 52 51 53 52 return (ambient + diffuse) * color * (1.0f - amb) + amb * color; … … 73 72 float amb = norm.w; 74 73 75 // expand normal 76 float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f)); 74 float3 normal = normalize(norm.xyz); 77 75 78 76 float4 col = shade(IN, color, position, normal, amb); … … 95 93 ) 96 94 { 97 float s;98 99 95 float total_d = 0.0; 100 //float total_d = tex2D(shadowMap, lightSpacePos).x;101 96 102 97 for (int i = 0; i < NUM_SAMPLES; ++ i) … … 118 113 float shadowDepth = tex2D(shadowMap, texcoord).x; 119 114 120 total_d += step(shadowDepth, depth); 121 //total_d += length(offsetTransformed); 115 total_d += step(depth, shadowDepth); 122 116 } 123 117 … … 199 193 200 194 /* 201 195 // hard shadows 202 196 float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x; 203 197 … … 212 206 return OUT; 213 207 } 208 214 209 #else 210 215 211 216 212 pixel main_shadow(fragment IN, … … 231 227 float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 232 228 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 229 230 const float3 normal = normalize(norm.xyz); 231 const float3 lightDir = normalize(float3(0.8f, -1.0f, 0.7f)); 232 233 // hack: an emmisive color term 234 float emmisive = norm.w; 235 236 // diffuse intensity 237 const float angle = saturate(dot(normal, lightDir)); 238 float diffuse = angle; 239 240 // calc diffuse illumination + shadow term 241 if ((emmisive < 0.95f) // hack: prevent shadowing the sky 242 && (angle > 1e-3f) 243 ) 244 { 245 position *= maxDepth; 246 position.w = 1.0f; 247 248 float4 lightSpacePos = mul(shadowMatrix, position); 249 lightSpacePos /= lightSpacePos.w; 250 251 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture); 252 253 diffuse *= shadowTerm; 254 } 255 256 // global ambient 257 const float4 ambient = 0.25f; 258 259 // base lighting 260 OUT.color = (ambient + diffuse) * color * (1.0f - emmisive) + emmisive * color; 261 258 262 // also write out depth component 259 263 OUT.color.w = color.w;
Note: See TracChangeset
for help on using the changeset viewer.