- Timestamp:
- 02/12/09 14:38:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3301 r3305 248 248 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 249 249 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 250 251 250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 252 251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); … … 300 299 mSortSamples(true), 301 300 mKernelRadius(1e-8f), 302 mSsaoFilterRadius(12.0f),303 301 mSampleIntensity(0.2f), 304 302 mSunVisiblePixels(0), … … 309 307 mUseToneMapping(false), 310 308 mUseAntiAliasing(false), 311 mUseDepthOfField(false) 309 mUseDepthOfField(false), 310 mSsaoUseFullResolution(ssaoUseFullResolution) 312 311 { 313 312 /////////// … … 316 315 int downSampledWidth, downSampledHeight; 317 316 318 if ( ssaoUseFullResolution)317 if (mSsaoUseFullResolution) 319 318 { 320 319 downSampledWidth = w; downSampledHeight = h; … … 327 326 } 328 327 329 /////// 328 329 ///////// 330 330 //-- the illumination fbo is either half size or full size 331 331 332 332 mIllumFbo = new FrameBufferObject(downSampledWidth, downSampledHeight, FrameBufferObject::DEPTH_NONE); 333 334 333 mFBOs.push_back(mIllumFbo); 335 334 … … 343 342 /////////////// 344 343 //-- the downsampled ssao + color bleeding textures: 345 //-- as GI is mostly low frequency, we can use lower resolution to improve performance344 //-- as GI is mostly low frequency, we can use lower resolution to improve performance 346 345 347 346 mDownSampleFbo = new FrameBufferObject(downSampledWidth, downSampledHeight, FrameBufferObject::DEPTH_NONE); … … 358 357 359 358 mFBOs.push_back(mDownSampleFbo); 359 360 361 ///////// 362 //-- temporal buffer 363 364 mTempFbo = new FrameBufferObject(mWidth, mHeight, FrameBufferObject::DEPTH_NONE); 365 mFBOs.push_back(mTempFbo); 366 367 mTempFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 368 FrameBufferObject::InitBuffer(mTempFbo, 0); 369 360 370 361 371 // create noise texture for ssao … … 397 407 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "GiFrag"); 398 408 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "CombineGi"); 399 //sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao"); 400 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "CombineSsaoFullRes", "CombineSsao"); 401 sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoFullRes", "FilterSsao"); 409 410 if (mSsaoUseFullResolution) 411 { 412 sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoFullRes", "FilterSsao"); 413 } 414 else 415 { 416 sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoHalfRes", "FilterSsao"); 417 } 418 419 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "CombineSsao", "CombineSsao"); 402 420 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "AntiAliasing"); 403 421 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "ToneMap"); … … 446 464 //////////////// 447 465 448 /*string combineSsaoParams[] =449 {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights",450 "ssaoFilterRadius", "modelViewProj", "bl", "br", "tl",451 "tr", "w", "h"};452 */453 466 string combineSsaoParams[] = 454 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "xyStep"};467 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"}; 455 468 456 469 //sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13); … … 461 474 462 475 string filterSsaoParams[] = 463 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", " xyStep"};476 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"}; 464 477 465 478 sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 7); … … 515 528 516 529 sCgDOFProgram->AddParameters(dofParams, 0, 4); 517 518 519 ////////////////520 //-- prepare filter for ssao521 522 PrepareSsaoFilter();523 530 524 531 … … 642 649 } 643 650 644 #if 0645 646 void DeferredRenderer::PrepareSsaoFilter()647 {648 const float filterWidth = 1.0f;649 650 PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f);651 poisson.Generate((float *)ssaoFilterOffsets);652 653 const float xoffs = (float)filterWidth / mWidth;654 const float yoffs = (float)filterWidth / mHeight;655 656 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i)657 {658 float x = ssaoFilterOffsets[2 * i + 0];659 float y = ssaoFilterOffsets[2 * i + 1];660 661 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);662 //ssaoFilterWeights[i] = 1.0f;663 664 ssaoFilterOffsets[2 * i + 0] *= xoffs;665 ssaoFilterOffsets[2 * i + 1] *= yoffs;666 }667 }668 669 #else670 671 /** star filter672 */673 void DeferredRenderer::PrepareSsaoFilter()674 {675 const float filterWidth = 1.0f;676 677 PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f);678 poisson.Generate((float *)ssaoFilterOffsets);679 680 const float xoffs = (float)filterWidth / mWidth;681 const float yoffs = (float)filterWidth / mHeight;682 683 const int n = NUM_SSAO_FILTER_SAMPLES / 2 + 1;684 685 for (int i = 0; i < n; ++ i)686 {687 const int idx = i - NUM_SSAO_FILTER_SAMPLES / 4;688 689 const float x = xoffs * (float)idx;690 const float y = 0;691 692 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);693 694 ssaoFilterOffsets[2 * i + 0] = x;695 ssaoFilterOffsets[2 * i + 1] = y;696 }697 698 int j = 2 * n;699 700 for (int i = 0; i < n; ++ i)701 {702 const int idx = i - NUM_SSAO_FILTER_SAMPLES / 4;703 704 if (idx)705 {706 const float x = 0;707 const float y = yoffs * (float)idx;708 709 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);710 //ssaoFilterWeights[i] = 1.0f;711 712 ssaoFilterOffsets[j + 0] = x;713 ssaoFilterOffsets[j + 1] = y;714 715 j += 2;716 }717 }718 719 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i)720 {721 cout << "samples " << i << ": " << ssaoFilterOffsets[i * 2] << " " << ssaoFilterOffsets[i * 2 + 1] << endl;722 }723 }724 725 #endif726 727 651 728 652 static inline float SqrMag(const Sample2 &s) … … 1045 969 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1046 970 1047 mIllumFbo->Bind(); 1048 glDrawBuffers(1, mrt + mIllumFboIndex + 1); 1049 1050 971 //mIllumFbo->Bind(); 972 //glDrawBuffers(1, mrt + mIllumFboIndex + 1); 973 mTempFbo->Bind(); 974 glDrawBuffers(1, mrt); 975 1051 976 int i = 0; 1052 977 … … 1059 984 } 1060 985 1061 sCgFilterSsaoProgram->SetValue2f(i ++, 1.0f / (float)mWidth, 0);986 sCgFilterSsaoProgram->SetValue2f(i ++, (float)mWidth, (float)mHeight); 1062 987 1063 988 DrawQuad(sCgFilterSsaoProgram); 1064 1065 989 PrintGLerror("combine ssao"); 1066 990 } … … 1071 995 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1072 996 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1073 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 997 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 998 GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 1074 999 1075 1000 FlipFbos(fbo); … … 1080 1005 sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 1081 1006 1082 //sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES);1083 //sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES);1084 //sCgCombineSsaoProgram->SetValue1f(i ++, mSsaoFilterRadius);1085 //sCgCombineSsaoProgram->SetMatrix(i ++, mProjViewMatrix);1086 1087 1007 for (int j = 0; j < 4; ++ j, ++ i) 1088 1008 { … … 1090 1010 } 1091 1011 1092 //float xOffs, yOffs; 1093 1094 //sCgCombineSsaoProgram->SetValue2f(i ++, 1.0f / (float)mWidth, 1.0f / (float)mHeight); 1095 sCgCombineSsaoProgram->SetValue2f(i ++, 0, 1.0f / (float)mHeight); 1012 sCgCombineSsaoProgram->SetValue2f(i ++, mWidth, mHeight); 1096 1013 1097 1014 DrawQuad(sCgCombineSsaoProgram); … … 1545 1462 1546 1463 1547 void DeferredRenderer::SetSsaoFilterRadius(float ssaoFilterRadius)1548 {1549 mSsaoFilterRadius = ssaoFilterRadius;1550 mRegenerateSamples = true;1551 }1552 1553 1554 1464 /*void DeferredRenderer::SetSortSamples(bool sortSamples) 1555 1465 {
Note: See TracChangeset
for help on using the changeset viewer.