Ignore:
Timestamp:
02/16/09 17:08:51 (15 years ago)
Author:
mattausch
Message:

reverted back to before poisson sampling scheme

File:
1 edited

Legend:

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

    r3311 r3313  
    4848        weight of the pixel in the new frame. 
    4949*/ 
    50 inline float3 temporalSmoothing(float4 worldPos, 
     50inline float2 temporalSmoothing(float4 worldPos, 
    5151                                                                float eyeSpaceDepth, 
    5252                                                                float2 texcoord0, 
     
    9696        // the weight of the accumulated samples from the previous frames 
    9797        float w; 
    98         float idx; 
    9998 
    10099        ////////////// 
     
    109108                // pixel valid => retrieve the convergence weight 
    110109                w = oldPixel.y; 
    111                 idx = oldPixel.z; 
    112110        } 
    113111        else 
    114112        {        
    115                 w = .0f; 
    116                 idx = .0f; 
    117         } 
    118  
    119         return float3(ssao, w, idx); 
     113                w = 0.0f; 
     114        } 
     115 
     116        return float2(ssao, w); 
    120117} 
    121118 
     
    145142        float validSamples = .0f; 
    146143 
    147  
    148         for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i)  
     144        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    149145        { 
    150146                const float2 offset = samples[i]; 
     
    224220                        sampler2D colors, 
    225221                        sampler2D noiseTex, 
    226                         sampler2D samples, 
     222                        float2 samples[NUM_SAMPLES], 
    227223                        float3 normal, 
    228224                        float3 centerPosition, 
     
    235231                        float convergence, 
    236232                        float sampleIntensity, 
    237                         bool isMovingObject, 
    238                         float idx 
     233                        bool isMovingObject 
    239234                        ) 
    240235{ 
     
    242237        float validSamples = .0f; 
    243238        float numSamples = .0f; 
    244          
     239 
    245240        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    246241        { 
     
    251246                //-- (affects performance for some reason!) 
    252247 
    253                 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
    254  
    255248                if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
    256249                { 
    257                         float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord.x * 4.0f + idx * 0.01f, IN.texCoord.y * 4.0f, 0, 0)).xy; 
     250                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    258251                        //offset = myreflect(samples[i], mynoise); 
    259                         //offset = myrotate(samples[i], mynoise.x); 
    260  
    261                         offset = myrotate(ssaoOffset, mynoise.x); 
     252                        offset = myrotate(samples[i], mynoise.x); 
    262253                } 
    263254                else 
    264255                { 
    265                         offset = ssaoOffset; 
    266                         //offset = samples[i]; 
     256                        offset = samples[i]; 
    267257                } 
    268258                 
     
    304294                // we check if the sample could have been near enough to the current pixel  
    305295                // to have any influence in the current or last frame 
    306                 //const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
     296                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    307297                //validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 
    308298                validSamples = max(validSamples, pixelValid); 
     
    313303                if (numSamples >= MIN_SAMPLES) 
    314304                { 
     305                        //break; 
    315306                        // if the pixel belongs to a static object and all the samples stay valid in the current frame 
    316307                        if (!isMovingObject && (validSamples < 1.0f)) break; 
    317                         // if the pixel belongs to a dynamic object but the #accumulated samples 
    318                         // for this pixel is sufficiently high (=> there was no discontinuity recently) 
     308                        // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high  
     309                        // (=> there was no discontinuity recently) 
    319310                        else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
    320311                } 
     
    344335                   uniform sampler2D normals, 
    345336                   uniform sampler2D noiseTex, 
    346                    uniform sampler2D samples, 
     337                   uniform float2 samples[NUM_SAMPLES], 
    347338                   uniform sampler2D oldTex, 
    348339                   uniform float4x4 modelViewProj, 
     
    391382        //-- compute temporal reprojection 
    392383 
    393         float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
     384        float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
    394385                                                oldTex, oldModelViewProj,  
    395386                                                                                        colors,  
     
    402393        const float oldSsao = temporalVals.x; 
    403394        float oldWeight = temporalVals.y; 
    404  
    405         float idx = (int)temporalVals.z; 
    406  
    407         if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 
    408  
     395         
    409396        float3 ao; 
    410397 
     
    412399        if (eyeSpaceDepth < DEPTH_THRESHOLD) 
    413400        { 
    414                 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz,  
    415                               scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight,  
    416                                   sampleIntensity, isMovingObject, idx); 
     401                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    417402                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    418403        } 
     
    429414        // the weight equals the number of sampled shot in this pass 
    430415        const float newWeight = ao.z; 
    431  
    432         idx += newWeight; 
    433416 
    434417        // completely reset the ao in this pixel 
     
    437420        const float partlyResetThres = 1.0f; 
    438421         
    439         // hack: just update static geometry 
    440         if (!isMovingObject) 
     422        if (1)//!isMovingObject) 
    441423        { 
    442424                if (ao.y > completelyResetThres)  
    443425                { 
    444                         oldWeight = .0f; 
    445                         idx = .0f; 
     426                        oldWeight = .0f;  
    446427                } 
    447428                else if (ao.y > partlyResetThres) 
    448429                { 
    449430                        oldWeight = min(oldWeight, 4.0f * newWeight); 
     431                        //oldWeight = .0f;  
    450432                } 
    451433        } 
    452  
    453434 
    454435        ////////// 
    455436        //-- blend ao between old and new samples (and avoid division by zero) 
    456437 
    457         OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 
     438        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 
     439 
    458440        OUT.illum_col.x /= (newWeight + oldWeight); 
    459441 
    460442        // the new weight for the next frame 
    461443        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    462          
     444 
    463445        OUT.illum_col.y = combinedWeight; 
    464446        // can be used to check if this pixel belongs to a moving object 
    465         //OUT.illum_col.z = SqrLen(diffVec); 
    466         OUT.illum_col.z = idx; 
     447        OUT.illum_col.z = SqrLen(diffVec); 
    467448        OUT.illum_col.w = eyeSpaceDepth; 
    468449 
Note: See TracChangeset for help on using the changeset viewer.