Changeset 3133 for GTP


Ignore:
Timestamp:
11/17/08 19:43:12 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r3132 r3133  
    9494{ 
    9595        float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho); 
    96     g *= expf( -(x*x + y*y) / (2.0f * rho * rho)); 
     96    g *= expf( -(x * x + y * y) / (2.0f * rho * rho)); 
    9797 
    9898    return g; 
     
    139139 
    140140                        idx += 2; 
     141                } 
     142        } 
     143} 
     144 
     145 
     146static 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; 
    141160                } 
    142161        } 
     
    445464        /////////// 
    446465 
    447  
     466#if 0 
    448467        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
    449468        poisson.Generate((float *)ssaoFilterOffsets); 
    450469 
    451         //const float filterWidth = 10.0f; 
    452         //const float filterWidth = 6.0f; 
    453         const float filterWidth = 20.0f; 
    454  
    455         //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); 
    456         //const float yoffs = filterWidth / mDownSampleFbo->GetHeight(); 
     470        const float filterWidth = 10.0f; 
    457471        const float xoffs = (float)filterWidth / mWidth; 
    458472        const float yoffs = (float)filterWidth / mHeight; 
     
    463477                float y = ssaoFilterOffsets[2 * i + 1]; 
    464478 
    465                 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    466                 //ssaoFilterWeights[i] = 1.0f; 
     479                //ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
     480                ssaoFilterWeights[i] = 1.0f; 
    467481 
    468482                ssaoFilterOffsets[2 * i + 0] *= xoffs; 
    469483                ssaoFilterOffsets[2 * i + 1] *= yoffs; 
    470484        } 
    471  
     485#else 
     486        //ComputeSampleOffsets(ssaoFilterOffsets, 1024, 768, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES);  
     487        ComputeSampleOffsets2(ssaoFilterOffsets, 1024, 768, 5, NUM_SSAO_FILTERSAMPLES);  
     488 
     489        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     490                ssaoFilterWeights[i] = 1.0f; 
     491 
     492#endif 
     493 
     494        /////// 
     495        //-- pcf tabs for shadowing 
    472496 
    473497        float filterWeights[NUM_PCF_TABS]; 
     
    501525                FirstPass(fbo, light); 
    502526 
    503  
    504527        if (mShadingMethod != 0) 
    505528        { 
    506                 // downsample fbo buffers for colors 
    507                 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 
    508                 // normals 
    509                 DownSample(fbo, 1, mDownSampleFbo, 1); 
    510                 // offsets 
    511                 DownSample(fbo, 2, mDownSampleFbo, 2); 
    512         } 
    513  
     529                // downsample fbo buffers 
     530                DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); // colors 
     531                DownSample(fbo, 1, mDownSampleFbo, 1); // normals 
     532                DownSample(fbo, 2, mDownSampleFbo, 2); // offsets 
     533        } 
     534 
     535        // antialiasing of the color buffer 
    514536        AntiAliasing(fbo, light); 
    515537 
     
    518540        case SSAO: 
    519541                ComputeSsao(fbo, tempCohFactor); 
    520                 //SmoothSsao(fbo); 
     542                SmoothSsao(fbo); 
    521543                CombineSsao(fbo); 
    522544                break; 
     
    562584        GLuint colorsTex, normalsTex, attribsTex; 
    563585 
    564         if (1) 
     586        if (0) 
    565587        { 
    566588                colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
     
    794816        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    795817        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    796         //GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    797         GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     818        GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     819        //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    798820         
    799821        FlipFbos(fbo); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3128 r3133  
    5858#define NUM_DOWNSAMPLES 9 
    5959 
    60 #define NUM_SSAO_FILTERSAMPLES 50 
     60#define NUM_SSAO_FILTERSAMPLES 49 
    6161//#define NUM_SSAO_FILTERSAMPLES 40 
    6262//#define NUM_SSAO_FILTERSAMPLES 100 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3132 r3133  
    7878        float depthFactor; 
    7979        float normalFactor; 
     80        float converganceFactor; 
    8081 
    8182        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     
    8990                depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    9091                normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 
    91  
    92                 w = filterWeights[i] * normalFactor * depthFactor; 
     92                converganceFactor = max(step(8.5f, aoSample.y), 1e-3f); 
     93 
     94                //w = filterWeights[i] * normalFactor * depthFactor * converganceFactor; 
     95                w = filterWeights[i];// * normalFactor * converganceFactor; 
    9396                //w = filterWeights[i] * depthFactor; 
    9497 
     
    107110                          uniform sampler2D ssaoTex, 
    108111                          uniform sampler2D normalsTex, 
     112                          uniform sampler2D offsetTex, 
    109113                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    110114                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
     
    119123        if (col.w < 1e10f) 
    120124        { 
    121                 const float xoffs = 4.0f / 1024.0f; 
    122                 const float yoffs = 4.0f / 768.0f; 
    123 /* 
     125                const float xoffs = 20.0f / 1024.0f; 
     126                const float yoffs = 20.0f / 768.0f; 
     127 
     128                /*float3 b2 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz; 
     129                float3 b3 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz; 
     130                float3 b4 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz; 
     131                float3 b5 = tex2Dlod(offsetTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).xyz; 
     132 
     133                float border = step(0.001f,  b2 
     134 
    124135                //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    125                 float3 x2 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz; 
     136*/ 
     137                 
     138                /*float3 x2 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).xyz; 
    126139                float3 x3 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).xyz; 
    127140                float3 x4 = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).xyz; 
     
    129142 
    130143                //ao.x = (ao.x + x2 + x3 + x4 + x5) * 0.2f; 
     144                if (ao.y < 1.5f) 
    131145                ao.x = (x2 + x3 + x4 + x5) * 0.25f; 
    132146 
     
    134148                const static float scaleFactor = 1.0f; 
    135149                //const static float scaleFactor = 10.0f; 
    136                 const static float adaptFactor = 50.0f; 
     150                const static float adaptFactor = 50000.0f; 
    137151 
    138152                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
     
    140154                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0); 
    141155                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0); 
    142         } 
    143  
     156 
     157                if (ao.y < 10.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 
     158                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 
     159        } 
     160 
     161        //float dummy = clamp(1.0f - ao.y * 1e-2f, 0, 1); 
     162        //float dummy2 = ao.y < 1.5f ? 1.0f : .0f; 
    144163        OUT.illum_col.xyz = col.xyz * ao.x; 
    145         //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    146         //OUT.illum_col.xyz = float3(1.0f - ao.x, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 
     164 
     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 
     168        //      if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0); 
     169        //OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w); 
     170        OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
     171 
     172        //OUT.illum_col.xyz = float3(1.0f - ao.x, dummy2, 0);//dummy2); 
     173        //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 
    147174        OUT.illum_col.w = col.w; 
    148175 
    149176        return OUT; 
    150177} 
     178 
    151179 
    152180float DiscontinuityFilter2(float2 texCoord, 
     
    181209                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    182210                depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    183                 normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 
     211                //normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 
    184212 
    185213                //w = filterWeights[i] * normalFactor * depthFactor; 
    186                 w = normalFactor * depthFactor; 
     214                //w = normalFactor * depthFactor; 
     215                w = depthFactor; 
    187216 
    188217                average += aoSample.y * w; 
     
    208237        //const static float scaleFactor = 20.0f; 
    209238        const static float scaleFactor = 10.0f; 
    210         ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 
     239        //ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 0.5f, 1); 
    211240        //ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor, 1); 
    212241         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3132 r3133  
    143143{ 
    144144        // compute position from old frame for dynamic objects + translational portion 
    145         const float3 translatedPos = diffVec + worldPos.xyz - oldEyePos; 
     145        const float3 translatedPos = diffVec - oldEyePos + worldPos.xyz; 
    146146 
    147147 
Note: See TracChangeset for help on using the changeset viewer.