Changeset 3361 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 04/20/09 09:11:32 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3360 r3361 407 407 cout << "using half resolution ssao" << endl; 408 408 } 409 409 #if 1 410 410 411 411 ///////// … … 467 467 468 468 PrepareLenseFlare(); 469 469 #endif 470 470 InitCg(); 471 471 } … … 660 660 */ 661 661 662 if (mShadingMethod != 0)662 if (mShadingMethod != DEFAULT) 663 663 { 664 664 PrepareSsao(fbo); // downsample fbo buffers … … 966 966 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 967 967 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 968 //GLuint aoTex = fbo->GetColorBuffer(1)->GetTexture(); 968 969 GLuint aoTex = mTempFbo->GetColorBuffer(1)->GetTexture(); 969 970 … … 1103 1104 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1104 1105 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1106 //GLuint ssaoTex = fbo->GetColorBuffer(1)->GetTexture(); 1105 1107 GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 1106 1108 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3360 r3361 149 149 150 150 bool useSkylightForIllum = true; 151 152 151 bool showFPS = true; 153 154 152 static int globalVisibleId = 0; 155 156 153 PerfTimer applicationTimer; 157 154 … … 203 200 // ssao parameters 204 201 float ssaoKernelRadius = 1e-8f; 205 float ssaoSampleIntensity = 0.2f;202 float ssaoSampleIntensity = .2f; 206 203 float ssaoFilterRadius = 3.0f; 207 204 float ssaoTempCohFactor = 255.0; … … 647 644 648 645 // for buddha (lowres) 649 /*positions.push_back(Vector3(6.07307, 8.20723, 6.62));646 positions.push_back(Vector3(6.07307, 8.20723, 6.62)); 650 647 positions.push_back(Vector3(-17.1935, 11.1687, 8.8781)); 651 positions.push_back(Vector3(1.50032, 31.1943, 19.1f)); */648 positions.push_back(Vector3(1.50032, 31.1943, 19.1f)); 652 649 653 650 // for happy buddha … … 658 655 // for dragon 659 656 //positions.push_back(Vector3(6.07307, 8.20723, 5.0f)); 660 positions.push_back(Vector3(0, 0, -0.8));657 //positions.push_back(Vector3(0, 0, -0.8)); 661 658 662 659 #endif … … 666 663 667 664 //LoadModel("hbuddha.dem", dynamicObjects); 668 LoadModel("horse.dem", dynamicObjects);669 //LoadModel("happy.dem", dynamicObjects);665 //LoadModel("horse.dem", dynamicObjects); 666 LoadModel("happy.dem", dynamicObjects); 670 667 //LoadModel("dragon.dem", dynamicObjects); 671 668 //LoadModel("torus.dem", dynamicObjects); … … 681 678 } 682 679 680 /* 683 681 const float rotAngle = M_PI / 2.0f; 684 682 const Matrix4x4 rotMatrix = RotationXMatrix(rotAngle); … … 689 687 dynamicObjects[0]->GetTransform()->MultMatrix(scaleMatrix); 690 688 691 //dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);692 //dynamicObjects[1]->GetTransform()->MultMatrix(scaleMatrix);693 694 //dynamicObjects[2]->GetTransform()->MultMatrix(rotMatrix);695 //dynamicObjects[2]->GetTransform()->MultMatrix(scaleMatrix);689 dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 690 dynamicObjects[1]->GetTransform()->MultMatrix(scaleMatrix); 691 692 dynamicObjects[2]->GetTransform()->MultMatrix(rotMatrix); 693 dynamicObjects[2]->GetTransform()->MultMatrix(scaleMatrix); 696 694 697 695 cout << "dynamic objects: " << (int)dynamicObjects.size() << endl; 698 696 */ 699 697 CreateAnimation(positions[0]); 698 700 699 #endif 701 700 … … 827 826 // buffer holding the difference vector to the old frame 828 827 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 828 //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 829 829 // another color buffer 830 830 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); … … 1172 1172 dynamicObjects[i]->GetTransform()->InitFrame(); 1173 1173 1174 if ( 0)//buddha)1174 if (buddha) 1175 1175 { 1176 1176 Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); … … 1194 1194 #endif 1195 1195 1196 #if 01196 #if 1 1197 1197 ///////////////////////// 1198 1198 //-- update animations 1199 1199 1200 1200 //const float rotAngle = M_PI * 1e-3f; 1201 //const float rotAngle = 0.3f * M_PI / 180.0f;1202 const float rotAngle = 0.6f * M_PI / 180.0f;1201 const float rotAngle = 0.3f * M_PI / 180.0f; 1202 //const float rotAngle = 0.6f * M_PI / 180.0f; 1203 1203 1204 1204 Matrix4x4 rotMatrix = RotationZMatrix(rotAngle); … … 1206 1206 dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 1207 1207 1208 // hack: second buddha 1208 1209 const float rotAngle2 = 0.0033f * M_PI; 1209 1210 1210 Matrix4x4 rotMatrix2 = RotationZMatrix(rotAngle); 1211 // hack: second buddha1212 1211 //dynamicObjects[3]->GetTransform()->MultMatrix(rotMatrix2); 1213 1214 1212 1215 1213 //const float moveSpeed = 5e-3f; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3360 r3361 14 14 //#define NUM_SAMPLES 24 15 15 #define NUM_SAMPLES 32 16 //#define NUM_SAMPLES 816 //#define NUM_SAMPLES 48 17 17 18 18 //#define MIN_SAMPLES 48 -
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.