Ignore:
Timestamp:
12/07/08 23:26:00 (16 years ago)
Author:
mattausch
Message:

made ssao parameters more flexible
started to implement lense flare

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
Files:
1 added
4 edited

Legend:

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

    r3209 r3212  
    125125 
    126126                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
    127                 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    128  
     127                 
    129128                // check spatial discontinuity 
    130129                // note: using the depth from the color texture is not 100% correct as depth was 
     
    136135                spatialFactor = 1.0f / max(len, 1e-3f); 
    137136 
     137                convergenceFactor = aoSample.y + 1.0f; 
     138 
     139                //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    138140                //normalFactor = max(step(.2f, dot(sampleNorm, centerNormal)), 1e-2f); 
    139                 convergenceFactor = aoSample.y + 1.0f; 
    140                  
     141 
    141142                // combine the weights 
    142143                w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor; 
     
    232233        return OUT; 
    233234} 
    234  
    235  
    236 /** Function combining image and indirect illumination buffer using a  
    237         depth and normal aware discontinuity filter. 
    238 */ 
    239 pixel SmoothSsao(fragment IN,  
    240                                  uniform sampler2D ssaoTex) 
    241 { 
    242         pixel OUT; 
    243  
    244         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    245  
    246         float4 dummy; 
    247         const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f; 
    248  
    249         // get positions exactly between old texel centers 
    250         dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y; 
    251         dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y; 
    252         dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y; 
    253         dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y; 
    254  
    255         const float m1 = min(dummy.x, dummy.y); 
    256         const float m2 = min(dummy.z, dummy.w); 
    257  
    258         ao.y = min(ao.y, min(m1, m2)); 
    259  
    260         return OUT; 
    261 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3210 r3212  
    261261        const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    262262        const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    263  
    264         //const float xOffs = 1.0f / 1024.0f;   const float yOffs = 1.0f / 768.0f; 
    265         //const float eps = 1e-6f; 
    266263 
    267264        // actually 0 means pixel is valid 
     
    334331        pix.color = color; 
    335332        pix.color.xy = pValid.xy; 
     333        pix.color.z = color.w; 
     334 
    336335        pix.normal = normal; 
    337336 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r3168 r3212  
    6565                                   uniform float3 br, 
    6666                                   uniform float3 tl, 
    67                                    uniform float3 tr 
    68                                    , uniform float3 viewDir 
     67                                   uniform float3 tr,  
     68                                   float3 viewDir, 
     69                                   float sampleIntensity 
    6970                                   ) 
    7071{ 
     
    125126                const float denom = (DISTANCE_SCALE + magSample * magSample); 
    126127 
    127                 float2 intensity = float2(SAMPLE_INTENSITY, ILLUM_INTENSITY); 
     128                float2 intensity = float2(sampleIntensity, ILLUM_INTENSITY); 
    128129                intensity /= denom; 
    129130 
     
    161162                   uniform float3 br, 
    162163                   uniform float3 tl, 
    163                    uniform float3 tr 
     164                   uniform float3 tr, 
     165                   uniform float kernelRadius, 
     166                   uniform float sampleIntensity 
    164167                   ) 
    165168{ 
    166169        pixel2 OUT; 
    167170 
    168         const float3 normal = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 
     171        const float3 normal = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz; 
    169172 
    170173         
     
    180183        float4 currentPos = mul(modelViewProj, eyeSpacePos); 
    181184 
    182         const float w = SAMPLE_RADIUS / currentPos.w; 
     185        const float w = kernelRadius / currentPos.w; 
    183186        currentPos /= currentPos.w; 
    184187         
     
    188191        //-- compute color bleeding + ao 
    189192 
    190         GiStruct gi = globIllum(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 
     193        GiStruct gi = globIllum(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view), sampleIntensity); 
    191194         
    192195 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3209 r3212  
    108108        const float ssao = oldPixel.x; 
    109109 
    110 #if USE_EYESPACE_DEPTH 
    111  
    112110        // calculate eye space position of sample in old frame 
    113111        const float oldEyeSpaceDepth = oldPixel.w; 
     
    120118         
    121119        const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
    122  
    123 #else 
    124  
    125         // calculate eye space position of sample in old frame 
    126         const float oldDepth = oldPixel.w; 
    127         // the depth projected into the old frame 
    128         const float projectedDepth = projPos.z; 
    129         // calculate depth difference  
    130         const float depthDif = abs(projectedDepth - oldDepth); 
    131  
    132 #endif 
    133120 
    134121        const float xOffs = 1.0f / 1024.0f; 
     
    176163                         float3 tr,  
    177164                         float3 viewDir, 
    178                          sampler2D normalTex 
     165                         sampler2D normalTex, 
     166                         float sampleIntensity 
    179167                         ) 
    180168{ 
     
    224212                cosAngle *= step(0.0f, dot(dirSample, normal)); 
    225213         
    226                 const float aoContrib = SAMPLE_INTENSITY / sqrLen; 
     214                const float aoContrib = sampleIntensity / sqrLen; 
    227215                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    228216 
     
    270258                        float3 viewDir, 
    271259                        float newWeight, 
    272                         bool isMovingObject 
     260                        float sampleIntensity 
    273261                        ) 
    274262{ 
     
    310298                // angle between current normal and direction to sample controls AO intensity. 
    311299                const float cosAngle = max(dot(dirSample, normal), .0f); 
    312                 const float aoContrib = SAMPLE_INTENSITY / sqrLen; 
     300                const float aoContrib = sampleIntensity / sqrLen; 
    313301                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    314302 
     
    338326 
    339327                //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 
    340                 if ((validSamples < 1.0f) && (numSamples >= 8) && !isMovingObject  
    341                         || (newWeight > NUM_SAMPLES * 5) && (numSamples >= 8) && isMovingObject 
    342                         ) 
    343                 { 
    344                         break; 
    345                 } 
     328                //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 
    346329        } 
    347330 
    348331        total_ao /= numSamples; 
    349332 
    350         //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    351         return float3(total_ao, validSamples, numSamples); 
     333        return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 
    352334} 
    353335 
     
    374356                   uniform float3 oldtl, 
    375357                   uniform float3 oldtr, 
    376                    uniform sampler2D attribsTex 
     358                   uniform sampler2D attribsTex, 
     359                   uniform float kernelRadius, 
     360                   uniform float sampleIntensity 
    377361                   ) 
    378362{ 
     
    396380        const float invw = 1.0f / projPos.w; 
    397381        projPos *= invw; 
    398         float scaleFactor = SAMPLE_RADIUS * invw; 
    399  
    400         const float sqrMoveSpeed = SqrLen(diffVec); 
    401         const bool isMovingObject = (sqrMoveSpeed > DYNAMIC_OBJECTS_THRESHOLD); 
     382        float scaleFactor = kernelRadius * invw; 
    402383 
    403384         
     
    422403        if (eyeSpaceDepth < 1e10f) 
    423404        { 
    424                 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, isMovingObject); 
    425                 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals); 
     405                ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity); 
     406                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    426407        } 
    427408        else 
     
    430411        } 
    431412 
    432         // equals the number of sampled shot in this pass 
    433         const float newWeight = ao.z; 
     413        const float squaredLen = SqrLen(diffVec); 
    434414 
    435415        // check if we have to reset pixel because one of the sample points was invalid 
    436         if (!isMovingObject) 
    437     //if (sqrMoveSpeed <= DYNAMIC_OBJECTS_THRESHOLD) 
     416        if (squaredLen < DYNAMIC_OBJECTS_THRESHOLD) 
    438417        { 
    439418                if (ao.y > 4.0f)  
    440419                        oldWeight = 0;  
    441420                else if (ao.y > 1.0f) 
    442                         oldWeight = min(oldWeight, 4.0f * newWeight); 
    443         } 
    444  
     421                        oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 
     422        } 
     423 
     424        const float newWeight = ao.z; 
    445425        const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 
    446426 
Note: See TracChangeset for help on using the changeset viewer.