Changeset 3083


Ignore:
Timestamp:
10/31/08 09:03:25 (16 years ago)
Author:
mattausch
Message:

debug version

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

Legend:

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

    r3081 r3083  
    1111// for quadratic falloff 
    1212//#define SAMPLE_INTENSITY 0.1f 
    13 //#define SAMPLE_INTENSITY 0.07f 
    14 #define SAMPLE_INTENSITY 0.03f 
     13#define SAMPLE_INTENSITY 0.07f 
     14//#define SAMPLE_INTENSITY 0.03f 
    1515 
    1616#define SAMPLE_RADIUS 8e-1f 
     
    5353#define NUM_SSAO_FILTERSAMPLES 100 
    5454 
     55#define PRECISION_SCALE 1e-3f 
     56 
     57 
    5558#endif // __SHADERENV_H 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3082 r3083  
    5454                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
    5555{ 
     56        texcoord.x += 1.0f / 1024.0f; texcoord.y += 1.0f / 768.0f; 
     57 
    5658        //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 
    5759        const float eyeSpaceDepth = tex2D(colors, texcoord).w; 
     
    6668        as well as a boolean that  
    6769*/ 
    68 pixel TemporalSmoothing(float currentPos, 
    69                                                 float currentDepth, 
    70                                                 uniform sampler2D oldTex) 
    71 { 
     70float4 temporalSmoothing(float4 currentProjPos, 
     71                                                 float4 worldPos, 
     72                                                 float currentDepth, 
     73                                                 uniform sampler2D oldTex, 
     74                                                 const uniform float4x4 oldModelViewProj, 
     75                                                 uniform float temporalCoherence, 
     76                                                 uniform float2 ao, 
     77                                                 uniform float2 samples[NUM_SAMPLES], 
     78                                                 uniform sampler2D colors, 
     79                                                 uniform sampler2D noiseTexture, 
     80                                                 uniform float scaleFactor, 
     81                                                 uniform float3 bl, 
     82                                                 uniform float3 br, 
     83                                                 uniform float3 tl, 
     84                                                 uniform float3 tr,  
     85                                                 float2 texcoord0 
     86                                                 ) 
     87{ 
     88        float4 illum_col; 
    7289 
    7390        ///////////////// 
    7491        //-- compute reprojection for temporal smoothing 
    7592 
    76  
    7793        // reproject into old frame and calculate projected depth 
    78         float4 projPos = mul(oldModelViewProj, worldPos); 
    79         projPos /= projPos.w; 
     94        float4 backProjPos = mul(oldModelViewProj, worldPos); 
     95        backProjPos /= backProjPos.w; 
    8096         
    8197        // the current depth projected into the old frame 
    82         const float projDepth = projPos.z * precisionScale; 
     98        const float backProjDepth = backProjPos.z * PRECISION_SCALE; 
    8399        // fit from unit cube into 0 .. 1 
    84         const float2 tex = projPos.xy * 0.5f + 0.5f; 
     100        const float2 tex = backProjPos.xy * 0.5f + 0.5f; 
    85101        // retrieve the sample from the last frame 
    86102        float4 oldCol = tex2D(oldTex, tex); 
    87103 
    88104        const float oldDepth = oldCol.z; 
    89         //const float depthDif = 1.0f - projDepth / oldDepth; 
    90         const float depthDif = projDepth - oldDepth; 
     105        const float depthDif = backProjDepth - oldDepth; 
    91106 
    92107        //const float oldNumSamples = oldCol.y; 
    93108        const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
    94  
    95109        float newWeight; 
     110 
     111        bool isValid = true; 
     112 
     113        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     114        { 
     115                const float2 offset = samples[i]; 
     116 
     117                //////////////////// 
     118                // add random noise: reflect around random normal vector (warning: slow!) 
     119 
     120                float2 mynoise = tex2D(noiseTexture, texcoord0).xy; 
     121                const float2 offsetTransformed = myreflect(offset, mynoise); 
     122 
     123                const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 
     124                const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 
     125 
     126                // reproject into old frame and calculate projected depth 
     127                float4 projPos = mul(oldModelViewProj, float4(samplePos, 1.0f)); 
     128                projPos /= projPos.w; 
     129 
     130                // the current depth projected into the old frame 
     131                const float projDepth = projPos.z * PRECISION_SCALE; 
     132                // fit from unit cube into 0 .. 1 
     133                // retrieve the sample from the last frame 
     134                const float4 oldSample = tex2D(oldTex, projPos.xy * 0.5f + 0.5f); 
     135                const float dDiff = projDepth - oldSample.z; 
     136 
     137                if (abs(dDiff) > 1e-5f) isValid = false; 
     138                //if (oldSample.y < oldWeight) isValid = false; 
     139        } 
    96140 
    97141        // the number of valid samples in this frame 
     
    101145                && (tex.x >= 0.0f) && (tex.x < 1.0f) 
    102146                && (tex.y >= 0.0f) && (tex.y < 1.0f) 
    103                 && (abs(depthDif) < MIN_DEPTH_DIFF)  
     147                //&& (abs(depthDif) < MIN_DEPTH_DIFF)  
    104148                // if visibility changed in the surrounding area we have to recompute 
    105149                //&& (oldNumSamples > 0.8f * newNumSamples) 
     150                && isValid 
    106151                ) 
    107152        { 
    108153                // increase the weight for convergence 
    109154                newWeight = oldWeight + 1.0f; 
    110                 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
     155                illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
    111156                //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
    112157        } 
    113158        else 
    114159        {        
    115                 OUT.illum_col.x = ao.x; 
     160                illum_col.x = ao.x; 
    116161                newWeight = .0f; 
    117162        } 
     
    122167        return illum_col; 
    123168} 
    124  
    125169 
    126170 
     
    128172*/ 
    129173float2 ssao(fragment IN, 
    130                    uniform sampler2D colors, 
    131                    uniform sampler2D noiseTexture, 
    132                    uniform float2 samples[NUM_SAMPLES], 
    133                    uniform float3 currentNormal, 
    134                    uniform float3 centerPosition, 
    135                    uniform float scaleFactor, 
    136                    uniform float3 bl, 
    137                    uniform float3 br, 
    138                    uniform float3 tl, 
    139                    uniform float3 tr,  
    140                    uniform float3 viewDir 
    141                    ) 
     174                        uniform sampler2D colors, 
     175                        uniform sampler2D noiseTexture, 
     176                        uniform float2 samples[NUM_SAMPLES], 
     177                        uniform float3 currentNormal, 
     178                        uniform float3 centerPosition, 
     179                        uniform float scaleFactor, 
     180                        uniform float3 bl, 
     181                        uniform float3 br, 
     182                        uniform float3 tl, 
     183                        uniform float3 tr,  
     184                        uniform float3 viewDir 
     185                        ) 
    142186{ 
    143187        // Check in a circular area around the current position. 
     
    209253                   uniform float2 samples[NUM_SAMPLES], 
    210254                   uniform sampler2D oldTex, 
     255                   const uniform float4x4 modelViewProj, 
    211256                   const uniform float4x4 oldModelViewProj, 
    212                    const uniform float4x4 modelViewProj, 
    213257                   uniform float temporalCoherence, 
    214258                   uniform float3 eyePos, 
     
    234278        //-- calculcate the current projected posiion (also used for next frame) 
    235279         
    236         float4 currentPos = mul(modelViewProj, worldPos); 
    237          
    238         const float w = SAMPLE_RADIUS / currentPos.w; 
    239         currentPos /= currentPos.w; 
    240          
    241         const float precisionScale = 1e-3f; 
    242         const float currentDepth = currentPos.z * precisionScale; 
     280        float4 projPos = mul(modelViewProj, worldPos); 
     281         
     282        const float w = SAMPLE_RADIUS / projPos.w; 
     283        projPos /= projPos.w; 
     284         
     285        const float currentDepth = projPos.z * PRECISION_SCALE; 
    243286 
    244287        const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
     
    248291        //-- compute temporally smoothing 
    249292         
    250         OUT.illum_col = TemporalSmoothing(currentPos, currentDepth, oldTex); 
     293        OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao, 
     294                                              samples, colors, noise, w, bl, br, tl, tr, IN.texCoord); 
    251295 
    252296        return OUT; 
     
    287331        float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    288332 
    289         if (ao.y < 10.0f)  
    290                 ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    291  
    292         OUT.illum_col = col * ao.x; 
    293         //OUT.illum_col.xyz = float3(ao.x,1-ao.y*1e-2f, 0); 
     333        //if (ao.y < 10.0f)  
     334        //      ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
     335 
     336        //OUT.illum_col = col * ao.x; 
     337        OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    294338        OUT.illum_col.w = col.w; 
    295339 
Note: See TracChangeset for help on using the changeset viewer.