Changeset 3313 for GTP


Ignore:
Timestamp:
02/16/09 17:08:51 (15 years ago)
Author:
mattausch
Message:

reverted back to before poisson sampling scheme

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env

    r3312 r3313  
    106106ssaoSampleIntensity=0.8f 
    107107# ssao temporal coherence factor 
    108 tempCohFactor=2048.0f 
     108tempCohFactor=2000.0f 
    109109# ssao filter radius 
    110110ssaoFilterRadius=12.0f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3311 r3313  
    7171static GLuint noiseTex2D = 0; 
    7272static GLuint noiseTex1D = 0; 
    73 static GLuint sampleTex2D = 0; 
    74  
    75  
    76 static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 
     73 
     74 
    7775// ssao random spherical samples 
    78 //static Sample2 samples2[NUM_SAMPLES]; 
    79  
     76static Sample2 samples2[NUM_SAMPLES]; 
     77//#define NUM_PRECOMPUTED_SAMPLES 240 
     78//static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 
    8079// pcf samples 
    8180static Sample2 pcfSamples[NUM_PCF_TABS]; 
     
    9291/** Helper method that computes the view vectors in the corners of the current view frustum. 
    9392*/ 
    94 static void ComputeViewVectors(PerspectiveCamera *cam,  
    95                                                            Vector3 &bl, 
    96                                                            Vector3 &br,  
    97                                                            Vector3 &tl, 
    98                                                            Vector3 &tr) 
     93static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr) 
    9994{ 
    10095        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     
    212207        case DeferredRenderer::SAMPLING_QUADRATIC: 
    213208                { 
    214                         QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
    215                         //static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
     209                        //static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
     210                        static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
    216211                        g.Generate((float *)samples2); 
    217212                } 
     
    262257 
    263258        cout << "created noise texture" << endl; 
    264  
    265         PrintGLerror("noisetexture"); 
    266 } 
    267  
    268  
    269 static void CreateSampleTex(Sample2 *samples, int numSamples) 
    270 { 
    271         glEnable(GL_TEXTURE_2D); 
    272         glGenTextures(1, &sampleTex2D); 
    273         glBindTexture(GL_TEXTURE_2D, sampleTex2D); 
    274                  
    275         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    276         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    277         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    278         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    279  
    280         int w = numSamples; 
    281         int h = 1; 
    282  
    283         float *tempBuffer = new float[numSamples * 3]; 
    284  
    285         for (int i = 0; i < numSamples; ++ i) 
    286         { 
    287                 tempBuffer[i * 3 + 0] = samples[i].x; 
    288                 tempBuffer[i * 3 + 1] = samples[i].y; 
    289                 tempBuffer[i * 3 + 2] = 0; 
    290                  
    291         } 
    292  
    293         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer); 
    294  
    295         glBindTexture(GL_TEXTURE_2D, 0); 
    296         glDisable(GL_TEXTURE_2D); 
    297  
    298         cout << "created sample texture" << endl; 
    299  
    300         delete [] tempBuffer; 
    301259 
    302260        PrintGLerror("noisetexture"); 
     
    469427 
    470428        string ssaoParams[] =  
    471             {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence",  
     429                {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence",  
    472430                 "samples", "bl", "br", "tl", "tr",  
    473431                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    474432                 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"}; 
    475          
    476433        sCgSsaoProgram->AddParameters(ssaoParams, 0, 20); 
    477434         
     
    783740        sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 
    784741 
    785         sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : .0f); 
    786          
    787         if (/*mUseTemporalCoherence || */mRegenerateSamples) 
     742        sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
     743         
     744        static int currentPos = 0; 
     745 
     746        if (mUseTemporalCoherence || mRegenerateSamples) 
    788747        { 
    789748                mRegenerateSamples = false; 
     
    792751                // in the first case, the sample patterns look nicer, but the kernel 
    793752                // needs longer to converge 
    794                 GenerateSamples(mSamplingMethod); 
    795                 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
     753                //if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)      { 
     754                        currentPos = 0; 
     755                        GenerateSamples(mSamplingMethod); 
     756                //} 
     757 
    796758                //if (mSortSamples) { SortSamples(); } 
    797                 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    798                 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 
    799                 sCgSsaoProgram->SetTexture(i, sampleTex2D); 
    800         } 
    801          
    802  
     759                sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES); 
     760 
     761                currentPos += NUM_SAMPLES; 
     762        } 
     763         
    803764        ++ i; 
    804765 
    805766        for (int j = 0; j < 4; ++ j, ++ i) 
    806         { 
    807767                sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 
    808         } 
    809768 
    810769        sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix); 
     
    815774        de.y = mOldEyePos.y - mEyePos.y;  
    816775        de.z = mOldEyePos.z - mEyePos.z; 
    817  
    818776 
    819777        sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r3311 r3313  
    5151        int tries = 0; 
    5252 
    53         cout << "minDist before= " << minDist << endl; 
     53        //cout << "minDist before= " << minDist << endl; 
    5454        Sample2 *s = (Sample2 *)samples; 
    5555 
     
    109109        } 
    110110 
    111         cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl; 
     111        //cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl; 
    112112} 
    113113 
     
    172172 
    173173QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius): 
    174 PoissonDiscSampleGenerator2D(numSamples, radius) 
    175 //RandomSampleGenerator2D(numSamples, radius) 
     174//PoissonDiscSampleGenerator2D(numSamples, radius) 
     175RandomSampleGenerator2D(numSamples, radius) 
    176176{} 
    177177 
     
    194194#else 
    195195 
    196         PoissonDiscSampleGenerator2D::Generate(samples); 
    197         //RandomSampleGenerator2D::Generate(samples); 
     196        //PoissonDiscSampleGenerator2D::Generate(samples); 
     197        RandomSampleGenerator2D::Generate(samples); 
    198198 
    199199        Sample2 *s = (Sample2 *)samples; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h

    r3311 r3313  
    7878        with the distance 
    7979*/ 
    80 class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D 
    81 //class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D 
     80//class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D 
     81class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D 
    8282{ 
    8383public: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3311 r3313  
    12111211        if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) 
    12121212        { 
    1213                 if (!shadowMap) shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 
    1214                 if (!shadowTraverser) shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 
     1213                if (!shadowMap) 
     1214                        shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 
     1215 
     1216                if (!shadowTraverser) 
     1217                        shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 
     1218 
    12151219        } 
    12161220         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3312 r3313  
    55//////////// 
    66//-- ssao + gi parameters 
    7 #define NUM_PRECOMPUTED_SAMPLES 2048 
     7 
    88//#define NUM_SAMPLES 8 
    99//#define NUM_SAMPLES 16 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3311 r3313  
    114114} 
    115115 
     116/** In between step that only filters in one direction 
     117*/ 
     118pixel FilterSsaoFullRes(fragment IN,  
     119                                                uniform sampler2D colorsTex, 
     120                                                uniform sampler2D ssaoTex, 
     121                                                uniform float3 bl, 
     122                                                uniform float3 br, 
     123                                                uniform float3 tl, 
     124                                                uniform float3 tr, 
     125                                                uniform float2 res 
     126                                                ) 
     127{ 
     128        pixel OUT; 
     129 
     130        const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 
     131 
     132        OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
     133        // just take unfiltered convergence in current pixel 
     134        const float convergence = OUT.illum_col.y; 
     135 
     136        // filter reaches size 1 pixel when sample size reaches threshold  
     137        // afterwards we do not use the filter anymore 
     138 
     139        float2 xyStep = float2(1.0f / res.x, 0); 
     140 
     141        // filter up to a certain convergance value and leave out background (sky) by checking depth 
     142        if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 
     143        { 
     144                // the filtered ssao value 
     145                OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 
     146        } 
     147 
     148        return OUT; 
     149} 
    116150 
    117151/** In between step that only filters in one direction 
     
    151185} 
    152186 
    153  
    154 /** In between step that only filters in one direction 
    155 */ 
    156 pixel FilterSsaoFullRes(fragment IN,  
    157                                                 uniform sampler2D colorsTex, 
    158                                                 uniform sampler2D ssaoTex, 
    159                                                 uniform float3 bl, 
    160                                                 uniform float3 br, 
    161                                                 uniform float3 tl, 
    162                                                 uniform float3 tr, 
    163                                                 uniform float2 res 
    164                                                 ) 
    165 { 
    166         pixel OUT; 
    167  
    168         const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 
    169  
    170         OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    171         // just take unfiltered convergence in current pixel 
    172         const float convergence = OUT.illum_col.y; 
    173  
    174         // filter reaches size 1 pixel when sample size reaches threshold  
    175         // afterwards we do not use the filter anymore 
    176  
    177         const float2 xyStep = float2(1.0f / res.x, 0); 
    178  
    179         // filter up to a certain convergance value and leave out background (sky) by checking depth 
    180         if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 
    181         { 
    182                 // the filtered ssao value 
    183                 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 
    184         } 
    185  
    186         return OUT; 
    187 } 
    188  
    189  
    190187/** Function combining image and indirect illumination buffer using a  
    191188    depth and convergence aware discontinuity filter. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3311 r3313  
    263263 
    264264        // check if the pixel belonged to a dyanmic object in the last frame 
    265         const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    266         const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
     265        const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
     266        const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    267267 
    268268        // actually 0 means pixel is valid 
    269269        const float pixelIsValid = 0.0f; 
    270270        // means that we only use slight temporal coherence over some frames 
    271         // so that there is no noticeable drag 
     271        // so that there si no noticeable drag 
    272272        const float pixelCouldBeValid = 2.0f; 
    273273        // this pixel information has to be discarded in order to not create artifacts 
    274274        const float pixelIsNotValid = 100.0f; 
    275275 
    276         // check if the pixel was outside of the frame buffer 
    277         if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) ||  
    278                 (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f) 
     276        const float xOffs = 0;// 0.5f / 1024.0f; 
     277        const float yOffs = 0;// 0.5f / 768.0f; 
     278 
     279        if ((oldTexCoords.x < xOffs) || (oldTexCoords.x > (1.0f - xOffs)) ||  
     280                (oldTexCoords.y < yOffs) || (oldTexCoords.y > (1.0f - yOffs)) 
    279281                ) 
    280282        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3311 r3313  
    4848        weight of the pixel in the new frame. 
    4949*/ 
    50 inline float3 temporalSmoothing(float4 worldPos, 
     50inline float2 temporalSmoothing(float4 worldPos, 
    5151                                                                float eyeSpaceDepth, 
    5252                                                                float2 texcoord0, 
     
    9696        // the weight of the accumulated samples from the previous frames 
    9797        float w; 
    98         float idx; 
    9998 
    10099        ////////////// 
     
    109108                // pixel valid => retrieve the convergence weight 
    110109                w = oldPixel.y; 
    111                 idx = oldPixel.z; 
    112110        } 
    113111        else 
    114112        {        
    115                 w = .0f; 
    116                 idx = .0f; 
    117         } 
    118  
    119         return float3(ssao, w, idx); 
     113                w = 0.0f; 
     114        } 
     115 
     116        return float2(ssao, w); 
    120117} 
    121118 
     
    145142        float validSamples = .0f; 
    146143 
    147  
    148         for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i)  
     144        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    149145        { 
    150146                const float2 offset = samples[i]; 
     
    224220                        sampler2D colors, 
    225221                        sampler2D noiseTex, 
    226                         sampler2D samples, 
     222                        float2 samples[NUM_SAMPLES], 
    227223                        float3 normal, 
    228224                        float3 centerPosition, 
     
    235231                        float convergence, 
    236232                        float sampleIntensity, 
    237                         bool isMovingObject, 
    238                         float idx 
     233                        bool isMovingObject 
    239234                        ) 
    240235{ 
     
    242237        float validSamples = .0f; 
    243238        float numSamples = .0f; 
    244          
     239 
    245240        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    246241        { 
     
    251246                //-- (affects performance for some reason!) 
    252247 
    253                 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
    254  
    255248                if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
    256249                { 
    257                         float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord.x * 4.0f + idx * 0.01f, IN.texCoord.y * 4.0f, 0, 0)).xy; 
     250                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    258251                        //offset = myreflect(samples[i], mynoise); 
    259                         //offset = myrotate(samples[i], mynoise.x); 
    260  
    261                         offset = myrotate(ssaoOffset, mynoise.x); 
     252                        offset = myrotate(samples[i], mynoise.x); 
    262253                } 
    263254                else 
    264255                { 
    265                         offset = ssaoOffset; 
    266                         //offset = samples[i]; 
     256                        offset = samples[i]; 
    267257                } 
    268258                 
     
    304294                // we check if the sample could have been near enough to the current pixel  
    305295                // to have any influence in the current or last frame 
    306                 //const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
     296                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    307297                //validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 
    308298                validSamples = max(validSamples, pixelValid); 
     
    313303                if (numSamples >= MIN_SAMPLES) 
    314304                { 
     305                        //break; 
    315306                        // if the pixel belongs to a static object and all the samples stay valid in the current frame 
    316307                        if (!isMovingObject && (validSamples < 1.0f)) break; 
    317                         // if the pixel belongs to a dynamic object but the #accumulated samples 
    318                         // for this pixel is sufficiently high (=> there was no discontinuity recently) 
     308                        // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high  
     309                        // (=> there was no discontinuity recently) 
    319310                        else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
    320311                } 
     
    344335                   uniform sampler2D normals, 
    345336                   uniform sampler2D noiseTex, 
    346                    uniform sampler2D samples, 
     337                   uniform float2 samples[NUM_SAMPLES], 
    347338                   uniform sampler2D oldTex, 
    348339                   uniform float4x4 modelViewProj, 
     
    391382        //-- compute temporal reprojection 
    392383 
    393         float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
     384        float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
    394385                                                oldTex, oldModelViewProj,  
    395386                                                                                        colors,  
     
    402393        const float oldSsao = temporalVals.x; 
    403394        float oldWeight = temporalVals.y; 
    404  
    405         float idx = (int)temporalVals.z; 
    406  
    407         if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 
    408  
     395         
    409396        float3 ao; 
    410397 
     
    412399        if (eyeSpaceDepth < DEPTH_THRESHOLD) 
    413400        { 
    414                 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz,  
    415                               scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight,  
    416                                   sampleIntensity, isMovingObject, idx); 
     401                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    417402                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    418403        } 
     
    429414        // the weight equals the number of sampled shot in this pass 
    430415        const float newWeight = ao.z; 
    431  
    432         idx += newWeight; 
    433416 
    434417        // completely reset the ao in this pixel 
     
    437420        const float partlyResetThres = 1.0f; 
    438421         
    439         // hack: just update static geometry 
    440         if (!isMovingObject) 
     422        if (1)//!isMovingObject) 
    441423        { 
    442424                if (ao.y > completelyResetThres)  
    443425                { 
    444                         oldWeight = .0f; 
    445                         idx = .0f; 
     426                        oldWeight = .0f;  
    446427                } 
    447428                else if (ao.y > partlyResetThres) 
    448429                { 
    449430                        oldWeight = min(oldWeight, 4.0f * newWeight); 
     431                        //oldWeight = .0f;  
    450432                } 
    451433        } 
    452  
    453434 
    454435        ////////// 
    455436        //-- blend ao between old and new samples (and avoid division by zero) 
    456437 
    457         OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 
     438        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 
     439 
    458440        OUT.illum_col.x /= (newWeight + oldWeight); 
    459441 
    460442        // the new weight for the next frame 
    461443        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    462          
     444 
    463445        OUT.illum_col.y = combinedWeight; 
    464446        // can be used to check if this pixel belongs to a moving object 
    465         //OUT.illum_col.z = SqrLen(diffVec); 
    466         OUT.illum_col.z = idx; 
     447        OUT.illum_col.z = SqrLen(diffVec); 
    467448        OUT.illum_col.w = eyeSpaceDepth; 
    468449 
Note: See TracChangeset for help on using the changeset viewer.