Changeset 3296 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 02/10/09 17:43:43 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3287 r3296 395 395 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "GiFrag"); 396 396 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "CombineGi"); 397 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao"); 397 //sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao"); 398 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoFullRes", "CombineSsao"); 398 399 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "AntiAliasing"); 399 400 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "ToneMap"); … … 624 625 } 625 626 627 #if 0 626 628 627 629 void DeferredRenderer::PrepareSsaoFilter() … … 647 649 } 648 650 } 651 652 #else 653 654 void DeferredRenderer::PrepareSsaoFilter() 655 { 656 const float filterWidth = 1.0f; 657 658 PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 659 poisson.Generate((float *)ssaoFilterOffsets); 660 661 const float xoffs = (float)filterWidth / mWidth; 662 const float yoffs = (float)filterWidth / mHeight; 663 664 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES / 2; ++ i) 665 { 666 float x = xoffs * (i - NUM_SSAO_FILTER_SAMPLES / 4); 667 float y = 0; 668 669 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 670 671 ssaoFilterOffsets[2 * i + 0] = xoffs; 672 ssaoFilterOffsets[2 * i + 1] = yoffs; 673 } 674 675 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES / 2; ++ i) 676 { 677 float x = 0; 678 float y = yoffs * (i - NUM_SSAO_FILTER_SAMPLES / 4); 679 680 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 681 //ssaoFilterWeights[i] = 1.0f; 682 683 ssaoFilterOffsets[2 * (NUM_SSAO_FILTER_SAMPLES / 2 + i) + 0] *= xoffs; 684 ssaoFilterOffsets[2 * (NUM_SSAO_FILTER_SAMPLES / 2 + i) + 1] *= yoffs; 685 } 686 } 687 688 #endif 649 689 650 690 … … 983 1023 984 1024 for (int j = 0; j < 4; ++ j, ++ i) 1025 { 985 1026 sCgCombineSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 1027 } 1028 1029 sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetWidth()); 1030 sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetHeight()); 1031 1032 DrawQuad(sCgCombineSsaoProgram); 1033 1034 PrintGLerror("combine ssao"); 1035 } 1036 1037 1038 void DeferredRenderer::CombineSsao2(FrameBufferObject *fbo) 1039 { 1040 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1041 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1042 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1043 1044 FlipFbos(fbo); 1045 1046 int i = 0; 1047 1048 sCgCombineSsaoProgram->SetTexture(i ++, colorsTex); 1049 sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); 1050 sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 1051 1052 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 1053 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 1054 sCgCombineSsaoProgram->SetValue1f(i ++, mSsaoFilterRadius); 1055 1056 sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); 1057 1058 for (int j = 0; j < 4; ++ j, ++ i) 1059 { 1060 sCgCombineSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 1061 } 986 1062 987 1063 sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetWidth()); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3242 r3296 168 168 void DepthOfField(FrameBufferObject *fbo); 169 169 170 void CombineSsao2(FrameBufferObject *fbo); 170 171 171 172 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3285 r3296 115 115 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 116 116 117 #if 0 // for half resolution118 119 117 // the following has to be done for half resolution ssao: 120 118 // get the minimum convergence by exactly sampling the 4 surrounding … … 141 139 const float convergence = minConvergence; 142 140 143 #else144 145 // just take unfiltered convergence in current pixel146 const float convergence = ao.y;147 148 #endif149 141 150 142 // filter reaches size 1 pixel when sample size reaches threshold … … 188 180 return OUT; 189 181 } 182 183 184 /** Function combining image and indirect illumination buffer using a 185 depth and normal aware discontinuity filter. We assume that 186 we are using half resolution ssao for this version of the combineSsao 187 */ 188 pixel CombineSsaoFullRes(fragment IN, 189 uniform sampler2D colorsTex, 190 uniform sampler2D ssaoTex, 191 uniform sampler2D normalsTex, 192 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 193 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 194 uniform float ssaoFilterRadius, 195 uniform float4x4 modelViewProj, 196 uniform float3 bl, 197 uniform float3 br, 198 uniform float3 tl, 199 uniform float3 tr, 200 uniform float w, 201 uniform float h 202 ) 203 { 204 pixel OUT; 205 206 float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 207 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 208 209 // just take unfiltered convergence in current pixel 210 const float convergence = ao.y; 211 212 // filter reaches size 1 pixel when sample size reaches threshold 213 // afterwards we do not use the filter anymore 214 215 // filter up to a certain convergance value and leave out background (sky) by checking depth 216 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (col.w < 1e10f)) 217 { 218 const float distanceScale = 1.0f; 219 220 // descend to zero filter size after reaching thres pixels 221 const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / (ssaoFilterRadius - 1.0f); 222 const float convergenceScale = convergenceWeight / (convergence + convergenceWeight); 223 const float scale = ssaoFilterRadius * convergenceScale * distanceScale; 224 225 // the filtered ssao value 226 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 227 } 228 229 // just apply ssao if we are not in the sky 230 if (col.w < 1e10f) 231 OUT.illum_col.xyz = col.xyz * max(2e-2f, 1.0f - ao.x); 232 //OUT.illum_col.xyz = col.xyz * ao.x; 233 else 234 OUT.illum_col.xyz = col.xyz; 235 236 OUT.illum_col.w = col.w; 237 238 return OUT; 239 }
Note: See TracChangeset
for help on using the changeset viewer.