Changeset 3204


Ignore:
Timestamp:
12/02/08 17:06:08 (15 years ago)
Author:
mattausch
Message:

debug version showing a visualization of the confidence

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

Legend:

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

    r3199 r3204  
    292292 
    293293 
    294  
    295294DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam): 
    296295mWidth(w), mHeight(h),  
     
    306305        //-- the flip-flop fbos 
    307306 
    308         const int dsw = w / 2; const int dsh = h / 2; 
     307        //const int dsw = w / 2; const int dsh = h / 2; 
     308        //const int dsw = 128; const int dsh = 96; 
     309        const int dsw = 16; const int dsh = 12; 
    309310        //const int dsw = w; const int dsh = h; 
    310311 
     
    325326 
    326327        mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
     328        // the downsampled color + depth buffer 
    327329        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    328 // downsample buffer for the normal texture 
    329 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     330        // downsample buffer for the normal texture 
     331        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
    330332 
    331333        for (int i = 0; i < 2; ++ i) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp

    r3193 r3204  
    176176        case WRAP_CLAMP_TO_EDGE: 
    177177                wrapParam = GL_CLAMP_TO_EDGE; break; 
     178        case WRAP_CLAMP_TO_BORDER: 
     179                wrapParam = GL_MIRROR_CLAMP_TO_EDGE_EXT; break; 
    178180        } 
    179181 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h

    r3147 r3204  
    1616 
    1717        enum FORMAT {RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 
    18         enum WRAP_TYPE {WRAP_REPEAT, WRAP_CLAMP_TO_EDGE}; 
     18        enum WRAP_TYPE {WRAP_REPEAT, WRAP_CLAMP_TO_EDGE, WRAP_CLAMP_TO_BORDER}; 
    1919        enum FILTER_TYPE {FILTER_NEAREST, FILTER_LINEAR}; 
    2020 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3203 r3204  
    88//#define NUM_SAMPLES 8 
    99//#define NUM_SAMPLES 16 
    10 #define NUM_SAMPLES 96 
     10#define NUM_SAMPLES 24 
     11//#define NUM_SAMPLES 96 
    1112 
    1213#define SAMPLE_INTENSITY 0.3f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3203 r3204  
    125125 
    126126                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
    127                 sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
     127                //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    128128 
    129129                // check spatial discontinuity 
    130  
    131130                // note: using the depth from the color texture is not 100% correct as depth was 
    132131                // not scaled with the interpolated view vector depth yet ... 
     
    137136                spatialFactor = 1.0f / max(len, 1e-3f); 
    138137 
    139                 //normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-2f); 
     138                //normalFactor = max(step(.2f, dot(sampleNorm, centerNormal)), 1e-2f); 
    140139                convergenceFactor = aoSample.y + 1.0f; 
    141140                 
     
    172171 
    173172        float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
    174         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
     173        float4 ao =  tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    175174 
    176175        // get the minimum convergence by exactly sampling the 4 surrounding 
     
    178177        // will be interpolated when upsampling and filter size does not match! 
    179178        float4 texelCenterConv; 
    180         const float w = 512.0f; const float h = 384.0f; 
     179        //const float w = 512.0f; const float h = 384.0f; 
     180        //const float w = 128.0f; const float h = 96.0f; 
     181        const float w = 16.0f; const float h = 12.0f; 
    181182        const float xoffs = .5f / w; const float yoffs = .5f / h; 
    182183 
    183184        // get position exactly between old texel centers 
    184185        float2 center; 
    185         center.x = float(floor(IN.texCoord.x * w - .5f) + 1.0f) / w; 
    186         center.y = float(floor(IN.texCoord.y * h - .5f) + 1.0f) / h; 
    187  
    188         texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2(xoffs, yoffs), 0, 0)).y; 
    189         texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2(xoffs, -yoffs), 0, 0)).y; 
    190         texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 
    191         texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
     186        center.x = (floor(IN.texCoord.x * w - .5f) + 1.0f) / w; 
     187        center.y = (floor(IN.texCoord.y * h - .5f) + 1.0f) / h; 
     188//center=IN.texCoord; 
     189        texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2( xoffs, yoffs), 0, 0)).y; 
     190        texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 
     191        texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
     192        texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y; 
    192193 
    193194        const float m1 = min(texelCenterConv.x, texelCenterConv.y); 
     
    196197        const float minConvergence = min(m1, m2); 
    197198 
    198         const float convergence = step(200.0f, minConvergence) * minConvergence; 
     199        const float convergence = minConvergence; 
     200        //const float convergence = 0; 
    199201        //const float convergence = ao.y; 
    200202 
    201         // filter reaches size 1 after thres samples 
     203        // filter reaches size 1 pixel after thres samples:  
     204        // afterwards we do not use the filter anymore 
    202205        const float thres = 500.0f;  
    203206 
     
    222225 
    223226        //OUT.illum_col.xyz = float3(ao.x, ao.x, step(thres, convergence)); 
    224         //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 
     227        OUT.illum_col.xyz = float3(0, convergence, 0); 
     228        //OUT.illum_col.xyz = float3(abs(center.x - IN.texCoord.x) * 16.0f, abs(center.y - IN.texCoord.y) * 12.0f, 0); 
     229         
    225230        //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 
    226231        //OUT.illum_col.xyz = float3(0, 1.0f - step(0.5f + NUM_SAMPLES, convergence), 1); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3199 r3204  
    256256        const float squaredLen = SqrLen(difVec); 
    257257         
    258         // test if this pixel was not valid in the old frame 
    259         float validPixel; 
     258        // test if this pixel was valid in the old frame 
     259        float pixelValid; 
    260260 
    261261        const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    262262        const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    263263 
    264         if (!(oldDynamic && !newDynamic) && !(!oldDynamic && newDynamic)  
    265                 && !(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF)) 
    266                 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
    267                 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
     264        const float xOffs = 1.0f / 1024.0f; 
     265        const float yOffs = 1.0f / 768.0f; 
     266 
     267        // actually 0 means pixel is valid 
     268        const float pixelIsValid = 0.0f; 
     269        const float pixelCouldBeValid = 2.0f; 
     270        const float pixelNotValid = 10.0f; 
     271 
     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) 
    268280                ) 
    269281        { 
    270                 validPixel = 0.0f; 
    271         } 
    272         else 
     282                pixelValid = pixelNotValid; 
     283        } 
     284        // check if changed from dynamic to not dynamic object 
     285        // or there is a depth discontinuity 
     286        else  
     287        if ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     288                (oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF))) 
    273289        {        
    274                 validPixel = 10.5f; 
    275         } 
    276  
    277         //return depthDif; 
    278         return validPixel; 
    279 } 
    280  
    281  
     290                pixelValid = pixelCouldBeValid;  
     291        } 
     292        else  
     293        { 
     294                pixelValid = pixelIsValid; 
     295        } 
     296 
     297        return pixelValid; 
     298} 
     299 
     300 
     301/** This function is called during downsampling of the buffers 
     302        for ssao. 
     303*/ 
    282304pixel PrepareSsao(fragment IN, 
    283305                                   uniform sampler2D colorsTex, 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3203 r3204  
    105105        const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 
    106106 
     107        // the ssao value in the old frame 
     108        const float ssao = oldPixel.x; 
     109 
    107110#if USE_EYESPACE_DEPTH 
    108111 
     
    129132#endif 
    130133 
    131         float newWeight; 
     134        const float xOffs = 1.0f / 1024.0f; 
     135        const float yOffs = 1.0f / 768.0f; 
     136        const float eps = 1e-6f; 
     137 
     138        // the weight of the old value 
     139        float w; 
     140 
     141        ////////////// 
     142        //-- reuse old value only if it was still valid in the old frame 
    132143 
    133144        if (1 
    134                 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
    135                 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
     145                && (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= 1.0f - xOffs + eps) 
     146                && (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= 1.0f - yOffs + eps) 
    136147                && (depthDif <= MIN_DEPTH_DIFF)  
    137148                ) 
    138149        { 
    139                 // increase the weight for convergence 
    140                 newWeight =  oldPixel.y; 
     150                // pixel valid => retrieve the convergence weight 
     151                w = 10.0f;//oldPixel.y; 
    141152        } 
    142153        else 
    143154        {        
    144                 newWeight = 0.0f; 
    145         } 
    146  
    147         return float2(oldPixel.x, newWeight); 
     155                w = 0.0f; 
     156        } 
     157 
     158        return float2(ssao, w); 
    148159} 
    149160 
     
    168179                         ) 
    169180{ 
    170         // Check in a circular area around the current position. 
    171         // Shoot vectors to the positions there, and check the angle to these positions. 
    172         // Summing up these angles gives an estimation of the occlusion at the current position. 
    173  
    174181        float total_ao = .0f; 
    175182        float numSamples = .0f; 
     
    198205                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
    199206                // the normal of the current sample 
    200                 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
    201207                const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 
    202208 
     
    218224                cosAngle *= step(0.0f, dot(dirSample, normal)); 
    219225         
    220                 // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    221                 // the distance to a sample approaches zero 
    222                 //const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 
    223226                const float aoContrib = SAMPLE_INTENSITY / sqrLen; 
    224227                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
     
    248251        This version of the ssao shader uses the dotproduct between  
    249252        pixel-to-sample direction and sample normal as weight. 
     253 
     254    The algorithm works like the following: 
     255        1) Check in a circular area around the current position. 
     256        2) Shoot vectors to the positions there, and check the angle to these positions. 
     257        3) Summing up these angles gives an estimation of the occlusion at the current position. 
    250258*/ 
    251259float3 ssao(fragment IN, 
     
    264272                        ) 
    265273{ 
    266         // Check in a circular area around the current position. 
    267         // Shoot vectors to the positions there, and check the angle to these positions. 
    268         // Summing up these angles gives an estimation of the occlusion at the current position. 
    269  
    270274        float total_ao = .0f; 
    271275        float validSamples = .0f; 
     
    278282#if 1 
    279283                //////////////////// 
    280                 //-- add random noise: reflect around random normal vector (rather slow!) 
     284                //-- add random noise: reflect around random normal vector  
     285                //-- (slows down the computation for some reason!) 
    281286 
    282287                float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     
    286291#endif 
    287292                // weight with projected coordinate to reach similar kernel size for near and far 
    288                 //const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter; 
    289293                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
    290294 
     
    321325                // hack: the distance measure can fail in some cases => choose something different 
    322326                const float tooFarAway = step(1.0f, lengthToSample); 
    323                 validSamples += (1.0f - tooFarAway) * sampleColor.x; 
     327                validSamples = max(validSamples, (1.0f - tooFarAway) * sampleColor.x); 
     328 
    324329                //validSamples += sampleColor.x; 
    325330 
     
    327332 
    328333                //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 
    329                 if ((validSamples < 1.0f) && (numSamples >= 8)) break; 
     334                //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 
    330335        } 
    331336 
     
    400405 
    401406        // cull background note: this should be done with the stencil buffer 
    402         //if (SqrLen(diffVec < 1e6f) && (eyeSpaceDepth < 1e10f)) 
    403407        if (eyeSpaceDepth < 1e10f) 
    404408        { 
     
    412416 
    413417        const float squaredLen = SqrLen(diffVec); 
    414          
    415         if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 
    416         {                
     418/*       
     419        if (ao.y > 4.0f) oldWeight = 0; 
     420        else if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 
    417421                oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 
    418         } 
    419  
     422*/       
    420423        const float newWeight = ao.z; 
    421424 
    422425        // blend between old and new samples (and avoid division by zero) 
    423426        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 
    424         OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
     427        OUT.illum_col.y = oldWeight;//clamp(newWeight + oldWeight, .0f, temporalCoherence); 
     428 
    425429        OUT.illum_col.z = SqrLen(diffVec); 
    426430        OUT.illum_col.w = eyeSpaceDepth; 
Note: See TracChangeset for help on using the changeset viewer.