Changeset 2916


Ignore:
Timestamp:
09/08/08 15:00:23 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
5 edited

Legend:

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

    r2915 r2916  
    655655        Matrix4x4 m; 
    656656 
    657 /*      m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]); 
    658         m.x[1][0] = .0f; 
    659         m.x[2][0] = .0f; 
    660         m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]); 
    661  
    662         m.x[0][1] = .0f; 
    663         m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]); 
    664         m.x[2][1] = .0f; 
    665         m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]); 
    666  
    667         m.x[0][2] = .0f; 
    668         m.x[1][2] = .0f; 
    669         m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]); 
    670         m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]); 
    671  
    672         m.x[0][3] = .0f; 
    673         m.x[1][3] = .0f; 
    674         m.x[2][3] = .0f; 
    675         m.x[3][3] = 1.0f;*/ 
    676  
    677657        m.x[0][0] = -2.0f / (box.Max()[0] - box.Min()[0]); 
    678658        m.x[0][1] = .0f; 
     
    698678} 
    699679 
     680/* 
     681Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box) 
     682{ 
     683        Matrix4x4 m; 
     684 
     685        m.x[0][0] = 2.0f / (box.Max()[0] - box.Min()[0]); 
     686        m.x[0][1] = .0f; 
     687        m.x[0][2] = .0f; 
     688        m.x[0][3] = .0f; 
     689 
     690        m.x[1][0] = .0f; 
     691        m.x[1][1] = 2.0f / (box.Max()[1] - box.Min()[1]); 
     692        m.x[1][2] = .0f; 
     693        m.x[1][3] = .0f; 
     694 
     695        m.x[2][0] = .0f; 
     696        m.x[2][1] = .0f; 
     697        m.x[2][2] = 2.0f / (box.Max()[2] - box.Min()[2]); 
     698        m.x[2][3] = .0f; 
     699 
     700        m.x[3][0] = -(box.Max()[0] + box.Min()[0]) / (box.Max()[0] - box.Min()[0]); 
     701        m.x[3][1] = -(box.Max()[1] + box.Min()[1]) / (box.Max()[1] - box.Min()[1]); 
     702        m.x[3][2] = -(box.Max()[2] + box.Min()[2]) / (box.Max()[2] - box.Min()[2]); 
     703        m.x[3][3] = 1.0f; 
     704 
     705        return m; 
     706}*/ 
    700707 
    701708//output is initialized with the same result as glFrustum 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h

    r2915 r2916  
    155155Vector3 GetTranslation(const Matrix4x4 &M); 
    156156Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box); 
    157  
     157Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far); 
    158158 
    159159} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2915 r2916  
    166166 
    167167 
    168 bool ShadowMap::CalcLightProjectionLispSM(Matrix4x4 &lightProj) 
    169 { 
     168float ShadowMap::ComputeN() const  
     169{ 
     170        const float n = mShadowCam->GetNear(); 
     171        const float f = mShadowCam->GetFar(); 
     172 
     173        const float d = fabs(f - n); 
     174         
     175        const float dotProd = DotProd(mCamera->GetDirection(), mShadowCam->GetDirection()); 
     176        const float sinGamma = sin(fabs(acos(dotProd))); 
     177 
     178        return (n + sqrt(n * (n + d * sinGamma))) /  sinGamma; 
     179} 
     180 
     181 
     182Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView) 
     183{/* 
    170184        Matrix4x4 lispMtx = IdentityMatrix(); 
    171185 
     
    212226        //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 
    213227 
    214         // use lispsm formulas 
    215         const float fac = 1.0f / sinGamma; 
    216          
    217         const float z_n = fac * mCamera->GetNear(); 
    218  
    219         // light space y size 
    220         const float d = fabs(extremalPoints.Max()[1] - extremalPoints.Min()[1]);  
    221  
    222         const float z_f = z_n + d * sinGamma; 
    223  
    224         // this is the famous n parameter 
    225         const float n = (z_n + sqrt(z_f * z_n)) /sinGamma; 
    226         const float f = n + d; 
     228        const float n = 1e20f;//ComputeN(); 
     229 
     230        cout << "n: " << n << endl; 
    227231 
    228232        const Vector3 nearPt = mShadowCam->GetNear() * mShadowCam->GetDirection() + mShadowCam->GetPosition(); 
     
    232236 
    233237        //c start has the x and y coordinate of e, the z coord of B.min() 
    234         const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z); 
     238        const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Min().y); 
    235239 
    236240        // the new projection center 
    237         Vector3 projCenter = startPt - Vector3(0, 0, 1) * n; 
     241        const Vector3 unit_y = Vector3(0, 1, 0); 
     242        Vector3 projCenter = startPt - unit_y * n; 
    238243 
    239244        //construct a translation that moves to the projection center 
    240245        const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); 
    241246 
    242         lightProj = IdentityMatrix(); 
    243  
    244         //one possibility for a simple perspective transformation matrix 
    245         //with the two parameters n(near) and f(far) in y direction 
    246          
    247         // a = (f+n)/(f-n); b = -2*f*n/(f-n); 
    248         // [ 1 0 0 0] 
    249         // [ 0 a 0 b] 
    250         // [ 0 0 1 0] 
    251         // [ 0 1 0 0] 
    252  
    253         lightProj.x[1][1] = (f + n) / (f - n);            
    254         lightProj.x[1][3] = 1.0f; 
    255  
    256         lightProj.x[3][1] = -2.0f * f * n / (f - n);             
    257         lightProj.x[3][3] = 0.0f;                                
     247        // light space y size 
     248        const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]);  
     249 
     250        lightProj = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 
    258251 
    259252        cout << "here4\n" << lightProj << endl; 
     
    270263        cout << "max: " << lightProj * pmax << endl; 
    271264         
    272  
    273         return true; 
     265*/ 
     266        return IdentityMatrix(); 
    274267} 
    275268 
     
    313306        } 
    314307 
     308        //Matrix4x4 m = CalcLispSMTransform(lightProj); 
     309 
    315310        // focus projection matrix on the extremal points 
    316311        lightProj = GetFittingProjectionMatrix(extremalPoints); 
    317312 
     313        //Matrix4x4 scale = ScaleMatrix(1, 1, -1); lightProj *= scale; 
     314         
    318315        return true; 
    319316} 
     
    408405        glEnable(GL_DEPTH_TEST); 
    409406 
    410          
    411407        // setup projection 
    412408        /*glMatrixMode(GL_PROJECTION); 
     
    418414        cout << "old:\n" << dummyMat << endl; 
    419415        */ 
     416 
    420417        Matrix4x4 lightView, lightProj; 
    421418 
    422419        mShadowCam->GetModelViewMatrix(lightView); 
    423  
    424         //CalcLightProjection(lightProj); 
    425         CalcLightProjectionLispSM(lightProj); 
     420        CalcLightProjection(lightProj); 
    426421 
    427422        glMatrixMode(GL_PROJECTION); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2915 r2916  
    6464        Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const; 
    6565         
    66         bool CalcLightProjectionLispSM(Matrix4x4 &lightProj); 
    6766        bool CalcLightProjection(Matrix4x4 &lightProj); 
     67        Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView); 
    6868 
    6969        void IncludeLightVolume(const Polyhedron &polyhedron,  
     
    7171                                                        const Vector3 lightDir, 
    7272                                                        const AxisAlignedBox3 &sceneBox); 
     73 
     74        float ComputeN() const; 
    7375 
    7476 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h

    r2911 r2916  
    4747        {} 
    4848 
    49         Vector3(float v): x(v), y(v), z(v){} 
     49        explicit Vector3(float v): x(v), y(v), z(v){} 
    5050        /** Copy constructor. 
    5151        */ 
Note: See TracChangeset for help on using the changeset viewer.