Changeset 3325 for GTP


Ignore:
Timestamp:
02/23/09 13:24:44 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3324 r3325  
    549549         
    550550        string prepareSsaoParams[] =  
    551                 {"colorsTex", "normalsTex", "diffVals", "oldTex",  
     551                {"colorsTex", "normalsTex", "diffVals", "oldTex", "oldTex2",  
    552552                 "oldEyePos", "modelViewProj", "oldModelViewProj", 
    553553                 "oldbl", "oldbr", "oldtl", "oldtr"}; 
    554554 
    555         sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11); 
     555        sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 12); 
    556556 
    557557 
     
    770770        attribsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    771771 
    772         // flip flop between illumination buffers 
    773         GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     772 
     773        ///////// 
     774        //-- flip flop between illumination buffers 
     775 
     776        GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    774777 
    775778        glPushAttrib(GL_VIEWPORT_BIT); 
     
    778781        // read the second buffer, write to the first buffer 
    779782        mIllumFbo->Bind(); 
    780         glDrawBuffers(1, mrt + mIllumFboIndex); 
     783        glDrawBuffers(2, mrt + mIllumFboIndex); 
    781784 
    782785        int i = 0; 
     
    784787        sCgSsaoProgram->SetTexture(i ++, colorsTex); 
    785788        sCgSsaoProgram->SetTexture(i ++, normalsTex); 
    786         sCgSsaoProgram->SetTexture(i ++, oldTex); 
     789        sCgSsaoProgram->SetTexture(i ++, oldSsaoTex); 
    787790        sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 
    788791 
    789792        sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    790793         
     794 
    791795        if (/*mUseTemporalCoherence || */mRegenerateSamples) 
    792796        { 
     
    11661170        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    11671171        GLuint diffVals = fbo->GetColorBuffer(2)->GetTexture(); 
     1172 
    11681173        // flip flop between illumination buffers 
    11691174        GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     1175        GLuint oldTex2 = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 
    11701176 
    11711177        int i = 0; 
     
    11751181        sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    11761182        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 
     1183        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex2); 
    11771184 
    11781185        Vector3 de; 
     
    11871194 
    11881195        for (int j = 0; j < 4; ++ j, ++ i) 
     1196        { 
    11891197                sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 
     1198        } 
    11901199 
    11911200        glPushAttrib(GL_VIEWPORT_BIT); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3321 r3325  
    657657        Matrix4x4 transl = TranslationMatrix(positions[0]); 
    658658         
    659         //LoadModel("hbuddha.dem", dynamicObjects); 
    660         LoadModel("venusm.dem", dynamicObjects); 
     659        LoadModel("hbuddha.dem", dynamicObjects); 
     660        //LoadModel("venusm.dem", dynamicObjects); 
    661661 
    662662        buddha = dynamicObjects.back(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3324 r3325  
    99//#define NUM_SAMPLES 16 
    1010//#define NUM_SAMPLES 24 
    11 #define NUM_SAMPLES 48 
     11#define NUM_SAMPLES 8 
    1212 
    1313//#define MIN_SAMPLES 48 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3324 r3325  
    3838 
    3939        // hack: prevent shading the sky 
    40         if (color.w > 1e19f) outColor = color; 
    41         else outColor = (ambient + diffuse) * color; 
     40        if (color.w > DEPTH_THRESHOLD) 
     41        { 
     42                outColor = color; 
     43        } 
     44        else  
     45        { 
     46                outColor = (ambient + diffuse) * color; 
     47        } 
    4248 
    4349        return outColor; 
     
    203209        */ 
    204210inline float2 PixelValid(sampler2D oldTex, 
    205                                                 float4 color, 
    206                                                 float3 difVec, 
    207                                                 float2 texCoord, 
    208                                                 float3 viewDir, 
    209                                                 float3 oldEyePos, 
    210                                                 float4x4 modelViewProj, 
    211                                                 float4x4 oldModelViewProj, 
    212                                                 float3 oldbl, 
    213                                                 float3 oldbr, 
    214                                                 float3 oldtl, 
    215                                                 float3 oldtr 
    216                                                 ) 
     211                                                 sampler2D oldTex2, 
     212                                                 float4 color, 
     213                                                 float3 difVec, 
     214                                                 float2 texCoord, 
     215                                                 float3 viewDir, 
     216                                                 float3 oldEyePos, 
     217                                                 float4x4 modelViewProj, 
     218                                                 float4x4 oldModelViewProj, 
     219                                                 float3 oldbl, 
     220                                                 float3 oldbr, 
     221                                                 float3 oldtl, 
     222                                                 float3 oldtr 
     223                                                 ) 
    217224{ 
    218225        // reconstruct position from the eye space depth 
     
    220227        const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
    221228 
    222          
    223229 
    224230        //////////////// 
     
    247253        // retrieve the sample from the last frame 
    248254        const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 
     255        const float4 oldPixel2 = tex2Dlod(oldTex2, float4(oldTexCoords, .0f, .0f)); 
    249256 
    250257        // calculate eye space position of sample in old frame 
     
    260267         
    261268        // test if this pixel was valid in the old frame 
    262         float IsPixelValid; 
    263  
    264         // check if the pixel belonged to a dyanmic object in the last frame 
    265         const bool oldDynamic =  false;(squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    266         const bool newDynamic = false; (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
     269        float isPixelValid; 
     270 
     271        // check if the pixel belonged to a dynamic object in the last frame 
     272        const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
     273        const bool oldDynamic = (oldPixel2.x > DYNAMIC_OBJECTS_THRESHOLD); 
    267274 
    268275        // actually 0 means pixel is valid 
     
    279286                ) 
    280287        { 
    281                 IsPixelValid = pixelIsNotValid; 
     288                isPixelValid = pixelIsNotValid; 
    282289        } 
    283290        else if (// check if changed from dynamic to not dynamic object 
     
    287294                // check if we have a dynamic object  
    288295                (oldDynamic || newDynamic) &&  
    289                 // and is a depth discontinuity 
     296                // and there is a depth discontinuity 
    290297                (depthDif > MIN_DEPTH_DIFF)))) 
    291298        {        
    292                 IsPixelValid = pixelCouldBeValid;  
     299                isPixelValid = pixelCouldBeValid;  
    293300        } 
    294301        else  
    295302        { 
    296                 IsPixelValid = pixelIsValid; 
    297         } 
    298  
    299         return float2(IsPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
     303                isPixelValid = pixelIsValid; 
     304        } 
     305 
     306        return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
    300307} 
    301308 
     
    309316                                   uniform sampler2D diffVals, 
    310317                                   uniform sampler2D oldTex, 
     318                                   uniform sampler2D oldTex2, 
    311319                                   uniform float4x4 modelViewProj, 
    312320                                   uniform float4x4 oldModelViewProj, 
     
    319327{    
    320328        pixel pix; 
     329 
    321330        float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
    322331        // store scaled view vector so wie don't have to normalize for e.g., ssao 
     
    329338        // do reprojection and filter out the pixels that are not save 
    330339        float2 pValid = PixelValid(oldTex, 
    331                               color,  
    332                                                           difVec.xyz, 
    333                                                           IN.texCoord, 
    334                                                           IN.view, 
    335                                                           oldEyePos, 
    336                                                           modelViewProj, 
    337                                                           oldModelViewProj, 
    338                                                           oldbl, oldbr, oldtl, oldtr 
    339                                                           ); 
     340                                       oldTex2, 
     341                                       color,  
     342                                                           difVec.xyz, 
     343                                                           IN.texCoord, 
     344                                                           IN.view, 
     345                                                           oldEyePos, 
     346                                                           modelViewProj, 
     347                                                           oldModelViewProj, 
     348                                                           oldbl, oldbr, oldtl, oldtr 
     349                                                           ); 
    340350 
    341351        pix.color = color; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3324 r3325  
    1717 
    1818 
    19 struct pixel 
     19/*struct pixel 
    2020{ 
    2121        float4 illum_col: COLOR0; 
    2222}; 
     23*/ 
     24 
     25struct pixel2 
     26{ 
     27        float4 illum_col: COLOR0; 
     28        float4 col: COLOR1; 
     29}; 
     30 
    2331 
    2432// this function is inspired from the paper of shamulgaan in order 
     
    125133        // the weight of the accumulated samples from the previous frames 
    126134        float w; 
    127  
    128         float idx = oldPixel.z; 
     135        float idx; 
    129136 
    130137        ////////////// 
     
    147154                //w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 
    148155                w = oldPixel.y; 
     156                idx = floor(oldPixel.z); 
     157 
    149158        } 
    150159        else 
    151160        {        
    152161                w = 0.0f; 
     162                idx = .0f; 
    153163        } 
    154164 
     
    182192                         bool isMovingObject, 
    183193                         sampler2D normalTex, 
    184                          int idx 
     194                         float idx 
    185195                         ) 
    186196{ 
     
    200210                //-- (affects performance for some reason!) 
    201211 
    202                 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
     212                if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD) 
    203213                { 
    204214                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     
    444454/** The mrt shader for screen space ambient occlusion 
    445455*/ 
    446 pixel main(fragment IN,  
    447                    uniform sampler2D colors, 
    448                    uniform sampler2D normals, 
    449                    uniform sampler2D noiseTex, 
    450                    uniform sampler2D samples, 
    451                    uniform sampler2D oldTex, 
    452                    uniform float4x4 modelViewProj, 
    453                    uniform float4x4 oldModelViewProj, 
    454                    uniform float temporalCoherence, 
    455                    uniform float3 bl, 
    456                    uniform float3 br, 
    457                    uniform float3 tl, 
    458                    uniform float3 tr, 
    459                    uniform float3 oldEyePos, 
    460                    uniform float3 oldbl, 
    461                    uniform float3 oldbr, 
    462                    uniform float3 oldtl, 
    463                    uniform float3 oldtr, 
    464                    uniform sampler2D attribsTex, 
    465                    uniform float kernelRadius, 
    466                    uniform float sampleIntensity 
    467                    ) 
    468 { 
    469         pixel OUT; 
     456pixel2 main(fragment IN,  
     457                        uniform sampler2D colors, 
     458                        uniform sampler2D normals, 
     459                        uniform sampler2D noiseTex, 
     460                        uniform sampler2D samples, 
     461                        uniform sampler2D oldTex, 
     462                        uniform float4x4 modelViewProj, 
     463                        uniform float4x4 oldModelViewProj, 
     464                        uniform float temporalCoherence, 
     465                        uniform float3 bl, 
     466                        uniform float3 br, 
     467                        uniform float3 tl, 
     468                        uniform float3 tr, 
     469                        uniform float3 oldEyePos, 
     470                        uniform float3 oldbl, 
     471                        uniform float3 oldbr, 
     472                        uniform float3 oldtl, 
     473                        uniform float3 oldtr, 
     474                        uniform sampler2D attribsTex, 
     475                        uniform float kernelRadius, 
     476                        uniform float sampleIntensity 
     477                        ) 
     478{ 
     479        pixel2 OUT; 
    470480 
    471481        //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     
    515525                //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    516526                ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 
    517                 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    518527        } 
    519528        else 
     
    535544        const float partlyResetThres = 1.0f; 
    536545         
     546        // don't check for moving objects, otherwise almost no coherence 
    537547        if (!isMovingObject) 
    538548        { 
    539549                if (ao.y > completelyResetThres)  
    540550                { 
     551                        oldWeight = .0f; 
     552                        oldIdx = .0f; 
     553                } 
     554                else if (ao.y > partlyResetThres) 
     555                { 
     556                        //oldWeight = min(oldWeight, 4.0f * newWeight); 
    541557                        oldWeight = .0f;  
    542                 } 
    543                 else if (ao.y > partlyResetThres) 
    544                 { 
    545                         oldWeight = min(oldWeight, 4.0f * newWeight); 
    546                         //oldWeight = .0f;  
     558                        oldIdx = .0f; 
    547559                } 
    548560        } 
     
    551563        //-- blend ao between old and new samples (and avoid division by zero) 
    552564 
    553         OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 
    554  
     565        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight); 
    555566        OUT.illum_col.x /= (newWeight + oldWeight); 
    556567 
     
    559570 
    560571        OUT.illum_col.y = combinedWeight; 
     572        OUT.illum_col.z = oldIdx + newWeight; // the new index 
     573        OUT.illum_col.w = eyeSpaceDepth; 
     574 
    561575        // can be used to check if this pixel belongs to a moving object 
     576        OUT.col.x = SqrLen(diffVec); 
    562577        //OUT.illum_col.z = SqrLen(diffVec); 
    563         OUT.illum_col.z = oldIdx + newWeight; 
    564         OUT.illum_col.w = eyeSpaceDepth; 
    565  
    566         //OUT.illum_col.yzw = diffVec; 
    567  
     578         
    568579        return OUT; 
    569580} 
Note: See TracChangeset for help on using the changeset viewer.