Ignore:
Timestamp:
12/22/08 10:56:58 (16 years ago)
Author:
mattausch
Message:

worked on sampling / convergence

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h

    r3213 r3227  
    4545        return rpt; 
    4646} 
     47 
     48 
     49 
     50 
     51inline float2 myrotate(float2 pt, float angle) 
     52{ 
     53        float2 rpt; 
     54 
     55        rpt.x = pt.x * cos(angle) - pt.y * sin(angle); 
     56        rpt.y = pt.y * cos(angle) + pt.x * sin(angle); 
     57 
     58        //normalize(rpt); 
     59        return rpt; 
     60} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3226 r3227  
    229229 
    230230        // compute position from old frame for dynamic objects + translational portion 
    231         const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 
     231        //const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 
     232        const float3 translatedPos = - oldEyePos + worldPos.xyz; 
    232233 
    233234 
     
    275276                pixelValid = pixelNotValid; 
    276277        } 
    277         else if ( 
     278        else if (!((oldEyeSpaceDepth > 1e10f) || (projectedEyeSpaceDepth > 1e10f)) && 
    278279                // check if changed from dynamic to not dynamic object 
    279                 (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     280                ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
    280281                // check if we have a dynamic object and is a depth discontinuity 
    281                 ((oldDynamic || newDynamic) && (depthDif <= MIN_DEPTH_DIFF))) 
     282                ( 
     283                //(oldDynamic || newDynamic) &&  
     284                (depthDif > MIN_DEPTH_DIFF)))) 
    282285        {        
    283286                pixelValid = pixelCouldBeValid;  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3226 r3227  
    11#include "../shaderenv.h" 
    2  
     2#include "common.h" 
    33 
    44//////////////////// 
     
    2828} 
    2929 
    30  
    31 inline float SqrLen(float3 v) 
    32 { 
    33         return v.x * v.x + v.y * v.y + v.z * v.z; 
    34 } 
    35  
    36  
    37 inline float2 myreflect(float2 pt, float2 n) 
    38 { 
    39         // distance to plane 
    40         float d = dot(n, pt); 
    41         // reflect around plane 
    42         float2 rpt = pt - d * 2.0f * n; 
    43  
    44         return rpt; 
    45 } 
    46  
    47  
    48 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
    49 { 
    50         float3 x1 = lerp(bl, tl, w.y); 
    51         float3 x2 = lerp(br, tr, w.y);  
    52         float3 v = lerp(x1, x2, w.x);  
    53  
    54         return v; 
    55 } 
    5630 
    5731 
     
    225199        total_ao /= numSamples; 
    226200 
    227 #if 0 
     201#if 1 
    228202        // if surface normal perpenticular to view dir, approx. half of the samples will not count 
    229203        // => compensate for this (on the other hand, projected sampling area could be larger!) 
    230204        const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 
    231         total_ao *= viewCorrection; 
     205        total_ao += cosAngle * aoContrib * viewCorrection; 
    232206 
    233207#endif 
    234208 
    235         //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    236         return float3(total_ao, validSamples, numSamples); 
     209        return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    237210} 
    238211 
     
    261234                        float newWeight, 
    262235                        float sampleIntensity, 
    263                         bool isMovingObject, 
    264                         sampler2D normalTex 
     236                        bool isMovingObject 
    265237                        ) 
    266238{ 
     
    273245                const float2 offset = samples[i]; 
    274246 
    275 #if 1 
     247                float2 offsetTransformed; 
     248 
    276249                //////////////////// 
    277250                //-- add random noise: reflect around random normal vector  
    278                 //-- (slows down the computation for some reason!) 
     251                //-- (affects performance for some reason!) 
    279252 
    280253                float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    281                 const float2 offsetTransformed = myreflect(offset, mynoise); 
    282 #else 
    283                 const float2 offsetTransformed = offset; 
    284 #endif 
     254                //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord, 0, 0)).xy; 
     255                //offsetTransformed = myreflect(offset, mynoise); 
     256                offsetTransformed = myrotate(offset, mynoise.x); 
     257                 
    285258                // weight with projected coordinate to reach similar kernel size for near and far 
    286259                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
     
    290263                 
    291264 
    292                 // the normal of the current sample 
    293                 //const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 
    294                 // angle between current normal and direction to sample controls AO intensity. 
    295                 //float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f; 
    296  
    297265                //////////////// 
    298266                //-- compute contribution of sample using the direction and angle 
     
    300268                float3 dirSample = samplePos - centerPosition; 
    301269 
    302                 const float sqrLen = max(SqrLen(dirSample), 1e-2f); 
    303                 const float lengthToSample = sqrt(sqrLen); 
     270                //const float sqrLen = max(SqrLen(dirSample), 1e-2f); 
     271                //const float lengthToSample = sqrt(sqrLen); 
     272                const float lengthToSample =  max(length(dirSample), 1e-2f); 
    304273 
    305274                dirSample /= lengthToSample; // normalize 
    306275 
    307276                // angle between current normal and direction to sample controls AO intensity. 
    308                 const float cosAngle = max(dot(dirSample, normal), .0f); 
    309                 const float aoContrib = sampleIntensity / sqrLen; 
     277                float cosAngle = dot(dirSample, normal); 
     278 
     279                //const float aoContrib = sampleIntensity / sqrLen; 
     280                const float aoContrib = sampleIntensity / lengthToSample; 
    310281                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    311282 
    312                 //total_ao += cosAngle2 * cosAngle * aoContrib; 
    313                 total_ao += cosAngle * aoContrib; 
     283                total_ao += max(cosAngle, 0) * aoContrib; 
    314284 
    315285                ++ numSamples; 
     
    324294                // to have any influence in the current or last frame 
    325295                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    326                 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid); 
    327  
    328 #if 1//#ifdef U//USE_GTX 
     296                validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 
     297 
     298#ifdef USE_GTX 
    329299                // we can bail out early and use a minimal #samples) 
    330300                // if some conditions are met as long as the hardware supports it 
     
    351321 
    352322        return float3(total_ao, validSamples, numSamples); 
    353         //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    354323} 
    355324 
     
    426395        if (eyeSpaceDepth < 1e10f) 
    427396        { 
    428                 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals); 
     397                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    429398                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    430399        } 
     
    460429        } 
    461430 
     431        ////////// 
     432        //-- blend ao between old and new samples (and avoid division by zero) 
     433 
     434        OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 
     435 
     436        OUT.illum_col.x /= (newWeight + oldWeight); 
     437 
    462438        // the new weight for the next frame 
    463439        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    464  
    465  
    466         ////////// 
    467         //-- blend ao between old and new samples (and avoid division by zero) 
    468  
    469         //OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight); 
    470         OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / (newWeight + oldWeight); 
    471440 
    472441        OUT.illum_col.y = combinedWeight; 
Note: See TracChangeset for help on using the changeset viewer.