Changeset 2942


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

lispsm finally working!!

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

Legend:

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

    r2941 r2942  
    4141        mIsOrtho = false; 
    4242 
    43         SetPosition(Vector3(0, 0, 0)); 
     43        SetPosition(Vector3::ZERO()); 
    4444 
    4545        mPitch = mYaw = 0; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp

    r2940 r2942  
    777777                                0,        0,        0,        1); 
    778778 
    779         Vector3 position = m * -pos; 
    780          
    781779        // note: left handed system => we go into positive z 
    782780        m.x[3][0] = -DotProd(nRight, pos); 
    783781        m.x[3][1] = -DotProd(nUp, pos); 
    784         m.x[3][2] =  DotProd(nDir, pos); 
     782        m.x[3][2] = DotProd(nDir, pos); 
    785783 
    786784        return m; 
     
    788786 
    789787 
    790 Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up)  
    791 { 
    792         const Vector3 nDir = Normalize(dir); 
    793         Vector3 nUp = Normalize(up); 
    794  
    795         Vector3 nRight = Normalize(CrossProd(nDir, nUp)); 
    796         nUp = Normalize(CrossProd(nRight, nDir)); 
    797  
    798         Matrix4x4 m(nRight, nUp, nDir); 
    799  
    800         Vector3 position = m * -pos; 
    801          
    802         // note: left handed system => we go into positive z 
    803         m.x[3][0] = position.x; 
    804         m.x[3][1] = position.y; 
    805         m.x[3][2] = position.z; 
    806  
    807         return m; 
    808 } 
    809  
    810  
    811 } 
     788} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h

    r2934 r2942  
    161161Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    162162Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    163 Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up); 
    164163 
    165164 
  • 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 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2936 r2942  
    8989        static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2); 
    9090 
    91  
     91        /** Internal shador render method. 
     92        */ 
     93        void _Render(RenderTraverser *renderer); 
    9294 
    9395        ////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2939 r2942  
    10351035        // this would conveniently solves some issues (e.g, skys without shadows) 
    10361036 
    1037         //RenderSky(); 
     1037        RenderSky(); 
    10381038         
    10391039 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2941 r2942  
    104104        lightSpacePos /= lightSpacePos.w; 
    105105 
    106         /*float shadowDepth[9]; 
     106        OUT.color = col; 
     107 
     108        float shadowDepth[9]; 
    107109 
    108110        float w = sampleWidth; 
     
    132134 
    133135        d /= 9.0f; 
    134         */ 
    135  
    136         OUT.color = col; 
     136         
     137        if (amb < 0.9f) // hack: prevent shadowing the sky       
     138        { 
     139                const float x = 0.1f; 
     140                OUT.color *= x + (1.0f - x) * (1.0f - d); 
     141        } 
     142         
     143        /* 
    137144 
    138145        float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x; 
     
    142149        { 
    143150                OUT.color *= 0.1f; 
    144         } 
    145         /* 
    146         if (amb < 0.9f) // hack: prevent shadowing the sky       
    147         { 
    148                 const float x = 0.1f; 
    149                 OUT.color *= x + (1.0f - x) * (1.0f - d); 
    150         } 
    151         */ 
    152         //OUT.color = lightSpacePos;//float4(lightSpacePos.z / lightSpacePos.w); 
    153         //OUT.color = float4(shadowDepth); 
     151        }*/ 
     152 
    154153        OUT.color.w = color.w; 
    155154 
Note: See TracChangeset for help on using the changeset viewer.