Ignore:
Timestamp:
11/16/08 03:46:19 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r3126 r3128  
    6363                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    6464                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    65                                                   float scale) 
     65                                                  float scale, 
     66                                                  int index) 
    6667{ 
    6768        float average = .0f; 
     
    8687 
    8788                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    88                  
    8989                depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    9090                normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
     
    9393                //w = filterWeights[i] * depthFactor; 
    9494 
    95                 average += aoSample.x * w; 
     95                average += aoSample[index] * w; 
    9696                total_w += w; 
    9797        } 
     
    119119        if (col.w < 1e10f) 
    120120        { 
    121                 //const static float scaleFactor = 10.0f; 
    122                 const static float scaleFactor = 50.0f; 
     121                //const static float scaleFactor = 50.0f; 
     122                const static float scaleFactor = 10.0f; 
     123                const static float adaptFactor = 10.0f; 
    123124 
    124125                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    125126                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
    126127                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
    127                 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
    128         } 
    129  
    130         OUT.illum_col = col * ao.x; 
     128                ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0); 
     129        } 
     130 
     131        OUT.illum_col.xyz = col.xyz * ao.x; 
    131132        //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    132133        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
     
    135136        return OUT; 
    136137} 
     138 
     139float DiscontinuityFilter2(float2 texCoord, 
     140                                                  float4 ao, 
     141                                                  uniform sampler2D ssaoTex, 
     142                                                  uniform sampler2D normalsTex, 
     143                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     144                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     145                                                  float scale, 
     146                                                  int index) 
     147{ 
     148        float average = .0f; 
     149        float total_w = .0f; 
     150 
     151        const float eyeSpaceDepth = ao.w; 
     152        const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
     153 
     154        float4 aoSample; 
     155        float3 sampleNorm; 
     156        float w; 
     157        float4 offs; 
     158        float depthFactor; 
     159        float normalFactor; 
     160 
     161        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     162        { 
     163                offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
     164                aoSample = tex2Dlod(ssaoTex, offs); 
     165                 
     166                sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
     167 
     168                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
     169                depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
     170                normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
     171 
     172                w = filterWeights[i] * normalFactor * depthFactor; 
     173                //w = filterWeights[i] * depthFactor; 
     174 
     175                average += aoSample.y * w; 
     176                total_w += w; 
     177        } 
     178 
     179        average *= 1.0f / max(total_w, 1e-6f); 
     180 
     181        return average; 
     182} 
     183 
     184pixel smoothSsao(fragment IN,  
     185                                 uniform sampler2D ssaoTex, 
     186                                 uniform sampler2D normalsTex, 
     187                                 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     188                                 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
     189                          ) 
     190{ 
     191        pixel OUT; 
     192 
     193        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
     194 
     195        //const static float scaleFactor = 10.0f; 
     196        const static float scaleFactor = 10.0f; 
     197 
     198        ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 
     199         
     200        OUT.illum_col = ao; 
     201 
     202        return OUT; 
     203} 
Note: See TracChangeset for help on using the changeset viewer.