Changeset 3082 for GTP


Ignore:
Timestamp:
10/30/08 18:46:32 (16 years ago)
Author:
mattausch
Message:

debug version: working on split up of ssao and reprojection

File:
1 edited

Legend:

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

    r3081 r3082  
    6161        return samplePos; 
    6262} 
     63 
     64 
     65/** This shader computes the reprojection and stores reprojected color / depth values 
     66        as well as a boolean that  
     67*/ 
     68pixel TemporalSmoothing(float currentPos, 
     69                                                float currentDepth, 
     70                                                uniform sampler2D oldTex) 
     71{ 
     72 
     73        ///////////////// 
     74        //-- compute reprojection for temporal smoothing 
     75 
     76 
     77        // reproject into old frame and calculate projected depth 
     78        float4 projPos = mul(oldModelViewProj, worldPos); 
     79        projPos /= projPos.w; 
     80         
     81        // the current depth projected into the old frame 
     82        const float projDepth = projPos.z * precisionScale; 
     83        // fit from unit cube into 0 .. 1 
     84        const float2 tex = projPos.xy * 0.5f + 0.5f; 
     85        // retrieve the sample from the last frame 
     86        float4 oldCol = tex2D(oldTex, tex); 
     87 
     88        const float oldDepth = oldCol.z; 
     89        //const float depthDif = 1.0f - projDepth / oldDepth; 
     90        const float depthDif = projDepth - oldDepth; 
     91 
     92        //const float oldNumSamples = oldCol.y; 
     93        const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
     94 
     95        float newWeight; 
     96 
     97        // the number of valid samples in this frame 
     98        //const float newNumSamples = ao.y; 
     99 
     100        if ((temporalCoherence > 0) 
     101                && (tex.x >= 0.0f) && (tex.x < 1.0f) 
     102                && (tex.y >= 0.0f) && (tex.y < 1.0f) 
     103                && (abs(depthDif) < MIN_DEPTH_DIFF)  
     104                // if visibility changed in the surrounding area we have to recompute 
     105                //&& (oldNumSamples > 0.8f * newNumSamples) 
     106                ) 
     107        { 
     108                // increase the weight for convergence 
     109                newWeight = oldWeight + 1.0f; 
     110                OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
     111                //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
     112        } 
     113        else 
     114        {        
     115                OUT.illum_col.x = ao.x; 
     116                newWeight = .0f; 
     117        } 
     118 
     119        illum_col.y = newWeight; 
     120        illum_col.z = currentDepth; 
     121 
     122        return illum_col; 
     123} 
     124 
    63125 
    64126 
     
    159221        pixel OUT; 
    160222 
    161         float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 
    162         const float3 normal = normalize(norm.xyz); 
    163  
    164         /// reconstruct position from the eye space depth 
    165         float3 viewDir = IN.view; 
     223        const float3 normal =  
     224                normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     225 
     226        // reconstruct position from the eye space depth 
     227        const float3 viewDir = IN.view; 
    166228        const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
    167229        const float3 eyeSpacePos = -viewDir * eyeDepth; 
     
    185247        ///////////////// 
    186248        //-- compute temporally smoothing 
    187  
    188  
    189         // reproject new frame into old one  
    190          
    191         // calculate projected depth 
    192         float4 projPos = mul(oldModelViewProj, worldPos); 
    193         projPos /= projPos.w; 
    194          
    195         // the current depth projected into the old frame 
    196         const float projDepth = projPos.z * precisionScale; 
    197         // fit from unit cube into 0 .. 1 
    198         const float2 tex = projPos.xy * 0.5f + 0.5f; 
    199         // retrieve the sample from the last frame 
    200         float4 oldCol = tex2D(oldTex, tex); 
    201  
    202         const float oldDepth = oldCol.z; 
    203         //const float depthDif = 1.0f - projDepth / oldDepth; 
    204         const float depthDif = projDepth - oldDepth; 
    205  
    206         //const float oldNumSamples = oldCol.y; 
    207         const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
    208  
    209         float newWeight; 
    210  
    211         // the number of valid samples in this frame 
    212         //const float newNumSamples = ao.y; 
    213  
    214         if ((temporalCoherence > 0) 
    215                 && (tex.x >= 0.0f) && (tex.x < 1.0f) 
    216                 && (tex.y >= 0.0f) && (tex.y < 1.0f) 
    217                 && (abs(depthDif) < MIN_DEPTH_DIFF)  
    218                 && (abs(oldCol.x - ao.x) < 0.1f) 
    219                 // if visibility changed in the surrounding area we have to recompute 
    220                 //&& (oldNumSamples > 0.8f * newNumSamples) 
    221                 ) 
    222         { 
    223                 // increase the weight for convergence 
    224                 newWeight = oldWeight + 1.0f; 
    225                 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
    226                 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
    227         } 
    228         else 
    229         {        
    230                 OUT.illum_col.x = ao.x; 
    231                 newWeight = .0f; 
    232         } 
    233  
    234         OUT.illum_col.y = newWeight; 
    235         OUT.illum_col.z = currentDepth; 
     249         
     250        OUT.illum_col = TemporalSmoothing(currentPos, currentDepth, oldTex); 
    236251 
    237252        return OUT; 
Note: See TracChangeset for help on using the changeset viewer.