Changeset 2922 for GTP/trunk


Ignore:
Timestamp:
09/09/08 17:35:18 (16 years ago)
Author:
mattausch
Message:

frustrated

File:
1 edited

Legend:

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

    r2921 r2922  
    189189        //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 
    190190 
    191         const float n = 10;//ComputeN(extremalPoints); 
     191        const float n = ComputeN(extremalPoints); 
    192192 
    193193        cout << "n: " << n << endl; 
     
    198198        const Vector3 lsNear = lightProjView * nearPt; 
    199199 
    200         //c start has the x and y coordinate of e, the z coord of B.min() 
    201         const Vector3 startPt = Vector3::ZERO();//Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z); 
     200        //c start has the x and y coordinate of e,  the z coord of the near plane of the light volume 
     201        const Vector3 startPt = Vector3(lsNear.x, lsNear.y, extremalPoints.Max().z); 
     202 
     203        cout << "mx: " <<  extremalPoints.Max() << endl; 
     204        cout << "mn: " << extremalPoints.Min() << endl; 
    202205 
    203206        // the new projection center 
    204207        Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
    205208 
     209        cout <<"start: " << startPt << " " << projCenter << endl; 
     210 
    206211        //construct a translation that moves to the projection center 
    207212        const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); 
    208213 
    209214        // light space y size 
    210         const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]);  
    211         cout << "d: " << d << endl; 
     215        const float d = fabs(extremalPoints.Max()[2] - extremalPoints.Min()[2]); 
     216 
     217        const float dy = fabs(extremalPoints.Max()[1] - extremalPoints.Min()[1]); 
     218        const float dx = fabs(extremalPoints.Max()[0] - extremalPoints.Min()[0]); 
     219 
     220        cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl; 
     221 
    212222        matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 
    213223 
    214         cout << "lispsm\n" << matLispSM << endl; 
     224        //cout << "lispsm\n" << matLispSM << endl; 
    215225 
    216226        matLispSM = projectionCenter * matLispSM; 
    217227 
    218228        cout << "center\n" << projectionCenter << endl; 
    219         cout << "new\n" << matLispSM << endl; 
     229        //cout << "new\n" << matLispSM << endl; 
    220230 
    221231        // transform into OpenGL right handed system 
     
    230240Vector3 ShadowMap::GetNearCameraPointE(const VertexArray &pts) const 
    231241{ 
    232         Vector3 nearest; 
    233         float minDist = 1e20f; 
     242        Vector3 nearest = Vector3::ZERO(); 
     243        float minDist = 1e25f; 
    234244 
    235245        Vector3 camPos = mCamera->GetPosition(); 
     
    279289 
    280290 
    281 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &lightView, 
     291static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 
    282292                                                                                 const VertexArray &pts) 
    283293{ 
     
    290300        { 
    291301                Vector3 pt = *it; 
    292                 pt = lightView * pt; 
     302                pt = m * pt; 
    293303 
    294304                extremalPoints.Include(pt); 
     
    301311bool ShadowMap::CalcLightProjection(Matrix4x4 &lightProj) 
    302312{ 
    303         DEL_PTR(polyhedron); 
    304  
    305  
    306313        /////////////////// 
    307314        //-- First step: calc frustum clipped by scene box 
    308315 
     316        DEL_PTR(polyhedron); 
    309317        polyhedron = CalcClippedFrustum(mSceneBox); 
    310318 
     
    329337        lightProj = IdentityMatrix();  
    330338 
     339        // switch coordinate system to that used in the lispsm algorithm for calculations 
     340        Matrix4x4 transform2LispSM = ZeroMatrix(); 
     341 
     342        transform2LispSM.x[0][0] =  1.0f; 
     343        transform2LispSM.x[1][2] = -1.0f; // y => -z 
     344        transform2LispSM.x[2][1] =  1.0f;  // z => y 
     345        transform2LispSM.x[3][3] =  1.0f; 
     346 
     347        //switch to the lightspace used in the article 
     348        lightProj = lightProj * transform2LispSM; 
     349 
    331350        const Vector3 projViewDir = GetProjViewDir(lightProj, frustumPoints); 
    332351 
     
    334353 
    335354        //do Light Space Perspective shadow mapping 
    336         //rotate the lightspace so that the proj light view always points upwards 
    337         //calculate a frame matrix that uses the projViewDir[light-space] as up vector 
     355        //rotate the lightspace so that the projected light view always points upwards 
     356        //calculate a frame matrix that uses the projViewDir[lightspace] as up vector 
    338357        //look(from position, into the direction of the projected direction, with unchanged up-vector) 
    339358        Matrix4x4 frame = LookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 
    340359        lightProj = frame * lightProj; 
    341360 
     361        cout << "here9\n" << lightProj << endl; 
     362 
    342363        const Matrix4x4 matLispSM =  
    343364                CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 
     
    345366        lightProj = matLispSM * lightProj; 
    346367 
     368        // change back to GL coordinate system 
     369        Matrix4x4 transformToGL = ZeroMatrix(); 
     370         
     371        transformToGL.x[0][0] =  1.0f; 
     372        transformToGL.x[1][2] =  1.0f; // z => y 
     373        transformToGL.x[2][1] = -1.0f; // y => -z 
     374        transformToGL.x[3][3] =  1.0f; 
     375 
     376        lightProj = lightProj * transformToGL; 
     377        //cout << "here4 \n" << lightProj << endl; 
     378 
    347379        AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 
    348380 
    349         //cout << "max: " << lightPts.Max() << endl; 
    350         //cout << "min: " << lightPts.Min() << endl; 
     381        //cout << "ma2: " << lightPts.Max() << endl; 
     382        //cout << "mi2: " << lightPts.Min() << endl; 
    351383 
    352384        // focus projection matrix on the extremal points => scale to unit cube 
    353         lightProj *= GetFittingProjectionMatrix(lightPts); 
    354         //lightProj *= GetFittingProjectionMatrix(extremalPoints); 
    355  
    356         cout << "max: " << lightProj * lightPts.Max() << endl; 
    357         cout << "min: " << lightProj * lightPts.Min() << endl; 
     385        Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 
     386        lightProj *= scaleTranslate; 
     387 
     388        cout << "max: " << lightProj * extremalPoints.Max() << endl; 
     389        cout << "min: " << lightProj * extremalPoints.Min() << endl; 
    358390 
    359391        // we have to flip the signs in order to tranform to opengl right handed system 
     
    413445        const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    414446         
    415         const Vector3 dir = mLight->GetDirection(); 
    416         //const Vector3 dir(0, 0, 1); 
     447        //const Vector3 dir = mLight->GetDirection(); 
     448        const Vector3 dir(0, 0, -1); 
    417449 
    418450        mShadowCam->SetDirection(dir); 
     
    426458        //mCamera->GetModelViewMatrix(camView); 
    427459 
    428         pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 
     460        pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.1f); 
    429461        mShadowCam->SetPosition(pos); 
    430462 
Note: See TracChangeset for help on using the changeset viewer.