Ignore:
Timestamp:
11/12/08 01:47:27 (16 years ago)
Author:
mattausch
Message:

worked on filtering now trying to reduce flickering (have to reorder ssao function quite much

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
Files:
2 edited

Legend:

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

    r3109 r3120  
    3636 
    3737 
     38float Filter(float2 texCoord,  
     39                         uniform sampler2D ssaoTex, 
     40                         uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     41                         uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     42                         float scale) 
     43{ 
     44        float average = .0f; 
     45        float w = .0f; 
     46 
     47        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     48        {        
     49                average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 
     50                w += filterWeights[i]; 
     51        } 
     52 
     53        average *= 1.0f / (float)w; 
     54 
     55        return average; 
     56} 
     57 
     58 
    3859float BilateralFilter(float2 texCoord, 
    3960                                          float4 ao, 
     
    4162                                          uniform sampler2D normalsTex, 
    4263                                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    43                                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 
     64                                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     65                                          float scale) 
    4466{ 
    4567        float average = .0f; 
    4668        float total_w = .0f; 
    4769 
    48         //const float eyeSpaceDepth = ao.w; 
     70        const float eyeSpaceDepth = ao.w; 
    4971        const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    5072 
     
    5274        float3 sampleNorm; 
    5375        float w; 
     76        float4 offs; 
     77        float depthFactor; 
    5478 
    5579        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    5680        { 
    57                 float4 offs = float4(texCoord + filterOffs[i], 0, 0); 
     81                offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    5882                aoSample = tex2Dlod(ssaoTex, offs); 
    59                 //aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]); 
    60                 //float sampleEyeSpaceDepth = aoSample.w; 
    61                 //factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth; 
     83                 
    6284                sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
     85                depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    6386                //sampleNorm = tex2Dlod(normalsTex, offs).xyz; 
    6487 
    65                 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f); 
     88                w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) * depthFactor; 
    6689 
    67                 average += w * aoSample.x; 
     90                average += aoSample.x * w; 
    6891                total_w += w; 
    6992        } 
    7093 
    71         average *= 1.0f / max(total_w, 1e-5f); 
     94        average *= 1.0f / max(total_w, 1e-6f); 
    7295 
    7396        return average; 
     
    88111        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    89112 
    90         //if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    91         //if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights); 
     113        if ((ao.y < 60.0f) && (col.w < 1e10f)) 
     114        { 
     115                const static float scaleFactor = 10.0f; 
    92116 
    93         //OUT.illum_col = col * ao.x; 
    94         //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 
    95         OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
     117                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
     118                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
     119                ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
     120                //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
     121        } 
     122 
     123        OUT.illum_col = col * ao.x; 
     124        //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    96125        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    97         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    98126        OUT.illum_col.w = col.w; 
    99127 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3119 r3120  
    189189        //float overallDepth = 0; 
    190190        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
    191  
     191#if 1 
    192192        if (squaredLen < 1e-8f) // object not dynamic 
    193193        { 
     
    210210                } 
    211211        } 
    212  
     212#endif 
    213213        const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 
    214214        float newWeight; 
     
    220220                // if visibility changed in the surrounding area we have to recompute 
    221221                //&& (oldNumSamples > 0.8f * newNumSamples) 
    222                 && (notValid < 1.0f) 
     222                //&& (notValid < 1.0f) 
    223223                ) 
    224224        { 
     
    226226                newWeight = oldWeight + 1.0f; 
    227227                illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight; 
    228                 //if (notValid > 1.0f) newWeight = 2.0f; 
     228                if (notValid > 1.0f) newWeight = 2.0f; 
    229229        } 
    230230        else 
     
    292292 
    293293                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
     294 
    294295                const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
    295296 
     
    378379        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    379380 
     381 
    380382        ///////////////// 
    381383        //-- compute temporal reprojection 
     
    393395                                                                          diffVec); 
    394396 
    395         //OUT.illum_col.xyz = id; 
    396         //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 
    397397        return OUT; 
    398398} 
    399  
    400  
    401 float Filter(float2 texCoord,  
    402                          uniform sampler2D ssaoTex, 
    403                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    404                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    405                          float scale) 
    406 { 
    407         float average = .0f; 
    408         float w = .0f; 
    409  
    410         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    411         {        
    412                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x; 
    413                 w += filterWeights[i]; 
    414         } 
    415  
    416         average *= 1.0f / (float)w; 
    417  
    418         return average; 
    419 } 
    420  
    421  
    422 pixel combine(fragment IN,  
    423                           uniform sampler2D colorsTex, 
    424                           uniform sampler2D ssaoTex, 
    425                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    426                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    427                           ) 
    428 { 
    429         pixel OUT; 
    430  
    431         const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
    432         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    433  
    434         //if ((ao.y < 10.0f) && (col.w < 1e10f)) 
    435         //      ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 
    436  
    437         OUT.illum_col = col * ao.x; 
    438         //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 
    439         //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 
    440         //OUT.illum_col = float4(ao.x, 0, 0, col.w); 
    441         //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    442         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    443         OUT.illum_col.w = col.w; 
    444  
    445         return OUT; 
    446 } 
Note: See TracChangeset for help on using the changeset viewer.