Changeset 3148


Ignore:
Timestamp:
11/20/08 13:09:15 (16 years ago)
Author:
mattausch
Message:

done a little cleanup

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r3144 r3148  
    5757static ShaderProgram *sCgToneProgram = NULL; 
    5858static ShaderProgram *sCgDownSampleProgram = NULL; 
    59 static ShaderProgram *sCgSmoothSsaoProgram = NULL; 
    6059static ShaderProgram *sCgScaleDepthProgram = NULL; 
    6160 
     
    374373        sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth"); 
    375374        sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 
    376         sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao"); 
    377375 
    378376 
     
    441439        //////////////// 
    442440 
    443         string smoothSsaoParams[] = {"normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 
    444         sCgSmoothSsaoProgram->AddParameters(smoothSsaoParams, 0, 4); 
    445          
    446          
    447         /////////// 
    448441 
    449442        const float filterWidth = 100.0f; 
     
    526519        case SSAO: 
    527520                ComputeSsao(fbo, tempCohFactor); 
    528                 //SmoothSsao(fbo); 
    529521                CombineSsao(fbo); 
    530522                break; 
     
    810802        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    811803        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    812         //GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    813804        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    814805         
     
    816807 
    817808        int i = 0; 
     809 
    818810        sCgCombineSsaoProgram->SetTexture(i ++, colorsTex); 
    819811        sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); 
     
    827819        Vector3 tl = mCornersView[2]; 
    828820        Vector3 tr = mCornersView[3]; 
    829  
    830         sCgCombineSsaoProgram->SetValue3f(i ++, bl.x, bl.y, bl.z); 
    831         sCgCombineSsaoProgram->SetValue3f(i ++, br.x, br.y, br.z); 
    832         sCgCombineSsaoProgram->SetValue3f(i ++, tl.x, tl.y, tl.z); 
    833         sCgCombineSsaoProgram->SetValue3f(i ++, tr.x, tr.y, tr.z); 
    834821 
    835822 
     
    11171104 
    11181105 
    1119 void DeferredRenderer::SmoothSsao(FrameBufferObject *fbo) 
    1120 { 
    1121         mIllumFbo->Bind(); 
    1122  
    1123         GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    1124         GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    1125  
    1126         // overwrite old ssao texture 
    1127         glDrawBuffers(1, mrt + 2 - mIllumFboIndex); 
    1128  
    1129         glPushAttrib(GL_VIEWPORT_BIT); 
    1130         glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    1131  
    1132         int i = 0; 
    1133         sCgSmoothSsaoProgram->SetTexture(i ++, normalsTex); 
    1134         sCgSmoothSsaoProgram->SetTexture(i ++, ssaoTex); 
    1135  
    1136         sCgSmoothSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 
    1137         sCgSmoothSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
    1138          
    1139         DrawQuad(sCgSmoothSsaoProgram); 
    1140  
    1141         glPopAttrib(); 
    1142  
    1143         PrintGLerror("combine ssao"); 
    1144 } 
    1145  
    1146  
    11471106} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3137 r3148  
    8282        void CombineSsao(FrameBufferObject *fbo); 
    8383        void CombineIllum(FrameBufferObject *fbo); 
    84         void SmoothSsao(FrameBufferObject *fbo); 
    8584 
    8685        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3143 r3148  
    11#include "../shaderenv.h" 
     2 
     3 
     4/******************************************/ 
     5/* Filter for combining ssao with image   */ 
     6/******************************************/ 
    27 
    38 
     
    1520 
    1621 
    17  
    18  
    19  
    20 inline 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 
    31 inline 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; 
    41 } 
    42  
    43  
    44 float Filter(float2 texCoord,  
    45                          uniform sampler2D ssaoTex, 
    46                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    47                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    48                          float scale) 
    49 { 
    50         float average = .0f; 
    51         float w = .0f; 
    52  
    53         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    54         {        
    55                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 
    56                 w += filterWeights[i]; 
    57         } 
    58  
    59         average *= 1.0f / (float)w; 
    60  
    61         return average; 
    62 } 
    63  
    64 //#define USE_POSITION 
    65  
     22/** Filter taking into account depth and normal differences,  
     23   and convergence of a sample   
     24*/ 
    6625float DiscontinuityFilter(float2 texCoord, 
    6726                                                  float4 ao, 
     
    7231                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    7332                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    74                                                   float scale, 
    75                                                   float3 bl, 
    76                                                   float3 br, 
    77                                                   float3 tl, 
    78                                                   float3 tr) 
     33                                                  float scale) 
    7934{ 
    8035        float average = .0f; 
    8136        float total_w = .0f; 
    8237 
    83 #ifdef USE_POSITION 
    84         const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 
    85 #else 
    8638        const float eyeSpaceDepth = color.w; 
    87         //const float eyeSpaceDepth = ao.w; 
    88 #endif 
    8939 
    9040        const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
     
    10959                //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    11060 
    111 #ifdef USE_POSITION 
    112                 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 
    113                 depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f); 
    114 #else // use depth 
     61                // check depth discontinuity 
    11562                sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w; 
    11663                //sampleDepth = aoSample.w; 
     64                 
    11765                //depthFactor = max(step(1e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth)), 1e-3f); 
    118                 //depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f); 
    119                 //depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f); 
    120  
    12166                depthFactor = 1.0f / max(abs(eyeSpaceDepth - sampleDepth), 1e-3f); 
    122 #endif 
    12367                //normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-6f); 
    12468                normalFactor = max(dot(sampleNorm, centerNormal), 1e-6f); 
    125                 convergenceFactor = min(200.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f); 
     69                convergenceFactor = min(200.0f, aoSample.y) * 0.01f; 
    12670 
    127                 //w = filterWeights[i] * normalFactor * depthFactor * convergenceFactor; 
    128                 //w = 1000.0f * normalFactor * depthFactor;// * convergenceFactor; 
    129                 //w = normalFactor; 
     71                // combine the weights 
    13072                w = depthFactor * normalFactor * convergenceFactor; 
    131                 //w = filterWeights[i] * normalFactor * converganceFactor; 
    132                 //w = filterWeights[i] * normalFactor * depthFactor; 
    133                 //w = convergenceFactor; 
    13473 
    13574                average += aoSample.x * w; 
    136                 //average += aoSample.x; 
    13775                total_w += w; 
    13876        } 
    13977 
    14078        average /= max(total_w, 1e-1f); 
    141         //average /= NUM_SSAO_FILTERSAMPLES; 
    14279 
    14380        return saturate(average ); 
    14481} 
    14582 
    146  
     83/** Function combining image and indirect illumination buffer using a  
     84        depth and normal aware discontinuity filter. 
     85*/ 
    14786pixel combine(fragment IN,  
    14887                          uniform sampler2D colorsTex, 
     
    15291                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    15392                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    154                           uniform float3 bl, 
    155                           uniform float3 br, 
    156                           uniform  float3 tl, 
    157                           uniform float3 tr) 
     93                          ) 
    15894{ 
    15995        pixel OUT; 
     
    167103                const float scaleFactor = 1.0f; 
    168104                const float adaptFactor = 10.0f; 
    169                 //const float adaptFactor = 500000.0f; 
    170  
    171                 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    172                 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
    173                 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0); 
    174                 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0); 
    175  
     105                 
    176106                const float scale =     adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y); 
    177                 //const float scale = scaleFactor * ao.z; 
    178                  
    179                 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale, bl, br, tl, tr); 
    180                 //if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr); 
    181                 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 
     107                         
     108                ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale); 
    182109        } 
    183110 
    184         //float dummy = clamp(1.0f - ao.y * 1e-2f, 0, 1); 
    185         //float dummy2 = ao.y < 1.5f ? 1.0f : .0f; 
    186111        OUT.illum_col.xyz = col.xyz * ao.x; 
    187112 
    188         //      if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0); 
    189         //      else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000); 
    190         //      else 
    191         //      if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0); 
    192         //OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w); 
    193         //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    194  
    195         //OUT.illum_col.xyz = float3(1.0f - ao.x, dummy2, 0);//dummy2); 
    196113        //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 
    197114        OUT.illum_col.w = col.w; 
     
    199116        return OUT; 
    200117} 
    201  
    202  
    203 float DiscontinuityFilter2(float2 texCoord, 
    204                                                   float4 ao, 
    205                                                   uniform sampler2D ssaoTex, 
    206                                                   uniform sampler2D normalsTex, 
    207                                                   uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    208                                                   uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    209                                                   float scale 
    210                                                   ) 
    211 { 
    212         float average = .0f; 
    213         float total_w = .0f; 
    214  
    215         const float eyeSpaceDepth = ao.w; 
    216         const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    217  
    218         float4 aoSample; 
    219         float3 sampleNorm; 
    220         float w; 
    221         float4 offs; 
    222         float depthFactor; 
    223         float normalFactor; 
    224  
    225         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    226         { 
    227                 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    228                 aoSample = tex2Dlod(ssaoTex, offs); 
    229                  
    230                 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
    231  
    232                 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    233                 //depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    234                 //normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 
    235                 w = filterWeights[i]; 
    236                 //w = filterWeights[i] * normalFactor * depthFactor; 
    237                 //w = normalFactor * depthFactor; 
    238                 //w = depthFactor; 
    239  
    240                 average += aoSample.y * w; 
    241                 total_w += w; 
    242         } 
    243  
    244         average *= 1.0f / max(total_w, 1e-3f); 
    245  
    246         return average; 
    247 } 
    248  
    249 pixel smoothSsao(fragment IN,  
    250                                  uniform sampler2D ssaoTex, 
    251                                  uniform sampler2D normalsTex, 
    252                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    253                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    254                           ) 
    255 { 
    256         pixel OUT; 
    257  
    258         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    259         //ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 0.1f); 
    260          
    261         OUT.illum_col = ao; 
    262  
    263         return OUT; 
    264 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3137 r3148  
    3535        // the rgb weights 
    3636        const float3 w = float3(0.299f, 0.587f, 0.114f); 
    37         //float3 w = float3(0.2125f, 0.7154f, 0.0721f); 
     37        //const float3 w = float3(0.2125f, 0.7154f, 0.0721f); 
    3838 
    3939        float4 color; 
Note: See TracChangeset for help on using the changeset viewer.