Changeset 3134 for GTP


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

filtering working more nicely now

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

Legend:

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

    r3123 r3134  
    3030 
    3131# initial camera position 
    32 camPosition=483.398f 242.364f 186.078f 
     32#camPosition=483.398f 242.364f 186.078f 
    3333# initial camera orientation 
    34 camDirection=1 0 0 
     34#camDirection=1 0 0 
     35 
     36camPosition=468.025 267.591 182.478 
     37camDirection=0.937282 0.348573 -0 
    3538 
    3639#lightDirection=-0.8f 1.0f -0.7f 
  • 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 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3128 r3134  
    11861186        { 
    11871187        case 27: 
     1188                Debug << "camPosition=" << camera->GetPosition().x << " " << camera->GetPosition().y << " " << camera->GetPosition().z << endl; 
     1189                Debug << "camDirection=" << camera->GetDirection().x << " " << camera->GetDirection().y << " " << camera->GetDirection().z << endl; 
     1190 
    11881191                CleanUp(); 
    11891192                exit(0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3133 r3134  
    5858#define NUM_DOWNSAMPLES 9 
    5959 
     60//#define NUM_SSAO_FILTERSAMPLES 25 
    6061#define NUM_SSAO_FILTERSAMPLES 49 
    61 //#define NUM_SSAO_FILTERSAMPLES 40 
    62 //#define NUM_SSAO_FILTERSAMPLES 100 
     62//#define NUM_SSAO_FILTERSAMPLES 81 
    6363 
    6464 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3133 r3134  
    1616 
    1717 
    18 float Filter(float2 texCoord,  
    19                          uniform sampler2D ssaoTex, 
    20                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    21                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 
    22 { 
    23         float average = .0f; 
    24         float w = .0f; 
    25  
    26         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    27         { 
    28                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x; 
    29                 w += filterWeights[i]; 
    30         } 
    31  
    32         average *= 1.0f / (float)w; 
    33  
    34         return average; 
     18 
     19 
     20inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     21{ 
     22        float3 x1 = lerp(bl, tl, w.y); 
     23        float3 x2 = lerp(br, tr, w.y);  
     24        float3 v = lerp(x1, x2, w.x);  
     25 
     26        return v; 
     27} 
     28 
     29 
     30// reconstruct world space position 
     31inline float3 ReconstructSamplePos(uniform sampler2D tex, 
     32                                                                   float2 texcoord,  
     33                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
     34{ 
     35        const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 
     36         
     37        float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 
     38        float3 samplePos = -viewVec * eyeSpaceDepth; 
     39 
     40        return samplePos; 
    3541} 
    3642 
     
    5662} 
    5763 
     64#define USE_POSITION 
    5865 
    5966float DiscontinuityFilter(float2 texCoord, 
     
    6471                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    6572                                                  float scale, 
    66                                                   int index) 
     73                                                  float3 bl, 
     74                                                  float3 br, 
     75                                                  float3 tl, 
     76                                                  float3 tr) 
    6777{ 
    6878        float average = .0f; 
    6979        float total_w = .0f; 
    7080 
     81#ifdef USE_POSITION 
     82        const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 
     83#else 
    7184        const float eyeSpaceDepth = ao.w; 
     85#endif 
     86 
    7287        const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    7388 
    7489        float4 aoSample; 
    7590        float3 sampleNorm; 
     91        float3 samplePos; 
    7692        float w; 
    77         float4 offs; 
     93        float4 sampleTexCoord; 
    7894        float depthFactor; 
    7995        float normalFactor; 
    80         float converganceFactor; 
     96        float convergenceFactor; 
    8197 
    8298        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    8399        { 
    84                 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    85                 aoSample = tex2Dlod(ssaoTex, offs); 
    86                  
    87                 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
    88  
    89                 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
     100                sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 
     101                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
     102                sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 
     103 
     104#ifdef USE_POSITION 
     105                samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 
     106                depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f); 
     107#else // use depth 
    90108                depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
     109#endif 
    91110                normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 
    92                 converganceFactor = max(step(8.5f, aoSample.y), 1e-3f); 
    93  
    94                 //w = filterWeights[i] * normalFactor * depthFactor * converganceFactor; 
    95                 w = filterWeights[i];// * normalFactor * converganceFactor; 
    96                 //w = filterWeights[i] * depthFactor; 
    97  
    98                 average += aoSample[index] * w; 
     111                convergenceFactor = min(60.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f); 
     112 
     113                w = filterWeights[i] * normalFactor * depthFactor * convergenceFactor; 
     114                //w = filterWeights[i] * normalFactor * converganceFactor; 
     115                //w = filterWeights[i] * normalFactor * depthFactor; 
     116 
     117                average += aoSample.x * w; 
    99118                total_w += w; 
    100119        } 
     
    112131                          uniform sampler2D offsetTex, 
    113132                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    114                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    115                           ) 
     133                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     134                          uniform float3 bl, 
     135                          uniform float3 br, 
     136                          uniform  float3 tl, 
     137                          uniform float3 tr) 
    116138{ 
    117139        pixel OUT; 
     
    132154 
    133155                float border = step(0.001f,  b2 
    134  
    135156                //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    136157*/ 
     
    155176                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0); 
    156177 
    157                 if (ao.y < 10.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 
     178                if (ao.y < 60.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor, bl, br, tl, tr); 
    158179                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 
    159180        } 
     
    163184        OUT.illum_col.xyz = col.xyz * ao.x; 
    164185 
    165 //      if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0); 
    166 //      else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000); 
    167 //      else 
     186        //      if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0); 
     187        //      else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000); 
     188        //      else 
    168189        //      if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0); 
    169190        //OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3104 r3134  
    291291 
    292292#endif 
     293 
     294 
     295float4 Output(fragment IN, uniform sampler2D colors): COLOR 
     296{     
     297        // let bilinear filtering do its work 
     298        return tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
     299} 
Note: See TracChangeset for help on using the changeset viewer.