Changeset 3311 for GTP


Ignore:
Timestamp:
02/13/09 18:37:42 (15 years ago)
Author:
mattausch
Message:

worked on sampling method for hierarchical poisson

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

Legend:

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

    r3310 r3311  
    106106ssaoSampleIntensity=0.8f 
    107107# ssao temporal coherence factor 
    108 tempCohFactor=100.0f 
     108tempCohFactor=1024.0f 
    109109# ssao filter radius 
    110110ssaoFilterRadius=12.0f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3310 r3311  
    7171static GLuint noiseTex2D = 0; 
    7272static GLuint noiseTex1D = 0; 
    73  
     73static GLuint sampleTex2D = 0; 
    7474 
    7575 
     
    9292/** Helper method that computes the view vectors in the corners of the current view frustum. 
    9393*/ 
    94 static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr) 
     94static void ComputeViewVectors(PerspectiveCamera *cam,  
     95                                                           Vector3 &bl, 
     96                                                           Vector3 &br,  
     97                                                           Vector3 &tl, 
     98                                                           Vector3 &tr) 
    9599{ 
    96100        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     
    258262 
    259263        cout << "created noise texture" << endl; 
     264 
     265        PrintGLerror("noisetexture"); 
     266} 
     267 
     268 
     269static 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; 
    260301 
    261302        PrintGLerror("noisetexture"); 
     
    428469 
    429470        string ssaoParams[] =  
    430                 {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence",  
     471            {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence",  
    431472                 "samples", "bl", "br", "tl", "tr",  
    432473                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    433474                 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"}; 
     475         
    434476        sCgSsaoProgram->AddParameters(ssaoParams, 0, 20); 
    435477         
     
    751793                // needs longer to converge 
    752794                GenerateSamples(mSamplingMethod); 
    753  
     795                CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
    754796                //if (mSortSamples) { SortSamples(); } 
    755797                //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    756                 sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 
     798                //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 
     799                sCgSsaoProgram->SetTexture(i, sampleTex2D); 
    757800        } 
    758801         
     
    772815        de.y = mOldEyePos.y - mEyePos.y;  
    773816        de.z = mOldEyePos.z - mEyePos.z; 
     817 
    774818 
    775819        sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r3247 r3311  
    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) 
     174PoissonDiscSampleGenerator2D(numSamples, radius) 
     175//RandomSampleGenerator2D(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

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

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

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

    r3310 r3311  
    145145        { 
    146146                // the filtered ssao value 
    147                 //OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 
     147                OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 
    148148        } 
    149149 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3309 r3311  
    263263 
    264264        // check if the pixel belonged to a dyanmic object in the last frame 
    265         const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    266         const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
     265        const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
     266        const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    267267 
    268268        // actually 0 means pixel is valid 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3310 r3311  
    224224                        sampler2D colors, 
    225225                        sampler2D noiseTex, 
    226                         float2 samples[NUM_PRECOMPUTED_SAMPLES], 
     226                        sampler2D samples, 
    227227                        float3 normal, 
    228228                        float3 centerPosition, 
     
    236236                        float sampleIntensity, 
    237237                        bool isMovingObject, 
    238                         int idx 
     238                        float idx 
    239239                        ) 
    240240{ 
     
    251251                //-- (affects performance for some reason!) 
    252252 
    253                 if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD) 
     253                const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
     254 
     255                if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
    254256                { 
    255                         float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     257                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord.x * 4.0f + idx * 0.01f, IN.texCoord.y * 4.0f, 0, 0)).xy; 
    256258                        //offset = myreflect(samples[i], mynoise); 
    257                         offset = myrotate(samples[i], mynoise.x); 
    258                         //offset = myrotate(samples[i + idx], mynoise.x); 
     259                        //offset = myrotate(samples[i], mynoise.x); 
     260 
     261                        offset = myrotate(ssaoOffset, mynoise.x); 
    259262                } 
    260263                else 
    261264                { 
    262                         //offset = samples[i + idx]; 
    263                         offset = samples[i]; 
     265                        offset = ssaoOffset; 
     266                        //offset = samples[i]; 
    264267                } 
    265268                 
     
    312315                        // if the pixel belongs to a static object and all the samples stay valid in the current frame 
    313316                        if (!isMovingObject && (validSamples < 1.0f)) break; 
    314                         // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high  
    315                         // (=> there was no discontinuity recently) 
     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) 
    316319                        else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
    317320                } 
     
    341344                   uniform sampler2D normals, 
    342345                   uniform sampler2D noiseTex, 
    343                    uniform float2 samples[NUM_PRECOMPUTED_SAMPLES], 
     346                   uniform sampler2D samples, 
    344347                   uniform sampler2D oldTex, 
    345348                   uniform float4x4 modelViewProj, 
     
    400403        float oldWeight = temporalVals.y; 
    401404 
    402         int idx = (int)temporalVals.z; 
    403                 //min(0, (int)oldWeight % max((int)temporalCoherence, 1)); 
     405        float idx = (int)temporalVals.z; 
     406 
     407        if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 
    404408 
    405409        float3 ao; 
     
    425429        // the weight equals the number of sampled shot in this pass 
    426430        const float newWeight = ao.z; 
     431 
     432        idx += newWeight; 
    427433 
    428434        // completely reset the ao in this pixel 
     
    442448                { 
    443449                        oldWeight = min(oldWeight, 4.0f * newWeight); 
    444                         idx = oldWeight; 
    445450                } 
    446451        } 
    447  
    448         float usedWeight = min(temporalCoherence, oldWeight); 
    449452 
    450453 
     
    452455        //-- blend ao between old and new samples (and avoid division by zero) 
    453456 
    454         OUT.illum_col.x = ao.x * newWeight;// + oldSsao * usedWeight; 
    455         OUT.illum_col.x /= max(newWeight + usedWeight, 1); 
    456  
    457         //if (oldWeight >= 10000) oldWeight = 1000; 
     457        OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 
     458        OUT.illum_col.x /= (newWeight + oldWeight); 
    458459 
    459460        // the new weight for the next frame 
    460         //const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    461         float combinedWeight = newWeight + oldWeight; 
    462  
    463         clamp(combinedWeight, 0, 1000); 
    464  
     461        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
     462         
    465463        OUT.illum_col.y = combinedWeight; 
    466464        // can be used to check if this pixel belongs to a moving object 
    467         OUT.illum_col.z = SqrLen(diffVec); 
     465        //OUT.illum_col.z = SqrLen(diffVec); 
     466        OUT.illum_col.z = idx; 
    468467        OUT.illum_col.w = eyeSpaceDepth; 
    469468 
Note: See TracChangeset for help on using the changeset viewer.