Changeset 3192 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 11/27/08 19:14:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3191 r3192 117 117 float len; 118 118 119 const float convergenceThresh = 200.0f; 120 119 121 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 120 122 { … … 126 128 // check spatial discontinuity 127 129 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 128 len = min(SqrLen(centerPos - samplePos), 1e 2f);130 len = min(SqrLen(centerPos - samplePos), 1e3f); 129 131 130 132 spatialFactor = 1.0f / max(len, 1e-3f); 131 133 132 normalFactor = max(step(.0 f, dot(sampleNorm, centerNormal)), 1e-3f);134 normalFactor = max(step(.01f, dot(sampleNorm, centerNormal)), 1e-3f); 133 135 //normalFactor = max(dot(sampleNorm, samplePos), 1e-3f); 134 convergenceFactor = min( 50.0f, aoSample.y);136 convergenceFactor = min(convergenceThresh, aoSample.y + 1); 135 137 //convergenceFactor = aoSample.y; 136 138 137 139 // combine the weights 138 140 w = convergenceFactor * spatialFactor * normalFactor; 139 //w = convergenceFactor * spatialFactor;141 //w = spatialFactor * normalFactor; 140 142 141 143 average += aoSample.x * w; … … 171 173 172 174 // filter up to a certain convergance value and leave out background (sky) by checking depth 173 if ((ao.y < 100.0f) && (col.w < 1e10f))175 if ((ao.y < 500.0f) && (col.w < 1e10f)) 174 176 //if (col.w < 1e10f) 175 177 { … … 178 180 const float distanceScale = 1.0f; 179 181 180 const float convergence = ao.y; 181 const float adaptWeight = 25.0f; 182 const float convergence = ao.y + 1; 182 183 const float convergenceScale = SSAO_CONVERGENCE_WEIGHT / (convergence + SSAO_CONVERGENCE_WEIGHT); 183 184 … … 188 189 } 189 190 190 OUT.illum_col.xyz = col.xyz * ao.x; 191 if (col.w < 1e10f) 192 OUT.illum_col.xyz = col.xyz * ao.x; 193 else 194 OUT.illum_col.xyz = col.xyz; 195 191 196 //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 192 197 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3190 r3192 337 337 338 338 // do reprojection and filter out the pixels that are not save 339 float pValid = PixelValid( 340 oldTex, 341 color, 342 difVec.xyz, 343 IN.texCoord, 344 viewDir, 345 oldEyePos, 346 modelViewProj, 347 oldModelViewProj, 348 oldbl, oldbr, oldtl, oldtr 349 ); 339 float pValid = PixelValid(oldTex, 340 color, 341 difVec.xyz, 342 IN.texCoord, 343 viewDir, 344 oldEyePos, 345 modelViewProj, 346 oldModelViewProj, 347 oldbl, oldbr, oldtl, oldtr 348 ); 350 349 351 350 pix.color = color; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3175 r3192 79 79 sampler2D oldTex, 80 80 float4x4 oldModelViewProj, 81 float temporalCoherence,82 81 sampler2D colors, 83 82 float3 projPos, … … 87 86 float3 oldtl, 88 87 float3 oldtr, 89 float3 diffVec, 90 float pixelValid 88 float3 diffVec 91 89 ) 92 90 { … … 131 129 #endif 132 130 133 const float squaredLen = SqrLen(diffVec);134 135 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);136 //const float oldWeight = oldPixel.y;137 138 131 float newWeight; 139 132 140 if ( (temporalCoherence > 1e-6f)133 if (1 141 134 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 142 135 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 143 136 && (depthDif <= MIN_DEPTH_DIFF) 144 // if visibility changed in the surrounding area we have to recompute145 //&& (oldNumSamples > 0.8f * newNumSamples)146 //&& (pixelValid < 1.0f)147 137 ) 148 138 { 149 139 // increase the weight for convergence 150 newWeight = oldWeight + 1.0f; 151 152 if ((pixelValid > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 153 { 154 newWeight = 4.0f; 155 //newWeight = 1.0f; 156 } 140 newWeight = oldPixel.y; 157 141 } 158 142 else 159 143 { 160 newWeight = 1.0f;144 newWeight = 0.0f; 161 145 } 162 146 … … 245 229 #endif 246 230 // check if the samples have been valid in the last frame 247 numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 231 //numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 232 numSamples += 1.0f - sampleColor.x; 248 233 } 249 234 … … 256 241 pixel-to-sample direction and sample normal as weight. 257 242 */ 258 float 2ssao(fragment IN,243 float3 ssao(fragment IN, 259 244 sampler2D colors, 260 245 sampler2D noiseTex, … … 267 252 float3 tl, 268 253 float3 tr, 269 float3 viewDir 254 float3 viewDir, 255 float newWeight 270 256 ) 271 257 { … … 275 261 276 262 float total_ao = .0f; 263 float validSamples = .0f; 277 264 float numSamples = .0f; 278 265 … … 325 312 326 313 // check if the samples have been valid in the last frame 327 numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 328 } 329 330 return float2(max(0.0f, 1.0f - total_ao), numSamples); 314 validSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 315 //validSamples += sampleColor.x; 316 317 ++ numSamples; 318 if ((validSamples < 1.0f) && (newWeight > 20) && (numSamples >= 8)) break; 319 } 320 321 total_ao /= numSamples; 322 323 return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 331 324 } 332 325 … … 378 371 379 372 380 float2 ao;381 382 // note: this should be done with the stencil buffer383 if (eyeSpaceDepth < 1e10f)384 {385 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir));386 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);387 }388 else389 {390 ao = float2(1.0f, 0);391 }392 393 394 373 ///////////////// 395 374 //-- compute temporal reprojection 396 375 397 376 float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 398 oldTex, oldModelViewProj, temporalCoherence,377 oldTex, oldModelViewProj, 399 378 colors, 400 379 projPos.xyz, 401 380 invw, 402 381 oldbl, oldbr, oldtl, oldtr, 403 diffVec, 404 ao.y 382 diffVec 405 383 ); 406 384 407 385 const float oldSsao = temporalVals.x; 408 const float newWeight = temporalVals.y; 409 410 411 OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 412 OUT.illum_col.y = newWeight; 413 OUT.illum_col.z = SqrLen(diffVec);//invw; 386 float oldWeight = temporalVals.y; 387 388 float3 ao; 389 390 // cull background note: this should be done with the stencil buffer 391 if (eyeSpaceDepth < 1e10f) 392 { 393 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight); 394 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 395 } 396 else 397 { 398 ao = float3(1.0f, .0f, .0f); 399 } 400 401 const float squaredLen = SqrLen(diffVec); 402 403 if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 404 { 405 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 406 } 407 408 const float newWeight = ao.z; 409 410 // blend between old and new samples (and avoid division by zero) 411 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 412 OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 413 OUT.illum_col.z = SqrLen(diffVec); 414 414 OUT.illum_col.w = eyeSpaceDepth; 415 415
Note: See TracChangeset
for help on using the changeset viewer.