Changeset 3148 for GTP/trunk/App/Demos
- Timestamp:
- 11/20/08 13:09:15 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3144 r3148 57 57 static ShaderProgram *sCgToneProgram = NULL; 58 58 static ShaderProgram *sCgDownSampleProgram = NULL; 59 static ShaderProgram *sCgSmoothSsaoProgram = NULL;60 59 static ShaderProgram *sCgScaleDepthProgram = NULL; 61 60 … … 374 373 sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth"); 375 374 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 376 sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao");377 375 378 376 … … 441 439 //////////////// 442 440 443 string smoothSsaoParams[] = {"normalsTex", "ssaoTex", "filterOffs", "filterWeights"};444 sCgSmoothSsaoProgram->AddParameters(smoothSsaoParams, 0, 4);445 446 447 ///////////448 441 449 442 const float filterWidth = 100.0f; … … 526 519 case SSAO: 527 520 ComputeSsao(fbo, tempCohFactor); 528 //SmoothSsao(fbo);529 521 CombineSsao(fbo); 530 522 break; … … 810 802 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 811 803 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 812 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();813 804 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 814 805 … … 816 807 817 808 int i = 0; 809 818 810 sCgCombineSsaoProgram->SetTexture(i ++, colorsTex); 819 811 sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); … … 827 819 Vector3 tl = mCornersView[2]; 828 820 Vector3 tr = mCornersView[3]; 829 830 sCgCombineSsaoProgram->SetValue3f(i ++, bl.x, bl.y, bl.z);831 sCgCombineSsaoProgram->SetValue3f(i ++, br.x, br.y, br.z);832 sCgCombineSsaoProgram->SetValue3f(i ++, tl.x, tl.y, tl.z);833 sCgCombineSsaoProgram->SetValue3f(i ++, tr.x, tr.y, tr.z);834 821 835 822 … … 1117 1104 1118 1105 1119 void DeferredRenderer::SmoothSsao(FrameBufferObject *fbo)1120 {1121 mIllumFbo->Bind();1122 1123 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();1124 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();1125 1126 // overwrite old ssao texture1127 glDrawBuffers(1, mrt + 2 - mIllumFboIndex);1128 1129 glPushAttrib(GL_VIEWPORT_BIT);1130 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());1131 1132 int i = 0;1133 sCgSmoothSsaoProgram->SetTexture(i ++, normalsTex);1134 sCgSmoothSsaoProgram->SetTexture(i ++, ssaoTex);1135 1136 sCgSmoothSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES);1137 sCgSmoothSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES);1138 1139 DrawQuad(sCgSmoothSsaoProgram);1140 1141 glPopAttrib();1142 1143 PrintGLerror("combine ssao");1144 }1145 1146 1147 1106 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3137 r3148 82 82 void CombineSsao(FrameBufferObject *fbo); 83 83 void CombineIllum(FrameBufferObject *fbo); 84 void SmoothSsao(FrameBufferObject *fbo);85 84 86 85 void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3143 r3148 1 1 #include "../shaderenv.h" 2 3 4 /******************************************/ 5 /* Filter for combining ssao with image */ 6 /******************************************/ 2 7 3 8 … … 15 20 16 21 17 18 19 20 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 21 { 22 float3 x1 = lerp(bl, tl, w.y); 23 float3 x2 = lerp(br, tr, w.y); 24 float3 v = lerp(x1, x2, w.x); 25 26 return v; 27 } 28 29 30 // reconstruct world space position 31 inline float3 ReconstructSamplePos(uniform sampler2D tex, 32 float2 texcoord, 33 float3 bl, float3 br, float3 tl, float3 tr) 34 { 35 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 36 37 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 38 float3 samplePos = -viewVec * eyeSpaceDepth; 39 40 return samplePos; 41 } 42 43 44 float Filter(float2 texCoord, 45 uniform sampler2D ssaoTex, 46 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 47 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 48 float scale) 49 { 50 float average = .0f; 51 float w = .0f; 52 53 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 54 { 55 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 56 w += filterWeights[i]; 57 } 58 59 average *= 1.0f / (float)w; 60 61 return average; 62 } 63 64 //#define USE_POSITION 65 22 /** Filter taking into account depth and normal differences, 23 and convergence of a sample 24 */ 66 25 float DiscontinuityFilter(float2 texCoord, 67 26 float4 ao, … … 72 31 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 73 32 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 74 float scale, 75 float3 bl, 76 float3 br, 77 float3 tl, 78 float3 tr) 33 float scale) 79 34 { 80 35 float average = .0f; 81 36 float total_w = .0f; 82 37 83 #ifdef USE_POSITION84 const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr);85 #else86 38 const float eyeSpaceDepth = color.w; 87 //const float eyeSpaceDepth = ao.w;88 #endif89 39 90 40 const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); … … 109 59 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 110 60 111 #ifdef USE_POSITION 112 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 113 depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f); 114 #else // use depth 61 // check depth discontinuity 115 62 sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w; 116 63 //sampleDepth = aoSample.w; 64 117 65 //depthFactor = max(step(1e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth)), 1e-3f); 118 //depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f);119 //depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f);120 121 66 depthFactor = 1.0f / max(abs(eyeSpaceDepth - sampleDepth), 1e-3f); 122 #endif123 67 //normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-6f); 124 68 normalFactor = max(dot(sampleNorm, centerNormal), 1e-6f); 125 convergenceFactor = min(200.0f, aoSample.y) * 0.01f; //max(step(18.5f, aoSample.y), 1e-3f);69 convergenceFactor = min(200.0f, aoSample.y) * 0.01f; 126 70 127 //w = filterWeights[i] * normalFactor * depthFactor * convergenceFactor; 128 //w = 1000.0f * normalFactor * depthFactor;// * convergenceFactor; 129 //w = normalFactor; 71 // combine the weights 130 72 w = depthFactor * normalFactor * convergenceFactor; 131 //w = filterWeights[i] * normalFactor * converganceFactor;132 //w = filterWeights[i] * normalFactor * depthFactor;133 //w = convergenceFactor;134 73 135 74 average += aoSample.x * w; 136 //average += aoSample.x;137 75 total_w += w; 138 76 } 139 77 140 78 average /= max(total_w, 1e-1f); 141 //average /= NUM_SSAO_FILTERSAMPLES;142 79 143 80 return saturate(average ); 144 81 } 145 82 146 83 /** Function combining image and indirect illumination buffer using a 84 depth and normal aware discontinuity filter. 85 */ 147 86 pixel combine(fragment IN, 148 87 uniform sampler2D colorsTex, … … 152 91 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 153 92 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 154 uniform float3 bl, 155 uniform float3 br, 156 uniform float3 tl, 157 uniform float3 tr) 93 ) 158 94 { 159 95 pixel OUT; … … 167 103 const float scaleFactor = 1.0f; 168 104 const float adaptFactor = 10.0f; 169 //const float adaptFactor = 500000.0f; 170 171 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 172 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 173 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z / (adaptFactor + ao.y), 0); 174 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor / (adaptFactor + ao.y), 0); 175 105 176 106 const float scale = adaptFactor * scaleFactor * ao.z / (adaptFactor + ao.y); 177 //const float scale = scaleFactor * ao.z; 178 179 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale, bl, br, tl, tr); 180 //if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr); 181 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 107 108 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale); 182 109 } 183 110 184 //float dummy = clamp(1.0f - ao.y * 1e-2f, 0, 1);185 //float dummy2 = ao.y < 1.5f ? 1.0f : .0f;186 111 OUT.illum_col.xyz = col.xyz * ao.x; 187 112 188 // if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0);189 // else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000);190 // else191 // if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0);192 //OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w);193 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);194 195 //OUT.illum_col.xyz = float3(1.0f - ao.x, dummy2, 0);//dummy2);196 113 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 197 114 OUT.illum_col.w = col.w; … … 199 116 return OUT; 200 117 } 201 202 203 float DiscontinuityFilter2(float2 texCoord,204 float4 ao,205 uniform sampler2D ssaoTex,206 uniform sampler2D normalsTex,207 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],208 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],209 float scale210 )211 {212 float average = .0f;213 float total_w = .0f;214 215 const float eyeSpaceDepth = ao.w;216 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);217 218 float4 aoSample;219 float3 sampleNorm;220 float w;221 float4 offs;222 float depthFactor;223 float normalFactor;224 225 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)226 {227 offs = float4(texCoord + filterOffs[i] * scale, 0, 0);228 aoSample = tex2Dlod(ssaoTex, offs);229 230 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz);231 232 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f);233 //depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);234 //normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);235 w = filterWeights[i];236 //w = filterWeights[i] * normalFactor * depthFactor;237 //w = normalFactor * depthFactor;238 //w = depthFactor;239 240 average += aoSample.y * w;241 total_w += w;242 }243 244 average *= 1.0f / max(total_w, 1e-3f);245 246 return average;247 }248 249 pixel smoothSsao(fragment IN,250 uniform sampler2D ssaoTex,251 uniform sampler2D normalsTex,252 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],253 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]254 )255 {256 pixel OUT;257 258 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));259 //ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 0.1f);260 261 OUT.illum_col = ao;262 263 return OUT;264 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3137 r3148 35 35 // the rgb weights 36 36 const float3 w = float3(0.299f, 0.587f, 0.114f); 37 // float3 w = float3(0.2125f, 0.7154f, 0.0721f);37 //const float3 w = float3(0.2125f, 0.7154f, 0.0721f); 38 38 39 39 float4 color;
Note: See TracChangeset
for help on using the changeset viewer.