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

debug version showing a visualization of the confidence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.