Changeset 3325
- Timestamp:
- 02/23/09 13:24:44 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3324 r3325 549 549 550 550 string prepareSsaoParams[] = 551 {"colorsTex", "normalsTex", "diffVals", "oldTex", 551 {"colorsTex", "normalsTex", "diffVals", "oldTex", "oldTex2", 552 552 "oldEyePos", "modelViewProj", "oldModelViewProj", 553 553 "oldbl", "oldbr", "oldtl", "oldtr"}; 554 554 555 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 1 1);555 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 12); 556 556 557 557 … … 770 770 attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 771 771 772 // flip flop between illumination buffers 773 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 772 773 ///////// 774 //-- flip flop between illumination buffers 775 776 GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 774 777 775 778 glPushAttrib(GL_VIEWPORT_BIT); … … 778 781 // read the second buffer, write to the first buffer 779 782 mIllumFbo->Bind(); 780 glDrawBuffers( 1, mrt + mIllumFboIndex);783 glDrawBuffers(2, mrt + mIllumFboIndex); 781 784 782 785 int i = 0; … … 784 787 sCgSsaoProgram->SetTexture(i ++, colorsTex); 785 788 sCgSsaoProgram->SetTexture(i ++, normalsTex); 786 sCgSsaoProgram->SetTexture(i ++, old Tex);789 sCgSsaoProgram->SetTexture(i ++, oldSsaoTex); 787 790 sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 788 791 789 792 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 790 793 794 791 795 if (/*mUseTemporalCoherence || */mRegenerateSamples) 792 796 { … … 1166 1170 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1167 1171 GLuint diffVals = fbo->GetColorBuffer(2)->GetTexture(); 1172 1168 1173 // flip flop between illumination buffers 1169 1174 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 1175 GLuint oldTex2 = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 1170 1176 1171 1177 int i = 0; … … 1175 1181 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 1176 1182 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 1183 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex2); 1177 1184 1178 1185 Vector3 de; … … 1187 1194 1188 1195 for (int j = 0; j < 4; ++ j, ++ i) 1196 { 1189 1197 sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 1198 } 1190 1199 1191 1200 glPushAttrib(GL_VIEWPORT_BIT); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3321 r3325 657 657 Matrix4x4 transl = TranslationMatrix(positions[0]); 658 658 659 //LoadModel("hbuddha.dem", dynamicObjects);660 LoadModel("venusm.dem", dynamicObjects);659 LoadModel("hbuddha.dem", dynamicObjects); 660 //LoadModel("venusm.dem", dynamicObjects); 661 661 662 662 buddha = dynamicObjects.back(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3324 r3325 9 9 //#define NUM_SAMPLES 16 10 10 //#define NUM_SAMPLES 24 11 #define NUM_SAMPLES 4811 #define NUM_SAMPLES 8 12 12 13 13 //#define MIN_SAMPLES 48 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3324 r3325 38 38 39 39 // hack: prevent shading the sky 40 if (color.w > 1e19f) outColor = color; 41 else outColor = (ambient + diffuse) * color; 40 if (color.w > DEPTH_THRESHOLD) 41 { 42 outColor = color; 43 } 44 else 45 { 46 outColor = (ambient + diffuse) * color; 47 } 42 48 43 49 return outColor; … … 203 209 */ 204 210 inline float2 PixelValid(sampler2D oldTex, 205 float4 color, 206 float3 difVec, 207 float2 texCoord, 208 float3 viewDir, 209 float3 oldEyePos, 210 float4x4 modelViewProj, 211 float4x4 oldModelViewProj, 212 float3 oldbl, 213 float3 oldbr, 214 float3 oldtl, 215 float3 oldtr 216 ) 211 sampler2D oldTex2, 212 float4 color, 213 float3 difVec, 214 float2 texCoord, 215 float3 viewDir, 216 float3 oldEyePos, 217 float4x4 modelViewProj, 218 float4x4 oldModelViewProj, 219 float3 oldbl, 220 float3 oldbr, 221 float3 oldtl, 222 float3 oldtr 223 ) 217 224 { 218 225 // reconstruct position from the eye space depth … … 220 227 const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 221 228 222 223 229 224 230 //////////////// … … 247 253 // retrieve the sample from the last frame 248 254 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 255 const float4 oldPixel2 = tex2Dlod(oldTex2, float4(oldTexCoords, .0f, .0f)); 249 256 250 257 // calculate eye space position of sample in old frame … … 260 267 261 268 // test if this pixel was valid in the old frame 262 float IsPixelValid;263 264 // check if the pixel belonged to a dy anmic object in the last frame265 const bool oldDynamic = false;(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);266 const bool newDynamic = false; (oldPixel.z> DYNAMIC_OBJECTS_THRESHOLD);269 float isPixelValid; 270 271 // check if the pixel belonged to a dynamic object in the last frame 272 const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 273 const bool oldDynamic = (oldPixel2.x > DYNAMIC_OBJECTS_THRESHOLD); 267 274 268 275 // actually 0 means pixel is valid … … 279 286 ) 280 287 { 281 IsPixelValid = pixelIsNotValid;288 isPixelValid = pixelIsNotValid; 282 289 } 283 290 else if (// check if changed from dynamic to not dynamic object … … 287 294 // check if we have a dynamic object 288 295 (oldDynamic || newDynamic) && 289 // and is a depth discontinuity296 // and there is a depth discontinuity 290 297 (depthDif > MIN_DEPTH_DIFF)))) 291 298 { 292 IsPixelValid = pixelCouldBeValid;299 isPixelValid = pixelCouldBeValid; 293 300 } 294 301 else 295 302 { 296 IsPixelValid = pixelIsValid;297 } 298 299 return float2( IsPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));303 isPixelValid = pixelIsValid; 304 } 305 306 return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 300 307 } 301 308 … … 309 316 uniform sampler2D diffVals, 310 317 uniform sampler2D oldTex, 318 uniform sampler2D oldTex2, 311 319 uniform float4x4 modelViewProj, 312 320 uniform float4x4 oldModelViewProj, … … 319 327 { 320 328 pixel pix; 329 321 330 float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 322 331 // store scaled view vector so wie don't have to normalize for e.g., ssao … … 329 338 // do reprojection and filter out the pixels that are not save 330 339 float2 pValid = PixelValid(oldTex, 331 color, 332 difVec.xyz, 333 IN.texCoord, 334 IN.view, 335 oldEyePos, 336 modelViewProj, 337 oldModelViewProj, 338 oldbl, oldbr, oldtl, oldtr 339 ); 340 oldTex2, 341 color, 342 difVec.xyz, 343 IN.texCoord, 344 IN.view, 345 oldEyePos, 346 modelViewProj, 347 oldModelViewProj, 348 oldbl, oldbr, oldtl, oldtr 349 ); 340 350 341 351 pix.color = color; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3324 r3325 17 17 18 18 19 struct pixel19 /*struct pixel 20 20 { 21 21 float4 illum_col: COLOR0; 22 22 }; 23 */ 24 25 struct pixel2 26 { 27 float4 illum_col: COLOR0; 28 float4 col: COLOR1; 29 }; 30 23 31 24 32 // this function is inspired from the paper of shamulgaan in order … … 125 133 // the weight of the accumulated samples from the previous frames 126 134 float w; 127 128 float idx = oldPixel.z; 135 float idx; 129 136 130 137 ////////////// … … 147 154 //w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 148 155 w = oldPixel.y; 156 idx = floor(oldPixel.z); 157 149 158 } 150 159 else 151 160 { 152 161 w = 0.0f; 162 idx = .0f; 153 163 } 154 164 … … 182 192 bool isMovingObject, 183 193 sampler2D normalTex, 184 int idx194 float idx 185 195 ) 186 196 { … … 200 210 //-- (affects performance for some reason!) 201 211 202 if ( convergence < SSAO_CONVERGENCE_THRESHOLD)212 if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD) 203 213 { 204 214 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; … … 444 454 /** The mrt shader for screen space ambient occlusion 445 455 */ 446 pixel main(fragment IN,447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 { 469 pixel OUT;456 pixel2 main(fragment IN, 457 uniform sampler2D colors, 458 uniform sampler2D normals, 459 uniform sampler2D noiseTex, 460 uniform sampler2D samples, 461 uniform sampler2D oldTex, 462 uniform float4x4 modelViewProj, 463 uniform float4x4 oldModelViewProj, 464 uniform float temporalCoherence, 465 uniform float3 bl, 466 uniform float3 br, 467 uniform float3 tl, 468 uniform float3 tr, 469 uniform float3 oldEyePos, 470 uniform float3 oldbl, 471 uniform float3 oldbr, 472 uniform float3 oldtl, 473 uniform float3 oldtr, 474 uniform sampler2D attribsTex, 475 uniform float kernelRadius, 476 uniform float sampleIntensity 477 ) 478 { 479 pixel2 OUT; 470 480 471 481 //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); … … 515 525 //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 516 526 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 517 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity);518 527 } 519 528 else … … 535 544 const float partlyResetThres = 1.0f; 536 545 546 // don't check for moving objects, otherwise almost no coherence 537 547 if (!isMovingObject) 538 548 { 539 549 if (ao.y > completelyResetThres) 540 550 { 551 oldWeight = .0f; 552 oldIdx = .0f; 553 } 554 else if (ao.y > partlyResetThres) 555 { 556 //oldWeight = min(oldWeight, 4.0f * newWeight); 541 557 oldWeight = .0f; 542 } 543 else if (ao.y > partlyResetThres) 544 { 545 oldWeight = min(oldWeight, 4.0f * newWeight); 546 //oldWeight = .0f; 558 oldIdx = .0f; 547 559 } 548 560 } … … 551 563 //-- blend ao between old and new samples (and avoid division by zero) 552 564 553 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 554 565 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight); 555 566 OUT.illum_col.x /= (newWeight + oldWeight); 556 567 … … 559 570 560 571 OUT.illum_col.y = combinedWeight; 572 OUT.illum_col.z = oldIdx + newWeight; // the new index 573 OUT.illum_col.w = eyeSpaceDepth; 574 561 575 // can be used to check if this pixel belongs to a moving object 576 OUT.col.x = SqrLen(diffVec); 562 577 //OUT.illum_col.z = SqrLen(diffVec); 563 OUT.illum_col.z = oldIdx + newWeight; 564 OUT.illum_col.w = eyeSpaceDepth; 565 566 //OUT.illum_col.yzw = diffVec; 567 578 568 579 return OUT; 569 580 }
Note: See TracChangeset
for help on using the changeset viewer.