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/globillum.cg

    r2903 r2904  
    3737} 
    3838 
     39struct GiStruct 
     40{ 
     41        float3 illum; 
     42        float2 ao; 
     43}; 
     44 
     45 
    3946/** Computes  diffuse reflections + ambient occlusion 
    4047*/ 
    41 float4 globIllum(fragment IN, 
     48GiStruct globIllum(fragment IN, 
    4249                                 uniform sampler2D colors, 
    4350                                 uniform sampler2D positions, 
     
    4956                                 ) 
    5057{ 
     58        GiStruct gi; 
     59 
    5160        // the w coordinate from the persp. projection 
    5261        float w = centerPosition.w; 
     
    5766 
    5867        // ao is in stored in the w component 
    59         float4 total_color = float4(0, 0, 0, 1); 
    60  
     68        float3 total_color = float3(0, 0, 0); 
     69        float total_ao = 0.0f; 
     70        float numSamples = 0.0f; 
    6171 
    6272        //////////// 
     
    7888                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    7989 
     90                if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 
     91                        ++ numSamples; 
     92 
    8093                // use lower lod level to improve cache coherence 
    8194                float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; 
     
    100113                total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 
    101114                */ 
    102                 total_color.w -= cos_angle * distance_intensity; 
    103                 total_color.xyz += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 
     115                total_ao += cos_angle * distance_intensity; 
     116                total_color += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 
    104117        } 
    105118 
    106         return saturate(total_color); 
     119        gi.illum = saturate(total_color); 
     120        gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 
     121 
     122        //return saturate(total_color); 
     123        return gi; 
    107124} 
    108125 
     
    144161        const float currentDepth = currentCol.w; 
    145162 
    146         float4 new_color = globIllum(IN, colors, positions, noiseTexture,  
    147                                  samples, normal, viewDir, centerPosition); 
     163        GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, centerPosition); 
    148164         
    149165 
     
    168184        float oldWeight = clamp(oldSsao.z, 0, temporalCoherence); 
    169185        float newWeight; 
     186 
     187        const float oldNumSamples = oldSsao.y; 
    170188 
    171189        if ((temporalCoherence > 0.0f) && 
    172190                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    173191                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    174                 (abs(depthDif)  < 1e-3f)) 
     192                (abs(depthDif)  < 1e-3f) 
     193                && (oldNumSamples > gi.ao.y - 1.5f) // check if something happened in the surrounding area 
     194                ) 
    175195        { 
    176196                newWeight = oldWeight + 1; 
    177197 
    178                 //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
    179                 OUT.ssao_col.x = (new_color.w + oldSsao.x * oldWeight) / newWeight; 
    180                 OUT.illum_col  = (new_color + oldIllum * oldWeight) / newWeight; 
    181  
    182                 //OUT.ssao_col.x = new_color.w * expFactor + oldSsao.x * (1.0f - expFactor); 
    183                 //OUT.illum_col = new_color * expFactor + oldIllum * (1.0f - expFactor); 
     198                OUT.ssao_col.xy = (gi.ao + oldSsao.xy * oldWeight) / newWeight; 
     199                OUT.illum_col.xyz  = (gi.illum + oldIllum.xyz * oldWeight) / newWeight; 
    184200        } 
    185201        else 
     
    187203                newWeight = 0; 
    188204 
    189                 OUT.ssao_col.x = new_color.w; 
    190                 OUT.illum_col = new_color; 
     205                OUT.ssao_col.xy = gi.ao.xy; 
     206                OUT.illum_col.xyz = gi.illum; 
    191207        } 
    192208 
     
    211227         
    212228        OUT.illum_col = (col + illum) * ao; 
     229        //OUT.illum_col = ao; 
     230 
    213231        OUT.illum_col.w = col.w; 
    214232 
Note: See TracChangeset for help on using the changeset viewer.