Changeset 3198 for GTP/trunk/App
- Timestamp:
- 11/30/08 20:41:23 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3197 r3198 10 10 #include "Light.h" 11 11 #include "ShaderManager.h" 12 #include <math.h> 12 13 13 14 #include <IL/il.h> … … 41 42 assert(ilGetError() == IL_NO_ERROR); 42 43 } 44 43 45 44 46 namespace CHCDemoEngine … … 111 113 fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg); 112 114 } 115 } 116 117 118 static Sample2 UnitTest2(float x, float y, int wi, int he) 119 { 120 Sample2 s; 121 122 s.x = float(floor(x * (float)wi - 0.5f) + 1.0f) / (float)wi; 123 s.y = float(floor(y * (float)he - 0.5f) + 1.0f) / (float)he; 124 125 return s; 113 126 } 114 127 … … 309 322 310 323 /////////////// 311 //-- the downsampled ssao + color bleeding textures: as gi is inherently low frequency, we can use these toimprove performance324 //-- the downsampled ssao + color bleeding textures: as GI is mostly low frequency, we can use lower resolution toimprove performance 312 325 313 326 mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 314 //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);315 327 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 316 // downsample buffer for the normal texture 317 //mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 318 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 319 // downsample buffer for the offset texture 320 //mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 321 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 322 323 for (int i = 0; i < 3; ++ i) 324 { 325 FrameBufferObject::InitBuffer(mDownSampleFbo, i); 326 } 328 329 FrameBufferObject::InitBuffer(mDownSampleFbo, 0); 327 330 328 331 mFBOs.push_back(mDownSampleFbo); … … 343 346 344 347 InitCg(); 348 349 float x = 400.5f / w; 350 float y = 100.5f / h; 351 352 Sample2 res = UnitTest2(x, y, dsw, dsh); 353 354 cout << "input : " << x << ", " << y << endl; 355 cout << "result : " << res.x << " " << res.y << endl; 356 cout << "result2: " << res.x * w << " " << res.y * h << endl; 345 357 } 346 358 … … 447 459 448 460 string prepareSsaoParams[] = 449 {"colorsTex", " normalsTex", "diffVals", "oldTex",461 {"colorsTex", "diffVals", "oldTex", 450 462 "oldEyePos", "modelViewProj", "oldModelViewProj", 451 463 "oldbl", "oldbr", "oldtl", "oldtr"}; 452 464 453 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 1 1);465 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 454 466 455 467 … … 634 646 635 647 if (0) 636 {637 648 colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 638 normalsTex = fbo->GetColorBuffer(1)->GetTexture();639 attribsTex = fbo->GetColorBuffer(2)->GetTexture();640 }641 649 else 642 {643 650 colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture(); 644 normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 645 attribsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 646 //attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 647 } 651 652 normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 653 attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 648 654 649 655 // flip flop between illumination buffers … … 1017 1023 void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 1018 1024 { 1019 GLuint colorsTex, normalsTex, diffVals, oldTex; 1020 1021 colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1022 normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1023 diffVals = fbo->GetColorBuffer(2)->GetTexture(); 1024 1025 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1026 GLuint diffVals = fbo->GetColorBuffer(2)->GetTexture(); 1025 1027 // flip flop between illumination buffers 1026 oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();1028 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 1027 1029 1028 1030 int i = 0; 1029 1031 1030 1032 sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 1031 sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex);1032 1033 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 1033 1034 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); … … 1051 1052 mDownSampleFbo->Bind(); 1052 1053 1053 glDrawBuffers( 3, mrt + 0);1054 glDrawBuffers(1, mrt); 1054 1055 1055 1056 DrawQuad(sCgPrepareSsaoProgram); … … 1189 1190 } 1190 1191 1191 1192 1192 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3196 r3198 6 6 //-- ssao + gi parameters 7 7 8 //#define NUM_SAMPLES 88 #define NUM_SAMPLES 8 9 9 //#define NUM_SAMPLES 16 10 #define NUM_SAMPLES 2410 //#define NUM_SAMPLES 24 11 11 12 // for quadratic falloff 13 //#define SAMPLE_INTENSITY 0.9f 14 //#define SAMPLE_INTENSITY 2.0f 15 16 //#define SAMPLE_INTENSITY 0.075f 17 #define SAMPLE_INTENSITY 0.2f 12 #define SAMPLE_INTENSITY 0.5f 13 //#define SAMPLE_INTENSITY 1.0f 18 14 19 15 #define SAMPLE_RADIUS 8e-1f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r3189 r3198 47 47 // weight the influence of normal discontinuities 48 48 //const float ne = saturate(dot(nd, weights.x)); 49 const float ne = nd.x * nd.y * nd.z * nd.w * weights.x;49 const float ne = nd.x * nd.y * nd.z * nd.w * weights.x; 50 50 51 51 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3197 r3198 122 122 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 123 123 { 124 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0);124 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, .0f, .0f); 125 125 126 126 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); … … 128 128 129 129 // check spatial discontinuity 130 // using the depth from the color texture is not 100% correct as depth was 130 131 // note: using the depth from the color texture is not 100% correct as depth was 131 132 // not scaled with the interpolated view vector depth yet ... 132 133 samplePos = ReconstructSamplePos(colorsTex, sampleTexCoord.xy, bl, br, tl, tr); … … 134 135 135 136 len = min(SqrLen(centerPos - samplePos), 1e2f); 136 137 137 spatialFactor = 1.0f / max(len, 1e-3f); 138 138 139 139 //normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-2f); 140 //normalFactor = max(dot(sampleNorm, samplePos), 1e-3f);141 140 convergenceFactor = aoSample.y + 1.0f; 142 //convergenceFactor = max(step(0.5f + NUM_SAMPLES, aoSample.y), 1e-2f); 143 //convergenceFactor = aoSample.y; 144 141 145 142 // combine the weights 146 143 w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor; 147 //w = spatialFactor * normalFactor; 148 144 149 145 average += aoSample.x * w; 150 146 total_w += w; … … 178 174 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 179 175 180 float4 dummy; 181 //const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f; 182 const float xoffs = 1.0f / 1024.0f; const float yoffs = 1.0f / 768.0f; 183 184 dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, yoffs), 0, 0)).w; 185 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, -yoffs), 0, 0)).w; 186 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, yoffs), 0, 0)).w; 187 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-yoffs, -yoffs), 0, 0)).w; 188 189 /*dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y; 190 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y; 191 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y; 192 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y; 193 */ 194 const float convergence = min(min(dummy.x, dummy.y), min(dummy.z, dummy.w)); 195 //const float convergence = max(max(dummy.x, dummy.y), max(dummy.z, dummy.w)); 176 // get the minimum convergence by exactly sampling the 4 surrounding 177 // texels in the old texture, otherwise flickering because convergence 178 // will be interpolated when upsampling and filter size does not match! 179 float4 texelCenterConv; 180 const float w = 512.0f; const float h = 384.0f; 181 const float xoffs = .5f / w; const float yoffs = .5f / h; 182 183 // get position exactly between old texel centers 184 float2 center; 185 center.x = float(floor(IN.texCoord.x * w - .5f) + 1.0f) / w; 186 center.y = float(floor(IN.texCoord.y * h - .5f) + 1.0f) / h; 187 188 texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2(xoffs, yoffs), 0, 0)).y; 189 texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2(xoffs, -yoffs), 0, 0)).y; 190 texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 191 texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 192 193 const float m1 = min(texelCenterConv.x, texelCenterConv.y); 194 const float m2 = min(texelCenterConv.z, texelCenterConv.w); 195 196 const float convergence = min(m1, m2); 196 197 //const float convergence = ao.y; 197 198 … … 201 202 // filter up to a certain convergance value and leave out background (sky) by checking depth 202 203 if ((convergence < thres) && (col.w < 1e10f)) 203 //if (col.w < 1e10f)204 204 { 205 //const float eyeSpaceDepth = col.w; const float distanceScaleWeight = 2.0f;206 //const float distanceScale = distanceScaleWeight / (eyeSpaceDepth + distanceScaleWeight);207 205 const float distanceScale = 1.0f; 208 206 209 207 const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f); 210 208 const float convergenceScale = convergenceWeight / (convergence + convergenceWeight); 211 212 209 const float scale = SSAO_FILTER_WIDTH * convergenceScale * distanceScale; 213 210 214 211 // the filtered ssao value 215 //ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr);212 ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 216 213 } 217 214 … … 221 218 OUT.illum_col.xyz = col.xyz; 222 219 223 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 224 //const float mydummy = ao.w * 1e-3f; 225 OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 220 //OUT.illum_col.xyz = float3(ao.x, ao.x, step(thres, convergence)); 221 //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 226 222 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 227 223 //OUT.illum_col.xyz = float3(0, 1.0f - step(0.5f + NUM_SAMPLES, convergence), 1); … … 230 226 return OUT; 231 227 } 228 229 230 231 /** Function combining image and indirect illumination buffer using a 232 depth and normal aware discontinuity filter. 233 */ 234 pixel SmoothSsao(fragment IN, 235 uniform sampler2D ssaoTex) 236 { 237 pixel OUT; 238 239 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 240 241 float4 dummy; 242 const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f; 243 244 // get positions exactly between old texel centers 245 dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y; 246 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y; 247 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y; 248 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y; 249 250 const float m1 = min(dummy.x, dummy.y); 251 const float m2 = min(dummy.z, dummy.w); 252 253 ao.y = min(ao.y, min(m1, m2)); 254 255 return OUT; 256 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3197 r3198 203 203 inline float PixelValid(sampler2D oldTex, 204 204 float4 color, 205 float3 dif fVec,205 float3 difVec, 206 206 float2 texCoord, 207 207 float3 viewDir, … … 229 229 230 230 // compute position from old frame for dynamic objects + translational portion 231 const float3 translatedPos = dif fVec - oldEyePos + worldPos.xyz;231 const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 232 232 233 233 … … 254 254 255 255 const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 256 const float squaredLen = SqrLen(dif fVec);256 const float squaredLen = SqrLen(difVec); 257 257 258 258 // test if this pixel was not valid in the old frame … … 280 280 281 281 282 pixelPrepareSsao(fragment IN,282 float4 PrepareSsao(fragment IN, 283 283 uniform sampler2D colorsTex, 284 uniform sampler2D normalsTex,285 284 uniform sampler2D diffVals, 286 285 uniform sampler2D oldTex, … … 292 291 uniform float3 oldtr, 293 292 uniform float3 oldEyePos 294 ) 293 ): COLOR0 295 294 { 296 pixel pix;297 298 const float3 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0 ,0)).xyz;299 300 const float3 viewDir = IN.view;301 295 float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 302 303 304 /*float4 dummy;305 const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f;306 //const float xoffs = 1.0f / 1024.0f; const float yoffs = 1.0f / 768.0f;307 308 dummy.x = tex2Dlod(colorsTex, float4(IN.texCoord + float2(xoffs, yoffs), 0, 0)).w;309 dummy.y = tex2Dlod(colorsTex, float4(IN.texCoord + float2(xoffs, -yoffs), 0, 0)).w;310 dummy.z = tex2Dlod(colorsTex, float4(IN.texCoord + float2(-xoffs, yoffs), 0, 0)).w;311 dummy.w = tex2Dlod(colorsTex, float4(IN.texCoord + float2(-yoffs, -yoffs), 0, 0)).w;312 color.w = min(min(dummy.x, dummy.y), min(dummy.z, dummy.w));313 //color.w = max(max(dummy.x, dummy.y), max(dummy.z, dummy.w));314 */315 316 //const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz);317 318 float3 dummy[4];319 const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f;320 //const float xoffs = 1.0f / 1024.0f; const float yoffs = 1.0f / 768.0f;321 322 dummy[0] = tex2Dlod(normalsTex, float4(IN.texCoord + float2(xoffs, yoffs), 0, 0)).xyz;323 dummy[1] = tex2Dlod(normalsTex, float4(IN.texCoord + float2(xoffs, -yoffs), 0, 0)).xyz;324 dummy[2] = tex2Dlod(normalsTex, float4(IN.texCoord + float2(-xoffs, yoffs), 0, 0)).xyz;325 dummy[3] = tex2Dlod(normalsTex, float4(IN.texCoord + float2(-yoffs, -yoffs), 0, 0)).xyz;326 327 float dot1 = dot(dummy[0], dummy[3]);328 float dot2 = dot(dummy[1], dummy[2]);329 330 float isEdge = step(.0f, dot1) * step(.0f, dot2);331 332 const float3 normal = isEdge * normalize(dummy[0] + dummy[1] + dummy[2] + dummy[3]);333 334 296 // store scaled view vector so wie don't have to normalize for e.g., ssao 335 297 color.w /= length(IN.view); 298 299 const float4 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0, 0)); 336 300 337 301 // do reprojection and filter out the pixels that are not save … … 340 304 difVec.xyz, 341 305 IN.texCoord, 342 viewDir,306 IN.view, 343 307 oldEyePos, 344 308 modelViewProj, … … 347 311 ); 348 312 349 pix.color = color; 350 pix.color.x = pValid; 351 352 pix.normal = normal; 353 pix.diffVal = difVec; 354 355 return pix; 313 color.x = pValid; 314 315 return color; 356 316 } 357 317 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
r3195 r3198 127 127 //const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz * 2.0f - float3(1.0f); 128 128 const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz; 129 pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);130 //pix.normal = tangentSpaceNorm;129 //pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm); 130 pix.normal = normalize(mul(tangToWorldTrafo, tangentSpaceNorm)); 131 131 132 132 return pix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3197 r3198 292 292 float3 dirSample = samplePos - centerPosition; 293 293 294 const float sqrLen = max(SqrLen(dirSample), 1e-3f); 295 //const float lengthToSample = max(length(dirSample), 1e-2f); 294 const float sqrLen = max(SqrLen(dirSample), 1e-2f); 296 295 const float lengthToSample = sqrt(sqrLen); 297 296 … … 395 394 396 395 // cull background note: this should be done with the stencil buffer 396 //if (SqrLen(diffVec < 1e6f) && (eyeSpaceDepth < 1e10f)) 397 397 if (eyeSpaceDepth < 1e10f) 398 398 { … … 402 402 else 403 403 { 404 ao = float3(1.0f, .0f,.0f);404 ao = float3(1.0f, 1.0f, 1.0f); 405 405 } 406 406 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3149 r3198 99 99 float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 100 100 101 float newImageKey = max(exp(logLum), 1e- 6f);101 float newImageKey = max(exp(logLum), 1e-3f); 102 102 103 103 // adjust to middle gray -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
r3168 r3198 103 103 // hack: no translational component anyway 104 104 OUT.oldWorldPos = oldOffs; 105 //OUT.oldWorldPos = float4(1e20f, 1e20f, 1e20f, oldOffs.w); 105 106 OUT.worldPos = offs; 106 107 107 108 return OUT; 108 109 } 110 111 /* 112 113 pixel fragtex(fragin IN, 114 uniform sampler2D tex: TEXUNIT0, 115 uniform float4x4 viewMatrix 116 ) 117 { 118 float4 texColor = tex2D(tex, IN.texCoord.xy); 119 120 // account for alpha blending 121 if (texColor.w < 0.5f) discard; 122 123 pixel pix; 124 125 // save color in first render target 126 // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 127 pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 128 // save world space normal in rt => transform back into world space by 129 // multiplying with inverse view. since transforming normal with T means to 130 // multiply with the inverse transpose of T, we multiple with 131 // Transp(Inv(Inv(view))) = Transp(view) 132 pix.norm = normalize(mul(transpose(viewMatrix), IN.normal).xyz); 133 //pix.norm = IN.normal.xyz; 134 // compute eye linear depth 135 pix.col.w = 1e20f;//length(IN.eyePos.xyz); 136 137 // the scene entity id 138 //pix.id = glstate.fog.color.xyz; 139 // the offset to the world pos from old frame 140 pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; 141 142 return pix; 143 }*/
Note: See TracChangeset
for help on using the changeset viewer.