Ignore:
Timestamp:
11/25/08 18:14:48 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r3166 r3167  
    7171 
    7272 
    73 static float ssaoFilterOffsets[NUM_SSAO_FILTERSAMPLES * 2]; 
    74 static float ssaoFilterWeights[NUM_SSAO_FILTERSAMPLES]; 
     73static float ssaoFilterOffsets[NUM_SSAO_FILTER_SAMPLES * 2]; 
     74static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 
    7575 
    7676 
     
    445445         
    446446        string prepareSsaoParams[] =  
    447                 {"colorsTex", "oldTex", "oldEyePos", "modelViewProj", "oldModelViewProj", 
    448                  "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"}; 
    449  
    450         sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 
     447                {"colorsTex", "normalsTex", "diffVals", "oldTex",  
     448                 "oldEyePos", "modelViewProj", "oldModelViewProj", 
     449                 "oldbl", "oldbr", "oldtl", "oldtr"}; 
     450 
     451        sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11); 
    451452 
    452453 
    453454        //////////////// 
    454455 
    455  
    456         //const float filterWidth = 100.0f; 
    457         const float filterWidth = 30.0f; 
    458         //const float filterWidth = 15.0f; 
    459  
    460         PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
     456        const float filterWidth = 1.0f; 
     457 
     458        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
    461459        poisson.Generate((float *)ssaoFilterOffsets); 
    462460 
     
    464462        const float yoffs = (float)filterWidth / mHeight; 
    465463 
    466         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     464        for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    467465        { 
    468466                float x = ssaoFilterOffsets[2 * i + 0]; 
     
    516514                //DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 
    517515                PrepareSsao(fbo); 
    518                 DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 
    519                 DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 
     516                //DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 
     517                //DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 
    520518        } 
    521519 
     
    570568 
    571569 
     570 
     571static inline float SqrMag(const Sample2 &s) 
     572{ 
     573        return (s.x * s.x + s.y * s.y); 
     574} 
     575 
     576 
     577static inline float SqrDist(const Sample2 &a, const Sample2 &b) 
     578{ 
     579        float x = a.x - b.x; 
     580        float y = a.y - b.y; 
     581         
     582        return x * x + y * y; 
     583} 
     584 
     585 
     586static inline bool lt(const Sample2 &a, const Sample2 &b) 
     587{ 
     588        return SqrMag(a) < SqrMag(b); 
     589} 
     590 
     591 
     592void DeferredRenderer::SortSamples() 
     593{ 
     594        //for (int i = 0; i < NUM_SAMPLES; ++ i)cout << SqrDist(samples2[i-1], samples2[i]) << "|"; 
     595        float dist = 0; 
     596        for (int i = 1; i < NUM_SAMPLES; ++ i) 
     597                dist += SqrDist(samples2[i-1], samples2[i]); 
     598                //cout << samples2[i].x << " " << samples2[i].y  
     599 
     600        //cout << "\nbefore: " << dist << endl; 
     601 
     602        //sort(samples2, samples2 + sizeof(samples2) / sizeof(Sample2), lt2); 
     603 
     604 
     605        static Sample2 tempSamples[NUM_SAMPLES]; 
     606        static bool checked[NUM_SAMPLES]; 
     607 
     608        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     609                checked[i] = false; 
     610 
     611        Sample2 currentSample; 
     612        currentSample.x = 0; currentSample.y = 0; 
     613        int ns = 0; // the next sample index 
     614 
     615        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     616        { 
     617                float minLen = 1e20f; 
     618 
     619                for (int j = 0; j < NUM_SAMPLES; ++ j) 
     620                { 
     621                        if (checked[j]) continue; 
     622 
     623                        Sample2 s = samples2[j]; 
     624                        const float len = SqrDist(s, currentSample); 
     625 
     626                        if (len < minLen)  
     627                        { 
     628                                minLen = len; 
     629                                ns = j; 
     630                        } 
     631                } 
     632 
     633                tempSamples[i] = samples2[ns]; 
     634                currentSample = samples2[ns]; 
     635                checked[ns] = true; 
     636        } 
     637 
     638        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     639                samples2[i] = tempSamples[i]; 
     640 
     641        dist = 0; 
     642        for (int i = 1; i < NUM_SAMPLES; ++ i) 
     643                dist += SqrDist(samples2[i-1], samples2[i]); 
     644                //cout << samples2[i].x << " " << samples2[i].y << " " << SqrDist(samples2[i-1], samples2[i]) << "|"; 
     645 
     646        //cout << "after:  " << dist << endl; 
     647} 
     648 
     649 
    572650void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo,  
    573651                                                                   float tempCohFactor) 
     
    616694                // needs longer to converge 
    617695                GenerateSamples(mSamplingMethod); 
     696 
     697                SortSamples(); 
    618698                sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    619699        } 
     
    821901        sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 
    822902 
    823         sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 
    824         sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
     903        sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 
     904        sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 
    825905         
    826906        sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); 
     
    9571037void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 
    9581038{ 
    959         GLuint colorsTex, diffVals, oldTex; 
     1039        GLuint colorsTex, normalsTex, diffVals, oldTex; 
    9601040 
    9611041        colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    962         //normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     1042        normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    9631043        diffVals = fbo->GetColorBuffer(2)->GetTexture(); 
    9641044        //diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 
     
    9701050 
    9711051        sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 
    972         //sCgSsaoProgram->SetTexture(i ++, normalsTex); 
     1052        sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex); 
     1053        sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    9731054        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 
    9741055 
     
    9861067                sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 
    9871068 
    988         sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    989  
    990  
    9911069        glPushAttrib(GL_VIEWPORT_BIT); 
    9921070        glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 
     
    9941072        mDownSampleFbo->Bind(); 
    9951073 
    996         glDrawBuffers(1, mrt + 0); 
     1074        glDrawBuffers(3, mrt + 0); 
    9971075 
    9981076        DrawQuad(sCgPrepareSsaoProgram); 
Note: See TracChangeset for help on using the changeset viewer.