Ignore:
Timestamp:
11/06/08 10:41:02 (16 years ago)
Author:
mattausch
Message:

still some error with ssao on edges
bilateral filter slow

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

Legend:

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

    r3094 r3103  
    104104                //-- reconstruct world space position from sample 
    105105 
    106                 //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
    107                 const float4 sample = tex2D(colors, texcoord); 
     106                const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     107                //const float4 sample = tex2D(colors, texcoord); 
    108108 
    109109                const float eyeSpaceDepth = sample.w; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3101 r3103  
    44// Screen Spaced Ambient Occlusion shader 
    55// based on shader of Alexander Kusternig 
    6  
    7  
    8 #define USE_EYE_SPACE_DEPTH 1 
    9  
    106 
    117struct fragment 
     
    8278                                                           ) 
    8379{ 
    84         const float2 mynoise = tex2D(noiseTex, texcoord0).xy; 
     80        const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy; 
    8581 
    8682        const float2 offsetTransformed = myreflect(offset, mynoise); 
     
    151147        //else trafo = inverseModelTrafo * oldModelViewProj; 
    152148 
    153         float3 dummyPt = worldPos.xyz - oldEyePos; 
     149        float3 translatedPt = worldPos.xyz - oldEyePos; 
    154150 
    155151        // reproject into old frame and calculate texture position of sample in old frame 
    156         float4 backProjPos = mul(oldModelViewProj, float4(dummyPt, 1.0f)); 
     152        float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 
    157153        backProjPos /= backProjPos.w; 
    158154        // fit from unit cube into 0 .. 1 
     
    169165         
    170166        const float invlen = 1.0f / length(viewVec); 
    171         const float projectedEyeSpaceDepth = length(dummyPt) * invlen; 
     167        const float projectedEyeSpaceDepth = length(translatedPt) * invlen; 
    172168         
    173169        const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
     170        //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 
    174171         
    175172        float notValid = 0.5f; 
    176173 
     174        /* 
    177175        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    178176        { 
     
    191189                if (sampleDif >= 5e-2f) ++ notValid; 
    192190        } 
     191        */ 
    193192 
    194193        // the number of valid samples in this frame 
     
    202201                && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
    203202                && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
    204                 && (abs(depthDif) <= MIN_DEPTH_DIFF)  
     203                && (depthDif <= MIN_DEPTH_DIFF)  
    205204                // if visibility changed in the surrounding area we have to recompute 
    206205                //&& (oldNumSamples > 0.8f * newNumSamples) 
     
    259258                //-- add random noise: reflect around random normal vector (rather slow!) 
    260259 
    261                 float2 mynoise = tex2D(noiseTex, IN.texCoord).xy; 
     260                float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    262261                const float2 offsetTransformed = myreflect(offset, mynoise); 
    263262#else 
     
    275274 
    276275                float3 dirSample = samplePos - centerPosition; 
    277                 const float lengthToSample = length(dirSample); 
     276                const float lengthToSample = max(length(dirSample), 1e-6f); 
    278277 
    279278                dirSample /= lengthToSample; // normalize 
    280279 
    281280                // angle between current normal and direction to sample controls AO intensity. 
    282                 const float cosAngle = max(dot(dirSample, normal), .0f); 
    283  
     281                float cosAngle = max(dot(dirSample, normal), .0f); 
     282         
    284283                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    285284                // the distance to a sample approaches zero 
     
    291290                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    292291 
    293                 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, normal); 
     292                const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 
    294293                total_ao += cosAngle * aoContrib * viewCorrection; 
    295294#else 
     
    352351                                                                          oldbl, oldbr, oldtl, oldtr); 
    353352 
     353        //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 
    354354        return OUT; 
    355355} 
    356  
    357  
    358 float Filter(float2 texCoord,  
    359                          uniform sampler2D ssaoTex, 
    360                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    361                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 
    362 { 
    363         float average = .0f; 
    364         float w = .0f; 
    365  
    366         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    367         { 
    368                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x; 
    369                 w += filterWeights[i]; 
    370         } 
    371  
    372         average *= 1.0f / (float)w; 
    373  
    374         return average; 
    375 } 
    376  
    377  
    378 pixel combine(fragment IN,  
    379                           uniform sampler2D colors, 
    380                           uniform sampler2D ssaoTex, 
    381                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    382                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    383                           ) 
    384 { 
    385         pixel OUT; 
    386  
    387         float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
    388         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    389  
    390         if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    391  
    392         OUT.illum_col = col * ao.x; 
    393         //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 
    394         //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    395         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    396         OUT.illum_col.w = col.w; 
    397  
    398         return OUT; 
    399 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3017 r3103  
    9191        { 
    9292                color = tex2D(colors, downSampleOffs[i]); 
    93  
    9493                const float intensity = dot(cols[i].rgb, w); 
    9594 
     
    146145         
    147146        // obtain new image key from highest mipmap level 
    148         float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w; 
     147        float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, MAX_LOD_LEVEL)).w; 
    149148        float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 
    150149 
     
    153152        // adjust to middle gray 
    154153        const float lum = middleGrey * pixLum / newImageKey; 
    155           
    156154        // map to range and calc burnout 
    157155        const float scaleLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 
     
    170168 
    171169        pixel OUT; 
    172          
     170 
    173171        const float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    174  
    175172        OUT.col = color; 
    176173 
     
    187184        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    188185 
    189         if (oldLogLum > 1e-5f) // too bright 
     186        // exponential smoothing of tone mapping over time 
     187        if (oldLogLum > 1e-5f) // loglum from last frame too bright 
    190188                OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    191189        else 
Note: See TracChangeset for help on using the changeset viewer.