Changeset 3094 for GTP/trunk/App/Demos
- Timestamp:
- 11/03/08 18:41:06 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3093 r3094 257 257 //-- the flip-flop fbos 258 258 259 // mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 260 mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 259 mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 260 //mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 261 261 262 mFBOs.push_back(mIllumFbo); 262 263 … … 267 268 } 268 269 269 //mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);270 mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);270 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 271 //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 271 272 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 272 273 // downsample buffer for the normal texture … … 328 329 sCgSsaoProgram->AddParameter("oldTex", i ++); 329 330 sCgSsaoProgram->AddParameter("noiseTex", i ++); 330 sCgSsaoProgram->AddParameter("eyePos", i ++);331 331 sCgSsaoProgram->AddParameter("temporalCoherence", i ++); 332 332 sCgSsaoProgram->AddParameter("samples", i ++); … … 350 350 sCgGiProgram->AddParameter("oldSsaoTex", i ++); 351 351 sCgGiProgram->AddParameter("oldIllumTex", i ++); 352 sCgGiProgram->AddParameter("eyePos", i ++);353 352 sCgGiProgram->AddParameter("temporalCoherence", i ++); 354 353 sCgGiProgram->AddParameter("samples", i ++); … … 540 539 sCgSsaoProgram->SetTexture(3, noiseTex); 541 540 542 //sCgSsaoProgram->SetValue3f(4, mEyePos.x, mEyePos.y, mEyePos.z); 543 sCgSsaoProgram->SetValue3f(4, 0, 0, 0); 544 545 sCgSsaoProgram->SetValue1f(5, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 541 sCgSsaoProgram->SetValue1f(4, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 546 542 547 543 if (mUseTemporalCoherence || mRegenerateSamples) … … 553 549 // needs longer to converge 554 550 GenerateSamples(mSamplingMethod); 555 sCgSsaoProgram->SetArray2f( 6, (float *)samples2, NUM_SAMPLES);551 sCgSsaoProgram->SetArray2f(5, (float *)samples2, NUM_SAMPLES); 556 552 } 557 553 … … 561 557 Vector3 tr = mCornersView[3]; 562 558 563 sCgSsaoProgram->SetValue3f(7, bl.x, bl.y, bl.z); 564 sCgSsaoProgram->SetValue3f(8, br.x, br.y, br.z); 565 sCgSsaoProgram->SetValue3f(9, tl.x, tl.y, tl.z); 566 sCgSsaoProgram->SetValue3f(10, tr.x, tr.y, tr.z); 567 568 //cout << "new projview:\n" << projViewMatrix << endl; 569 //cout << "old projview:\n" << oldProjViewMatrix << endl; 570 571 sCgSsaoProgram->SetMatrix(11, mProjViewMatrix); 572 sCgSsaoProgram->SetMatrix(12, mOldProjViewMatrix); 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); 573 566 574 567 bl = mOldCornersView[0]; … … 578 571 579 572 Vector3 d = mOldEyePos - mEyePos; 580 581 //sCgSsaoProgram->SetValue3f(13, mOldEyePos.x, mOldEyePos.y, mOldEyePos.z); 582 sCgSsaoProgram->SetValue3f(1 3, d.x, d.y, d.z);583 sCgSsaoProgram->SetValue3f(1 4, bl.x, bl.y, bl.z);584 sCgSsaoProgram->SetValue3f(1 5, br.x, br.y, br.z);585 sCgSsaoProgram->SetValue3f(1 6, tl.x, tl.y, tl.z);586 sCgSsaoProgram->SetValue3f(1 7, tr.x, tr.y, tr.z);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); 587 580 588 581 DrawQuad(sCgSsaoProgram); … … 692 685 sCgGiProgram->SetTexture(4, oldIllumTex); 693 686 694 sCgGiProgram->SetValue3f(5, mEyePos.x, mEyePos.y, mEyePos.z); 695 696 697 sCgGiProgram->SetValue1f(6, 687 sCgGiProgram->SetValue1f(5, 698 688 (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 699 689 … … 707 697 GenerateSamples(mSamplingMethod); 708 698 709 sCgGiProgram->SetArray2f( 7, (float *)samples2, NUM_SAMPLES);699 sCgGiProgram->SetArray2f(6, (float *)samples2, NUM_SAMPLES); 710 700 } 711 701 … … 715 705 Vector3 tr = mCornersView[3]; 716 706 717 sCgGiProgram->SetValue3f( 8, bl.x, bl.y, bl.z);718 sCgGiProgram->SetValue3f( 9, br.x, br.y, br.z);719 sCgGiProgram->SetValue3f( 10, tl.x, tl.y, tl.z);720 sCgGiProgram->SetValue3f(1 1, tr.x, tr.y, tr.z);721 722 sCgGiProgram->SetMatrix(1 2, mOldProjViewMatrix);723 sCgGiProgram->SetMatrix(1 3, mProjViewMatrix);707 sCgGiProgram->SetValue3f(7, bl.x, bl.y, bl.z); 708 sCgGiProgram->SetValue3f(8, br.x, br.y, br.z); 709 sCgGiProgram->SetValue3f(9, tl.x, tl.y, tl.z); 710 sCgGiProgram->SetValue3f(10, tr.x, tr.y, tr.z); 711 712 sCgGiProgram->SetMatrix(11, mOldProjViewMatrix); 713 sCgGiProgram->SetMatrix(12, mProjViewMatrix); 724 714 725 715 … … 825 815 sCgDeferredShadowProgram->SetTexture(2, shadowTex); 826 816 sCgDeferredShadowProgram->SetTexture(3, noiseTex); 827 828 817 sCgDeferredShadowProgram->SetMatrix(4, shadowMatrix); 829 830 818 sCgDeferredShadowProgram->SetValue1f(5, 2.0f / shadowMap->GetSize()); 831 819 832 820 const Vector3 lightDir = -light->GetDirection(); 833 821 sCgDeferredShadowProgram->SetValue3f(6, lightDir.x, lightDir.y, lightDir.z); 834 835 822 sCgDeferredShadowProgram->SetValue3f(7, mEyePos.x, mEyePos.y, mEyePos.z); 836 823 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3084 r3094 158 158 const uniform float4x4 modelViewProj, 159 159 uniform float temporalCoherence, 160 uniform float3 eyePos,161 160 uniform float3 bl, 162 161 uniform float3 br, … … 177 176 const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 178 177 179 const float3 eyeSpacePos = -viewDir * eyeDepth; 180 181 const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 178 const float4 eyeSpacePos = float4(-viewDir * eyeDepth, 1.0f); 182 179 183 180 // calculcate the current projected depth for next frame 184 float4 currentPos = mul(modelViewProj, worldPos);181 float4 currentPos = mul(modelViewProj, eyeSpacePos); 185 182 186 183 const float w = SAMPLE_RADIUS / currentPos.w; … … 200 197 // reprojection new frame into old one 201 198 // calculate projected depth 202 float4 projPos = mul(oldModelViewProj, worldPos);199 float4 projPos = mul(oldModelViewProj, eyeSpacePos); 203 200 projPos /= projPos.w; 204 201 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3093 r3094 73 73 uniform float3 tr, 74 74 float2 texcoord0, 75 float3 eyePos,76 75 float3 oldEyePos, 77 76 uniform float3 oldbl, … … 87 86 float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 88 87 //texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f; 89 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos;88 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 90 89 91 90 // reproject into old frame and calculate projected depth … … 114 113 as well as a boolean that 115 114 */ 116 float4 temporalSmoothing(float4 currentProjPos, 117 float4 worldPos, 115 float4 temporalSmoothing(float4 eyeSpacePos, 118 116 uniform sampler2D oldTex, 119 117 const uniform float4x4 oldModelViewProj, … … 129 127 uniform float3 tr, 130 128 float2 texcoord0, 131 float3 eyePos,132 129 float eyeSpaceDepth, 133 130 float3 oldEyePos, … … 151 148 152 149 // reproject into old frame and calculate projected depth 153 float4 backProjPos = mul(oldModelViewProj, worldPos);150 float4 backProjPos = mul(oldModelViewProj, eyeSpacePos); 154 151 backProjPos /= backProjPos.w; 155 152 // fit from unit cube into 0 .. 1 … … 162 159 163 160 const float oldEyeSpaceDepth = oldCol.w; 164 //oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f;165 161 166 162 float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 167 //float3 oldSamplePos = -viewVec * eyeSpaceDepth + oldEyePos; 168 float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 169 170 const float depthDif = length(oldSamplePos - worldPos.xyz); 171 const float dummy5 = abs(oldEyeSpaceDepth - eyeSpaceDepth); 172 //const float dummy5 = length(oldTexCoords - texcoord0) * 1e5f; 173 //const float dummy5 = depthDif; 163 float3 oldEyeSpacePos = oldEyePos - viewVec * oldEyeSpaceDepth; 164 165 const float depthDif = length(oldEyeSpacePos - eyeSpacePos.xyz); 174 166 175 167 float notValid = 0.5f; 176 168 177 for (int i = 0; i < NUM_SAMPLES; ++ i)169 /*for (int i = 0; i < NUM_SAMPLES; ++ i) 178 170 { 179 171 float sampleDif = ComputeDifference(samples[i], … … 185 177 bl, br, tl, tr, 186 178 texcoord0, 187 eyePos,188 179 oldEyePos, 189 180 oldbl, oldbr, oldtl, oldtr, 190 worldPos.xyz);181 eyePos.xyz); 191 182 192 183 if (sampleDif >= 1e-1f) ++ notValid; 193 } 184 }*/ 194 185 195 186 //if (notValid < 1.0f) temporalCoherence = 4.0f; … … 213 204 newWeight = oldWeight + 1.0f; 214 205 illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 215 if (notValid > 1.0f) newWeight = 2 ;206 if (notValid > 1.0f) newWeight = 2.0f; 216 207 } 217 208 else … … 223 214 illum_col.y = newWeight; 224 215 illum_col.w = eyeSpaceDepth; 225 //illum_col.y = dummy5;216 226 217 227 218 return illum_col; … … 270 261 271 262 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 272 273 263 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 274 264 … … 316 306 uniform float4x4 oldModelViewProj, 317 307 uniform float temporalCoherence, 318 uniform float3 eyePos,319 308 uniform float3 bl, 320 309 uniform float3 br, … … 335 324 const float3 viewDir = IN.view; 336 325 const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 337 const float3 eyeSpacePos = -viewDir * eyeSpaceDepth; 338 const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 326 const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1); 339 327 340 328 … … 342 330 //-- calculcate the current projected posiion (also used for next frame) 343 331 344 float4 projPos = mul(modelViewProj, worldPos); 332 float4 projPos = mul(modelViewProj, eyeSpacePos); 333 float w = SAMPLE_RADIUS / projPos.w; 345 334 346 float w = 1.0f / projPos.w; 347 projPos *= w; 348 w *= SAMPLE_RADIUS; 349 350 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 335 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, w, bl, br, tl, tr, normalize(viewDir)); 351 336 352 337 … … 354 339 //-- compute temporally smoothing 355 340 356 OUT.illum_col = temporalSmoothing( projPos, worldPos, oldTex, oldModelViewProj, temporalCoherence, ao,357 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eye Pos, eyeSpaceDepth,341 OUT.illum_col = temporalSmoothing(eyeSpacePos, oldTex, oldModelViewProj, temporalCoherence, ao, 342 samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyeSpaceDepth, 358 343 oldEyePos, oldbl, oldbr, oldtl, oldtr); 359 344
Note: See TracChangeset
for help on using the changeset viewer.