- Timestamp:
- 11/25/08 18:14:48 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3166 r3167 71 71 72 72 73 static float ssaoFilterOffsets[NUM_SSAO_FILTER SAMPLES * 2];74 static float ssaoFilterWeights[NUM_SSAO_FILTER SAMPLES];73 static float ssaoFilterOffsets[NUM_SSAO_FILTER_SAMPLES * 2]; 74 static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 75 75 76 76 … … 445 445 446 446 string prepareSsaoParams[] = 447 {"colorsTex", "oldTex", "oldEyePos", "modelViewProj", "oldModelViewProj", 448 "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"}; 449 450 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 447 {"colorsTex", "normalsTex", "diffVals", "oldTex", 448 "oldEyePos", "modelViewProj", "oldModelViewProj", 449 "oldbl", "oldbr", "oldtl", "oldtr"}; 450 451 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11); 451 452 452 453 453 454 //////////////// 454 455 455 456 //const float filterWidth = 100.0f; 457 const float filterWidth = 30.0f; 458 //const float filterWidth = 15.0f; 459 460 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 456 const float filterWidth = 1.0f; 457 458 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 461 459 poisson.Generate((float *)ssaoFilterOffsets); 462 460 … … 464 462 const float yoffs = (float)filterWidth / mHeight; 465 463 466 for (int i = 0; i < NUM_SSAO_FILTER SAMPLES; ++ i)464 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 467 465 { 468 466 float x = ssaoFilterOffsets[2 * i + 0]; … … 516 514 //DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 517 515 PrepareSsao(fbo); 518 DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals519 DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets516 //DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 517 //DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 520 518 } 521 519 … … 570 568 571 569 570 571 static inline float SqrMag(const Sample2 &s) 572 { 573 return (s.x * s.x + s.y * s.y); 574 } 575 576 577 static inline float SqrDist(const Sample2 &a, const Sample2 &b) 578 { 579 float x = a.x - b.x; 580 float y = a.y - b.y; 581 582 return x * x + y * y; 583 } 584 585 586 static inline bool lt(const Sample2 &a, const Sample2 &b) 587 { 588 return SqrMag(a) < SqrMag(b); 589 } 590 591 592 void DeferredRenderer::SortSamples() 593 { 594 //for (int i = 0; i < NUM_SAMPLES; ++ i)cout << SqrDist(samples2[i-1], samples2[i]) << "|"; 595 float dist = 0; 596 for (int i = 1; i < NUM_SAMPLES; ++ i) 597 dist += SqrDist(samples2[i-1], samples2[i]); 598 //cout << samples2[i].x << " " << samples2[i].y 599 600 //cout << "\nbefore: " << dist << endl; 601 602 //sort(samples2, samples2 + sizeof(samples2) / sizeof(Sample2), lt2); 603 604 605 static Sample2 tempSamples[NUM_SAMPLES]; 606 static bool checked[NUM_SAMPLES]; 607 608 for (int i = 0; i < NUM_SAMPLES; ++ i) 609 checked[i] = false; 610 611 Sample2 currentSample; 612 currentSample.x = 0; currentSample.y = 0; 613 int ns = 0; // the next sample index 614 615 for (int i = 0; i < NUM_SAMPLES; ++ i) 616 { 617 float minLen = 1e20f; 618 619 for (int j = 0; j < NUM_SAMPLES; ++ j) 620 { 621 if (checked[j]) continue; 622 623 Sample2 s = samples2[j]; 624 const float len = SqrDist(s, currentSample); 625 626 if (len < minLen) 627 { 628 minLen = len; 629 ns = j; 630 } 631 } 632 633 tempSamples[i] = samples2[ns]; 634 currentSample = samples2[ns]; 635 checked[ns] = true; 636 } 637 638 for (int i = 0; i < NUM_SAMPLES; ++ i) 639 samples2[i] = tempSamples[i]; 640 641 dist = 0; 642 for (int i = 1; i < NUM_SAMPLES; ++ i) 643 dist += SqrDist(samples2[i-1], samples2[i]); 644 //cout << samples2[i].x << " " << samples2[i].y << " " << SqrDist(samples2[i-1], samples2[i]) << "|"; 645 646 //cout << "after: " << dist << endl; 647 } 648 649 572 650 void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 573 651 float tempCohFactor) … … 616 694 // needs longer to converge 617 695 GenerateSamples(mSamplingMethod); 696 697 SortSamples(); 618 698 sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 619 699 } … … 821 901 sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 822 902 823 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER SAMPLES);824 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER SAMPLES);903 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 904 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 825 905 826 906 sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); … … 957 1037 void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 958 1038 { 959 GLuint colorsTex, diffVals, oldTex;1039 GLuint colorsTex, normalsTex, diffVals, oldTex; 960 1040 961 1041 colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 962 //normalsTex = fbo->GetColorBuffer(1)->GetTexture();1042 normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 963 1043 diffVals = fbo->GetColorBuffer(2)->GetTexture(); 964 1044 //diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); … … 970 1050 971 1051 sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 972 //sCgSsaoProgram->SetTexture(i ++, normalsTex); 1052 sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex); 1053 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 973 1054 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 974 1055 … … 986 1067 sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 987 1068 988 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals);989 990 991 1069 glPushAttrib(GL_VIEWPORT_BIT); 992 1070 glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); … … 994 1072 mDownSampleFbo->Bind(); 995 1073 996 glDrawBuffers( 1, mrt + 0);1074 glDrawBuffers(3, mrt + 0); 997 1075 998 1076 DrawQuad(sCgPrepareSsaoProgram);
Note: See TracChangeset
for help on using the changeset viewer.