Changeset 3129 for GTP


Ignore:
Timestamp:
11/16/08 23:57:33 (16 years ago)
Author:
mattausch
Message:

tried different techniques for smoothing the flickering for moving objects
fixed kernel + rotation + jittering not working yet
smoothssao function working better now (also test different filter sizes!)

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r3128 r3129  
    6060 
    6161 
    62 static GLuint noiseTex = 0; 
     62static GLuint noiseTex2D = 0; 
     63static GLuint noiseTex1D = 0; 
    6364 
    6465 
     
    214215 
    215216        glEnable(GL_TEXTURE_2D); 
    216         glGenTextures(1, &noiseTex); 
    217         glBindTexture(GL_TEXTURE_2D, noiseTex); 
     217        glGenTextures(1, &noiseTex2D); 
     218        glBindTexture(GL_TEXTURE_2D, noiseTex2D); 
    218219                 
    219220        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     
    233234        PrintGLerror("noisetexture"); 
    234235} 
     236 
     237 
     238static void CreateNoiseTex1D(int w) 
     239{ 
     240        float *randomValues = new float[w * 3]; 
     241 
     242        static HaltonSequence halton; 
     243         
     244        randomValues[0] = randomValues[1] = randomValues[2] = 0; 
     245 
     246        for (int i = 3; i < w * 3; i += 3) 
     247        { 
     248                // create random samples on a circle 
     249                randomValues[i + 0] = 20.0f * RandomValue(0, 1) / 512.0f; 
     250                randomValues[i + 1] = 20.0f * RandomValue(0, 1) / 384.0f; 
     251                randomValues[i + 2] = 0; 
     252        } 
     253 
     254        glEnable(GL_TEXTURE_2D); 
     255        glGenTextures(1, &noiseTex1D); 
     256        glBindTexture(GL_TEXTURE_2D, noiseTex1D); 
     257                 
     258        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     259        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     260        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
     261        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
     262 
     263        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, 1, 0, GL_RGB, GL_FLOAT, randomValues); 
     264 
     265        glBindTexture(GL_TEXTURE_2D, 0); 
     266        glDisable(GL_TEXTURE_2D); 
     267 
     268        delete [] randomValues; 
     269 
     270        cout << "created noise texture 1D" << endl; 
     271 
     272        PrintGLerror("noisetexture 1D"); 
     273} 
     274 
    235275 
    236276 
     
    284324        //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    285325        CreateNoiseTex2D(mWidth / 8, mHeight / 8); 
     326        CreateNoiseTex1D(mWidth / 8); 
    286327 
    287328        mProjViewMatrix = IdentityMatrix(); 
     
    302343{ 
    303344        CLEAR_CONTAINER(mFBOs); 
    304         glDeleteTextures(1, &noiseTex); 
     345        glDeleteTextures(1, &noiseTex2D); 
     346        glDeleteTextures(1, &noiseTex1D); 
    305347} 
    306348 
     
    337379                 "samples", "bl", "br", "tl", "tr",  
    338380                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    339                  "oldtl", "oldtr", "attribsTex"}; 
    340         sCgSsaoProgram->AddParameters(ssaoParams, 0, 18); 
     381                 "oldtl", "oldtr", "attribsTex", "noiseTex1D"}; 
     382        sCgSsaoProgram->AddParameters(ssaoParams, 0, 19); 
    341383         
    342384        string giParams[] =  
     
    538580        sCgSsaoProgram->SetTexture(i ++, normalsTex); 
    539581        sCgSsaoProgram->SetTexture(i ++, oldTex); 
    540         sCgSsaoProgram->SetTexture(i ++, noiseTex); 
     582        sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 
    541583 
    542584        sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    543585         
    544         //if (mUseTemporalCoherence || mRegenerateSamples) 
    545         if (mRegenerateSamples) 
     586        if (mUseTemporalCoherence || mRegenerateSamples) 
     587        //if (mRegenerateSamples) 
    546588        { 
    547589                mRegenerateSamples = false; 
     
    550592                // in the first case, the sample patterns look nicer, but the kernel 
    551593                // needs longer to converge 
    552                 GenerateSamples(mSamplingMethod);  
     594                GenerateSamples(mSamplingMethod); 
    553595                sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    554596        } 
     
    573615 
    574616        sCgSsaoProgram->SetTexture(i ++, attribsTex); 
     617 
     618        sCgSsaoProgram->SetTexture(i ++, noiseTex1D); 
    575619 
    576620        DrawQuad(sCgSsaoProgram); 
     
    675719        sCgGiProgram->SetTexture(0, colorsTex); 
    676720        sCgGiProgram->SetTexture(1, normalsTex); 
    677         sCgGiProgram->SetTexture(2, noiseTex); 
     721        sCgGiProgram->SetTexture(2, noiseTex2D); 
    678722        sCgGiProgram->SetTexture(3, oldSsaoTex); 
    679723        sCgGiProgram->SetTexture(4, oldIllumTex); 
     
    748792        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    749793        GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     794        //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    750795 
    751796        // overwrite old color texture 
     
    787832        sCgDeferredShadowProgram->SetTexture(1, normalsTex); 
    788833        sCgDeferredShadowProgram->SetTexture(2, shadowTex); 
    789         sCgDeferredShadowProgram->SetTexture(3, noiseTex); 
     834        sCgDeferredShadowProgram->SetTexture(3, noiseTex2D); 
    790835        sCgDeferredShadowProgram->SetMatrix(4, shadowMatrix); 
    791836        sCgDeferredShadowProgram->SetValue1f(5, 2.0f / shadowMap->GetSize()); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h

    r2839 r3129  
    156156 
    157157        // special construtor for pregenerating static halton sequences 
    158         HaltonSequence(const int dim, const int number); 
    159  
    160         HaltonSequence(): index(1) {} 
    161  
    162         void Reset()  
    163         { 
    164                 index = 1; 
    165         } 
    166  
    167         void 
    168                 GetNext(const int dimensions, float *p); 
    169  
    170         void GenerateNext()  
    171         { 
    172                 ++ index; 
    173         } 
     158        HaltonSequence(int dim, int number); 
     159 
     160        HaltonSequence(): index(1)  
     161        {  
     162                float dummy[2];  
     163                for (int i = 0; i < 20; ++ i) GetNext(2, dummy); 
     164        } 
     165 
     166        void Reset() { index = 1; } 
     167 
     168        void GetNext(int dimensions, float *p); 
     169 
     170        void GenerateNext() { ++ index; } 
    174171 
    175172        double GetNumber(const int dimension)   
    176173        { 
    177174                int base = FindPrime(dimension); 
    178                 if(base == 1) { 
    179                         base++;  //The first dimension uses base 2. 
     175                if (base == 1)  
     176                { 
     177                        base++;  // The first dimension uses base 2. 
    180178                }  
    181179 
    182180                int _p1 = base; 
    183                 float _ip1 = 1.0f/base; 
     181                float _ip1 = 1.0f / base; 
    184182                float p, u=0.0f; 
    185183                int kk, a; 
     
    198196                @param dimension the dimension 
    199197        */ 
    200         double GetNumberOld(const int dimension)   
     198        double GetNumberOld(int dimension)   
    201199        { 
    202200                int base = FindPrime(dimension); 
     
    214212                if ((base >= 2) && (index >= 1))  
    215213                { 
    216                         while(copyOfIndex > 0)  
     214                        while (copyOfIndex > 0)  
    217215                        { 
    218216                                N1 = (copyOfIndex / base); 
     
    226224                else  
    227225                { 
    228                         std::cerr<<"Error generating Halton sequence."<<std::endl; 
     226                        std::cerr << "Error generating Halton sequence." << std::endl; 
    229227                        exit(1); 
    230228                } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3128 r3129  
    167167 
    168168                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    169                 depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    170                 normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
    171  
    172                 w = filterWeights[i] * normalFactor * depthFactor; 
    173                 //w = filterWeights[i] * depthFactor; 
     169                depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
     170                normalFactor = max(step(0.3f, dot(sampleNorm, norm)), 1e-3f); 
     171 
     172                //w = filterWeights[i] * normalFactor * depthFactor; 
     173                w = normalFactor * depthFactor; 
    174174 
    175175                average += aoSample.y * w; 
     
    177177        } 
    178178 
    179         average *= 1.0f / max(total_w, 1e-6f); 
     179        average *= 1.0f / max(total_w, 1e-3f); 
    180180 
    181181        return average; 
     
    193193        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    194194 
    195         //const static float scaleFactor = 10.0f; 
     195        //const static float scaleFactor = 20.0f; 
    196196        const static float scaleFactor = 10.0f; 
    197  
    198197        ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 
    199198         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3128 r3129  
    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; 
     
    220220                // if visibility changed in the surrounding area we have to recompute 
    221221                //&& (oldNumSamples > 0.8f * newNumSamples) 
    222                 && (notValid < 1.0f) 
     222                //&& (notValid < 1.0f) 
    223223                ) 
    224224        { 
    225225                // increase the weight for convergence 
    226226                newWeight = oldWeight + 1.0f; 
    227                 //if (notValid > 1.0f) newWeight = 10.0f; 
     227                if (notValid > 1.0f) newWeight = 10.0f; 
    228228                //if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f); 
    229229        } 
     
    236236        //      newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 
    237237        //if (newWeight >= 2000) newWeight = 1000; 
    238         //newWeight -= step(2000.0f, newWeight) * 1000.0f; 
     238        newWeight -= step(512.0f, newWeight) * 256.0f; 
    239239 
    240240        return float3(oldPixel.x, newWeight, eyeSpaceDepth); 
     
    257257                        float3 viewDir 
    258258                        , float2 noiseOffs 
     259                        , sampler2D noiseTex1D 
    259260                        ) 
    260261{ 
     
    266267        float numSamples = .0f; 
    267268 
     269 
     270        //float2 jitter = tex2Dlod(noiseTex1D, float4(IN.texCoord.x * 4.0f + noiseOffs.x, 0.5f, 0, 0)).xy; 
     271        //float2 jitter = tex2Dlod(noiseTex1D, float4(noiseOffs.x, 0.5f, 0, 0)).xy; 
    268272 
    269273        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     
    282286#endif 
    283287                // weight with projected coordinate to reach similar kernel size for near and far 
     288                //const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter; 
    284289                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
    285290 
    286291                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    287  
    288292                const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
    289293 
     
    340344                   uniform float3 oldtl, 
    341345                   uniform float3 oldtr, 
    342                    uniform sampler2D attribsTex 
     346                   uniform sampler2D attribsTex, 
     347                   uniform sampler2D noiseTex1D 
    343348                   ) 
    344349{ 
     
    378383                                                                                        scaleFactor,  
    379384                                                                                        oldbl, oldbr, oldtl, oldtr, 
    380                                                                                         diffVec); 
     385                                                                                        diffVec 
     386                                                                                        ); 
    381387 
    382388        const float oldSsao = temporalVals.x; 
    383         const float newWeight = clamp(temporalVals.y, .0f, temporalCoherence); 
    384  
    385         //float2 noiseOffs = float2(temporalVals.y / 139.0f, temporalVals.y / 141.0f); 
    386         float2 noiseOffs = float2(.0f); 
     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); 
    387392 
    388393        float2 ao; 
     
    392397        { 
    393398                ao = ssao(IN, colors, noiseTex, samples, normal,  
    394                           eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs); 
     399                          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs, noiseTex1D); 
    395400        } 
    396401        else 
Note: See TracChangeset for help on using the changeset viewer.