- Timestamp:
- 11/17/08 16:41:32 (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
r3129 r3132 144 144 145 145 146 void DeferredRenderer::FlipFbos(FrameBufferObject *fbo) 147 { 148 fbo->Bind(); 149 colorBufferIdx = 3 - colorBufferIdx; 150 glDrawBuffers(1, mrt + colorBufferIdx); 151 } 152 153 146 154 void DeferredRenderer::DrawQuad(ShaderProgram *p) 147 155 { 148 p->Bind();156 if (p) p->Bind(); 149 157 150 158 // interpolate the view vector … … 288 296 //-- the flip-flop fbos 289 297 290 const int dsw = w / 2; const int dsh = h / 2;291 //const int dsw = w; const int dsh = h;298 //const int dsw = w / 2; const int dsh = h / 2; 299 const int dsw = w; const int dsh = h; 292 300 293 301 mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); … … 322 330 323 331 // create noise texture for ssao 324 //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight());325 CreateNoiseTex2D(mWidth / 8, mHeight / 8);332 CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 333 //CreateNoiseTex2D(mIllumFbo->GetWidth() / 4, mIllumFbo->GetWidth() / 4); 326 334 CreateNoiseTex1D(mWidth / 8); 327 335 … … 504 512 } 505 513 514 AntiAliasing(fbo, light); 515 506 516 switch (mShadingMethod) 507 517 { 508 518 case SSAO: 509 519 ComputeSsao(fbo, tempCohFactor); 510 SmoothSsao(fbo);520 //SmoothSsao(fbo); 511 521 CombineSsao(fbo); 512 522 break; … … 528 538 } 529 539 530 AntiAliasing(fbo, light);540 Output(fbo); 531 541 532 542 glEnable(GL_LIGHTING); … … 552 562 GLuint colorsTex, normalsTex, attribsTex; 553 563 554 if ( 0)564 if (1) 555 565 { 556 566 colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); … … 563 573 normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 564 574 attribsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 575 //attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 565 576 } 566 577 … … 644 655 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light) 645 656 { 646 FrameBufferObject::Release();647 648 657 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 649 650 658 GLuint colorsTex = colorBuffer->GetTexture(); 651 659 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 660 661 //FrameBufferObject::Release(); 662 663 // read the second buffer, write to the first buffer 664 FlipFbos(fbo); 665 652 666 653 667 sCgAntiAliasingProgram->SetTexture(0, colorsTex); … … 678 692 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 679 693 680 fbo->Bind(); 681 682 colorBufferIdx = 3 - colorBufferIdx; 683 glDrawBuffers(1, mrt + colorBufferIdx); 694 FlipFbos(fbo); 684 695 685 696 const Vector3 lightDir = -light->GetDirection(); … … 767 778 GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 768 779 769 770 fbo->Bind(); 771 772 // overwrite old color texture 773 colorBufferIdx = 3 - colorBufferIdx; 774 775 glDrawBuffers(1, mrt + colorBufferIdx); 780 FlipFbos(fbo); 776 781 777 782 sCgCombineIllumProgram->SetTexture(0, colorsTex); … … 787 792 void DeferredRenderer::CombineSsao(FrameBufferObject *fbo) 788 793 { 789 fbo->Bind();790 791 794 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 792 795 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 793 GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 794 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 795 796 // overwrite old color texture 797 colorBufferIdx = 3 - colorBufferIdx; 798 glDrawBuffers(1, mrt + colorBufferIdx); 796 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 797 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 798 799 FlipFbos(fbo); 799 800 800 801 int i = 0; … … 816 817 ShadowMap *shadowMap) 817 818 { 818 fbo->Bind();819 820 819 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 821 820 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); … … 826 825 shadowMap->GetTextureMatrix(shadowMatrix); 827 826 828 colorBufferIdx = 3 - colorBufferIdx; 829 glDrawBuffers(1, mrt + colorBufferIdx);827 828 FlipFbos(fbo); 830 829 831 830 sCgDeferredShadowProgram->SetTexture(0, colorsTex); … … 891 890 GLuint colorsTex = colorBuffer->GetTexture(); 892 891 893 fbo->Bind(); 894 895 colorBufferIdx = 3 - colorBufferIdx; 896 glDrawBuffers(1, mrt + colorBufferIdx); 892 FlipFbos(fbo); 897 893 898 894 sCgLogLumProgram->SetTexture(0, colorsTex); … … 973 969 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 974 970 GLuint colorsTex = colorBuffer->GetTexture(); 975 976 fbo->Bind(); 977 978 colorBufferIdx = 3 - colorBufferIdx; 979 glDrawBuffers(1, mrt + colorBufferIdx); 971 //FrameBufferObject::Release(); 972 973 FlipFbos(fbo); 980 974 981 975 sCgToneProgram->SetTexture(0, colorsTex); … … 987 981 988 982 PrintGLerror("ToneMap"); 983 } 984 985 986 void DeferredRenderer::Output(FrameBufferObject *fbo) 987 { 988 glPushAttrib(GL_VIEWPORT_BIT); 989 glViewport(0, 0, fbo->GetWidth(), fbo->GetHeight()); 990 991 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 992 GLuint colorsTex = colorBuffer->GetTexture(); 993 994 sCgDownSampleProgram->SetTexture(0, colorsTex); 995 996 FrameBufferObject::Release(); 997 DrawQuad(sCgDownSampleProgram); 998 999 PrintGLerror("OUTPUT"); 989 1000 } 990 1001 … … 1030 1041 const float oldFar = mCamera->GetFar(); 1031 1042 const float oldNear = mCamera->GetNear(); 1032 //mCamera->SetFar(1e3f); 1033 //mCamera->SetNear(3.0f); 1034 //mCamera->SetFar(1e2f); 1043 1035 1044 1036 1045 Matrix4x4 matViewing, matProjection; 1037 /* 1038 mCamera->SetPosition(mOldEyePos - mEyePos); 1039 1040 mCamera->GetModelViewMatrix(matViewing); 1041 mCamera->GetProjectionMatrix(matProjection); 1042 1043 mOldProjViewMatrix = matViewing * matProjection; 1044 mCamera->SetPosition(mEyePos);*/ 1046 1045 1047 1046 1048 /////////////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3128 r3132 94 94 void DrawQuad(ShaderProgram *p); 95 95 96 void Output(FrameBufferObject *fbo); 97 96 98 /** Initialises the deferred shader and loads the required shaders: 97 99 This function has to be called only once. … … 101 103 */ 102 104 void InitFrame(); 105 106 void FlipFbos(FrameBufferObject *fbo); 103 107 104 108 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3130 r3132 119 119 if (col.w < 1e10f) 120 120 { 121 const float xoffs = 4.0f / 1024.0f; 122 const float yoffs = 4.0f / 768.0f; 123 /* 124 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 125 float3 x2 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz; 126 float3 x3 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz; 127 float3 x4 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz; 128 float3 x5 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).xyz; 129 130 //ao.x = (ao.x + x2 + x3 + x4 + x5) * 0.2f; 131 ao.x = (x2 + x3 + x4 + x5) * 0.25f; 132 133 */ 121 134 const static float scaleFactor = 1.0f; 122 135 //const static float scaleFactor = 10.0f; … … 126 139 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 127 140 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z / (adaptFactor + ao.y), 0); 128 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor / (adaptFactor + ao.y), 0);129 } 130 131 //OUT.illum_col.xyz = col.xyz * ao.x;141 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor / (adaptFactor + ao.y), 0); 142 } 143 144 OUT.illum_col.xyz = col.xyz * ao.x; 132 145 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 133 OUT.illum_col.xyz = float3(1.0f - ao.x, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);146 //OUT.illum_col.xyz = float3(1.0f - ao.x, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 134 147 OUT.illum_col.w = col.w; 135 148 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3129 r3132 143 143 { 144 144 // compute position from old frame for dynamic objects + translational portion 145 const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec;145 const float3 translatedPos = diffVec + worldPos.xyz - oldEyePos; 146 146 147 147 … … 186 186 const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 187 187 188 #if 1188 #if 0 189 189 if (squaredLen < 1e-8f) // object not dynamic 190 190 { … … 209 209 #endif 210 210 211 //const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);212 const float oldWeight = oldPixel.y;211 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 212 //const float oldWeight = oldPixel.y; 213 213 214 214 float newWeight; … … 236 236 // newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 237 237 //if (newWeight >= 2000) newWeight = 1000; 238 newWeight -= step(512.0f, newWeight) * 256.0f;238 //newWeight -= step(512.0f, newWeight) * 256.0f; 239 239 240 240 return float3(oldPixel.x, newWeight, eyeSpaceDepth); … … 279 279 //-- add random noise: reflect around random normal vector (rather slow!) 280 280 281 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f + noiseOffs, 0, 0)).xy; 281 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f + noiseOffs, 0, 0)).xy; 282 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord, .0f, .0f)).xy; 282 283 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 283 284 const float2 offsetTransformed = myreflect(offset, mynoise); … … 357 358 const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1.0f); 358 359 360 /*const float xoffs = 2.0f / 1024.0f; 361 const float yoffs = 2.0f / 768.0f; 362 359 363 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 364 float3 x1 = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 365 float3 x2 = tex2Dlod(attribsTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz; 366 float3 x3 = tex2Dlod(attribsTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz; 367 float3 x4 = tex2Dlod(attribsTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz; 368 float3 x5 = tex2Dlod(attribsTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).xyz; 369 370 float3 diffVec = (x1+x2+x3+x4+x5) * .25f; 371 */ 360 372 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 361 373 … … 387 399 388 400 const float oldSsao = temporalVals.x; 389 const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence); 390 float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f); 391 //float2 noiseOffs = float2(.0f); 401 //const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence); 402 const float newWeight = temporalVals.y; 403 //float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f); 404 float2 noiseOffs = float2(.0f); 392 405 393 406 float2 ao; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3125 r3132 29 29 /* 30 30 float4 average = .0f; 31 32 31 for (int i = 0; i < NUM_DOWNSAMPLES; ++ i) 33 32 { 34 33 average += tex2Dlod(colors, float4(IN.texCoord + downSampleOffs[i], 0, 0)); 35 } 36 34 } 37 35 average *= 1.0f / (float)NUM_DOWNSAMPLES; 38 36 … … 151 149 152 150 float lum = dot(color.rgb, w); 153 float logLum = log( 1e-5f + lum);151 float logLum = log(max(1e-3f, lum)); 154 152 155 153 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; … … 158 156 const float expFactor = 0.1f; 159 157 // exponential smoothing of tone mapping over time 160 if (oldLogLum > 1e- 5f) // check if loglum from last frame too small (=> tm too bright)158 if (oldLogLum > 1e-3f) // check if loglum from last frame too small (=> tm too bright) 161 159 OUT.col.w = lerp(oldLogLum, logLumScaled, expFactor); 162 160 else
Note: See TracChangeset
for help on using the changeset viewer.