Changeset 3192


Ignore:
Timestamp:
11/27/08 19:14:48 (15 years ago)
Author:
mattausch
Message:

worked on adaptive sampling .. changed to using real number of samples for convergence measure

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

Legend:

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

    r3175 r3192  
    6363 
    6464# ssao temporal coherence factor 
    65 tempCohFactor=100.0f 
     65tempCohFactor=1000.0f 
    6666# tone mapping 
    6767useHDR=0 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3190 r3192  
    329329        // for performance reasons we use a smaller texture and repeat it over the screen 
    330330        CreateNoiseTex2D(mIllumFbo->GetWidth() / 4, mIllumFbo->GetWidth() / 4); 
    331         //CreateNoiseTex1D(mIllumFbo->GetWidth() / 4); 
    332  
     331         
    333332        mProjViewMatrix = IdentityMatrix(); 
    334333        mOldProjViewMatrix = IdentityMatrix(); 
     
    674673                GenerateSamples(mSamplingMethod); 
    675674 
    676                 if (mSortSamples) { SortSamples(); } 
     675                //if (mSortSamples) { SortSamples(); } 
    677676                sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    678677        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3189 r3192  
    77 
    88//#define NUM_SAMPLES 8 
    9 #define NUM_SAMPLES 16 
    10 //#define NUM_SAMPLES 24 
     9//#define NUM_SAMPLES 16 
     10#define NUM_SAMPLES 48 
    1111 
    1212// for quadratic falloff 
    13 //#define SAMPLE_INTENSITY 0.2f 
    14 //#define SAMPLE_INTENSITY 0.07f 
    15 #define SAMPLE_INTENSITY 0.008f 
     13#define SAMPLE_INTENSITY 0.2f 
     14//#define SAMPLE_INTENSITY 0.1f 
    1615 
    1716//#define SAMPLE_INTENSITY 0.075f 
    1817//#define SAMPLE_INTENSITY 0.2f 
    1918 
    20 //#define SAMPLE_RADIUS 8e-1f 
    21 #define SAMPLE_RADIUS 4e-1f 
     19#define SAMPLE_RADIUS 8e-1f 
     20//#define SAMPLE_RADIUS 4e-1f 
    2221 
    2322//#define DISTANCE_SCALE 1e-1f 
    2423#define DISTANCE_SCALE 1e-2f 
    25 //#define DISTANCE_SCALE 0.2f 
    2624 
    2725//#define ILLUM_INTENSITY 8e-2f 
     
    3230//#define NUM_SSAO_FILTERSAMPLES 80 
    3331#define NUM_SSAO_FILTER_SAMPLES 16 
    34 #define NUM_SSAO_FILTER_WIDTH 10.0f 
    35 #define SSAO_CONVERGENCE_WEIGHT 25.0f 
     32#define NUM_SSAO_FILTER_WIDTH 15.0f 
     33#define SSAO_CONVERGENCE_WEIGHT 200.0f 
    3634 
    3735 
     
    6765#define NUM_DOWNSAMPLES 9 
    6866 
    69  
    7067#define DYNAMIC_OBJECTS_THRESHOLD 1e-8f 
    7168 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3191 r3192  
    117117        float len; 
    118118 
     119        const float convergenceThresh = 200.0f; 
     120 
    119121        for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    120122        { 
     
    126128                // check spatial discontinuity 
    127129                samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 
    128                 len = min(SqrLen(centerPos - samplePos), 1e2f); 
     130                len = min(SqrLen(centerPos - samplePos), 1e3f); 
    129131 
    130132                spatialFactor = 1.0f / max(len, 1e-3f); 
    131133 
    132                 normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-3f); 
     134                normalFactor = max(step(.01f, dot(sampleNorm, centerNormal)), 1e-3f); 
    133135                //normalFactor = max(dot(sampleNorm, samplePos), 1e-3f); 
    134                 convergenceFactor = min(50.0f, aoSample.y); 
     136                convergenceFactor = min(convergenceThresh, aoSample.y + 1); 
    135137                //convergenceFactor = aoSample.y; 
    136138 
    137139                // combine the weights 
    138140                w = convergenceFactor * spatialFactor * normalFactor; 
    139                 //w = convergenceFactor * spatialFactor; 
     141                //w = spatialFactor * normalFactor; 
    140142 
    141143                average += aoSample.x * w; 
     
    171173 
    172174        // filter up to a certain convergance value and leave out background (sky) by checking depth 
    173         if ((ao.y < 100.0f) && (col.w < 1e10f)) 
     175        if ((ao.y < 500.0f) && (col.w < 1e10f)) 
    174176        //if (col.w < 1e10f) 
    175177        { 
     
    178180                const float distanceScale = 1.0f; 
    179181 
    180                 const float convergence = ao.y; 
    181                 const float adaptWeight = 25.0f; 
     182                const float convergence = ao.y + 1; 
    182183                const float convergenceScale = SSAO_CONVERGENCE_WEIGHT / (convergence + SSAO_CONVERGENCE_WEIGHT); 
    183184 
     
    188189        } 
    189190 
    190         OUT.illum_col.xyz = col.xyz * ao.x; 
     191        if (col.w < 1e10f) 
     192                OUT.illum_col.xyz = col.xyz * ao.x; 
     193        else 
     194                OUT.illum_col.xyz = col.xyz; 
     195 
    191196        //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 
    192197        //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3190 r3192  
    337337 
    338338        // do reprojection and filter out the pixels that are not save 
    339         float pValid = PixelValid( 
    340                 oldTex, 
    341                 color,  
    342                 difVec.xyz, 
    343                 IN.texCoord, 
    344                 viewDir, 
    345                 oldEyePos, 
    346                 modelViewProj, 
    347                 oldModelViewProj, 
    348                 oldbl, oldbr, oldtl, oldtr 
    349                 ); 
     339        float pValid = PixelValid(oldTex, 
     340                              color,  
     341                                                          difVec.xyz, 
     342                                                          IN.texCoord, 
     343                                                          viewDir, 
     344                                                          oldEyePos, 
     345                                                          modelViewProj, 
     346                                                          oldModelViewProj, 
     347                                                          oldbl, oldbr, oldtl, oldtr 
     348                                                          ); 
    350349 
    351350        pix.color = color; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3175 r3192  
    7979                                                                sampler2D oldTex, 
    8080                                                                float4x4 oldModelViewProj, 
    81                                                                 float temporalCoherence, 
    8281                                                                sampler2D colors, 
    8382                                                                float3 projPos, 
     
    8786                                                                float3 oldtl, 
    8887                                                                float3 oldtr, 
    89                                                                 float3 diffVec, 
    90                                                                 float pixelValid 
     88                                                                float3 diffVec 
    9189                                                                ) 
    9290{ 
     
    131129#endif 
    132130 
    133         const float squaredLen = SqrLen(diffVec); 
    134  
    135         const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 
    136         //const float oldWeight = oldPixel.y; 
    137  
    138131        float newWeight; 
    139132 
    140         if ((temporalCoherence > 1e-6f) 
     133        if (1 
    141134                && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
    142135                && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
    143136                && (depthDif <= MIN_DEPTH_DIFF)  
    144                 // if visibility changed in the surrounding area we have to recompute 
    145                 //&& (oldNumSamples > 0.8f * newNumSamples) 
    146                 //&& (pixelValid < 1.0f) 
    147137                ) 
    148138        { 
    149139                // increase the weight for convergence 
    150                 newWeight = oldWeight + 1.0f; 
    151                  
    152                 if ((pixelValid > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 
    153                 {                
    154                         newWeight = 4.0f; 
    155                         //newWeight = 1.0f; 
    156                 } 
     140                newWeight =  oldPixel.y; 
    157141        } 
    158142        else 
    159143        {        
    160                 newWeight = 1.0f; 
     144                newWeight = 0.0f; 
    161145        } 
    162146 
     
    245229#endif 
    246230                // check if the samples have been valid in the last frame 
    247                 numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 
     231                //numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 
     232                numSamples += 1.0f - sampleColor.x; 
    248233        } 
    249234 
     
    256241        pixel-to-sample direction and sample normal as weight. 
    257242*/ 
    258 float2 ssao(fragment IN, 
     243float3 ssao(fragment IN, 
    259244                        sampler2D colors, 
    260245                        sampler2D noiseTex, 
     
    267252                        float3 tl, 
    268253                        float3 tr,  
    269                         float3 viewDir 
     254                        float3 viewDir, 
     255                        float newWeight 
    270256                        ) 
    271257{ 
     
    275261 
    276262        float total_ao = .0f; 
     263        float validSamples = .0f; 
    277264        float numSamples = .0f; 
    278265 
     
    325312 
    326313                // check if the samples have been valid in the last frame 
    327                 numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 
    328         } 
    329  
    330         return float2(max(0.0f, 1.0f - total_ao), numSamples); 
     314                validSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x; 
     315                //validSamples += sampleColor.x; 
     316 
     317                ++ numSamples; 
     318                if ((validSamples < 1.0f) && (newWeight > 20) && (numSamples >= 8)) break; 
     319        } 
     320 
     321        total_ao /= numSamples; 
     322 
     323        return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    331324} 
    332325 
     
    378371 
    379372         
    380         float2 ao; 
    381  
    382         // note: this should be done with the stencil buffer 
    383         if (eyeSpaceDepth < 1e10f) 
    384         { 
    385                 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 
    386                 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 
    387         } 
    388         else 
    389         { 
    390                  ao = float2(1.0f, 0); 
    391         } 
    392  
    393  
    394373        ///////////////// 
    395374        //-- compute temporal reprojection 
    396375 
    397376        float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
    398                                                 oldTex, oldModelViewProj, temporalCoherence, 
     377                                                oldTex, oldModelViewProj,  
    399378                                                                                        colors,  
    400379                                                                                        projPos.xyz,  
    401380                                                                                        invw,  
    402381                                                                                        oldbl, oldbr, oldtl, oldtr, 
    403                                                                                         diffVec, 
    404                                                                                         ao.y 
     382                                                                                        diffVec 
    405383                                                                                        ); 
    406384 
    407385        const float oldSsao = temporalVals.x; 
    408         const float newWeight = temporalVals.y; 
    409  
    410  
    411         OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 
    412         OUT.illum_col.y = newWeight; 
    413         OUT.illum_col.z = SqrLen(diffVec);//invw; 
     386        float oldWeight = temporalVals.y; 
     387         
     388        float3 ao; 
     389 
     390        // cull background note: this should be done with the stencil buffer 
     391        if (eyeSpaceDepth < 1e10f) 
     392        { 
     393                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight); 
     394                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 
     395        } 
     396        else 
     397        { 
     398                 ao = float3(1.0f, .0f, .0f); 
     399        } 
     400 
     401        const float squaredLen = SqrLen(diffVec); 
     402         
     403        if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 
     404        {                
     405                oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 
     406        } 
     407 
     408        const float newWeight = ao.z; 
     409 
     410        // blend between old and new samples (and avoid division by zero) 
     411        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 
     412        OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
     413        OUT.illum_col.z = SqrLen(diffVec); 
    414414        OUT.illum_col.w = eyeSpaceDepth; 
    415415 
Note: See TracChangeset for help on using the changeset viewer.