Changeset 3085 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 10/31/08 17:35:42 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3084 r3085 71 71 72 72 73 /** Helper method that computes the view vectors in the corners of the current view frustum. 74 */ 75 static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr) 76 { 77 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 78 79 cam->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 80 81 bl = Normalize(nbl - fbl); 82 br = Normalize(nbr - fbr); 83 tl = Normalize(ntl - ftl); 84 tr = Normalize(ntr - ftr); 85 } 86 73 87 74 88 static float GaussianDistribution(float x, float y, float rho) … … 127 141 void DeferredRenderer::DrawQuad(ShaderProgram *p) 128 142 { 129 Vector3 tl, tr, bl, br;130 ComputeViewVectors(tl, tr, bl, br);131 132 143 p->Bind(); 144 145 Vector3 bl = mCornersView[0]; 146 Vector3 br = mCornersView[1]; 147 Vector3 tl = mCornersView[2]; 148 Vector3 tr = mCornersView[3]; 133 149 134 150 // note: slightly larger texture could hide ambient occlusion error on border but costs resolution … … 258 274 CreateNoiseTex2D(mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 259 275 276 mProjViewMatrix = IdentityMatrix(); 277 mOldProjViewMatrix = IdentityMatrix(); 278 279 for (int i = 0; i < 4; ++ i) 280 { 281 mCornersView[i] = mOldCornersView[i] = Vector3::UNIT_X(); 282 } 283 284 mEyePos = mOldEyePos = Vector3::ZERO(); 285 260 286 InitCg(); 261 287 } … … 308 334 sCgSsaoProgram->AddParameter("oldModelViewProj", i ++); 309 335 336 sCgSsaoProgram->AddParameter("oldEyePos", i ++); 337 sCgSsaoProgram->AddParameter("oldbl", i ++); 338 sCgSsaoProgram->AddParameter("oldbr", i ++); 339 sCgSsaoProgram->AddParameter("oldtl", i ++); 340 sCgSsaoProgram->AddParameter("oldtr", i ++); 341 310 342 i = 0; 311 343 sCgGiProgram->AddParameter("colors", i ++); … … 379 411 380 412 void DeferredRenderer::Render(FrameBufferObject *fbo, 381 const Matrix4x4 &oldProjViewMatrix,382 const Matrix4x4 &projViewMatrix,383 413 float tempCohFactor, 384 414 DirectionalLight *light, … … 387 417 ) 388 418 { 419 InitFrame(); 420 389 421 // switch roles of old and new fbo 390 422 // the algorihm uses two input fbos, where the one … … 429 461 DownSample(fbo, 1, mDownSampleFbo, 1); 430 462 431 ComputeSsao(fbo, tempCohFactor , projViewMatrix, oldProjViewMatrix);463 ComputeSsao(fbo, tempCohFactor); 432 464 CombineSsao(fbo); 433 465 break; … … 437 469 DownSample(fbo, 1, mDownSampleFbo, 1); 438 470 439 ComputeGlobIllum(fbo, tempCohFactor , projViewMatrix, oldProjViewMatrix);471 ComputeGlobIllum(fbo, tempCohFactor); 440 472 CombineIllum(fbo); 441 473 break; … … 472 504 473 505 void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 474 float tempCohFactor, 475 const Matrix4x4 &projViewMatrix, 476 const Matrix4x4 &oldProjViewMatrix 506 float tempCohFactor 507 477 508 ) 478 509 { … … 499 530 sCgSsaoProgram->SetTexture(3, noiseTex); 500 531 501 const Vector3 pos = mCamera->GetPosition(); 502 sCgSsaoProgram->SetValue3f(4, pos.x, pos.y, pos.z); 532 sCgSsaoProgram->SetValue3f(4, mEyePos.x, mEyePos.y, mEyePos.z); 503 533 504 534 sCgSsaoProgram->SetValue1f(5, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); … … 514 544 sCgSsaoProgram->SetArray2f(6, (float *)samples2, NUM_SAMPLES); 515 545 } 516 517 Vector3 tl, tr, bl, br; 518 ComputeViewVectors(tl, tr, bl, br); 546 547 Vector3 bl = mCornersView[0]; 548 Vector3 br = mCornersView[1]; 549 Vector3 tl = mCornersView[2]; 550 Vector3 tr = mCornersView[3]; 519 551 520 552 sCgSsaoProgram->SetValue3f(7, bl.x, bl.y, bl.z); … … 526 558 //cout << "old projview:\n" << oldProjViewMatrix << endl; 527 559 528 sCgSsaoProgram->SetMatrix(11, projViewMatrix); 529 sCgSsaoProgram->SetMatrix(12, oldProjViewMatrix); 560 sCgSsaoProgram->SetMatrix(11, mProjViewMatrix); 561 sCgSsaoProgram->SetMatrix(12, mOldProjViewMatrix); 562 563 bl = mOldCornersView[0]; 564 br = mOldCornersView[1]; 565 tl = mOldCornersView[2]; 566 tr = mOldCornersView[3]; 567 568 sCgSsaoProgram->SetValue3f(13, mOldEyePos.x, mOldEyePos.y, mOldEyePos.z); 569 sCgSsaoProgram->SetValue3f(14, bl.x, bl.y, bl.z); 570 sCgSsaoProgram->SetValue3f(15, br.x, br.y, br.z); 571 sCgSsaoProgram->SetValue3f(16, tl.x, tl.y, tl.z); 572 sCgSsaoProgram->SetValue3f(17, tr.x, tr.y, tr.z); 530 573 531 574 … … 535 578 536 579 PrintGLerror("ssao first pass"); 537 }538 539 540 void DeferredRenderer::ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br)541 {542 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;543 544 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr);545 546 bl = Normalize(nbl - fbl);547 br = Normalize(nbr - fbr);548 tl = Normalize(ntl - ftl);549 tr = Normalize(ntr - ftr);550 580 } 551 581 … … 622 652 623 653 void DeferredRenderer::ComputeGlobIllum(FrameBufferObject *fbo, 624 float tempCohFactor, 625 const Matrix4x4 &projViewMatrix, 626 const Matrix4x4 &oldProjViewMatrix) 654 float tempCohFactor) 627 655 { 628 656 #if 0 … … 652 680 sCgGiProgram->SetTexture(4, oldIllumTex); 653 681 654 const Vector3 pos = mCamera->GetPosition(); 655 sCgGiProgram->SetValue3f(5, pos.x, pos.y, pos.z); 682 sCgGiProgram->SetValue3f(5, mEyePos.x, mEyePos.y, mEyePos.z); 656 683 657 684 … … 671 698 } 672 699 673 674 Vector3 tl, tr, bl, br; 675 ComputeViewVectors(tl, tr, bl, br); 676 700 Vector3 bl = mCornersView[0]; 701 Vector3 br = mCornersView[1]; 702 Vector3 tl = mCornersView[2]; 703 Vector3 tr = mCornersView[3]; 704 677 705 sCgGiProgram->SetValue3f(8, bl.x, bl.y, bl.z); 678 706 sCgGiProgram->SetValue3f(9, br.x, br.y, br.z); … … 680 708 sCgGiProgram->SetValue3f(11, tr.x, tr.y, tr.z); 681 709 682 sCgGiProgram->SetMatrix(12, oldProjViewMatrix);683 sCgGiProgram->SetMatrix(13, projViewMatrix);710 sCgGiProgram->SetMatrix(12, mOldProjViewMatrix); 711 sCgGiProgram->SetMatrix(13, mProjViewMatrix); 684 712 685 713 … … 792 820 sCgDeferredShadowProgram->SetValue3f(6, lightDir.x, lightDir.y, lightDir.z); 793 821 794 const Vector3 pos = mCamera->GetPosition(); 795 sCgDeferredShadowProgram->SetValue3f(7, pos.x, pos.y, pos.z); 822 sCgDeferredShadowProgram->SetValue3f(7, mEyePos.x, mEyePos.y, mEyePos.z); 796 823 797 824 DrawQuad(sCgDeferredShadowProgram); … … 972 999 973 1000 1001 void DeferredRenderer::InitFrame() 1002 { 1003 mOldProjViewMatrix = mProjViewMatrix; 1004 1005 Matrix4x4 matViewing, matProjection; 1006 1007 mCamera->GetModelViewMatrix(matViewing); 1008 mCamera->GetProjectionMatrix(matProjection); 1009 1010 mProjViewMatrix = matViewing * matProjection; 1011 1012 for (int i = 0; i < 4; ++ i) 1013 { 1014 mOldCornersView[i] = mCornersView[i]; 1015 } 1016 1017 ComputeViewVectors(mCamera, mCornersView[0], mCornersView[1], mCornersView[2], mCornersView[3]); 1018 1019 mOldEyePos = mEyePos; 1020 mEyePos = mCamera->GetPosition(); 1021 } 1022 974 1023 975 1024 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3068 r3085 3 3 4 4 #include "common.h" 5 #include "glInterface.h" 6 #include "ShaderProgram.h" 7 8 #include <Cg/cg.h> 9 #include <Cg/cgGL.h> 10 5 #include "Matrix4x4.h" 6 #include "Vector3.h" 11 7 12 8 namespace CHCDemoEngine … … 42 38 43 39 void Render(FrameBufferObject *fbo, 44 const Matrix4x4 &oldProjViewMatrix,45 const Matrix4x4 &projViewMatrix,46 40 float tempCohFactor, 47 41 DirectionalLight *light, … … 69 63 protected: 70 64 71 void ComputeSsao(FrameBufferObject *fbo, 72 float tempCohFactor, 73 const Matrix4x4 &projViewMatrix, 74 const Matrix4x4 &oldProjViewMatrix 75 ); 65 void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor); 76 66 77 void ComputeGlobIllum(FrameBufferObject *fbo, 78 float tempCohFactor, 79 const Matrix4x4 &projViewMatrix, 80 const Matrix4x4 &oldProjViewMatrix); 67 void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor); 81 68 82 69 void FirstPass(FrameBufferObject *fbo, DirectionalLight *light); … … 97 84 98 85 void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); 99 /** Helper method that computes the view vectors in the corners of the current view frustum.100 */101 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);102 103 86 /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the 104 87 resolution of fbo. … … 113 96 */ 114 97 void InitCg(); 98 /** Is called once per render call and sets the most important parameters. 99 */ 100 void InitFrame(); 115 101 116 102 … … 139 125 140 126 static ShaderContainer sShaders; 127 128 Matrix4x4 mProjViewMatrix; 129 Matrix4x4 mOldProjViewMatrix; 130 131 Vector3 mCornersView[4]; 132 Vector3 mOldCornersView[4]; 133 134 Vector3 mEyePos; 135 Vector3 mOldEyePos; 141 136 }; 142 137 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3071 r3085 7 7 #include "Camera.h" 8 8 9 #include "glInterface.h"10 #include <Cg/cg.h>11 #include <Cg/cgGL.h>12 9 13 10 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r3071 r3085 2 2 #define __SCENEENTITY_H 3 3 4 #include "glInterface.h"5 #include <Cg/cg.h>6 #include <Cg/cgGL.h>7 4 #include "common.h" 8 5 #include "AxisAlignedBox3.h" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
r3038 r3085 2 2 #define _SKYPREETHAM_H__ 3 3 4 #include "glInterface.h"5 4 #include "common.h" 6 5 #include "ShaderProgram.h" 7 6 8 #include <Cg/cg.h>9 #include <Cg/cgGL.h>10 7 11 8 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3080 r3085 1065 1065 1066 1066 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1067 ssaoShader->Render(fbo, oldViewProjMat, viewProjMat,ssaoTempCohFactor, light, useHDR, sm);1067 ssaoShader->Render(fbo, ssaoTempCohFactor, light, useHDR, sm); 1068 1068 } 1069 1069 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3084 r3085 42 42 #define MAX_LOD_LEVEL 10 43 43 44 #define MIN_DEPTH_DIFF 1e- 6f45 #define PRECISION_SCALE 1e- 3f44 #define MIN_DEPTH_DIFF 1e-3f 45 #define PRECISION_SCALE 1e-1f 46 46 47 47 // burnout -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3084 r3085 50 50 51 51 // reconstruct world space position 52 inline float3 ReconstructSamplePos(uniform sampler2D colors,52 inline float3 ReconstructSamplePos(uniform sampler2D tex, 53 53 float2 texcoord, 54 54 float3 bl, float3 br, float3 tl, float3 tr) 55 55 { 56 const float eyeSpaceDepth = tex2D( colors, texcoord).w;56 const float eyeSpaceDepth = tex2D(tex, texcoord).w; 57 57 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 58 58 float3 samplePos = -viewVec * eyeSpaceDepth; … … 81 81 uniform float3 tr, 82 82 float2 texcoord0, 83 float3 eyePos 83 float3 eyePos, 84 float eyeSpaceDepth, 85 float3 oldEyePos, 86 uniform float3 oldbl, 87 uniform float3 oldbr, 88 uniform float3 oldtl, 89 uniform float3 oldtr 84 90 ) 85 91 { … … 90 96 91 97 // reproject into old frame and calculate projected depth 92 const float3 dummyPos = ReconstructSamplePos(colors, texcoord0, bl, br, tl, tr) + eyePos; 93 float4 backProjPos = mul(oldModelViewProj, float4(dummyPos, 1.0f)); 94 //float4 backProjPos = mul(oldModelViewProj, worldPos); 95 98 float4 backProjPos = mul(oldModelViewProj, worldPos); 96 99 backProjPos /= backProjPos.w; 97 98 // the current depth projected into the old frame99 const float backProjDepth = backProjPos.z * PRECISION_SCALE;100 100 // fit from unit cube into 0 .. 1 101 const float2 tex = backProjPos.xy * 0.5f + 0.5f; 101 const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 102 102 103 // retrieve the sample from the last frame 103 float4 oldCol = tex2D(oldTex, tex); 104 105 const float oldDepth = oldCol.z; 106 const float depthDif = backProjDepth - oldDepth; 104 float4 oldCol = tex2D(oldTex, oldTexCoords); 105 const float oldEyeSpaceDepth = oldCol.z; 106 107 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 108 //float3 oldSamplePos = -viewVec * eyeSpaceDepth + oldEyePos; 109 float3 oldSamplePos = oldEyePos - viewVec * oldCol.z; 110 111 //const float oldDepth = oldCol.z; 112 const float depthDif = length(oldSamplePos - worldPos.xyz); 107 113 108 114 //const float oldNumSamples = oldCol.y; … … 110 116 float newWeight; 111 117 112 bool isValid = true;118 /*bool isValid = true; 113 119 114 120 for (int i = 0; i < NUM_SAMPLES; ++ i) … … 134 140 135 141 if (abs(dDiff) > 1e-5f) isValid = false; 136 } 142 }*/ 137 143 138 144 // the number of valid samples in this frame … … 140 146 141 147 if ((temporalCoherence > 1e-6f) 142 && ( tex.x >= 0.0f) && (tex.x < 1.0f)143 && ( tex.y >= 0.0f) && (tex.y < 1.0f)148 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 149 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 144 150 && (abs(depthDif) <= MIN_DEPTH_DIFF) 145 151 // if visibility changed in the surrounding area we have to recompute 146 152 //&& (oldNumSamples > 0.8f * newNumSamples) 147 && isValid153 // && isValid 148 154 ) 149 155 { … … 162 168 //illum_col.y = isValid / 16.0f; 163 169 illum_col.y = newWeight; 164 illum_col.z = currentDepth;170 illum_col.z = eyeSpaceDepth; 165 171 166 172 return illum_col; … … 252 258 uniform float2 samples[NUM_SAMPLES], 253 259 uniform sampler2D oldTex, 254 constuniform float4x4 modelViewProj,255 constuniform float4x4 oldModelViewProj,260 uniform float4x4 modelViewProj, 261 uniform float4x4 oldModelViewProj, 256 262 uniform float temporalCoherence, 257 263 uniform float3 eyePos, … … 259 265 uniform float3 br, 260 266 uniform float3 tl, 261 uniform float3 tr 267 uniform float3 tr, 268 uniform float3 oldEyePos, 269 uniform float3 oldbl, 270 uniform float3 oldbr, 271 uniform float3 oldtl, 272 uniform float3 oldtr 262 273 ) 263 274 { 264 275 pixel OUT; 265 276 266 const float3 normal = 267 normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 277 const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 268 278 269 279 // reconstruct position from the eye space depth … … 292 302 293 303 OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao, 294 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos); 304 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos, eyeDepth, 305 oldEyePos,oldbl, oldbr, oldtl, oldtr); 295 306 296 307 return OUT;
Note: See TracChangeset
for help on using the changeset viewer.