Ignore:
Timestamp:
05/19/09 19:17:41 (15 years ago)
Author:
mattausch
Message:

reverted but now a good version

File:
1 edited

Legend:

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

    r3371 r3372  
    5353 
    5454        // get position exactly between texel centers 
    55         float2 center = (floor(texCoord * res) + float2(.5f)) * texCoord; 
    56         //center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x; 
    57         //center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y; 
    58         //center.y = (floor(texCoord.y * res.y) + .5f) * yOffs; 
    59  
    60         /*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs,  yoffs), 0, 0)).y; 
    61         texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 
    62         texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
    63         texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y; 
    64  
    65         const float m1 = min(texelCenterConv.x, texelCenterConv.y); 
    66         const float m2 = min(texelCenterConv.z, texelCenterConv.w); 
    67  
    68         const float convergence = min(m1, m2);*/ 
    69  
     55        float2 center = (floor(texCoord * res) + float2(.5f)) * invRes; 
     56         
    7057        //const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y; 
    7158        const float convergence = tex2Dlod(tex, float4(texCoord, 0, 0)).y; 
     
    133120 
    134121        if (1 
    135                 && (oldTexCoords.x > 0) && (oldTexCoords.x < 1.0f) 
    136                 && (oldTexCoords.y > 0) && (oldTexCoords.y < 1.0f) 
     122                && (oldTexCoords.x > .0f) && (oldTexCoords.x < 1.0f) 
     123                && (oldTexCoords.y > .0f) && (oldTexCoords.y < 1.0f) 
    137124                && (depthDif <= MIN_DEPTH_DIFF)  
    138125                ) 
    139126        { 
    140                 // pixel valid => retrieve the convergence weight 
    141                 /*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    142                 float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    143                 float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    144                 float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    145  
    146                 w = min(min(w1, w2), min(w3, w4));*/ 
     127#if 0 
     128                idx = floor(oldPixel.z); 
     129#else 
     130 
     131                // nearest neighbour 
     132                float2 center; 
     133                center.x = (floor(oldTexCoords.x * 1024) + .5f) / 1024; 
     134                center.y = (floor(oldTexCoords.y * 768) + .5f) / 768; 
    147135                 
    148                 //w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 
    149                 w   = oldPixel.y; 
    150                 idx = floor(oldPixel.z); 
    151                 //idx = oldPixel.z; 
     136                const float4 oldPixelExact = tex2Dlod(oldTex, float4(center, .0f, .0f));  
     137                idx = oldPixelExact.z; 
     138#endif 
     139 
     140                w = oldPixel.y; 
    152141        } 
    153142        else 
     
    487476                float2 offset; 
    488477 
    489                 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 
     478                const float2 ssaoOffset = tex2Dlod(samples, float4((.5f + i + floor(oldIdx)) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 
    490479                //const float2 ssaoOffset = dummySamples[i]; 
    491480 
     
    494483                //-- (affects performance for some reason!) 
    495484 
    496                 if (1)//!USE_OPTIMIZATION || 
    497                         //(convergence < SSAO_CONVERGENCE_THRESHOLD)) 
     485                if (!USE_OPTIMIZATION || 
     486                        (convergence < SSAO_CONVERGENCE_THRESHOLD)) 
    498487                { 
    499488                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     
    521510                float3 dirSample = samplePos - centerPosition; 
    522511 
    523                 const float minDist = 1e-6f; 
    524512                const float eps = 1e-3f; 
    525513 
     
    527515                const float sampleWeight = 1.0f / max(lengthToSample, eps); 
    528516 
    529                 dirSample /= max(length(dirSample), minDist); // normalize 
     517                dirSample /= max(length(dirSample), eps); // normalize 
    530518 
    531519                // angle between current normal and direction to sample controls AO intensity. 
     
    540528 
    541529 
    542 //#ifdef PERFORMANCE_TEST 
    543 #if 1 
     530#ifdef PERFORMANCE_TEST 
    544531                // check if the samples have been valid in the last frame 
    545532                // only mark sample as invalid if in the last / current frame 
     
    552539                const float distanceDiff = abs(oldDistance - lengthToSample); 
    553540 
    554                 float pixelValid = (oldSamplePos.x > 1e14f) ? 100.0f : .0f; 
    555  
    556                 if ((cosAngle >= 0) && (pixelValid < 90.0f))// || (cosAngle2 >= 0)) 
    557                 { 
    558                         pixelValid = (distanceDiff > 1e-3f) ? 100.0f : .0f; 
    559                         //pixelValid = (distanceDiff > 1e-3f) ? 5.0f : .0f; 
     541                float pixelValid = .0f; 
     542 
     543                if ((texcoord.x > .0f) && (texcoord.x < 1.0f) && (texcoord.y > .0f) && (texcoord.y < 1.0f)) 
     544                { 
     545                        if ((oldSamplePos.x > 1e14f))// || ((cosAngle >= 0) && (distanceDiff > 1e-3f))) 
     546                        { 
     547                                pixelValid = 100.0f; 
     548                        } 
     549                        else if ((cosAngle >= 0) && (distanceDiff > 1e-3f)) 
     550                        { 
     551                                pixelValid = 5.0f; 
     552                        } 
    560553                } 
    561554 
     
    742735 
    743736                oldWeight = min(oldWeight, factor * NUM_SAMPLES); 
     737 
    744738                if (newIdx >= factor * NUM_SAMPLES)  
    745739                { 
Note: See TracChangeset for help on using the changeset viewer.