Changeset 3081


Ignore:
Timestamp:
10/30/08 18:32:56 (16 years ago)
Author:
mattausch
Message:

trying to get ssao to work with dynamic objects

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3079 r3081  
    604604        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    605605        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    606         GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    607606 
    608607        fbo->Bind(); 
     
    724723 
    725724        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    726         GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    727725         
    728726        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     
    774772        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    775773        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    776         GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    777774 
    778775        GLuint shadowTex = shadowMap->GetDepthTexture(); 
     
    948945 
    949946 
     947/* 
     948void DeferredRenderer::BackProject(FrameBufferObject *fbo) 
     949{ 
     950        // back project new frame into old one and check 
     951        // if pixel still valid. store this property with ssao texture or even  
     952        // betteer with color / depth texture. This way 
     953        // we can sample this property together with the color / depth 
     954        // values and we do not require additional texture lookups 
     955        fbo->Bind(); 
     956 
     957        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
     958        //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     959 
     960        // overwrite old color texture 
     961        //colorBufferIdx = 3 - colorBufferIdx; 
     962        //glDrawBuffers(1, mrt + colorBufferIdx); 
     963        //glDrawBuffers(1, mrt + colorBufferIdx); 
     964 
     965        sCgCombineSsaoProgram->SetTexture(0, colorsTex); 
     966        //sCgCombineSsaoProgram->SetTexture(1, ssaoTex); 
     967 
     968        DrawQuad(sCgBackProjectProgram); 
     969         
     970        PrintGLerror("combine ssao"); 
     971} 
     972*/ 
     973 
     974 
     975 
    950976} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3080 r3081  
    66//-- ssao + gi parameters 
    77 
    8 #define NUM_SAMPLES 8 
    9 //#define NUM_SAMPLES 16 
     8//#define NUM_SAMPLES 8 
     9#define NUM_SAMPLES 16 
    1010 
    1111// for quadratic falloff 
    1212//#define SAMPLE_INTENSITY 0.1f 
    13 #define SAMPLE_INTENSITY 0.07f 
     13//#define SAMPLE_INTENSITY 0.07f 
     14#define SAMPLE_INTENSITY 0.03f 
    1415 
    1516#define SAMPLE_RADIUS 8e-1f 
     
    1819#define DISTANCE_SCALE 5e-2f 
    1920 
    20 #define ILLUM_INTENSITY 8e-2f 
     21//#define ILLUM_INTENSITY 8e-2f 
     22#define ILLUM_INTENSITY 2e-2f 
    2123 
    2224#define VIEW_CORRECTION_SCALE 1.0f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3034 r3081  
    211211} 
    212212 
     213#if 0 
     214/** This shader computes the reprojection and stores reprojected color / depth values 
     215        as well as a boolean that  
     216*/ 
     217pixel (fragment IN,  
     218                   uniform sampler2D colors, 
     219                   uniform sampler2D normals, 
     220{ 
     221        float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)); 
     222        const float3 normal = normalize(norm.xyz); 
     223 
     224        /// reconstruct position from the eye space depth 
     225        float3 viewDir = IN.view; 
     226        const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
     227        const float3 eyeSpacePos = -viewDir * eyeDepth; 
     228        const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 
     229 
     230 
     231        //////////////// 
     232        //-- calculcate the current projected posiion (also used for next frame) 
     233         
     234        float4 currentPos = mul(modelViewProj, worldPos); 
     235         
     236        const float w = SAMPLE_RADIUS / currentPos.w; 
     237        currentPos /= currentPos.w; 
     238         
     239        const float precisionScale = 1e-3f; 
     240        const float currentDepth = currentPos.z * precisionScale; 
     241 
     242        const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
     243 
     244 
     245        ///////////////// 
     246        //-- compute temporally smoothing 
     247 
     248 
     249        // reproject new frame into old one  
     250         
     251        // calculate projected depth 
     252        float4 projPos = mul(oldModelViewProj, worldPos); 
     253        projPos /= projPos.w; 
     254         
     255        // the current depth projected into the old frame 
     256        const float projDepth = projPos.z * precisionScale; 
     257        // fit from unit cube into 0 .. 1 
     258        const float2 tex = projPos.xy * 0.5f + 0.5f; 
     259        // retrieve the sample from the last frame 
     260        float4 oldCol = tex2D(oldTex, tex); 
     261 
     262        const float oldDepth = oldCol.z; 
     263        //const float depthDif = 1.0f - projDepth / oldDepth; 
     264        const float depthDif = projDepth - oldDepth; 
     265 
     266        //const float oldNumSamples = oldCol.y; 
     267        const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
     268 
     269        float newWeight; 
     270 
     271        // the number of valid samples in this frame 
     272        //const float newNumSamples = ao.y; 
     273 
     274        if ((temporalCoherence > 0) 
     275                && (tex.x >= 0.0f) && (tex.x < 1.0f) 
     276                && (tex.y >= 0.0f) && (tex.y < 1.0f) 
     277                && (abs(depthDif) < MIN_DEPTH_DIFF)  
     278                && (abs(oldCol.x - ao.x) < 0.1f) 
     279                // if visibility changed in the surrounding area we have to recompute 
     280                //&& (oldNumSamples > 0.8f * newNumSamples) 
     281                ) 
     282        { 
     283                // increase the weight for convergence 
     284                newWeight = oldWeight + 1.0f; 
     285                OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
     286                //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
     287        } 
     288        else 
     289        {        
     290                OUT.illum_col.x = ao.x; 
     291                newWeight = .0f; 
     292        } 
     293 
     294        OUT.illum_col.y = newWeight; 
     295        OUT.illum_col.z = currentDepth; 
     296 
     297        return OUT; 
     298} 
     299 
     300#endif 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3080 r3081  
    2020        float4 illum_col: COLOR0; 
    2121}; 
     22 
     23 
     24inline float occlusionPower(float radius, float dist) 
     25{ 
     26        return 6.283185307179586476925286766559f * (1.0f - cos(asin(radius / dist))); 
     27} 
    2228 
    2329 
     
    106112 
    107113                float3 dirSample = samplePos - centerPosition; 
    108                 const float magSample = length(dirSample); 
     114                const float lengthToSample = length(dirSample); 
    109115                // normalize 
    110                 dirSample /= magSample; 
     116                dirSample /= lengthToSample; 
    111117 
    112118                // angle between current normal and direction to sample controls AO intensity. 
     
    115121                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    116122                // the distance to a sample approaches zero 
    117                 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample); 
     123                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
     124                const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 
    118125 
    119126#if 1 
     
    121128                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    122129                const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 
    123                 total_ao += cosAngle * intensity * viewCorrection; 
     130                total_ao += cosAngle * aoContrib * viewCorrection; 
    124131#else 
    125132                total_ao += cosAngle * intensity; 
     
    130137} 
    131138 
    132 #pragma position_invariant main 
     139//#pragma position_invariant main 
    133140 
    134141/** The mrt shader for screen space ambient occlusion 
     
    188195        // the current depth projected into the old frame 
    189196        const float projDepth = projPos.z * precisionScale; 
    190  
    191197        // fit from unit cube into 0 .. 1 
    192198        const float2 tex = projPos.xy * 0.5f + 0.5f; 
    193  
    194199        // retrieve the sample from the last frame 
    195200        float4 oldCol = tex2D(oldTex, tex); 
     
    199204        const float depthDif = projDepth - oldDepth; 
    200205 
    201  
    202206        //const float oldNumSamples = oldCol.y; 
    203207        const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
     
    208212        //const float newNumSamples = ao.y; 
    209213 
    210         if ((temporalCoherence > 0) && 
    211                 (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    212                 (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    213                 (abs(depthDif) < MIN_DEPTH_DIFF)  
     214        if ((temporalCoherence > 0) 
     215                && (tex.x >= 0.0f) && (tex.x < 1.0f) 
     216                && (tex.y >= 0.0f) && (tex.y < 1.0f) 
     217                && (abs(depthDif) < MIN_DEPTH_DIFF)  
     218                && (abs(oldCol.x - ao.x) < 0.1f) 
    214219                // if visibility changed in the surrounding area we have to recompute 
    215220                //&& (oldNumSamples > 0.8f * newNumSamples) 
     
    224229        {        
    225230                OUT.illum_col.x = ao.x; 
    226                 newWeight = 0; 
     231                newWeight = .0f; 
    227232        } 
    228233 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt

    r3013 r3081  
    3232 
    3333 
     34 
     35ssao: 
     36 
     371) implement bilateral filtering 
     382) check physical properties  
     39 
     40paper of 2007 arikan formula: 
     41 
     42SW(P, C, r) = 2 * pi * (1 - cos(asin (r / |PC|))) 
     43 
     44but not working properly! 
     45 
     463) normal mapping 
     47 
     48 
     49problems: 
     50 
     514) update of converged regions 
     52 
     53something could become visible  
     54 
     55a) from outside 
     56b) from previously occluded regions 
     57 
     58a) could use ratio of samples outside current frame / last frame 
     59   but slows donw code 
     60 
     615) dynamic objects: 
     62 
     63a) make ao stick on object: this should 
     64   be possible somehow, as the information is still available!! 
     65  
     66   tried to use difference of ao intensity between previous and 
     67   current frame to find out if pixel ao is not valid anymore. 
     68   but problems as some flickering was introduced while update of  
     69   dynamic objects was not fast enough (annoying grey fade effect) 
     70 
     71b) fix the contact shadow on the floor: 
     72 
     73check when pixel not valid anymore: do that by checking for each 
     74sample if they were invalidated recently. if so, then invalidate 
     75current pixel ao. for each point, theoretically you don't have 
     76to compare the depth of the current pixel, but the depth of the 
     77samples taken for ao 
Note: See TracChangeset for help on using the changeset viewer.