Ignore:
Timestamp:
07/14/08 17:20:08 (16 years ago)
Author:
mattausch
Message:

removed ambient occlusion bugs

File:
1 edited

Legend:

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

    r2834 r2835  
    77//#define SAMPLE_INTENSITY 0.125f 
    88// rule of thumb: approx 1 / NUM_SAMPLES 
    9 #define SAMPLE_INTENSITY 0.2 //0.0625f 
     9#define SAMPLE_INTENSITY 0.16 //0.0625f 
    1010 
    1111#define AREA_SIZE 5e-1f 
     
    7676 
    7777                //sample noisetex; r stores costheta, g stores sintheta 
    78                 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     78                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
    7979 
    8080                // rotation 
    8181                //float2 offsetTransformed = offset; 
    82                 float2 offsetTransformed = rotate(offset, noise); 
     82                float2 offsetTransformed = rotate(offset, mynoise); 
    8383                //float2 offsetTransformed = reflect(offset, noise); 
    8484 
     
    9595                float cos_angle = dot(direction_to_sample, currentNormal); 
    9696                cos_angle = max(cos_angle, 0.0f); 
    97                 // take quadratic influence to sharpen contrast 
    98                 //cos_angle *= cos_angle; 
    9997 
    10098                // distance between current position and sample position controls AO intensity. 
    101                 //const float maxdist = 2e-1f; 
    102                 //const float maxdist = 5e-1f; 
    10399                const float distanceScale = 1e-6f; 
    104100 
     
    107103 
    108104                // if normal perpenticular to view dir, only half of the samples count 
    109                 float view_correction = (2.0f - dot(currentViewDir, currentNormal)); 
    110                 view_correction *= view_correction; 
     105                float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 
    111106 
    112107                total_ao += cos_angle * distance_intensity * view_correction; 
     
    144139 
    145140                //sample noisetex; r stores costheta, g stores sintheta 
    146                 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     141                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
    147142 
    148143                // rotation 
    149                 float2 offsetTransformed = rotate(offset, noise); 
     144                float2 offsetTransformed = rotate(offset, mynoise); 
    150145 
    151146                // weight with projected coordinate to reach similar kernel size for near and far 
     
    171166                // if normal perpenticular to view dir, only half of the samples count 
    172167                float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 
    173                 //view_correction *= view_correction; 
    174168 
    175169                total_ao += cos_angle * distance_intensity * view_correction; 
     
    218212                                uniform float noiseMultiplier, 
    219213                                uniform sampler2D oldTex, 
    220                                 const uniform float4x4 oldModelViewProj 
     214                                const uniform float4x4 oldModelViewProj, 
     215                                uniform float maxDepth 
    221216                                ) 
    222217{ 
     
    236231 
    237232        //float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
    238         float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
     233        float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition);  
    239234        float ao = new_col.w; 
    240235 
     
    244239        //OUT.color = ao; 
    245240        //OUT.color = ao * col;  
    246         float4 dummy = centerPosition / 0.000487676f; 
     241        float4 dummy = centerPosition * maxDepth; 
    247242        dummy.w = 1.0f; 
    248243        float4 oldPos = mul(oldModelViewProj, dummy); 
     
    250245        float newDepth = oldPos.z / oldPos.w; 
    251246  
    252         const float x = 0.05f; 
     247        const float x = 0.1f; 
    253248 
    254249        float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     
    257252        float oldDepth = col1.w; 
    258253 
    259         if ((tex.x >= 0) && (tex.x <= 1) && (tex.y >= 0) && (tex.y <= 1) && (abs(newDepth - oldDepth) < 5e-4f)) 
     254        if ((tex.x >= 0.0f) && (tex.x < 1.0f) && (tex.y >= 0.0f) && (tex.y < 1.0f) && (abs(newDepth - oldDepth) < 9e-4f)) 
    260255                OUT.color = attenuated_color * x + col1 * float4(1.0f - x); 
    261         else            OUT.color = attenuated_color;// * x + col1 * float4(1.0f - x); 
     256        else 
     257                OUT.color = attenuated_color; 
    262258 
    263259        //OUT.color = float4(centerPosition.w); 
     
    292288        float4 col1 = tex2D(oldTex, IN.texCoord.xy); 
    293289 
    294         const float x = 0.1f; 
     290        const float x = 0.01f; 
    295291        OUT.color = col * x + col1 * float4(1.0f - x); 
    296292 
Note: See TracChangeset for help on using the changeset viewer.