Ignore:
Timestamp:
09/13/08 14:03:47 (16 years ago)
Author:
mattausch
Message:

lispsm finally working!!

File:
1 edited

Legend:

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

    r2941 r2942  
    570570void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView) 
    571571{ 
    572         const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    573         const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    574          
    575         const Vector3 dir = mLight->GetDirection(); 
    576         //const Vector3 dir(0, 0, -1); 
    577  
    578         // set position so that we can see the whole scene 
    579         //Vector3 pos = mSceneBox.Center(); 
    580         //pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 
    581         //mShadowCam->SetPosition(pos); 
    582         mShadowCam->SetPosition(mCamera->GetPosition()); 
    583  
    584         Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    585         Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec); 
    586         //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection()); 
    587  
    588         Matrix4x4 refl = ScaleMatrix(-1, 1, 1);  
    589         lightView = lightView * refl; 
    590  
    591         mShadowCam->mViewOrientation = lightView; 
    592  
    593  
    594572        mFbo->Bind(); 
    595573         
     
    598576        glPushAttrib(GL_VIEWPORT_BIT); 
    599577        glViewport(0, 0, mSize, mSize); 
    600  
    601         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    602578 
    603579        glDisable(GL_LIGHTING); 
     
    605581        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    606582 
    607 //glDisable(GL_CULL_FACE); 
    608  
    609         glPolygonOffset(1.0f, 2000.0f); 
    610         glEnable(GL_POLYGON_OFFSET_FILL); 
    611         //glDisable(GL_POLYGON_OFFSET_FILL); 
    612  
    613583        glShadeModel(GL_FLAT); 
    614         glEnable(GL_DEPTH_TEST); 
    615  
    616         Matrix4x4 lightProj; 
    617  
    618         CalcLightProjection(lightProj); 
    619  
    620         glMatrixMode(GL_PROJECTION); 
    621         glPushMatrix(); 
    622         glLoadMatrixf((float *)lightProj.x); 
    623  
    624         mLightProjView = lightView * lightProj; 
    625  
    626         cout << "here3" << endl; 
    627         DEL_PTR(lightPoly); 
    628         lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 
    629         cout << "here4\n" << lightView << endl; 
    630  
    631         glMatrixMode(GL_MODELVIEW); 
    632         glPushMatrix(); 
    633         glLoadIdentity(); 
    634  
    635         mShadowCam->SetupCameraView(); 
    636  
    637         dummyMat = mLightProjView; 
     584 
     585 
     586        ///////////// 
     587        //-- render scene into shadow map 
     588 
     589        _Render(renderer); 
    638590 
    639591 
     
    648600        mTextureMatrix = mLightProjView * biasMatrix;  
    649601 
    650  
    651  
    652  
    653         ///////////// 
    654         //-- render scene into shadow map 
    655  
    656         renderer->RenderScene(); 
    657  
    658          
    659         glDisable(GL_POLYGON_OFFSET_FILL); 
    660         glMatrixMode(GL_MODELVIEW); 
    661         glPopMatrix(); 
    662  
    663         glMatrixMode(GL_PROJECTION); 
    664         glPopMatrix(); 
    665  
    666602        glPopAttrib(); 
    667  
    668603         
    669604        glEnable(GL_LIGHTING); 
     
    680615        PrintGLerror("shadow map"); 
    681616#endif 
     617         
    682618        FrameBufferObject::Release(); 
    683619} 
     
    685621 
    686622void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView) 
     623{ 
     624        glEnable(GL_LIGHTING); 
     625        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     626 
     627        _Render(renderer); 
     628         
     629        glDisable(GL_POLYGON_OFFSET_FILL); 
     630        glDisable(GL_LIGHTING); 
     631} 
     632 
     633 
     634void ShadowMap::_Render(RenderTraverser *renderer) 
    687635{ 
    688636        const Vector3 dir = mLight->GetDirection(); 
     
    700648        Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir); 
    701649        Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec); 
    702         //Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection()); 
    703  
    704         //Matrix4x4 refl = ScaleMatrix(-1, 1, 1);  
    705         //lightView = lightView * refl; 
    706650 
    707651        mShadowCam->mViewOrientation = lightView; 
    708652 
    709653        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    710  
    711         glEnable(GL_LIGHTING); 
    712         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    713654 
    714655        glPolygonOffset(1.0f, 2000.0f); 
    715656        glEnable(GL_POLYGON_OFFSET_FILL); 
    716657         
    717         glEnable(GL_DEPTH_TEST); 
    718  
    719658        Matrix4x4 lightProj; 
    720659        CalcLightProjection(lightProj); 
     
    730669        lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 
    731670 
    732         Frustum frustum(mLightProjView); 
    733         cout << "near: " << Normalize(frustum.mClipPlanes[4].mNormal) << endl; 
    734         cout << "far: " << Normalize(frustum.mClipPlanes[5].mNormal) << endl; 
    735  
    736671        glMatrixMode(GL_MODELVIEW); 
    737672        glPushMatrix(); 
     
    739674 
    740675        //glDisable(GL_CULL_FACE); 
    741  
    742676        mShadowCam->SetupCameraView(); 
    743          
    744  
     677 
     678         
    745679        ///////////// 
    746680        //-- render scene into shadow map 
     
    748682        renderer->RenderScene(); 
    749683 
    750          
    751         glDisable(GL_POLYGON_OFFSET_FILL); 
    752  
    753         glDisable(GL_LIGHTING); 
    754         glDisable(GL_DEPTH_TEST); 
    755  
    756         glLineWidth(2); 
    757         Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 
    758         DrawPoly(hpoly, Vector3(1, 1, 1), Vector3(0, 1, 1)); 
    759  
    760         DEL_PTR(hpoly); 
    761  
    762  
    763         glEnable(GL_LIGHTING); 
    764         glEnable(GL_DEPTH_TEST); 
    765  
    766684        glMatrixMode(GL_MODELVIEW); 
    767685        glPopMatrix(); 
     
    770688        glPopMatrix(); 
    771689 
    772  
    773 #if 0 
    774         float *data = new float[mSize * mSize]; 
    775  
    776         GrabDepthBuffer(data, mFbo->GetDepthTex()); 
    777         ExportDepthBuffer(data, mSize); 
    778  
    779         delete [] data; 
    780          
    781         PrintGLerror("shadow map"); 
    782 #endif 
    783         FrameBufferObject::Release(); 
    784 } 
    785  
    786  
    787  
    788  
     690         
     691        glDisable(GL_POLYGON_OFFSET_FILL); 
     692} 
    789693} // namespace 
Note: See TracChangeset for help on using the changeset viewer.