Changeset 3361 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 04/20/09 09:11:32 (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/combineSsaoSep.cg
r3356 r3361 248 248 } 249 249 250 //OUT.illum_col.xyz = float3(ao.x * 1e1f, col.yz); 251 250 252 //OUT.illum_col.xyz = float3(ao.w * 5e-1f, 0, 0); 251 253 //OUT.illum_col.xyz = float3(ao.z * 1e-3f); 252 //OUT.illum_col.xyz = float3(ao.y * 1e-3f); x254 //OUT.illum_col.xyz = float3(ao.y * 1e-3f); 253 255 //OUT.illum_col.xyz = ao.xyz; 254 256 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3360 r3361 40 40 41 41 // hack: prevent to shade the sky 42 #if 142 #if 0 43 43 if (color.w > DEPTH_THRESHOLD) 44 44 { … … 250 250 251 251 // compute position from old frame for dynamic objects + translational portion 252 //const float3 translatedPos = difVec - oldEyePos + worldPos.xyz;252 const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 253 253 // don't use difVec here: want to detect if the actual pixel has changed => ssao changed 254 const float3 translatedPos = -oldEyePos + worldPos.xyz;254 //const float3 translatedPos = -oldEyePos + worldPos.xyz; 255 255 256 256 … … 293 293 // means that we only use slight temporal coherence over some frames 294 294 // so that there is no noticeable drag 295 const float pixelCouldBeValid = 2.0f;295 const float pixelCouldBeValid = 4.0f; 296 296 // this pixel information has to be discarded in order to not create artifacts 297 297 const float pixelIsNotValid = 100.0f; … … 306 306 } 307 307 else if ( // check if changed from dynamic to not dynamic object 308 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 308 ( 309 (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 309 310 ( 310 311 (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 311 312 (oldDynamic || newDynamic) && // check if we have a dynamic object 312 (depthDif > MIN_DEPTH_DIFF)))) // and there is a depth discontinuity 313 (depthDif > MIN_DEPTH_DIFF))) 314 ) // and there is a depth discontinuity 313 315 { 314 316 isPixelValid = pixelCouldBeValid; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3355 r3361 308 308 } 309 309 310 //#define TRYOUT 311 312 #ifdef TRYOUT 310 313 311 314 /** The ssao shader returning the an intensity value between 0 and 1. … … 399 402 // check if the samples have been valid in the last frame 400 403 // only mark sample as invalid if in the last / current frame 401 // they possibly have any influence on the ao404 // they possibly have any influence on the AO 402 405 403 406 const float changeFactor = sampleColor.y; … … 412 415 const float partlyResetThres = 1.0f; 413 416 414 const float tooFarAway = step( 0.5f, lengthToSample - changeFactor);417 const float tooFarAway = step(.5f, lengthToSample - changeFactor); 415 418 if (0)//pixelValid <= partlyResetThres) 416 419 validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); … … 451 454 } 452 455 456 #else 457 458 float3 ssao(fragment IN, 459 sampler2D colors, 460 sampler2D noiseTex, 461 sampler2D samples, 462 float3 normal, 463 float3 centerPosition, 464 float radius, 465 float3 bl, 466 float3 br, 467 float3 tl, 468 float3 tr, 469 float3 viewDir, 470 float convergence, 471 float sampleIntensity, 472 bool isMovingObject, 473 float oldIdx, 474 sampler2D attribsTex 475 ) 476 { 477 float total_ao = .0f; 478 float validSamples = .0f; 479 float numSamples = .0f; 480 481 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 482 483 for (int i = 0; i < NUM_SAMPLES; ++ i) 484 { 485 float2 offset; 486 487 const float2 ssaoOffset = 488 tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 489 490 491 //////////////////// 492 //-- add random noise: reflect around random normal vector 493 //-- (affects performance for some reason!) 494 495 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 496 { 497 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 498 //offset = myreflect(samples[i], mynoise); 499 //offset = myrotate(samples[i], mynoise.x); 500 offset = myrotate(ssaoOffset, mynoise.x); 501 } 502 else 503 { 504 offset = ssaoOffset; 505 } 506 507 508 // weight with projected coordinate to reach similar kernel size for near and far 509 const float2 texcoord = IN.texCoord.xy + offset * radius; 510 511 const float4 sampleColor = tex2Dlod(colors, float4(texcoord, .0f, .0f)); 512 const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 513 514 515 516 //////////////// 517 //-- compute contribution of sample using the direction and angle 518 519 float3 dirSample = samplePos - centerPosition; 520 521 const float minDist = 1e-6f; 522 const float eps = 1e-3f; 523 524 const float lengthToSample = length(dirSample); 525 const float sampleWeight = 1.0f / max(lengthToSample, eps); 526 527 dirSample /= max(length(dirSample), minDist); // normalize 528 529 // angle between current normal and direction to sample controls AO intensity. 530 const float cosAngle = dot(dirSample, normal); 531 532 //const float aoContrib = sampleIntensity / sqrLen; 533 const float aoContrib = sampleIntensity * sampleWeight; 534 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 535 536 total_ao += max(cosAngle, .0f) * aoContrib; 537 538 ++ numSamples; 539 540 541 #ifdef PERFORMANCE_TEST 542 // check if the samples have been valid in the last frame 543 // only mark sample as invalid if in the last / current frame 544 // they possibly have any influence on the ao 545 546 //const float pixelValid = sampleColor.x; 547 //const float pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f; 548 //float pixelValid = max(sampleColor.x, length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f); 549 float pixelValid = sampleColor.x; 550 551 if (pixelValid < 1) 552 { 553 const float3 sampleDiffVec = tex2Dlod(attribsTex, float4(texcoord, .0f, .0f)).xyz; 554 pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f; 555 } 556 557 // hack: 558 // we check if the sample could have been near enough to the current pixel 559 // or if the angle is small enough 560 // to have any influence in the current or last frame 561 562 #if 1 563 const float changeFactor = sampleColor.y; 564 const float partlyResetThres = 1.0f; 565 566 if (0)//pixelValid <= partlyResetThres) 567 { 568 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 569 validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); 570 } 571 else 572 { 573 validSamples = max(validSamples, pixelValid); 574 } 575 #endif 576 577 #ifdef USE_GTX 578 // we can bail out early and use a minimal #samples) 579 // if some conditions are met as long as the hardware supports it 580 if (numSamples >= MIN_SAMPLES) 581 { 582 //break; 583 // if the pixel belongs to a static object and all the samples stay valid in the current frame 584 if (!isMovingObject && (validSamples < 1.0f) && (convergence > NUM_SAMPLES)) break; 585 // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 586 // (=> there was no discontinuity recently) 587 //else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break; 588 else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 589 } 590 #endif 591 592 #endif // PERFORMANCE_TEST 593 } 594 595 // "normalize" ao contribution 596 total_ao /= numSamples; 597 598 #if 1 599 // if surface normal perpenticular to view dir, approx. half of the samples will not count 600 // => compensate for this (on the other hand, projected sampling area could be larger!) 601 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 602 total_ao *= viewCorrection; 603 #endif 604 605 //return float3(total_ao, validSamples, numSamples); 606 return float3(min(1.0f, total_ao), validSamples, numSamples); 607 } 608 #endif 453 609 454 610 … … 501 657 502 658 #ifdef PERFORMANCE_TEST 503 //#if 0504 659 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 505 660 … … 530 685 const float3 diffVec = float3(.0f); 531 686 const bool isMovingObject = false; 532 const float oldSsao = 0;533 534 float oldWeight = 0;535 float oldIdx = 0;687 const float oldSsao = .0f; 688 689 float oldWeight = .0f; 690 float oldIdx = .0f; 536 691 537 692 #endif … … 544 699 if (1) 545 700 { 701 #ifdef TRYOUT 546 702 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 547 703 radiusMult, bl, br, tl, tr, normalize(viewDir), 548 704 oldWeight, sampleIntensity, isMovingObject, oldIdx); 705 #else 706 707 ao = ssao(IN, colors, noiseTex, samples, 708 normal, eyeSpacePos.xyz, radiusMult, bl, 709 br, tl, tr, normalize(viewDir), 710 oldWeight, sampleIntensity, isMovingObject, oldIdx, 711 attribsTex); 712 #endif 549 713 } 550 714 else 551 715 { 552 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, radiusMult,716 /*ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, radiusMult, 553 717 bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 554 718 isMovingObject, normals, oldIdx); 719 */ 555 720 } 556 721 } … … 575 740 576 741 // don't check for moving objects, otherwise almost no coherence 577 if ( !isMovingObject)742 if (1)//!isMovingObject) 578 743 { 579 744 if (ao.y > completelyResetThres) … … 584 749 else if (ao.y > partlyResetThres) 585 750 { 586 oldWeight = min(oldWeight, 4.0f * newWeight); 751 const float factor = 4.0f; 752 oldWeight = min(oldWeight, factor * newWeight); 587 753 //oldWeight = .0f; 588 754 //oldIdx = .0f; … … 594 760 //-- blend ao between old and new samples (and avoid division by zero) 595 761 596 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);762 OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 597 763 OUT.illum_col.x /= (newWeight + oldWeight); 764 //OUT.illum_col.x = clamp(OUT.illum_col.x, 0, 1); 765 //OUT.illum_col.x = ao.y; 598 766 599 767 // the new weight for the next frame
Note: See TracChangeset
for help on using the changeset viewer.