Changeset 3305 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 02/12/09 14:38:14 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3295 r3305 298 298 ++ mNumShapes; 299 299 300 if (!currentMat) cout << "here3" << endl;301 300 LoadShape(faceVertices, faceNormals, faceTexcoords, currentMat); 302 301 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3296 r3305 820 820 </File> 821 821 <File 822 RelativePath=".\src\shaders\combineSsao.cg"823 >824 </File>825 <File826 822 RelativePath=".\src\shaders\combineSsaoSep.cg" 827 823 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3297 r3305 144 144 # ssao temporal coherence factor 145 145 tempCohFactor=2000.0f 146 # ssao filter radius147 ssaoFilterRadius=12.0f148 146 149 147 -
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 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3301 r3305 63 63 */ 64 64 void SetKernelRadius(float kernelRadius); 65 /** Sets ssao filter radius.66 */67 void SetSsaoFilterRadius(float radius);68 65 /** Passes the number of pixels that are visible from the sun. 69 66 */ … … 161 158 162 159 void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light); 163 164 void PrepareSsaoFilter();165 160 166 161 void SaveFrame(FrameBufferObject *fbo); … … 196 191 197 192 FrameBufferObject *mDownSampleFbo; 193 FrameBufferObject *mTempFbo; 198 194 199 195 FBOContainer mFBOs; … … 211 207 212 208 float mKernelRadius; 213 float mSsaoFilterRadius;214 209 float mSampleIntensity; 215 210 … … 224 219 bool mUseToneMapping; 225 220 bool mUseAntiAliasing; 226 bool mUseDepthOfField; 221 bool mUseDepthOfField; 222 223 bool mSsaoUseFullResolution; 227 224 }; 228 225 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3297 r3305 204 204 float ssaoKernelRadius = 1e-8f; 205 205 float ssaoSampleIntensity = 0.2f; 206 float ssaoFilterRadius = 12.0f;206 float ssaoFilterRadius = 3.0f; 207 207 float ssaoTempCohFactor = 255.0; 208 208 bool sortSamples = true; … … 1383 1383 deferredShader->SetKernelRadius(ssaoKernelRadius); 1384 1384 deferredShader->SetSampleIntensity(ssaoSampleIntensity); 1385 deferredShader->SetSsaoFilterRadius(ssaoFilterRadius);1386 1385 } 1387 1386 … … 1574 1573 cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 1575 1574 break; 1576 case 'o':1577 ssaoFilterRadius *= 0.9f;1575 /*case 'o': 1576 if (ssaoFilterRadius >= 0.0f) ssaoFilterRadius -= 1.0f; 1578 1577 if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 1579 1578 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1580 1579 break; 1581 1580 case 'O': 1582 ssaoFilterRadius *= 1.0f / 0.9f;1581 ssaoFilterRadius += 1.0f; 1583 1582 if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 1584 1583 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1585 break; 1584 break;*/ 1586 1585 /* case 'o': 1587 1586 case 'O': -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3304 r3305 107 107 uniform float3 tl, 108 108 uniform float3 tr, 109 uniform float2 res olution109 uniform float2 res 110 110 ) 111 111 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
r3304 r3305 19 19 float4 illum_col: COLOR0; 20 20 }; 21 22 23 float ComputeConvergenceHalfRes(uniform sampler2D ssaoTex, 24 float2 texCoord, 25 float2 halfres) 26 { 27 // the following has to be done for half resolution ssao: 28 // get the minimum convergence by exactly sampling the 4 surrounding 29 // texels in the old texture, otherwise flickering because convergence 30 // will be interpolated when upsampling and filter size does not match! 31 32 float4 texelCenterConv; 33 const float xoffs = .5f / halfres.x; const float yoffs = .5f / halfres.y; 34 35 // get position exactly between old texel centers 36 float2 center; 37 center.x = (floor(texCoord.x * halfres.x - .5f) + 1.0f) / halfres.x; 38 center.y = (floor(texCoord.y * halfres.y - .5f) + 1.0f) / halfres.y; 39 40 texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2( xoffs, yoffs), 0, 0)).y; 41 texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 42 texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 43 texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 44 45 const float m1 = min(texelCenterConv.x, texelCenterConv.y); 46 const float m2 = min(texelCenterConv.z, texelCenterConv.w); 47 48 const float minConvergence = min(m1, m2); 49 return minConvergence; 50 } 21 51 22 52 … … 45 75 // combine the weights 46 76 float w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor; 47 48 77 float average = aoSample.x * w; 49 78 … … 94 123 uniform float3 tl, 95 124 uniform float3 tr, 96 uniform float2 xyStep97 125 uniform float2 res 126 ) 98 127 { 99 128 pixel OUT; … … 108 137 // afterwards we do not use the filter anymore 109 138 139 float2 xyStep = float2(1.0f / res.x, 0); 140 110 141 // filter up to a certain convergance value and leave out background (sky) by checking depth 111 142 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) … … 118 149 } 119 150 151 /** In between step that only filters in one direction 152 */ 153 pixel FilterSsaoHalfRes(fragment IN, 154 uniform sampler2D colorsTex, 155 uniform sampler2D ssaoTex, 156 uniform float3 bl, 157 uniform float3 br, 158 uniform float3 tl, 159 uniform float3 tr, 160 uniform float2 res 161 ) 162 { 163 pixel OUT; 164 165 const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 166 167 OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 168 // just take unfiltered convergence in current pixel 169 const float convergence = ComputeConvergenceHalfRes(ssaoTex, IN.texCoord, res * 0.5f); 170 171 const float2 xyStep = float2(1.0f / res.x, 0); 172 173 // filter reaches size 1 pixel when sample size reaches threshold 174 // afterwards we do not use the filter anymore 175 176 // filter up to a certain convergance value and leave out background (sky) by checking depth 177 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 178 { 179 // the filtered ssao value 180 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 181 } 182 183 return OUT; 184 } 120 185 121 186 /** Function combining image and indirect illumination buffer using a 122 187 depth and convergence aware discontinuity filter. 123 188 */ 124 pixel CombineSsao FullRes(fragment IN,125 126 127 128 129 130 131 uniform float2 xyStep132 189 pixel CombineSsao(fragment IN, 190 uniform sampler2D colorsTex, 191 uniform sampler2D ssaoTex, 192 uniform float3 bl, 193 uniform float3 br, 194 uniform float3 tl, 195 uniform float3 tr, 196 uniform float2 res 197 ) 133 198 { 134 199 pixel OUT; … … 141 206 const float convergence = ao.y; 142 207 208 const float2 xyStep = float2(0, 1.0f / res.y); 209 143 210 // filter reaches size 1 pixel when sample size reaches threshold 144 211 // afterwards we do not use the filter anymore
Note: See TracChangeset
for help on using the changeset viewer.