- Timestamp:
- 12/07/08 23:26:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3209 r3212 108 108 const float ssao = oldPixel.x; 109 109 110 #if USE_EYESPACE_DEPTH111 112 110 // calculate eye space position of sample in old frame 113 111 const float oldEyeSpaceDepth = oldPixel.w; … … 120 118 121 119 const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 122 123 #else124 125 // calculate eye space position of sample in old frame126 const float oldDepth = oldPixel.w;127 // the depth projected into the old frame128 const float projectedDepth = projPos.z;129 // calculate depth difference130 const float depthDif = abs(projectedDepth - oldDepth);131 132 #endif133 120 134 121 const float xOffs = 1.0f / 1024.0f; … … 176 163 float3 tr, 177 164 float3 viewDir, 178 sampler2D normalTex 165 sampler2D normalTex, 166 float sampleIntensity 179 167 ) 180 168 { … … 224 212 cosAngle *= step(0.0f, dot(dirSample, normal)); 225 213 226 const float aoContrib = SAMPLE_INTENSITY/ sqrLen;214 const float aoContrib = sampleIntensity / sqrLen; 227 215 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 228 216 … … 270 258 float3 viewDir, 271 259 float newWeight, 272 bool isMovingObject260 float sampleIntensity 273 261 ) 274 262 { … … 310 298 // angle between current normal and direction to sample controls AO intensity. 311 299 const float cosAngle = max(dot(dirSample, normal), .0f); 312 const float aoContrib = SAMPLE_INTENSITY/ sqrLen;300 const float aoContrib = sampleIntensity / sqrLen; 313 301 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 314 302 … … 338 326 339 327 //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 340 if ((validSamples < 1.0f) && (numSamples >= 8) && !isMovingObject 341 || (newWeight > NUM_SAMPLES * 5) && (numSamples >= 8) && isMovingObject 342 ) 343 { 344 break; 345 } 328 //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 346 329 } 347 330 348 331 total_ao /= numSamples; 349 332 350 //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 351 return float3(total_ao, validSamples, numSamples); 333 return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 352 334 } 353 335 … … 374 356 uniform float3 oldtl, 375 357 uniform float3 oldtr, 376 uniform sampler2D attribsTex 358 uniform sampler2D attribsTex, 359 uniform float kernelRadius, 360 uniform float sampleIntensity 377 361 ) 378 362 { … … 396 380 const float invw = 1.0f / projPos.w; 397 381 projPos *= invw; 398 float scaleFactor = SAMPLE_RADIUS * invw; 399 400 const float sqrMoveSpeed = SqrLen(diffVec); 401 const bool isMovingObject = (sqrMoveSpeed > DYNAMIC_OBJECTS_THRESHOLD); 382 float scaleFactor = kernelRadius * invw; 402 383 403 384 … … 422 403 if (eyeSpaceDepth < 1e10f) 423 404 { 424 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, isMovingObject);425 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals );405 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity); 406 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 426 407 } 427 408 else … … 430 411 } 431 412 432 // equals the number of sampled shot in this pass 433 const float newWeight = ao.z; 413 const float squaredLen = SqrLen(diffVec); 434 414 435 415 // check if we have to reset pixel because one of the sample points was invalid 436 if (!isMovingObject) 437 //if (sqrMoveSpeed <= DYNAMIC_OBJECTS_THRESHOLD) 416 if (squaredLen < DYNAMIC_OBJECTS_THRESHOLD) 438 417 { 439 418 if (ao.y > 4.0f) 440 419 oldWeight = 0; 441 420 else if (ao.y > 1.0f) 442 oldWeight = min(oldWeight, 4.0f * newWeight); 443 } 444 421 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 422 } 423 424 const float newWeight = ao.z; 445 425 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 446 426
Note: See TracChangeset
for help on using the changeset viewer.