Changeset 3206


Ignore:
Timestamp:
12/02/08 19:15:08 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
5 edited

Legend:

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

    r3205 r3206  
    116116 
    117117 
    118 static Sample2 UnitTest2(float x, float y, int wi, int he) 
     118static Sample2 UnitTest(float x, float y, int wi, int he) 
    119119{ 
    120120        Sample2 s; 
     
    351351 
    352352        InitCg(); 
    353  
    354         float x = 400.5f / w; 
    355         float y = 100.5f / h; 
    356          
    357         Sample2 res = UnitTest2(x, y, dsw, dsh); 
    358  
    359         cout << "input  : " << x << ", " << y << endl; 
    360         cout << "result : " << res.x << " " << res.y << endl; 
    361         cout << "result2: " << res.x * w << " " << res.y * h << endl; 
    362353} 
    363354 
     
    366357{ 
    367358        CLEAR_CONTAINER(mFBOs); 
     359 
    368360        glDeleteTextures(1, &noiseTex2D); 
    369361        glDeleteTextures(1, &noiseTex1D); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3204 r3206  
    1111//#define NUM_SAMPLES 96 
    1212 
    13 #define SAMPLE_INTENSITY 0.3f 
     13#define SAMPLE_INTENSITY 0.2f 
    1414//#define SAMPLE_INTENSITY 2.0f 
    1515 
     
    2727//#define NUM_SSAO_FILTERSAMPLES 80 
    2828#define NUM_SSAO_FILTER_SAMPLES 16 
     29 
    2930#define SSAO_FILTER_WIDTH 12.0f 
    30 #define SSAO_CONVERGENCE_WEIGHT 300.0f 
     31//#define SSAO_FILTER_WIDTH 6.0f 
     32 
     33#define SSAO_CONVERGENCE_THRESHOLD 700.0f 
    3134 
    3235 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3205 r3206  
    166166                          uniform float3 tl, 
    167167                          uniform float3 tr, 
    168                           uniform float3 w, 
    169                           uniform float3 h 
     168                          uniform float w, 
     169                          uniform float h 
    170170                          ) 
    171171{ 
     
    200200        //const float convergence = ao.y; 
    201201 
    202         // filter reaches size 1 pixel after thres samples:  
     202        // filter reaches size 1 pixel when sample size reaches threshold  
    203203        // afterwards we do not use the filter anymore 
    204         const float thres = 500.0f;  
    205204 
    206205        // filter up to a certain convergance value and leave out background (sky) by checking depth 
    207         if ((convergence < thres) && (col.w < 1e10f)) 
     206        if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (col.w < 1e10f)) 
    208207        { 
    209208                const float distanceScale = 1.0f; 
    210209 
    211210                // descend to zero filter size after reaching thres pixels 
    212                 const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f); 
     211                const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / (SSAO_FILTER_WIDTH - 1.0f); 
    213212                const float convergenceScale = convergenceWeight / (convergence + convergenceWeight); 
    214213                const float scale = SSAO_FILTER_WIDTH * convergenceScale * distanceScale; 
     
    235234 
    236235 
    237  
    238236/** Function combining image and indirect illumination buffer using a  
    239237        depth and normal aware discontinuity filter. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3204 r3206  
    201201        valid in the current frame 
    202202        */ 
    203 inline float PixelValid(sampler2D oldTex, 
     203inline float2 PixelValid(sampler2D oldTex, 
    204204                                                float4 color, 
    205205                                                float3 difVec, 
     
    262262        const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    263263 
    264         const float xOffs = 1.0f / 1024.0f; 
    265         const float yOffs = 1.0f / 768.0f; 
     264        //const float xOffs = 1.0f / 1024.0f;   const float yOffs = 1.0f / 768.0f; 
     265        //const float eps = 1e-6f; 
    266266 
    267267        // actually 0 means pixel is valid 
     
    270270        const float pixelNotValid = 10.0f; 
    271271 
    272         const float eps = 1e-6f; 
    273  
    274         if (0 
    275                 //&& !(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF)) 
    276                 //&& (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= (1.0f - xOffs) + eps ) 
    277                 //&& (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= (1.0f - yOffs) + eps ) 
    278                 || (oldTexCoords.x < .0f) || (oldTexCoords.x >= 1.0f) 
    279                 || (oldTexCoords.y < .0f) || (oldTexCoords.y >= 1.0f) 
    280                 ) 
     272        if ((oldTexCoords.x < .0f) || (oldTexCoords.x >= 1.0f) ||  
     273                (oldTexCoords.y < .0f) || (oldTexCoords.y >= 1.0f)) 
    281274        { 
    282275                pixelValid = pixelNotValid; 
    283276        } 
    284         // check if changed from dynamic to not dynamic object 
    285         // or there is a depth discontinuity 
    286277        else  
    287         if ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
    288                 (oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF))) 
     278        if ( 
     279                // check if changed from dynamic to not dynamic object 
     280                (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     281                // check if we have a dynamic object and is a depth discontinuity 
     282                ((oldDynamic || newDynamic) && (depthDif <= MIN_DEPTH_DIFF))) 
    289283        {        
    290284                pixelValid = pixelCouldBeValid;  
     
    295289        } 
    296290 
    297         return pixelValid; 
     291        return float2(pixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
    298292} 
    299293 
     
    325319 
    326320        // do reprojection and filter out the pixels that are not save 
    327         float pValid = PixelValid(oldTex, 
     321        float2 pValid = PixelValid(oldTex, 
    328322                              color,  
    329323                                                          difVec.xyz, 
     
    337331 
    338332        pix.color = color; 
    339         pix.color.x = pValid; 
     333        pix.color.xy = pValid.xy; 
    340334        pix.normal = normal; 
    341335 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3205 r3206  
    322322#endif 
    323323 
     324                ++ numSamples; 
     325                 
    324326                // check if the samples have been valid in the last frame 
    325                 // hack: the distance measure can fail in some cases => choose something different 
    326                 const float tooFarAway = step(1.0f, lengthToSample); 
    327                 validSamples = max(validSamples, (1.0f - tooFarAway) * sampleColor.x); 
    328  
     327                // only mark sample as invalid if taking it into account can have influence the ssao: 
     328                // hence we also check if the sample or the same sample in the previous frame 
     329                // had any chance to be near the current sample 
     330                const float changeFactor = sampleColor.y; 
     331                const float pixelValid = sampleColor.x; 
     332 
     333                // hack: cedistance measure can fail in some cases => choose something different 
     334                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
     335                validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid); 
    329336                //validSamples += sampleColor.x; 
    330  
    331                 ++ numSamples; 
    332337 
    333338                //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 
     
    417422        const float squaredLen = SqrLen(diffVec); 
    418423 
    419         if (ao.y > 4.0f) oldWeight = 0; 
    420         else if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 
    421                 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 
    422          
     424        // check if we have to reset pixel because one of the sample points was invalid 
     425        if (squaredLen < DYNAMIC_OBJECTS_THRESHOLD) 
     426        { 
     427                if (ao.y > 4.0f)  
     428                        oldWeight = 0;  
     429                else if (ao.y > 1.0f) 
     430                        oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 
     431        } 
     432 
    423433        const float newWeight = ao.z; 
    424  
     434        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
     435 
     436         
    425437        // blend between old and new samples (and avoid division by zero) 
    426         OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 
    427         OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    428  
     438        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight); 
    429439        OUT.illum_col.z = SqrLen(diffVec); 
     440        OUT.illum_col.y = combinedWeight; 
    430441        OUT.illum_col.w = eyeSpaceDepth; 
    431442 
Note: See TracChangeset for help on using the changeset viewer.