Changeset 2897


Ignore:
Timestamp:
09/03/08 01:57:45 (16 years ago)
Author:
mattausch
Message:

improved shadow mapping

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r2892 r2897  
    1010winHeight=768 
    1111camPosition=483.398f 242.364f 186.078f 
    12 camDirection=1 0 0 
     12camDirection=0 1 0 
    1313useFullScreen=0 
    1414useLODs=1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2895 r2897  
    7777mAxis(-1),  
    7878mDepth(0),  
    79 mLastRenderedFrame(-999), 
    8079mFirst(-1),  
    8180mLast(-1), 
     
    9190                mPlaneMask[i] = 0; 
    9291                mPreferredPlane[i]= 0; 
     92                mLastRenderedFrame[i] = -1; 
    9393        } 
    9494} 
     
    105105        { 
    106106                mVisibility[i].Reset(); 
    107         } 
    108  
    109         mLastRenderedFrame = -999; 
     107                mLastRenderedFrame[i] = -1; 
     108                mPlaneMask[i] = 0; 
     109                mPreferredPlane[i]= 0; 
     110        } 
    110111} 
    111112 
     
    179180void Bvh::Init() 
    180181{ 
    181         mCamera = NULL; 
    182182        mRoot = NULL; 
    183183        mVertices = NULL; 
     
    364364 
    365365 
    366 void Bvh::InitFrame() 
     366void Bvh::InitFrame(Camera *cam) 
    367367{ 
    368368        // = 0011 1111 which means that at the beginning, all six planes have to frustum culled 
    369369        mRoot->mPlaneMask[BvhNode::sCurrentState] = 0x3f; 
    370370 
    371         mCamera->CalcFrustum(sFrustum); 
     371        cam->CalcFrustum(sFrustum); 
    372372        sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices); 
    373373 
    374374        // store near plane 
    375         sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 
     375        sNearPlane = Plane3(cam->GetDirection(), cam->GetPosition()); 
    376376} 
    377377 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2895 r2897  
    166166 
    167167        ////////////// 
    168         //-- these members define the current state 
     168        //-- members that define the current state 
    169169 
    170170        /// stores the visibility related info  
    171171        VisibilityInfo mVisibility[NUM_STATES]; 
    172  
    173         ///////// 
    174         //-- used for view frustum culling 
    175  
     172         
     173        /// used for view frustum culling 
    176174        int mPlaneMask[NUM_STATES]; 
    177175        int mPreferredPlane[NUM_STATES]; 
    178176 
     177        /// when the node was last rendered 
     178        int mLastRenderedFrame[NUM_STATES]; 
     179 
     180 
    179181        // the current state 
    180182        static int sCurrentState; 
     
    184186 
    185187 
     188        /// #leaves under this node 
     189        int mNumLeaves; 
     190 
     191 
    186192        //////////// 
    187193        //-- rendering related options 
    188194         
    189         /// when the node was last rendered 
    190         int mLastRenderedFrame; 
    191         /// #leaves under this node 
    192         int mNumLeaves; 
    193195         
    194196        // Indices to first and last triangle in the triangle array 
     
    322324} 
    323325 
     326 
    324327int BvhNode::GetLastRenderedFrame() const  
    325328{  
    326         return mLastRenderedFrame;  
     329        return mLastRenderedFrame[sCurrentState];  
    327330} 
    328331         
     
    330333void BvhNode::SetLastRenderedFrame(int lastRenderedFrame) 
    331334{ 
    332         mLastRenderedFrame = lastRenderedFrame; 
     335        mLastRenderedFrame[sCurrentState] = lastRenderedFrame; 
    333336} 
    334337         
     
    468471        /** Sets the scene camera 
    469472        */ 
    470         void SetCamera(Camera * camera) { mCamera = camera; } 
     473        //void SetCamera(Camera * camera) { mCamera = camera; } 
    471474 
    472475        /////////////// 
     
    516519        /** Sets frame dependent values 
    517520        */ 
    518         void InitFrame(); 
     521        void InitFrame(Camera *camera); 
    519522        /** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 
    520523                note that negative values can appear because culling is done only afterwards 
     
    640643        /// #of entities 
    641644        size_t mGeometrySize; 
    642  
    643         /// the current camera 
    644         Camera *mCamera; 
    645645 
    646646 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2896 r2897  
    5050static CGparameter sNoiseTexParam; 
    5151static CGparameter sNoiseMultiplierParam; 
    52 static CGparameter sExpFactorParam; 
    53  
     52static CGparameter sTemporalCoherenceParam; 
    5453 
    5554 
     
    6968static CGparameter sNoiseTexGiParam; 
    7069static CGparameter sNoiseMultiplierGiParam; 
    71 static CGparameter sExpFactorGiParam; 
     70static CGparameter sTemporalCoherenceGiParam; 
    7271 
    7372 
     
    299298                cgGLLoadProgram(sCgSsaoProgram); 
    300299 
    301                 // we need size of texture for scaling 
    302300                sPositionsTexParam = cgGetNamedParameter(sCgSsaoProgram, "positions");   
    303301                sColorsTexParam = cgGetNamedParameter(sCgSsaoProgram, "colors");   
     
    308306                sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 
    309307                sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 
    310                 sExpFactorParam = cgGetNamedParameter(sCgSsaoProgram, "expFactor"); 
     308                sTemporalCoherenceParam = cgGetNamedParameter(sCgSsaoProgram, "temporalCoherence"); 
    311309 
    312310                sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex");   
     
    339337                sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj"); 
    340338                sMaxDepthGiParam = cgGetNamedParameter(sCgGiProgram, "maxDepth"); 
    341                 sExpFactorGiParam = cgGetNamedParameter(sCgGiProgram, "expFactor"); 
     339                sTemporalCoherenceGiParam = cgGetNamedParameter(sCgGiProgram, "temporalCoherence"); 
    342340 
    343341                sSamplesGiParam = cgGetNamedParameter(sCgGiProgram, "samples"); 
     
    437435 
    438436void DeferredRenderer::Render(FrameBufferObject *fbo,  
    439                                                 const Matrix4x4 &oldProjViewMatrix, 
    440                                                 float expFactor, 
    441                                                 ShadowMap *shadowMap) 
    442 { 
    443          
     437                                                          const Matrix4x4 &oldProjViewMatrix, 
     438                                                          float expFactor, 
     439                                                          ShadowMap *shadowMap) 
     440{ 
    444441        // switch roles of old and new fbo 
    445442        // the algorihm uses two input fbos, where the one 
    446443        // contais the color buffer from the last frame,  
    447444        // the other one will be written 
     445 
     446        mFboIndex = 2 - mFboIndex; 
    448447        //swap(mNewFbo, mOldFbo);        
    449         mFboIndex = 2 - mFboIndex; 
     448 
    450449        FrameBufferObject::Release(); 
    451450 
     
    463462        glLoadIdentity(); 
    464463 
     464        const float offs = 0.5f; 
     465        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     466 
    465467        glMatrixMode(GL_MODELVIEW); 
    466468        glPushMatrix(); 
    467469        glLoadIdentity(); 
    468  
    469         const float offs = 0.5f; 
    470         glOrtho(-offs, offs, -offs, offs, 0, 1); 
    471470 
    472471        if (shadowMap) 
     
    557556        cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 
    558557         
     558        cgGLSetParameter1f(sTemporalCoherenceParam, (mUseTemporalCoherence && !mRegenerateSamples) ? 255 : 0); 
    559559 
    560560        if (mUseTemporalCoherence || mRegenerateSamples) 
     
    570570        } 
    571571 
    572         cgGLSetParameter1f(sExpFactorParam, mUseTemporalCoherence ? expFactor : 1.0f); 
    573  
    574572        Vector3 tl, tr, bl, br; 
    575573        ComputeViewVectors(tl, tr, bl, br); 
     
    782780        cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor); 
    783781 
     782        cgGLSetParameter1f(sTemporalCoherenceGiParam, (mUseTemporalCoherence && !mRegenerateSamples) ? 255 : 0); 
     783 
    784784 
    785785        if (mUseTemporalCoherence || mRegenerateSamples) 
     
    787787                mRegenerateSamples = false; 
    788788                cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f)); 
    789                 cgGLSetParameter1f(sExpFactorGiParam, expFactor); 
    790789 
    791790                // q: should we generate new samples or only rotate the old ones? 
     
    796795        } 
    797796 
    798         cgGLSetParameter1f(sExpFactorParam, mUseTemporalCoherence ? expFactor : 1.0f); 
    799797 
    800798        Vector3 tl, tr, bl, br; 
     
    10041002} 
    10051003 
     1004 
     1005void DeferredRenderer::SetShadingMethod(SHADING_METHOD s) 
     1006{ 
     1007        if (s != mShadingMethod) 
     1008        { 
     1009                mShadingMethod = s;  
     1010                mRegenerateSamples = true; 
     1011        } 
     1012} 
     1013 
    10061014} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2896 r2897  
    5454        void SetSamplingMethod(SAMPLING_METHOD s); 
    5555 
    56         void SetShadingMethod(SHADING_METHOD s) { mShadingMethod = s; } 
     56        void SetShadingMethod(SHADING_METHOD s); 
    5757 
    5858protected: 
     
    8686        Camera *mCamera; 
    8787 
    88         //FrameBufferObject *mOldFbo; 
    89         //FrameBufferObject *mNewFbo; 
    9088        FrameBufferObject *mFbo; 
    9189 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2848 r2897  
    148148        ++ mFrameId; 
    149149 
    150         mBvh->InitFrame(); 
     150        mBvh->InitFrame(mCamera); 
    151151 
    152152        mStats.Reset(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2802 r2897  
    7676        /** Sets the camera. 
    7777        */ 
    78         void SetCamera(Camera *cam)  {mCamera = cam;} 
     78        void SetCamera(Camera *cam) { mCamera = cam;} 
    7979        /** Sets the render queue. 
    8080        */ 
    8181        void SetRenderQueue(RenderQueue *rq) {mRenderQueue =rq;} 
    82         /** Renders a visualization of the hierarchy 
    83         */ 
    84         void RenderVisualization(); 
    8582        /** Sets the current render state 
    8683        */ 
     
    133130        */ 
    134131        const SceneEntityContainer &GetVisibleObjects() const { return mVisibleObjects; } 
     132        /** Returns the current camera. 
     133        */ 
     134        Camera *GetCamera() const { return mCamera; } 
     135 
    135136 
    136137protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2892 r2897  
    137137 
    138138        orthoCam->SetNear(0.0f); 
     139        orthoCam->Yaw(.5 * M_PI); 
    139140        orthoCam->SetDirection(Vector3(0, 0, -1)); 
    140141 
     
    155156        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    156157 
    157         glFrontFace(GL_CCW); 
    158         glCullFace(GL_BACK); 
    159          
    160         glEnable(GL_CULL_FACE); 
     158        glDisable(GL_CULL_FACE); 
    161159 
    162160        glShadeModel(GL_FLAT); 
    163161        glEnable(GL_DEPTH_TEST); 
    164162 
     163        glMatrixMode(GL_MODELVIEW); 
     164        glPushMatrix(); 
     165        glLoadIdentity(); 
     166 
    165167        glMatrixMode(GL_PROJECTION); 
    166168        glPushMatrix(); 
     169        glLoadIdentity(); 
    167170 
    168171        glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);  
    169172 
    170173        glMatrixMode(GL_MODELVIEW); 
    171         glPushMatrix(); 
    172174 
    173175        orthoCam->SetupCameraView(); 
     
    175177        mDepth = new float[texHeight * texWidth]; 
    176178 
     179        Camera *oldCam = renderer->GetCamera(); 
     180        renderer->SetCamera(orthoCam); 
     181 
    177182        renderer->RenderScene(); 
    178          
     183 
     184        renderer->SetCamera(oldCam); 
     185         
     186 
     187        glEnable(GL_CULL_FACE); 
     188 
     189        glMatrixMode(GL_MODELVIEW); 
    179190        glPopMatrix(); 
     191         
    180192        glMatrixMode(GL_PROJECTION); 
    181          
    182193        glPopMatrix(); 
    183194 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2894 r2897  
    7979 
    8080 
    81 ShadowMap::ShadowMap(int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
    82 mSceneBox(sceneBox), mSize(size), mCamera(cam) 
     81ShadowMap::ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
     82mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 
    8383{ 
    8484        mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true); 
     
    9494{ 
    9595        DEL_PTR(mFbo); 
    96 } 
    97  
    98  
    99  
    100 void ShadowMap::ComputeShadowMap(Light *light, RenderTraverser *traverser) 
    101 { 
    102         mLight = light; 
    103  
     96        DEL_PTR(mShadowCam); 
     97} 
     98 
     99 
     100void ShadowMap::ComputeShadowMap(RenderTraverser *renderer) 
     101{ 
    104102        const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    105103        const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    106104         
    107         mShadowCam->SetDirection(light->GetDirection()); 
     105        mShadowCam->SetDirection(mLight->GetDirection()); 
    108106         
    109107        // set position so that we can see the whole scene 
    110108        Vector3 pos = mSceneBox.Center(); 
    111109 
    112         pos -= light->GetDirection() * Magnitude(mSceneBox.Diagonal() * 0.5f); 
     110        pos -= mLight->GetDirection() * Magnitude(mSceneBox.Diagonal() * 0.5f); 
    113111        mShadowCam->SetPosition(pos); 
    114112 
     
    142140        glMatrixMode(GL_MODELVIEW); 
    143141        glPushMatrix(); 
    144  
    145142        glLoadIdentity(); 
    146143 
    147144        // setup shadow camera 
    148145        mShadowCam->SetupCameraView(); 
     146 
    149147 
    150148        ////////////// 
     
    168166        //-- render scene into shadow map 
    169167 
    170         traverser->RenderScene(); 
     168        renderer->RenderScene(); 
     169 
    171170         
    172171        glDisable(GL_POLYGON_OFFSET_FILL); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2895 r2897  
    2929                The shadow map has resolution size * size. 
    3030        */ 
    31         ShadowMap(int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
     31        ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
    3232 
    3333        ~ShadowMap(); 
    3434        /** Computes the shadow map 
    3535        */ 
    36         void ComputeShadowMap(Light *light, RenderTraverser *traverser); 
     36        void ComputeShadowMap(RenderTraverser *traverser); 
    3737        /** Returns computed shadow texture. 
    3838        */ 
     
    4949        */ 
    5050        int GetSize() const { return mSize; } 
     51 
     52        Camera *GetShadowCamera() const { return mShadowCam; } 
     53 
    5154 
    5255protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2896 r2897  
    8383RenderQueue *renderQueue = NULL; 
    8484 
     85// traverses and renders the hierarchy 
     86RenderTraverser *shadowTraverser = NULL; 
     87 
     88 
    8589/// these values get scaled with the frame rate 
    8690static float keyForwardMotion = 30.0f; 
     
    211215void MiddleMotion(int x, int y); 
    212216void CalcDecimalPoint(string &str, int d); 
    213 void ResetTraverser(); 
     217 
     218RenderTraverser *CreateTraverser(Camera *cam); 
    214219 
    215220void KeyHorizontalMotion(float shift); 
     
    427432        bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 
    428433 
    429         bvh->SetCamera(camera); 
     434        //bvh->SetCamera(camera); 
    430435         
    431436        InitCg(); 
     
    435440 
    436441        // initialize the render traverser 
    437         ResetTraverser(); 
     442        traverser = CreateTraverser(camera); 
    438443 
    439444        visualization = new Visualization(bvh, camera, NULL, &state); 
    440  
     445         
     446        state.SetRenderType(RenderState::FIXED); 
    441447        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
    442448 
     
    691697 
    692698 
    693 void ResetTraverser() 
    694 { 
    695         DEL_PTR(traverser); 
    696  
     699RenderTraverser *CreateTraverser(Camera *cam) 
     700{ 
     701        RenderTraverser *tr; 
     702         
    697703        bvh->ResetNodeClassifications(); 
    698704 
     
    700706        { 
    701707        case RenderTraverser::CULL_FRUSTUM: 
    702                 traverser = new FrustumCullingTraverser(); 
     708                tr = new FrustumCullingTraverser(); 
    703709                break; 
    704710        case RenderTraverser::STOP_AND_WAIT: 
    705                 traverser = new StopAndWaitTraverser(); 
     711                tr = new StopAndWaitTraverser(); 
    706712                break; 
    707713        case RenderTraverser::CHC: 
    708                 traverser = new CHCTraverser(); 
     714                tr = new CHCTraverser(); 
    709715                break; 
    710716        case RenderTraverser::CHCPLUSPLUS: 
    711                 traverser = new CHCPlusPlusTraverser(); 
     717                tr = new CHCPlusPlusTraverser(); 
    712718                break; 
    713719         
    714720        default: 
    715                 traverser = new FrustumCullingTraverser(); 
    716         } 
    717  
    718         traverser->SetCamera(camera); 
    719         traverser->SetHierarchy(bvh); 
    720         traverser->SetRenderQueue(renderQueue); 
    721         traverser->SetRenderState(&state); 
    722         traverser->SetUseOptimization(useOptimization); 
    723         traverser->SetUseRenderQueue(useRenderQueue); 
    724         traverser->SetVisibilityThreshold(threshold); 
    725         traverser->SetAssumedVisibleFrames(assumedVisibleFrames); 
    726         traverser->SetMaxBatchSize(maxBatchSize); 
    727         traverser->SetUseMultiQueries(useMultiQueries); 
    728         traverser->SetUseTightBounds(useTightBounds); 
    729         traverser->SetUseDepthPass(renderType == RenderState::DEPTH_PASS); 
    730         traverser->SetRenderQueue(renderQueue); 
     721                tr = new FrustumCullingTraverser(); 
     722        } 
     723 
     724        tr->SetCamera(cam); 
     725        tr->SetHierarchy(bvh); 
     726        tr->SetRenderQueue(renderQueue); 
     727        tr->SetRenderState(&state); 
     728        tr->SetUseOptimization(useOptimization); 
     729        tr->SetUseRenderQueue(useRenderQueue); 
     730        tr->SetVisibilityThreshold(threshold); 
     731        tr->SetAssumedVisibleFrames(assumedVisibleFrames); 
     732        tr->SetMaxBatchSize(maxBatchSize); 
     733        tr->SetUseMultiQueries(useMultiQueries); 
     734        tr->SetUseTightBounds(useTightBounds); 
     735        tr->SetUseDepthPass(renderType == RenderState::DEPTH_PASS); 
     736        tr->SetRenderQueue(renderQueue); 
     737 
     738        return tr; 
    731739} 
    732740 
     
    866874        } 
    867875         
    868         if (showShadowMap && !shadowMap) 
    869         { 
    870                 const float shadowSize = 4096; 
    871                 shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 
    872         } 
    873876 
    874877        // render without shading 
     
    908911        case RenderState::DEFERRED: 
    909912 
    910                 // change CHC state (must be done for each change of camera) 
    911                 BvhNode::SetCurrentState(1); 
    912  
    913                 if (showShadowMap && shadowChanged) 
     913                if (showShadowMap)// && shadowChanged) 
    914914                { 
     915                        if (!shadowMap) 
     916                        { 
     917                                const float shadowSize = 4096; 
     918                                shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 
     919                        } 
     920 
     921                        // change CHC state (must be done for each change of camera) 
     922                        BvhNode::SetCurrentState(1); 
     923 
     924                        if (!shadowTraverser) 
     925                                shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 
     926 
    915927                        shadowChanged = false; 
    916928 
     
    921933 
    922934                        // the scene is rendered withouth any shading    
    923                         shadowMap->ComputeShadowMap(light, traverser); 
     935                        shadowMap->ComputeShadowMap(shadowTraverser); 
    924936 
    925937                        // change back state 
     
    10731085        case 32: //space 
    10741086                renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES; 
    1075                 ResetTraverser(); 
     1087 
     1088                DEL_PTR(traverser); 
     1089                traverser = CreateTraverser(camera); 
     1090 
     1091                if (shadowTraverser && shadowMap)  
     1092                { 
     1093                        DEL_PTR(shadowTraverser); 
     1094                        //shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 
     1095                } 
     1096 
    10761097                break; 
    10771098        case 'h': 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2892 r2897  
    121121                   const uniform float4x4 oldModelViewProj, 
    122122                   uniform float maxDepth, 
    123                    uniform float expFactor 
     123                   uniform float temporalCoherence 
    124124                   ) 
    125125{ 
     
    167167        const float depthDif = 1.0f - newDepth / oldDepth; 
    168168 
    169  
    170         if ((tex.x >= 0.0f) && (tex.x < 1.0f) &&  
     169        float oldWeight = clamp(oldSsao.z, 0, temporalCoherence); 
     170        float newWeight; 
     171 
     172        if ((temporalCoherence > 0.0f) && 
     173                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    171174                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    172175                (abs(depthDif)  < 1e-3f)) 
    173176        { 
    174                 OUT.ssao_col.x = new_color.w * expFactor + oldSsao.x * (1.0f - expFactor); 
    175                 OUT.illum_col = new_color * expFactor + oldIllum * (1.0f - expFactor); 
     177                newWeight = oldWeight + 1; 
     178 
     179                //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
     180                OUT.ssao_col.x = (new_color.w + oldSsao.x * oldWeight) / newWeight; 
     181                OUT.illum_col  = (new_color + oldIllum * oldWeight) / newWeight; 
     182 
     183                //OUT.ssao_col.x = new_color.w * expFactor + oldSsao.x * (1.0f - expFactor); 
     184                //OUT.illum_col = new_color * expFactor + oldIllum * (1.0f - expFactor); 
    176185        } 
    177186        else 
    178187        { 
     188                newWeight = 0; 
     189 
    179190                OUT.ssao_col.x = new_color.w; 
    180191                OUT.illum_col = new_color; 
    181192        } 
    182193 
     194        OUT.ssao_col.z = newWeight; 
    183195        OUT.ssao_col.w = currentDepth; 
    184196 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2893 r2897  
    114114                   const uniform float4x4 oldModelViewProj, 
    115115                   uniform float maxDepth, 
    116                    uniform float expFactor 
     116                   uniform float temporalCoherence 
    117117                   ) 
    118118{ 
     
    157157        const float depthDif = 1.0f - newDepth / oldDepth; 
    158158 
    159  
    160         if ((tex.x >= 0.0f) && (tex.x < 1.0f) &&  
     159        float oldWeight = clamp(oldCol.z, 0, temporalCoherence); 
     160        float newWeight; 
     161 
     162        if ((temporalCoherence > 0) && 
     163                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    161164                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    162                 (abs(depthDif) < 1e-3f)) 
     165                (abs(depthDif) < 1e-4f)) 
    163166        { 
    164                 OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
     167                newWeight = oldWeight + 1; 
     168 
     169                //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
     170                OUT.illum_col = (float4)(ao + oldCol.x * oldWeight) / newWeight; 
    165171        } 
    166172        else 
    167173        { 
    168174                OUT.illum_col = (float4)ao; 
     175                newWeight = 0; 
    169176        } 
    170177 
    171         //OUT.illum_col.xyz = viewDir; 
     178 
     179        OUT.illum_col.z = newWeight; 
    172180        OUT.illum_col.w = currentDepth; 
    173181 
     
    188196        //OUT.illum_col = ao; 
    189197 
     198        //OUT.illum_col.z = ao.z; 
    190199        OUT.illum_col.w = ao.w; 
    191200 
Note: See TracChangeset for help on using the changeset viewer.