Changeset 3366 for GTP


Ignore:
Timestamp:
04/29/09 18:56:18 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
Files:
2 edited

Legend:

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

    r3365 r3366  
    221221        if the reprojected pixel from last frame is still 
    222222        valid in the current frame 
    223         */ 
    224 inline float2 PixelValid(sampler2D oldTex, 
    225                                                  float4 color, 
    226                                                  float3 difVec, 
    227                                                  float2 texCoord, 
    228                                                  float3 viewDir, 
    229                                                  float3 oldEyePos, 
    230                                                  float4x4 modelViewProj, 
    231                                                  float4x4 oldModelViewProj, 
    232                                                  float3 oldbl, 
    233                                                  float3 oldbr, 
    234                                                  float3 oldtl, 
    235                                                  float3 oldtr, 
    236                                                  sampler2D myTex 
    237                                                  ) 
     223*/ 
     224/*inline float2 ComputeInfo(sampler2D oldTex, 
     225                                                  float4 color, 
     226                                                  float3 difVec, 
     227                                                  float2 texCoord, 
     228                                                  float3 viewDir, 
     229                                                  float3 oldEyePos, 
     230                                                  float4x4 modelViewProj, 
     231                                                  float4x4 oldModelViewProj, 
     232                                                  float3 oldbl, 
     233                                                  float3 oldbr, 
     234                                                  float3 oldtl, 
     235                                                  float3 oldtr, 
     236                                                  sampler2D myTex 
     237                                                  ) 
    238238{ 
    239239        // reconstruct position from the eye space depth 
     
    241241        const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
    242242 
    243  
    244         //////////////// 
    245         //-- calculcate the current projected posiion (also used for next frame) 
    246          
    247         float4 projPos = mul(modelViewProj, worldPos); 
    248         const float invw = 1.0f / projPos.w; 
    249         projPos *= invw; 
    250  
    251243        // compute position from old frame for dynamic objects + translational portion 
    252244        const float3 translatedPos = -oldEyePos + worldPos.xyz + difVec; 
    253         // don't use difVec here: want to detect if the actual pixel has changed => ssao changed 
    254         //const float3 translatedPos = -oldEyePos + worldPos.xyz; 
    255245 
    256246 
     
    275265        const float3 oldViewDir = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
    276266        const float invLen = 1.0f / length(oldViewDir); 
    277         const float projectedEyeSpaceDepth = invLen * length(translatedPos); 
    278          
    279         const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
    280         const float squaredLen = SqrLen(difVec); 
    281          
    282  
    283         // test if this pixel was valid in the old frame 
    284         float isPixelValid; 
    285  
    286         // check if the pixel belonged to a dynamic object in the last frame 
    287         const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    288         const bool oldDynamic = (oldDiff > DYNAMIC_OBJECTS_THRESHOLD); 
    289  
    290  
    291         // actually 0 means pixel is valid 
    292         const float pixelIsValid = .0f; 
    293         // means that we only use slight temporal coherence over some frames 
    294         // so that there is no noticeable drag 
    295         //const float pixelCouldBeValid = 4.0f; 
    296         const float pixelCouldBeValid = 100.0f; 
    297         // this pixel information has to be discarded in order to not create artifacts 
    298         const float pixelIsNotValid = 100.0f; 
    299  
     267         
    300268 
    301269        // check if the pixel was outside of the frame buffer 
     
    324292        //isPixelValid = depthDif; 
    325293 
    326         return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
     294        return float3(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
     295} 
     296*/ 
     297 
     298 
     299/** This shader computes the reprojection and checks 
     300        if the reprojected pixel from last frame is still 
     301        valid in the current frame 
     302*/ 
     303inline float3 ComputeTranslatedPos( 
     304                                                 float4 color, 
     305                                                 float3 difVec, 
     306                                                 float3 viewDir, 
     307                                                 float3 oldEyePos 
     308                                                 ) 
     309{ 
     310        // reconstruct position from the eye space depth 
     311        const float eyeSpaceDepth = color.w; 
     312        const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
     313        // compute position from old frame for dynamic objects + translational portion 
     314        const float3 translatedPos = -oldEyePos + worldPos.xyz + difVec; 
     315         
     316        return translatedPos; 
    327317} 
    328318 
     
    355345        const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0, 0)).xyz); 
    356346 
    357 #ifdef PERFORMANCE_TEST 
    358347        // do reprojection and filter out the pixels that are not save 
    359         const float2 pValid = PixelValid(oldTex, 
     348/*      const float2 pValid = PixelValid(oldTex, 
    360349                                             color,  
    361350                                                                         difVec.xyz, 
     
    368357                                                                         myTex 
    369358                                                                         ); 
    370 #else 
    371         const float2 pValid = float2(0, 0); 
    372 #endif 
    373359 
    374360        pix.color = color; 
    375361        pix.color.xy = pValid.xy; 
    376362        pix.color.z = color.w; 
    377  
     363*/ 
     364        const float3 translatedPos = ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos); 
     365 
     366        pix.color.xyz = translatedPos; 
     367        pix.color.w = color.w; 
    378368        pix.normal = normal; 
    379369 
     
    390380        return color; 
    391381} 
     382 
     383 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3365 r3366  
    474474                        bool isMovingObject, 
    475475                        float oldIdx, 
    476                         sampler2D attribsTex 
     476                        sampler2D attribsTex, 
     477                        float3 oldPos 
    477478                        ) 
    478479{ 
     
    481482        float numSamples = .0f; 
    482483 
    483         float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     484        //float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    484485 
    485486        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     
    513514 
    514515                const float4 sampleColor = tex2Dlod(colors, float4(texcoord, .0f, .0f)); 
     516                const float3 oldSamplePos = sampleColor.xyz; 
    515517                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
    516518                 
     
    549551                if (cosAngle >= 0) 
    550552                { 
    551                         float pixelValid = 0;//sampleColor.x; 
    552  
    553                         if (1)//pixelValid < 0.5f) 
    554                         { 
    555                                 const float3 sampleDiffVec = tex2Dlod(attribsTex, float4(texcoord, .0f, .0f)).xyz; 
    556                                 //pixelValid = max(pixelValid, length(sampleDiffVec - diffVec) < 5e-3f ? .0f : 100.0f); 
    557                                 pixelValid = max(pixelValid, length(sampleDiffVec - diffVec) < 5e-3f ? .0f : 4.0f); 
    558                                 //pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f; 
    559                         } 
    560  
    561                         // hack: 
    562                         // we check if the sample could have been near enough to the current pixel  
    563                         // or if the angle is small enough 
    564                         // to have any influence in the current or last frame 
    565  
    566                         const float changeFactor = sampleColor.y; 
    567                         const float partlyResetThres = 1.0f; 
    568  
    569                         if (0)//pixelValid <= partlyResetThres) 
    570                         { 
    571                                 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    572                                 validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); 
    573                         } 
    574                         else 
    575                         { 
    576                                 validSamples = max(validSamples, pixelValid); 
    577                         } 
     553                        const float oldDistance = length(oldSamplePos - oldPos); 
     554                        const float distanceDiff = abs(oldDistance - lengthToSample); 
     555 
     556                        float pixelValid = (distanceDiff > 1e-3f) ? 100.0f : 0; 
     557 
     558                        validSamples = max(validSamples, pixelValid); 
    578559                } 
    579560#ifdef USE_GTX 
     
    643624        // reconstruct position from the eye space depth 
    644625        const float3 viewDir = IN.view; 
    645         const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
     626        const float4 mycolor = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
     627        const float eyeSpaceDepth = mycolor.w; 
    646628        const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
    647629 
     
    712694                                          br, tl, tr, normalize(viewDir),  
    713695                                          oldWeight, sampleIntensity, isMovingObject, oldIdx, 
    714                                           attribsTex); 
     696                                          attribsTex, mycolor.xyz); 
    715697#endif                             
    716698                } 
Note: See TracChangeset for help on using the changeset viewer.