Ignore:
Timestamp:
11/18/08 11:28:38 (16 years ago)
Author:
mattausch
Message:

filtering working more nicely now

File:
1 edited

Legend:

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

    r3133 r3134  
    112112} 
    113113 
    114 static void ComputeSampleOffsets(float *sampleOffsets, int w, int h) 
    115 { 
    116         /* 
    117         const float xoffs = 0.5f / w; 
    118         const float yoffs = 0.5f / h; 
    119  
    120         sampleOffsets[0] =  xoffs; sampleOffsets[1] =  yoffs; 
    121         sampleOffsets[2] =  xoffs; sampleOffsets[3] = -yoffs; 
    122         sampleOffsets[4] = -xoffs; sampleOffsets[5] = -yoffs; 
    123         sampleOffsets[6] = -xoffs; sampleOffsets[7] =  yoffs; 
    124         */ 
    125         //const float xoffs = .5f / w; 
    126         //const float yoffs = .5f / h; 
    127          
    128         const float xoffs = 1.0f / w; 
    129         const float yoffs = 1.0f / h; 
    130  
    131         int idx  = 0; 
    132  
    133         for (int x = -1; x <= 1; ++ x) 
    134         { 
    135                 for (int y = -1; y <= 1; ++ y) 
     114 
     115static void ComputeSampleOffsets(float *sampleOffsets,  
     116                                                                 int imageW, int imageH, 
     117                                                                 float width,  
     118                                                                 int samples) 
     119{ 
     120        const float xoffs = width / (float)imageW; 
     121        const float yoffs = width / (float)imageH; 
     122         
     123        const int numSamples = (int)sqrt((float)samples); 
     124        const int startSamples = -numSamples / 2; 
     125        const int endSamples = numSamples + startSamples - 1; 
     126        //cout << startSamples << " " << endSamples << endl; 
     127 
     128        int idx = 0; 
     129 
     130        for (int x = startSamples; x <= endSamples; ++ x) 
     131        { 
     132                for (int y = startSamples; y <= endSamples; ++ y) 
    136133                { 
    137                         sampleOffsets[idx + 0] = x * xoffs; 
    138                         sampleOffsets[idx + 1] = y * yoffs; 
    139  
     134                        sampleOffsets[idx + 0] = (float)x * xoffs; 
     135                        sampleOffsets[idx + 1] = (float)y * yoffs; 
    140136                        idx += 2; 
    141                 } 
    142         } 
    143 } 
    144  
    145  
    146 static void ComputeSampleOffsets2(float *sampleOffsets, int w, int h, float width, int samples) 
    147 { 
    148         const float xoffs = width / (float)w; 
    149         const float yoffs = width / (float)h; 
    150          
    151         const int numSamples = (int)sqrt((float)samples); 
    152  
    153         for (int x = 0; x < numSamples; ++ x) 
    154         { 
    155                 for (int y = 0; y < numSamples; ++ y) 
    156                 { 
    157                         int idx = (y * numSamples + x) * 2; 
    158                         sampleOffsets[idx + 0] = ((float)x - 0.5f * numSamples) * xoffs; 
    159                         sampleOffsets[idx + 1] = ((float)y - 0.5f * numSamples) * yoffs; 
    160137                } 
    161138        } 
     
    434411        //////////////// 
    435412 
    436         string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 
    437         sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 5); 
     413        string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights", "bl", "br", "tl", "tr"}; 
     414        sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9); 
    438415 
    439416        ////////////// 
     
    464441        /////////// 
    465442 
    466 #if 0 
     443        const float filterWidth = 10.0f; 
     444 
     445#if 1 
    467446        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
    468447        poisson.Generate((float *)ssaoFilterOffsets); 
    469448 
    470         const float filterWidth = 10.0f; 
    471449        const float xoffs = (float)filterWidth / mWidth; 
    472450        const float yoffs = (float)filterWidth / mHeight; 
     
    484462        } 
    485463#else 
    486         //ComputeSampleOffsets(ssaoFilterOffsets, 1024, 768, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES);  
    487         ComputeSampleOffsets2(ssaoFilterOffsets, 1024, 768, 5, NUM_SSAO_FILTERSAMPLES);  
    488  
     464        //ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES);  
     465        ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, filterWidth, NUM_SSAO_FILTERSAMPLES);  
     466        //cout<<"ssao filter size: " << NUM_SSAO_FILTERSAMPLES << endl; 
    489467        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    490468                ssaoFilterWeights[i] = 1.0f; 
     
    829807        sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
    830808         
     809        Vector3 bl = mCornersView[0]; 
     810        Vector3 br = mCornersView[1]; 
     811        Vector3 tl = mCornersView[2]; 
     812        Vector3 tr = mCornersView[3]; 
     813 
     814        sCgCombineSsaoProgram->SetValue3f(i ++, bl.x, bl.y, bl.z); 
     815        sCgCombineSsaoProgram->SetValue3f(i ++, br.x, br.y, br.z); 
     816        sCgCombineSsaoProgram->SetValue3f(i ++, tl.x, tl.y, tl.z); 
     817        sCgCombineSsaoProgram->SetValue3f(i ++, tr.x, tr.y, tr.z); 
     818 
     819 
    831820        DrawQuad(sCgCombineSsaoProgram); 
    832821         
     
    968957        sCgDownSampleProgram->SetTexture(0, colorsTex); 
    969958 
     959        const float filterWidth = 1.0f; 
    970960        float downSampleOffsets[NUM_DOWNSAMPLES * 2]; 
    971         ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight()); 
    972  
     961        //ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight(), filterWidth, NUM_DOWNSAMPLES); 
     962         
    973963        sCgDownSampleProgram->SetArray2f(1, (float *)downSampleOffsets, NUM_DOWNSAMPLES); 
    974964 
     
    979969         
    980970        glPopAttrib(); 
    981          
    982971        PrintGLerror("downsample"); 
    983972} 
     
    10191008        DrawQuad(sCgDownSampleProgram); 
    10201009 
    1021         PrintGLerror("OUTPUT"); 
     1010        PrintGLerror("output"); 
    10221011} 
    10231012 
Note: See TracChangeset for help on using the changeset viewer.