- Timestamp:
- 02/16/09 17:08:51 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3311 r3313 48 48 weight of the pixel in the new frame. 49 49 */ 50 inline float 3temporalSmoothing(float4 worldPos,50 inline float2 temporalSmoothing(float4 worldPos, 51 51 float eyeSpaceDepth, 52 52 float2 texcoord0, … … 96 96 // the weight of the accumulated samples from the previous frames 97 97 float w; 98 float idx;99 98 100 99 ////////////// … … 109 108 // pixel valid => retrieve the convergence weight 110 109 w = oldPixel.y; 111 idx = oldPixel.z;112 110 } 113 111 else 114 112 { 115 w = .0f; 116 idx = .0f; 117 } 118 119 return float3(ssao, w, idx); 113 w = 0.0f; 114 } 115 116 return float2(ssao, w); 120 117 } 121 118 … … 145 142 float validSamples = .0f; 146 143 147 148 for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i) 144 for (int i = 0; i < NUM_SAMPLES; ++ i) 149 145 { 150 146 const float2 offset = samples[i]; … … 224 220 sampler2D colors, 225 221 sampler2D noiseTex, 226 sampler2D samples,222 float2 samples[NUM_SAMPLES], 227 223 float3 normal, 228 224 float3 centerPosition, … … 235 231 float convergence, 236 232 float sampleIntensity, 237 bool isMovingObject, 238 float idx 233 bool isMovingObject 239 234 ) 240 235 { … … 242 237 float validSamples = .0f; 243 238 float numSamples = .0f; 244 239 245 240 for (int i = 0; i < NUM_SAMPLES; ++ i) 246 241 { … … 251 246 //-- (affects performance for some reason!) 252 247 253 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;254 255 248 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 256 249 { 257 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord .x * 4.0f + idx * 0.01f, IN.texCoord.y* 4.0f, 0, 0)).xy;250 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 258 251 //offset = myreflect(samples[i], mynoise); 259 //offset = myrotate(samples[i], mynoise.x); 260 261 offset = myrotate(ssaoOffset, mynoise.x); 252 offset = myrotate(samples[i], mynoise.x); 262 253 } 263 254 else 264 255 { 265 offset = ssaoOffset; 266 //offset = samples[i]; 256 offset = samples[i]; 267 257 } 268 258 … … 304 294 // we check if the sample could have been near enough to the current pixel 305 295 // to have any influence in the current or last frame 306 //const float tooFarAway = step(0.5f, lengthToSample - changeFactor);296 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 307 297 //validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 308 298 validSamples = max(validSamples, pixelValid); … … 313 303 if (numSamples >= MIN_SAMPLES) 314 304 { 305 //break; 315 306 // if the pixel belongs to a static object and all the samples stay valid in the current frame 316 307 if (!isMovingObject && (validSamples < 1.0f)) break; 317 // if the pixel belongs to a dynamic object but the #accumulated samples 318 // for this pixel is sufficiently high(=> there was no discontinuity recently)308 // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 309 // (=> there was no discontinuity recently) 319 310 else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 320 311 } … … 344 335 uniform sampler2D normals, 345 336 uniform sampler2D noiseTex, 346 uniform sampler2D samples,337 uniform float2 samples[NUM_SAMPLES], 347 338 uniform sampler2D oldTex, 348 339 uniform float4x4 modelViewProj, … … 391 382 //-- compute temporal reprojection 392 383 393 float 3temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,384 float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 394 385 oldTex, oldModelViewProj, 395 386 colors, … … 402 393 const float oldSsao = temporalVals.x; 403 394 float oldWeight = temporalVals.y; 404 405 float idx = (int)temporalVals.z; 406 407 if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 408 395 409 396 float3 ao; 410 397 … … 412 399 if (eyeSpaceDepth < DEPTH_THRESHOLD) 413 400 { 414 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 415 scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, 416 sampleIntensity, isMovingObject, idx); 401 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 417 402 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 418 403 } … … 429 414 // the weight equals the number of sampled shot in this pass 430 415 const float newWeight = ao.z; 431 432 idx += newWeight;433 416 434 417 // completely reset the ao in this pixel … … 437 420 const float partlyResetThres = 1.0f; 438 421 439 // hack: just update static geometry 440 if (!isMovingObject) 422 if (1)//!isMovingObject) 441 423 { 442 424 if (ao.y > completelyResetThres) 443 425 { 444 oldWeight = .0f; 445 idx = .0f; 426 oldWeight = .0f; 446 427 } 447 428 else if (ao.y > partlyResetThres) 448 429 { 449 430 oldWeight = min(oldWeight, 4.0f * newWeight); 431 //oldWeight = .0f; 450 432 } 451 433 } 452 453 434 454 435 ////////// 455 436 //-- blend ao between old and new samples (and avoid division by zero) 456 437 457 OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 438 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 439 458 440 OUT.illum_col.x /= (newWeight + oldWeight); 459 441 460 442 // the new weight for the next frame 461 443 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 462 444 463 445 OUT.illum_col.y = combinedWeight; 464 446 // can be used to check if this pixel belongs to a moving object 465 //OUT.illum_col.z = SqrLen(diffVec); 466 OUT.illum_col.z = idx; 447 OUT.illum_col.z = SqrLen(diffVec); 467 448 OUT.illum_col.w = eyeSpaceDepth; 468 449
Note: See TracChangeset
for help on using the changeset viewer.