Changeset 3132 for GTP


Ignore:
Timestamp:
11/17/08 16:41:32 (16 years ago)
Author:
mattausch
Message:

reordered functions: antialiasing comes after initial shading pass and before ssao.cgadded final output pass which does nothing but stream everything out

now ssao much nicer but slower!!

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  
    144144 
    145145 
     146void DeferredRenderer::FlipFbos(FrameBufferObject *fbo) 
     147{ 
     148        fbo->Bind(); 
     149        colorBufferIdx = 3 - colorBufferIdx; 
     150        glDrawBuffers(1, mrt + colorBufferIdx); 
     151} 
     152 
     153 
    146154void DeferredRenderer::DrawQuad(ShaderProgram *p) 
    147155{ 
    148         p->Bind(); 
     156        if (p) p->Bind(); 
    149157 
    150158        // interpolate the view vector 
     
    288296        //-- the flip-flop fbos 
    289297 
    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; 
    292300 
    293301        mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
     
    322330 
    323331        // 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); 
    326334        CreateNoiseTex1D(mWidth / 8); 
    327335 
     
    504512        } 
    505513 
     514        AntiAliasing(fbo, light); 
     515 
    506516        switch (mShadingMethod) 
    507517        { 
    508518        case SSAO: 
    509519                ComputeSsao(fbo, tempCohFactor); 
    510                 SmoothSsao(fbo); 
     520                //SmoothSsao(fbo); 
    511521                CombineSsao(fbo); 
    512522                break; 
     
    528538        } 
    529539 
    530         AntiAliasing(fbo, light); 
     540        Output(fbo); 
    531541 
    532542        glEnable(GL_LIGHTING); 
     
    552562        GLuint colorsTex, normalsTex, attribsTex; 
    553563 
    554         if (0) 
     564        if (1) 
    555565        { 
    556566                colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
     
    563573                normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture(); 
    564574                attribsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 
     575                //attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    565576        } 
    566577 
     
    644655void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light) 
    645656{ 
    646         FrameBufferObject::Release(); 
    647  
    648657        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    649  
    650658        GLuint colorsTex = colorBuffer->GetTexture(); 
    651659        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         
    652666 
    653667        sCgAntiAliasingProgram->SetTexture(0, colorsTex); 
     
    678692        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    679693 
    680         fbo->Bind(); 
    681  
    682         colorBufferIdx = 3 - colorBufferIdx; 
    683         glDrawBuffers(1, mrt + colorBufferIdx); 
     694        FlipFbos(fbo); 
    684695 
    685696        const Vector3 lightDir = -light->GetDirection(); 
     
    767778        GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
    768779 
    769  
    770         fbo->Bind(); 
    771  
    772         // overwrite old color texture 
    773         colorBufferIdx = 3 - colorBufferIdx; 
    774  
    775         glDrawBuffers(1, mrt + colorBufferIdx); 
     780        FlipFbos(fbo); 
    776781 
    777782        sCgCombineIllumProgram->SetTexture(0, colorsTex); 
     
    787792void DeferredRenderer::CombineSsao(FrameBufferObject *fbo) 
    788793{ 
    789         fbo->Bind(); 
    790  
    791794        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    792795        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); 
    799800 
    800801        int i = 0; 
     
    816817                                                                           ShadowMap *shadowMap) 
    817818{ 
    818         fbo->Bind(); 
    819  
    820819        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    821820        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     
    826825        shadowMap->GetTextureMatrix(shadowMatrix); 
    827826 
    828         colorBufferIdx = 3 - colorBufferIdx; 
    829         glDrawBuffers(1, mrt + colorBufferIdx); 
     827 
     828        FlipFbos(fbo); 
    830829 
    831830        sCgDeferredShadowProgram->SetTexture(0, colorsTex); 
     
    891890        GLuint colorsTex = colorBuffer->GetTexture(); 
    892891 
    893         fbo->Bind(); 
    894  
    895         colorBufferIdx = 3 - colorBufferIdx; 
    896         glDrawBuffers(1, mrt + colorBufferIdx); 
     892        FlipFbos(fbo); 
    897893         
    898894        sCgLogLumProgram->SetTexture(0, colorsTex); 
     
    973969        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    974970        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); 
    980974 
    981975        sCgToneProgram->SetTexture(0, colorsTex); 
     
    987981 
    988982        PrintGLerror("ToneMap"); 
     983} 
     984 
     985 
     986void 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"); 
    9891000} 
    9901001 
     
    10301041        const float oldFar = mCamera->GetFar(); 
    10311042        const float oldNear = mCamera->GetNear(); 
    1032         //mCamera->SetFar(1e3f); 
    1033         //mCamera->SetNear(3.0f); 
    1034         //mCamera->SetFar(1e2f); 
     1043         
    10351044 
    10361045        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 
    10451047 
    10461048        /////////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3128 r3132  
    9494        void DrawQuad(ShaderProgram *p); 
    9595 
     96        void Output(FrameBufferObject *fbo); 
     97 
    9698        /** Initialises the deferred shader and loads the required shaders: 
    9799                This function has to be called only once. 
     
    101103        */ 
    102104        void InitFrame(); 
     105 
     106        void FlipFbos(FrameBufferObject *fbo); 
    103107 
    104108 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3130 r3132  
    119119        if (col.w < 1e10f) 
    120120        { 
     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*/ 
    121134                const static float scaleFactor = 1.0f; 
    122135                //const static float scaleFactor = 10.0f; 
     
    126139                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
    127140                //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; 
    132145        //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); 
    134147        OUT.illum_col.w = col.w; 
    135148 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3129 r3132  
    143143{ 
    144144        // 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; 
    146146 
    147147 
     
    186186        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
    187187 
    188 #if 1 
     188#if 0 
    189189        if (squaredLen < 1e-8f) // object not dynamic 
    190190        { 
     
    209209#endif 
    210210 
    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; 
    213213 
    214214        float newWeight; 
     
    236236        //      newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 
    237237        //if (newWeight >= 2000) newWeight = 1000; 
    238         newWeight -= step(512.0f, newWeight) * 256.0f; 
     238        //newWeight -= step(512.0f, newWeight) * 256.0f; 
    239239 
    240240        return float3(oldPixel.x, newWeight, eyeSpaceDepth); 
     
    279279                //-- add random noise: reflect around random normal vector (rather slow!) 
    280280 
    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; 
    282283                //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    283284                const float2 offsetTransformed = myreflect(offset, mynoise); 
     
    357358        const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
    358359 
     360        /*const float xoffs = 2.0f / 1024.0f; 
     361        const float yoffs = 2.0f / 768.0f; 
     362 
    359363        //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*/ 
    360372        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    361373         
     
    387399 
    388400        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); 
    392405 
    393406        float2 ao; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3125 r3132  
    2929/* 
    3030    float4 average = .0f; 
    31  
    3231    for (int i = 0; i < NUM_DOWNSAMPLES; ++ i) 
    3332    { 
    3433                average += tex2Dlod(colors, float4(IN.texCoord + downSampleOffs[i], 0, 0)); 
    35     } 
    36         
     34    }   
    3735        average *= 1.0f / (float)NUM_DOWNSAMPLES; 
    3836 
     
    151149 
    152150        float lum = dot(color.rgb, w); 
    153         float logLum = log(1e-5f + lum); 
     151        float logLum = log(max(1e-3f, lum)); 
    154152 
    155153        float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 
     
    158156        const float expFactor = 0.1f; 
    159157        // 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) 
    161159                OUT.col.w = lerp(oldLogLum, logLumScaled, expFactor); 
    162160        else 
Note: See TracChangeset for help on using the changeset viewer.