Changeset 3095 for GTP/trunk/App
- Timestamp:
- 11/05/08 00:35:08 (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
r3094 r3095 422 422 InitFrame(); 423 423 424 // switch roles of old and new fbo425 // the algorihm uses two input fbos, where the one426 // contais the color buffer from the last frame,427 // the other one will be written428 429 mIllumFboIndex = 2 - mIllumFboIndex;430 431 // enable fragment shading432 ShaderManager::GetSingleton()->EnableFragmentProfile();433 434 glDisable(GL_ALPHA_TEST);435 glDisable(GL_TEXTURE_2D);436 glDisable(GL_LIGHTING);437 glDisable(GL_BLEND);438 glDisable(GL_DEPTH_TEST);439 440 glPolygonMode(GL_FRONT, GL_FILL);441 442 glMatrixMode(GL_PROJECTION);443 glPushMatrix();444 glLoadIdentity();445 446 const float offs = 0.5f;447 //glOrtho(-offs, offs, -offs, offs, 0, 1);448 //glOrtho(0, 1, 0, 1, 0, 1);449 gluOrtho2D(0, 1, 0, 1);450 451 452 glMatrixMode(GL_MODELVIEW);453 glPushMatrix();454 glLoadIdentity();455 456 457 glPushAttrib(GL_VIEWPORT_BIT);458 glViewport(0, 0, mWidth, mHeight);459 460 424 if (shadowMap) 461 425 FirstPassShadow(fbo, light, shadowMap); … … 534 498 glDrawBuffers(1, mrt + mIllumFboIndex); 535 499 536 sCgSsaoProgram->SetTexture(0, colorsTex); 537 sCgSsaoProgram->SetTexture(1, normalsTex); 538 sCgSsaoProgram->SetTexture(2, oldTex); 539 sCgSsaoProgram->SetTexture(3, noiseTex); 540 541 sCgSsaoProgram->SetValue1f(4, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 500 int i = 0; 501 502 sCgSsaoProgram->SetTexture(i ++, colorsTex); 503 sCgSsaoProgram->SetTexture(i ++, normalsTex); 504 sCgSsaoProgram->SetTexture(i ++, oldTex); 505 sCgSsaoProgram->SetTexture(i ++, noiseTex); 506 507 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 542 508 543 509 if (mUseTemporalCoherence || mRegenerateSamples) … … 549 515 // needs longer to converge 550 516 GenerateSamples(mSamplingMethod); 551 sCgSsaoProgram->SetArray2f(5, (float *)samples2, NUM_SAMPLES); 552 } 553 554 Vector3 bl = mCornersView[0]; 555 Vector3 br = mCornersView[1]; 556 Vector3 tl = mCornersView[2]; 557 Vector3 tr = mCornersView[3]; 558 559 sCgSsaoProgram->SetValue3f(6, bl.x, bl.y, bl.z); 560 sCgSsaoProgram->SetValue3f(7, br.x, br.y, br.z); 561 sCgSsaoProgram->SetValue3f(8, tl.x, tl.y, tl.z); 562 sCgSsaoProgram->SetValue3f(9, tr.x, tr.y, tr.z); 563 564 sCgSsaoProgram->SetMatrix(10, mProjViewMatrix); 565 sCgSsaoProgram->SetMatrix(11, mOldProjViewMatrix); 566 567 bl = mOldCornersView[0]; 568 br = mOldCornersView[1]; 569 tl = mOldCornersView[2]; 570 tr = mOldCornersView[3]; 571 572 Vector3 d = mOldEyePos - mEyePos; 573 //Vector3 d = mEyePos - mOldEyePos; 574 575 sCgSsaoProgram->SetValue3f(12, d.x, d.y, d.z); 576 sCgSsaoProgram->SetValue3f(13, bl.x, bl.y, bl.z); 577 sCgSsaoProgram->SetValue3f(14, br.x, br.y, br.z); 578 sCgSsaoProgram->SetValue3f(15, tl.x, tl.y, tl.z); 579 sCgSsaoProgram->SetValue3f(16, tr.x, tr.y, tr.z); 517 sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 518 } 519 520 ++ i; 521 522 for (int j = 0; j < 4; ++ j, ++ i) 523 sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 524 525 sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix); 526 sCgSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix); 527 528 Vector3 de = mOldEyePos - mEyePos; 529 //Vector3 de = mEyePos - mOldEyePos; 530 531 sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z); 532 533 for (int j = 0; j < 4; ++ j, ++ i) 534 sCgSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 580 535 581 536 DrawQuad(sCgSsaoProgram); … … 1001 956 void DeferredRenderer::InitFrame() 1002 957 { 958 for (int i = 0; i < 4; ++ i) 959 mOldCornersView[i] = mCornersView[i]; 960 1003 961 mOldProjViewMatrix = mProjViewMatrix; 962 mOldEyePos = mEyePos; 963 964 965 /////////////////// 1004 966 1005 967 Matrix4x4 matViewing, matProjection; … … 1010 972 1011 973 mProjViewMatrix = matViewing * matProjection; 1012 1013 for (int i = 0; i < 4; ++ i)1014 {1015 mOldCornersView[i] = mCornersView[i];1016 }1017 1018 974 ComputeViewVectors(mCamera, mCornersView[0], mCornersView[1], mCornersView[2], mCornersView[3]); 1019 1020 mOldEyePos = mEyePos;1021 975 mEyePos = mCamera->GetPosition(); 976 977 978 // switch roles of old and new fbo 979 // the algorihm uses two input fbos, where the one 980 // contais the color buffer from the last frame, 981 // the other one will be written 982 983 mIllumFboIndex = 2 - mIllumFboIndex; 984 985 // enable fragment shading 986 ShaderManager::GetSingleton()->EnableFragmentProfile(); 987 988 glDisable(GL_ALPHA_TEST); 989 glDisable(GL_TEXTURE_2D); 990 glDisable(GL_LIGHTING); 991 glDisable(GL_BLEND); 992 glDisable(GL_DEPTH_TEST); 993 994 glPolygonMode(GL_FRONT, GL_FILL); 995 996 glMatrixMode(GL_PROJECTION); 997 glPushMatrix(); 998 glLoadIdentity(); 999 1000 gluOrtho2D(0, 1, 0, 1); 1001 1002 1003 glMatrixMode(GL_MODELVIEW); 1004 glPushMatrix(); 1005 glLoadIdentity(); 1006 1007 1008 glPushAttrib(GL_VIEWPORT_BIT); 1009 glViewport(0, 0, mWidth, mHeight); 1022 1010 } 1023 1011 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3092 r3095 42 42 #define MAX_LOD_LEVEL 10 43 43 44 #define MIN_DEPTH_DIFF 1e-3f44 #define MIN_DEPTH_DIFF 5e-2f 45 45 #define PRECISION_SCALE 1e-1f 46 46 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3092 r3095 73 73 OUT.color = col; 74 74 75 // store scaled view vector from now on so wie don't have to normalize for e.g., ssao 76 float3 viewDir = IN.view; 77 const float lenView = length(viewDir); 78 79 OUT.color.w = color.w / lenView; 75 // store scaled view vector so wie don't have to normalize for e.g., ssao 76 OUT.color.w = color.w;// / length(IN.view); 80 77 81 78 return OUT; … … 132 129 float3 x1 = lerp(bl, tl, w.y); 133 130 float3 x2 = lerp(br, tr, w.y); 134 float3 v = lerp(x1, x2, w.x);131 float3 v = lerp(x1, x2, w.x); 135 132 136 133 return v; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3094 r3095 55 55 { 56 56 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 57 float3 viewVec = Interpol(texcoord, bl, br, tl, tr);57 float3 viewVec = normalize(Interpol(texcoord, bl, br, tl, tr)); 58 58 float3 samplePos = -viewVec * eyeSpaceDepth; 59 59 … … 81 81 ) 82 82 { 83 float2 mynoise = tex2D(noiseTex, texcoord0).xy;83 const float2 mynoise = tex2D(noiseTex, texcoord0).xy; 84 84 85 85 const float2 offsetTransformed = myreflect(offset, mynoise); 86 86 float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 87 //texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f;87 88 88 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 89 89 … … 93 93 94 94 // fit from unit cube into 0 .. 1 95 float2 oldTexCoords = projPos.xy * 0.5f + 0.5f;95 const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 96 96 // retrieve the sample from the last frame 97 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 98 99 float oldEyeSpaceDepth = oldCol.w; 100 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 101 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 102 97 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 98 99 const float oldEyeSpaceDepth = oldPixel.w; 100 const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 101 102 const float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 103 103 104 float dDiff = length(oldSamplePos - samplePos.xyz); 104 105 if (length(worldPos.xyz - samplePos.xyz) > 5.0f) 106 dDiff = .0f; 105 if (length(worldPos.xyz - samplePos.xyz) > 5.0f) dDiff = .0f; 107 106 108 107 return dDiff; … … 113 112 as well as a boolean that 114 113 */ 115 float4 temporalSmoothing(float4 eyeSpacePos,116 uniform sampler2D oldTex,117 const uniform float4x4 oldModelViewProj,118 uniform float temporalCoherence,119 uniform float2 ao,120 uniform float2 samples[NUM_SAMPLES],121 uniform sampler2D colors,122 uniform sampler2D noiseTex,123 uniform float scaleFactor,124 uniform float3 bl,125 uniform float3 br,126 uniform float3 tl,127 uniform float3 tr,128 float2 texcoord0,129 float eyeSpaceDepth,130 float3 oldEyePos,131 uniformfloat3 oldbl,132 uniformfloat3 oldbr,133 uniformfloat3 oldtl,134 uniformfloat3 oldtr135 136 114 inline float4 temporalSmoothing(float4 worldPos, 115 float eyeSpaceDepth, 116 float2 ao, 117 float2 texcoord0, 118 float3 oldEyePos, 119 sampler2D oldTex, 120 float4x4 oldModelViewProj, 121 float temporalCoherence, 122 float2 samples[NUM_SAMPLES], 123 sampler2D colors, 124 sampler2D noiseTex, 125 float scaleFactor, 126 float3 bl, 127 float3 br, 128 float3 tl, 129 float3 tr, 130 float3 oldbl, 131 float3 oldbr, 132 float3 oldtl, 133 float3 oldtr 134 //,const uniform float4x4 inverseModelTrafo 135 //, float id 137 136 ) 138 137 { … … 147 146 //else trafo = inverseModelTrafo * oldModelViewProj; 148 147 149 // reproject into old frame and calculate projected depth 150 float4 backProjPos = mul(oldModelViewProj, eyeSpacePos); 148 float4 dummyPt = worldPos - float4(oldEyePos,0); 149 150 // reproject into old frame and calculate texture position of sample in old frame 151 float4 backProjPos = mul(oldModelViewProj, dummyPt); 151 152 backProjPos /= backProjPos.w; 152 153 // fit from unit cube into 0 .. 1 153 154 const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 154 // float2 oldTexCoords = texcoord0;155 //const float2 oldTexCoords = texcoord0; 155 156 156 157 // retrieve the sample from the last frame 157 float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 158 //float4 oldCol = tex2D(oldTex, oldTexCoords); 159 160 const float oldEyeSpaceDepth = oldCol.w; 161 162 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 163 float3 oldEyeSpacePos = oldEyePos - viewVec * oldEyeSpaceDepth; 164 165 const float depthDif = length(oldEyeSpacePos - eyeSpacePos.xyz); 158 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 159 // calculate eye space position of sample in old frame 160 const float oldEyeSpaceDepth = oldPixel.w; 161 162 // vector from eye pos to old sample 163 const float3 viewVec = normalize(Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr)); 164 const float3 oldWorldPos = oldEyeSpaceDepth * (-viewVec) + oldEyePos; 165 //const float3 oldWorldPos = - viewVec * eyeSpaceDepth; 166 //const float3 dummy14 = Interpol(texcoord0, bl, br, tl, tr); 167 168 // the euclidian world space distance 169 const float depthDif = length(oldWorldPos - worldPos.xyz); 170 //const float depthDif = length(dummy14 - viewVec); 171 //const float depthDif = length(oldEyeSpaceDepth - eyeSpaceDepth); 172 //const float depthDif = length(oldEyePos); 166 173 167 174 float notValid = 0.5f; … … 184 191 }*/ 185 192 186 //if (notValid < 1.0f) temporalCoherence = 4.0f;187 193 // the number of valid samples in this frame 188 194 //const float newNumSamples = ao.y; 189 190 195 //const float oldNumSamples = oldCol.y; 191 const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 196 197 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 192 198 float newWeight; 193 199 … … 203 209 // increase the weight for convergence 204 210 newWeight = oldWeight + 1.0f; 205 illum_col.x = (ao.x + old Col.x * oldWeight) / newWeight;206 if (notValid > 1.0f) newWeight = 2.0f;211 illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight; 212 //if (notValid > 1.0f) newWeight = 2.0f; 207 213 } 208 214 else … … 214 220 illum_col.y = newWeight; 215 221 illum_col.w = eyeSpaceDepth; 216 222 //illum_col.y = depthDif; 217 223 218 224 return illum_col; … … 269 275 float3 dirSample = samplePos - centerPosition; 270 276 const float lengthToSample = length(dirSample); 271 // normalize 272 dirSample /= lengthToSample; 277 278 dirSample /= lengthToSample; // normalize 273 279 274 280 // angle between current normal and direction to sample controls AO intensity. … … 283 289 // if surface normal perpenticular to view dir, approx. half of the samples will not count 284 290 // => compensate for this (on the other hand, projected sampling area could be larger!) 291 285 292 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 286 293 total_ao += cosAngle * aoContrib * viewCorrection; … … 292 299 return float2(max(0.0f, 1.0f - total_ao), numSamples); 293 300 } 294 295 //#pragma position_invariant main296 301 297 302 /** The mrt shader for screen space ambient occlusion … … 322 327 323 328 // reconstruct position from the eye space depth 324 const float3 viewDir = IN.view;329 const float3 viewDir = normalize(IN.view); 325 330 const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 326 const float4 eyeSpacePos = float4( -viewDir * eyeSpaceDepth, 1);331 const float4 eyeSpacePos = float4(eyeSpaceDepth * (-viewDir), 1.0f); 327 332 328 333 … … 333 338 float w = SAMPLE_RADIUS / projPos.w; 334 339 335 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, w, bl, br, tl, tr, normalize(viewDir)); 340 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, 341 eyeSpacePos.xyz, w, bl, br, tl, tr, normalize(viewDir)); 336 342 337 343 338 344 ///////////////// 339 345 //-- compute temporally smoothing 340 341 OUT.illum_col = temporalSmoothing(eyeSpacePos, oldTex, oldModelViewProj, temporalCoherence, ao, 342 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyeSpaceDepth, 343 oldEyePos, oldbl, oldbr, oldtl, oldtr); 346 347 OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos, 348 oldTex, oldModelViewProj, temporalCoherence, 349 samples, colors, noiseTex, w, bl, br, tl, tr, 350 oldbl, oldbr, oldtl, oldtr); 344 351 345 352 return OUT;
Note: See TracChangeset
for help on using the changeset viewer.