Changeset 3094 for GTP


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

some error with reprojection when moving

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

Legend:

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

    r3093 r3094  
    257257        //-- the flip-flop fbos 
    258258 
    259 //      mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
    260         mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     259        mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
     260        //mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     261 
    261262        mFBOs.push_back(mIllumFbo); 
    262263 
     
    267268        } 
    268269 
    269         //mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
    270         mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     270        mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
     271        //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    271272        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    272273        // downsample buffer for the normal texture 
     
    328329        sCgSsaoProgram->AddParameter("oldTex", i ++); 
    329330        sCgSsaoProgram->AddParameter("noiseTex", i ++); 
    330         sCgSsaoProgram->AddParameter("eyePos", i ++); 
    331331        sCgSsaoProgram->AddParameter("temporalCoherence", i ++); 
    332332        sCgSsaoProgram->AddParameter("samples", i ++); 
     
    350350        sCgGiProgram->AddParameter("oldSsaoTex", i ++); 
    351351        sCgGiProgram->AddParameter("oldIllumTex", i ++); 
    352         sCgGiProgram->AddParameter("eyePos", i ++); 
    353352        sCgGiProgram->AddParameter("temporalCoherence", i ++); 
    354353        sCgGiProgram->AddParameter("samples", i ++); 
     
    540539        sCgSsaoProgram->SetTexture(3, noiseTex); 
    541540 
    542         //sCgSsaoProgram->SetValue3f(4, mEyePos.x, mEyePos.y, mEyePos.z); 
    543         sCgSsaoProgram->SetValue3f(4, 0, 0, 0); 
    544  
    545         sCgSsaoProgram->SetValue1f(5, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
     541        sCgSsaoProgram->SetValue1f(4, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    546542         
    547543        if (mUseTemporalCoherence || mRegenerateSamples) 
     
    553549                // needs longer to converge 
    554550                GenerateSamples(mSamplingMethod);  
    555                 sCgSsaoProgram->SetArray2f(6, (float *)samples2, NUM_SAMPLES); 
     551                sCgSsaoProgram->SetArray2f(5, (float *)samples2, NUM_SAMPLES); 
    556552        } 
    557553         
     
    561557        Vector3 tr = mCornersView[3]; 
    562558 
    563         sCgSsaoProgram->SetValue3f(7, bl.x, bl.y, bl.z); 
    564         sCgSsaoProgram->SetValue3f(8, br.x, br.y, br.z); 
    565         sCgSsaoProgram->SetValue3f(9, tl.x, tl.y, tl.z); 
    566         sCgSsaoProgram->SetValue3f(10, tr.x, tr.y, tr.z); 
    567  
    568         //cout << "new projview:\n" << projViewMatrix << endl; 
    569         //cout << "old projview:\n" << oldProjViewMatrix << endl; 
    570  
    571         sCgSsaoProgram->SetMatrix(11, mProjViewMatrix); 
    572         sCgSsaoProgram->SetMatrix(12, mOldProjViewMatrix); 
     559        sCgSsaoProgram->SetValue3f(6, bl.x, bl.y, bl.z); 
     560        sCgSsaoProgram->SetValue3f(7, br.x, br.y, br.z); 
     561        sCgSsaoProgram->SetValue3f(8, tl.x, tl.y, tl.z); 
     562        sCgSsaoProgram->SetValue3f(9, tr.x, tr.y, tr.z); 
     563 
     564        sCgSsaoProgram->SetMatrix(10, mProjViewMatrix); 
     565        sCgSsaoProgram->SetMatrix(11, mOldProjViewMatrix); 
    573566 
    574567        bl = mOldCornersView[0]; 
     
    578571 
    579572        Vector3 d = mOldEyePos - mEyePos; 
    580  
    581         //sCgSsaoProgram->SetValue3f(13, mOldEyePos.x, mOldEyePos.y, mOldEyePos.z); 
    582         sCgSsaoProgram->SetValue3f(13, d.x, d.y, d.z); 
    583         sCgSsaoProgram->SetValue3f(14, bl.x, bl.y, bl.z); 
    584         sCgSsaoProgram->SetValue3f(15, br.x, br.y, br.z); 
    585         sCgSsaoProgram->SetValue3f(16, tl.x, tl.y, tl.z); 
    586         sCgSsaoProgram->SetValue3f(17, tr.x, tr.y, tr.z); 
     573        //Vector3 d = mEyePos - mOldEyePos; 
     574 
     575        sCgSsaoProgram->SetValue3f(12, d.x, d.y, d.z); 
     576        sCgSsaoProgram->SetValue3f(13, bl.x, bl.y, bl.z); 
     577        sCgSsaoProgram->SetValue3f(14, br.x, br.y, br.z); 
     578        sCgSsaoProgram->SetValue3f(15, tl.x, tl.y, tl.z); 
     579        sCgSsaoProgram->SetValue3f(16, tr.x, tr.y, tr.z); 
    587580 
    588581        DrawQuad(sCgSsaoProgram); 
     
    692685        sCgGiProgram->SetTexture(4, oldIllumTex); 
    693686 
    694         sCgGiProgram->SetValue3f(5, mEyePos.x, mEyePos.y, mEyePos.z); 
    695  
    696  
    697         sCgGiProgram->SetValue1f(6,  
     687        sCgGiProgram->SetValue1f(5,  
    698688                (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    699689 
     
    707697                GenerateSamples(mSamplingMethod);  
    708698 
    709                 sCgGiProgram->SetArray2f(7, (float *)samples2, NUM_SAMPLES); 
     699                sCgGiProgram->SetArray2f(6, (float *)samples2, NUM_SAMPLES); 
    710700        } 
    711701 
     
    715705        Vector3 tr = mCornersView[3]; 
    716706 
    717         sCgGiProgram->SetValue3f(8, bl.x, bl.y, bl.z); 
    718         sCgGiProgram->SetValue3f(9, br.x, br.y, br.z); 
    719         sCgGiProgram->SetValue3f(10, tl.x, tl.y, tl.z); 
    720         sCgGiProgram->SetValue3f(11, tr.x, tr.y, tr.z); 
    721  
    722         sCgGiProgram->SetMatrix(12, mOldProjViewMatrix); 
    723         sCgGiProgram->SetMatrix(13, mProjViewMatrix); 
     707        sCgGiProgram->SetValue3f(7, bl.x, bl.y, bl.z); 
     708        sCgGiProgram->SetValue3f(8, br.x, br.y, br.z); 
     709        sCgGiProgram->SetValue3f(9, tl.x, tl.y, tl.z); 
     710        sCgGiProgram->SetValue3f(10, tr.x, tr.y, tr.z); 
     711 
     712        sCgGiProgram->SetMatrix(11, mOldProjViewMatrix); 
     713        sCgGiProgram->SetMatrix(12, mProjViewMatrix); 
    724714 
    725715 
     
    825815        sCgDeferredShadowProgram->SetTexture(2, shadowTex); 
    826816        sCgDeferredShadowProgram->SetTexture(3, noiseTex); 
    827  
    828817        sCgDeferredShadowProgram->SetMatrix(4, shadowMatrix); 
    829  
    830818        sCgDeferredShadowProgram->SetValue1f(5, 2.0f / shadowMap->GetSize()); 
    831819 
    832820        const Vector3 lightDir = -light->GetDirection(); 
    833821        sCgDeferredShadowProgram->SetValue3f(6, lightDir.x, lightDir.y, lightDir.z); 
    834  
    835822        sCgDeferredShadowProgram->SetValue3f(7, mEyePos.x, mEyePos.y, mEyePos.z); 
    836823 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r3084 r3094  
    158158                   const uniform float4x4 modelViewProj, 
    159159                   uniform float temporalCoherence, 
    160                    uniform float3 eyePos, 
    161160                   uniform float3 bl, 
    162161                   uniform float3 br, 
     
    177176        const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
    178177         
    179         const float3 eyeSpacePos = -viewDir * eyeDepth; 
    180  
    181         const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 
     178        const float4 eyeSpacePos = float4(-viewDir * eyeDepth, 1.0f); 
    182179 
    183180        // calculcate the current projected depth for next frame 
    184         float4 currentPos = mul(modelViewProj, worldPos); 
     181        float4 currentPos = mul(modelViewProj, eyeSpacePos); 
    185182 
    186183        const float w = SAMPLE_RADIUS / currentPos.w; 
     
    200197        // reprojection new frame into old one  
    201198        // calculate projected depth 
    202         float4 projPos = mul(oldModelViewProj, worldPos); 
     199        float4 projPos = mul(oldModelViewProj, eyeSpacePos); 
    203200        projPos /= projPos.w; 
    204201 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3093 r3094  
    7373                                                           uniform float3 tr,  
    7474                                                           float2 texcoord0, 
    75                                                            float3 eyePos, 
    7675                                                           float3 oldEyePos, 
    7776                                                           uniform float3 oldbl, 
     
    8786        float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 
    8887        //texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f; 
    89         const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 
     88        const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 
    9089 
    9190        // reproject into old frame and calculate projected depth 
     
    114113        as well as a boolean that  
    115114*/ 
    116 float4 temporalSmoothing(float4 currentProjPos, 
    117                                                  float4 worldPos, 
     115float4 temporalSmoothing(float4 eyeSpacePos, 
    118116                                                 uniform sampler2D oldTex, 
    119117                                                 const uniform float4x4 oldModelViewProj, 
     
    129127                                                 uniform float3 tr,  
    130128                                                 float2 texcoord0, 
    131                                                  float3 eyePos, 
    132129                                                 float eyeSpaceDepth, 
    133130                                                 float3 oldEyePos, 
     
    151148 
    152149        // reproject into old frame and calculate projected depth 
    153         float4 backProjPos = mul(oldModelViewProj, worldPos); 
     150        float4 backProjPos = mul(oldModelViewProj, eyeSpacePos); 
    154151        backProjPos /= backProjPos.w; 
    155152        // fit from unit cube into 0 .. 1 
     
    162159 
    163160        const float oldEyeSpaceDepth = oldCol.w; 
    164         //oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f; 
    165161 
    166162        float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
    167         //float3 oldSamplePos = -viewVec * eyeSpaceDepth + oldEyePos; 
    168         float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 
    169  
    170         const float depthDif = length(oldSamplePos - worldPos.xyz); 
    171         const float dummy5 = abs(oldEyeSpaceDepth - eyeSpaceDepth); 
    172         //const float dummy5 = length(oldTexCoords - texcoord0) * 1e5f; 
    173         //const float dummy5 = depthDif; 
     163        float3 oldEyeSpacePos = oldEyePos - viewVec * oldEyeSpaceDepth; 
     164 
     165        const float depthDif = length(oldEyeSpacePos - eyeSpacePos.xyz); 
    174166 
    175167        float notValid = 0.5f; 
    176168 
    177         for (int i = 0; i < NUM_SAMPLES; ++ i)  
     169        /*for (int i = 0; i < NUM_SAMPLES; ++ i)  
    178170        { 
    179171                float sampleDif = ComputeDifference(samples[i], 
     
    185177                                                          bl, br, tl, tr,  
    186178                                                          texcoord0, 
    187                                                           eyePos, 
    188179                                                          oldEyePos, 
    189180                                                          oldbl, oldbr, oldtl, oldtr, 
    190                                                           worldPos.xyz); 
     181                                                          eyePos.xyz); 
    191182 
    192183                if (sampleDif >= 1e-1f) ++ notValid; 
    193         } 
     184        }*/ 
    194185 
    195186        //if (notValid < 1.0f) temporalCoherence = 4.0f; 
     
    213204                newWeight = oldWeight + 1.0f; 
    214205                illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
    215                 if (notValid > 1.0f) newWeight = 2; 
     206                if (notValid > 1.0f) newWeight = 2.0f; 
    216207        } 
    217208        else 
     
    223214        illum_col.y = newWeight; 
    224215        illum_col.w = eyeSpaceDepth; 
    225         //illum_col.y = dummy5; 
     216         
    226217 
    227218        return illum_col; 
     
    270261 
    271262                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    272  
    273263                const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
    274264 
     
    316306                   uniform float4x4 oldModelViewProj, 
    317307                   uniform float temporalCoherence, 
    318                    uniform float3 eyePos, 
    319308                   uniform float3 bl, 
    320309                   uniform float3 br, 
     
    335324        const float3 viewDir = IN.view; 
    336325        const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
    337         const float3 eyeSpacePos = -viewDir * eyeSpaceDepth; 
    338         const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 
     326        const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1); 
    339327 
    340328 
     
    342330        //-- calculcate the current projected posiion (also used for next frame) 
    343331         
    344         float4 projPos = mul(modelViewProj, worldPos); 
     332        float4 projPos = mul(modelViewProj, eyeSpacePos); 
     333        float w = SAMPLE_RADIUS / projPos.w; 
    345334         
    346         float w = 1.0f / projPos.w; 
    347         projPos *= w; 
    348         w *= SAMPLE_RADIUS; 
    349          
    350         const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
     335        const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, w, bl, br, tl, tr, normalize(viewDir)); 
    351336 
    352337 
     
    354339        //-- compute temporally smoothing 
    355340         
    356         OUT.illum_col = temporalSmoothing(projPos, worldPos, oldTex, oldModelViewProj, temporalCoherence, ao, 
    357                                               samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos, eyeSpaceDepth, 
     341        OUT.illum_col = temporalSmoothing(eyeSpacePos, oldTex, oldModelViewProj, temporalCoherence, ao, 
     342                                              samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyeSpaceDepth, 
    358343                                                                          oldEyePos, oldbl, oldbr, oldtl, oldtr); 
    359344 
Note: See TracChangeset for help on using the changeset viewer.