Changeset 3120 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 11/12/08 01:47:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3109 r3120 36 36 37 37 38 float Filter(float2 texCoord, 39 uniform sampler2D ssaoTex, 40 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 41 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 42 float scale) 43 { 44 float average = .0f; 45 float w = .0f; 46 47 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 48 { 49 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 50 w += filterWeights[i]; 51 } 52 53 average *= 1.0f / (float)w; 54 55 return average; 56 } 57 58 38 59 float BilateralFilter(float2 texCoord, 39 60 float4 ao, … … 41 62 uniform sampler2D normalsTex, 42 63 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 43 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 64 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 65 float scale) 44 66 { 45 67 float average = .0f; 46 68 float total_w = .0f; 47 69 48 //const float eyeSpaceDepth = ao.w;70 const float eyeSpaceDepth = ao.w; 49 71 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 50 72 … … 52 74 float3 sampleNorm; 53 75 float w; 76 float4 offs; 77 float depthFactor; 54 78 55 79 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 56 80 { 57 float4 offs = float4(texCoord + filterOffs[i], 0, 0);81 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 58 82 aoSample = tex2Dlod(ssaoTex, offs); 59 //aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]); 60 //float sampleEyeSpaceDepth = aoSample.w; 61 //factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth; 83 62 84 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 85 depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 63 86 //sampleNorm = tex2Dlod(normalsTex, offs).xyz; 64 87 65 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) ;88 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) * depthFactor; 66 89 67 average += w * aoSample.x;90 average += aoSample.x * w; 68 91 total_w += w; 69 92 } 70 93 71 average *= 1.0f / max(total_w, 1e- 5f);94 average *= 1.0f / max(total_w, 1e-6f); 72 95 73 96 return average; … … 88 111 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 89 112 90 //if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 91 //if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights); 113 if ((ao.y < 60.0f) && (col.w < 1e10f)) 114 { 115 const static float scaleFactor = 10.0f; 92 116 93 //OUT.illum_col = col * ao.x; 94 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 95 OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 117 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 118 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 119 ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 120 //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 121 } 122 123 OUT.illum_col = col * ao.x; 124 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 96 125 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 97 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);98 126 OUT.illum_col.w = col.w; 99 127 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3119 r3120 189 189 //float overallDepth = 0; 190 190 const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 191 191 #if 1 192 192 if (squaredLen < 1e-8f) // object not dynamic 193 193 { … … 210 210 } 211 211 } 212 212 #endif 213 213 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 214 214 float newWeight; … … 220 220 // if visibility changed in the surrounding area we have to recompute 221 221 //&& (oldNumSamples > 0.8f * newNumSamples) 222 && (notValid < 1.0f)222 //&& (notValid < 1.0f) 223 223 ) 224 224 { … … 226 226 newWeight = oldWeight + 1.0f; 227 227 illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight; 228 //if (notValid > 1.0f) newWeight = 2.0f;228 if (notValid > 1.0f) newWeight = 2.0f; 229 229 } 230 230 else … … 292 292 293 293 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 294 294 295 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 295 296 … … 378 379 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 379 380 381 380 382 ///////////////// 381 383 //-- compute temporal reprojection … … 393 395 diffVec); 394 396 395 //OUT.illum_col.xyz = id;396 //OUT.illum_col.xyz = normal * 0.5f + 0.5f;397 397 return OUT; 398 398 } 399 400 401 float Filter(float2 texCoord,402 uniform sampler2D ssaoTex,403 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],404 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],405 float scale)406 {407 float average = .0f;408 float w = .0f;409 410 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)411 {412 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x;413 w += filterWeights[i];414 }415 416 average *= 1.0f / (float)w;417 418 return average;419 }420 421 422 pixel combine(fragment IN,423 uniform sampler2D colorsTex,424 uniform sampler2D ssaoTex,425 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],426 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]427 )428 {429 pixel OUT;430 431 const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));432 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));433 434 //if ((ao.y < 10.0f) && (col.w < 1e10f))435 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);436 437 OUT.illum_col = col * ao.x;438 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);439 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);440 //OUT.illum_col = float4(ao.x, 0, 0, col.w);441 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);442 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);443 OUT.illum_col.w = col.w;444 445 return OUT;446 }
Note: See TracChangeset
for help on using the changeset viewer.