Ignore:
Timestamp:
10/03/08 14:35:07 (16 years ago)
Author:
mattausch
Message:

trying to use smaller fbo

File:
1 edited

Legend:

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

    r2997 r2999  
    4848                                                                                float3 bl, float3 br, float3 tl, float3 tr) 
    4949{ 
    50 #if 0 
     50#if 1 
    5151        float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
    52         float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
    53          
    54         float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
     52        //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     53        float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
     54         
     55        float3 samplePos = eyePos - rotView * eyeSpaceDepth; 
    5556#else 
    56         float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
    57 #endif 
    58         return sample_position; 
     57        float3 samplePos = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
     58#endif 
     59        return samplePos; 
    5960} 
    6061 
     
    101102                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * scaleFactor; 
    102103 
    103                 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 
    104                         ++ numSamples; 
    105  
    106                 float3 sample_position = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 
    107  
    108                 float3 vector_to_sample = sample_position - centerPosition.xyz; 
    109                 const float length_to_sample = length(vector_to_sample); 
    110  
    111                 float3 direction_to_sample = vector_to_sample / length_to_sample; 
     104                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f))++ numSamples; 
     105 
     106                // get sample world space position 
     107                float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
     108                //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     109                float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
     110         
     111                float3 samplePos = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 
     112 
     113 
     114                /////// 
     115                //-- compute contribution of current sample taking into account direction and angle 
     116 
     117                float3 dirSample = samplePos - centerPosition.xyz; 
     118                const float lengthSample = length(dirSample); 
     119 
     120                float3 nDirSample = dirSample / lengthSample; 
    112121 
    113122                // angle between current normal and direction to sample controls AO intensity. 
    114                 const float cos_angle = max(dot(direction_to_sample, currentNormal), 0.0f); 
     123                const float cos_angle = max(dot(nDirSample, currentNormal), 0.0f); 
    115124 
    116125                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    117126                // the distance to a sample approaches zero 
    118                 const float distance_intensity =  
    119                         (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample); 
     127                const float intensity =  
     128                        (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + lengthSample * lengthSample); 
    120129 
    121130#if 0 
    122131                // if surface normal perpenticular to view dir, approx. half of the samples will not count 
    123132                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    124                 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
    125                 total_ao += cos_angle * distance_intensity * view_correction; 
    126 #endif 
    127                 total_ao += cos_angle * distance_intensity; 
     133                const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
     134                total_ao += cos_angle * intensity * viewCorrection; 
     135#endif 
     136                total_ao += cos_angle * intensity; 
    128137        } 
    129138 
    130139        return float2(max(0.0f, 1.0f - total_ao), numSamples); 
    131         //return saturate(dot(currentViewDir, currentNormal)); 
    132140} 
    133141 
     
    165173        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    166174 
    167 #if 1    
     175#if 0    
    168176        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    169177 
     
    197205        float4 oldPos = mul(oldModelViewProj, realPos); 
    198206 
     207        const float4 projPos = oldPos / oldPos.w; 
     208 
    199209        // the current depth projected into the old frame 
    200         const float projDepth = oldPos.z / oldPos.w; 
     210        const float projDepth = projPos.z; 
    201211 
    202212        // fit from unit cube into 0 .. 1 
    203         float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     213        float2 tex = (projPos.xy) * 0.5f + 0.5f; 
    204214 
    205215        // optain the sample from the last frame 
     
    212222        const float depthDif = 1.0f - projDepth / oldDepth; 
    213223 
    214  
    215224        float newWeight; 
    216225 
    217226        // the number of valid samples in this frame 
    218         const float newNumSamples = ao.y; 
     227        //const float newNumSamples = ao.y; 
    219228 
    220229 
     
    224233                (abs(depthDif) < 1e-4f)  
    225234                // if visibility changed in the surrounding area we have to recompute 
    226                 && (oldNumSamples > 0.8f * newNumSamples) 
     235                //&& (oldNumSamples > 0.8f * newNumSamples) 
    227236                ) 
    228237        { 
Note: See TracChangeset for help on using the changeset viewer.