Ignore:
Timestamp:
09/04/08 16:46:27 (16 years ago)
Author:
mattausch
Message:

got rid of error with newly visible surfaces, much faster

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2903 r2904  
    3535/** The ssao shader returning the an intensity value between 0 and 1 
    3636*/ 
    37 float ssao(fragment IN, 
     37float2 ssao(fragment IN, 
    3838                   uniform sampler2D positions, 
    3939                   uniform sampler2D noiseTexture, 
    4040                   uniform float2 samples[NUM_SAMPLES], 
    4141                   uniform float3 currentNormal, 
    42                    uniform float3 currentViewDir, 
    4342                   uniform float4 centerPosition 
     43                   //,uniform float3 currentViewDir 
    4444                   ) 
    4545{ 
     
    5252 
    5353        float total_ao = 0.0; 
     54        float numSamples = 0; 
    5455 
    5556        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     
    6869                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    6970 
    70                 //if ((texcoord.x <= 1.0f) || (texcoord.x >= 0.0f) || (texcoord.y <= 1.0f) || (texcoord.y >= 0.0f)) 
    71                  
     71                if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 
     72                        ++ numSamples; 
     73 
    7274                // sample downsampled texture in order to speed up texture accesses 
    7375                float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; 
     
    9294 
    9395                total_ao += cos_angle * distance_intensity; 
     96 
     97                //total_ao /= j; 
    9498        } 
    9599 
    96         return max(0.0f, 1.0f - total_ao); 
     100        return float2(max(0.0f, 1.0f - total_ao), numSamples); 
    97101        //return saturate(dot(currentViewDir, currentNormal)); 
    98102} 
     
    124128         
    125129        /// the current view direction 
    126         float3 viewDir;// = normalize(IN.view); 
     130        //float3 viewDir = normalize(IN.view); 
    127131 
    128132        // the current world position 
     
    133137        const float currentDepth = currentCol.w; 
    134138 
    135         const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, centerPosition); 
     139        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition);//, viewDir); 
    136140                 
    137141 
     
    154158 
    155159        float oldWeight = clamp(oldCol.z, 0, temporalCoherence); 
     160        float oldNumSamples = oldCol.y; 
     161 
    156162        float newWeight; 
    157163 
    158         if ((temporalCoherence > 0) && 
     164        if (//(temporalCoherence > 0) && 
    159165                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    160166                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    161                 (abs(depthDif) < 1e-4f)) 
     167                (abs(depthDif) < 1e-3f)  
     168                && (oldNumSamples > ao.y - 1.5f) // check if something happened in the surrounding area 
     169                ) 
    162170        { 
    163                 newWeight = oldWeight + 1; 
     171                // increase the weight for convergence 
     172                newWeight = oldWeight + 1.0f; 
    164173 
    165174                //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
    166                 OUT.illum_col = (float4)(ao + oldCol.x * oldWeight) / newWeight; 
     175                OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight; 
     176 
     177                //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
    167178        } 
    168179        else 
    169180        { 
    170                 OUT.illum_col = (float4)ao; 
     181                OUT.illum_col.xy = ao.xy; 
    171182                newWeight = 0; 
    172183        } 
    173184 
    174185 
     186        //OUT.illum_col.y = ao.y; 
    175187        OUT.illum_col.z = newWeight; 
    176188        OUT.illum_col.w = currentDepth; 
Note: See TracChangeset for help on using the changeset viewer.