Changeset 2924


Ignore:
Timestamp:
09/09/08 21:01:13 (16 years ago)
Author:
mattausch
Message:

so ein schas das lispsm

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

Legend:

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

    r2920 r2924  
    717717{ 
    718718        const Vector3 nDir = Normalize(dir); 
    719          
    720719        Vector3 nUp = Normalize(up); 
    721720 
     
    723722        nUp = Normalize(CrossProd(nRight, nDir)); 
    724723 
    725         Matrix4x4 m; 
    726         Matrix4x4(nRight, nUp, -nDir); 
     724        Matrix4x4 m(nRight, nUp, -nDir); 
    727725 
    728726        m.x[3][0] = -DotProd(nRight, pos); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2923 r2924  
    8585 
    8686 
     87static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 
     88                                                                                 const VertexArray &pts) 
     89{ 
     90        AxisAlignedBox3 extremalPoints; 
     91        extremalPoints.Initialize(); 
     92 
     93        VertexArray::const_iterator it, it_end = pts.end(); 
     94                 
     95        for (it = pts.begin(); it != it_end; ++ it) 
     96        { 
     97                Vector3 pt = *it; 
     98                pt = m * pt; 
     99 
     100                extremalPoints.Include(pt); 
     101        } 
     102 
     103        return extremalPoints; 
     104} 
     105 
     106 
    87107ShadowMap::ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
    88108mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light) 
     
    179199 
    180200 
    181 Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightProjView,  
     201Matrix4x4 ShadowMap::CalcLispSMTransform(const Matrix4x4 &lightSpace,  
    182202                                                                                 const AxisAlignedBox3 &extremalPoints, 
    183                                                                                  const VertexArray &pts 
     203                                                                                 const VertexArray &body 
    184204                                                                                 ) 
    185205{ 
    186         Matrix4x4 matLispSM; 
     206        AxisAlignedBox3 bounds_ls = GetExtremalPoints(lightSpace, body); 
     207        //return IdentityMatrix(); 
    187208 
    188209        /////////////// 
    189210        //-- We apply the lispsm algorithm in order to calculate an optimal light projection matrix 
    190211 
    191         const float n = ComputeN(extremalPoints); 
     212 
     213        //////// 
     214        //-- first find the free parameter values n, and P (the projection center), and the projection depth 
     215 
     216        const float n = 1e6;//ComputeN(bounds_ls); 
    192217 
    193218        cout << "n: " << n << endl; 
    194219 
    195         const Vector3 nearPt = GetNearCameraPointE(pts); 
    196  
     220        const Vector3 nearPt = GetNearCameraPointE(body); 
     221        const float dummy = 0; 
    197222        //get the coordinates of the near camera point in light space 
    198         const Vector3 lsNear = lightProjView * nearPt; 
     223        const Vector3 lsNear = lightSpace * nearPt; 
    199224 
    200225        //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; 
     226        const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 
     227 
     228        cout << "mx: " <<  bounds_ls.Max() << endl; 
     229        cout << "mn: " << bounds_ls.Min() << endl; 
    205230 
    206231        // the new projection center 
    207232        Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
    208233 
    209         cout <<"start: " << startPt << " " << projCenter << endl; 
     234        cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 
    210235 
    211236        //construct a translation that moves to the projection center 
     
    213238 
    214239        // light space y size 
    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]); 
     240        const float d = fabs(bounds_ls.Max()[2] - bounds_ls.Min()[2])+dummy; 
     241 
     242        const float dy = fabs(bounds_ls.Max()[1] - bounds_ls.Min()[1]); 
     243        const float dx = fabs(bounds_ls.Max()[0] - bounds_ls.Min()[0]); 
    219244 
    220245        cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl; 
    221246 
    222         matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 
     247         
     248 
     249        //////// 
     250        //-- now apply these values to construct the perspective lispsm matrix 
     251 
     252        Matrix4x4 matLispSM; 
     253         
     254        matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n+dummy, n + d); 
    223255 
    224256        //cout << "lispsm\n" << matLispSM << endl; 
    225257 
     258        // translate to the projection center 
    226259        matLispSM = projectionCenter * matLispSM; 
    227260 
    228         cout << "center\n" << projectionCenter << endl; 
    229261        //cout << "new\n" << matLispSM << endl; 
    230262 
     
    232264        Matrix4x4 refl = ScaleMatrix(1.0f, 1.0f, -1.0f); 
    233265        matLispSM *= refl; 
    234         matLispSM = IdentityMatrix(); 
    235  
     266         
    236267        return matLispSM; 
    237268} 
     
    243274        float minDist = 1e25f; 
    244275 
    245         Vector3 camPos = mCamera->GetPosition(); 
     276        const Vector3 camPos = mCamera->GetPosition(); 
    246277 
    247278        /*Matrix4x4 inverseCamView; 
     
    281312        Vector3 projDir(b_lp - e_lp); 
    282313 
     314        Matrix4x4 dummy = lightSpace; 
     315        Invert(dummy); 
     316        Vector3 dummyVec = dummy * e_lp; 
     317        Vector3 dummyVec2 = dummy * b_lp; 
     318 
     319        //projDir.z = -projDir.z; 
     320 
     321        cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl; 
    283322        //project the view direction into the shadow map plane 
    284323        projDir.y = 0.0; 
    285         //projDir.z = 0.0; 
    286324 
    287325        return Normalize(projDir); 
    288 } 
    289  
    290  
    291 static AxisAlignedBox3 GetExtremalPoints(const Matrix4x4 &m, 
    292                                                                                  const VertexArray &pts) 
    293 { 
    294         AxisAlignedBox3 extremalPoints; 
    295         extremalPoints.Initialize(); 
    296  
    297         VertexArray::const_iterator it, it_end = pts.end(); 
    298                  
    299         for (it = pts.begin(); it != it_end; ++ it) 
    300         { 
    301                 Vector3 pt = *it; 
    302                 pt = m * pt; 
    303  
    304                 extremalPoints.Include(pt); 
    305         } 
    306  
    307         return extremalPoints; 
     326        //return projDir; 
    308327} 
    309328 
     
    342361        transform2LispSM.x[0][0] =  1.0f; 
    343362        transform2LispSM.x[1][2] = -1.0f; // y => -z 
    344         transform2LispSM.x[2][1] =  1.0f;  // z => y 
     363        transform2LispSM.x[2][1] =  1.0f; // z => y 
    345364        transform2LispSM.x[3][3] =  1.0f; 
    346365 
     
    348367        lightProj = lightProj * transform2LispSM; 
    349368 
    350         const Vector3 projViewDir = GetProjViewDir(lightProj, frustumPoints); 
    351  
    352         cout << "projViewDir: " << projViewDir << endl; 
     369        const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 
     370 
     371 
     372        cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl; 
    353373 
    354374        //do Light Space Perspective shadow mapping 
     
    357377        //look(from position, into the direction of the projected direction, with unchanged up-vector) 
    358378        Matrix4x4 frame = LookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 
    359         //lightProj = lightProj * frame; 
     379 
     380        cout << "frame\n " << frame << endl; 
     381        lightProj = lightProj * frame; 
    360382 
    361383        cout << "here9\n" << lightProj << endl; 
     
    364386                CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 
    365387 
     388        Vector3 mydummy = Vector3::UNIT_Z(); 
     389 
     390        cout << "yoyo: " << Normalize(lightView * lightProj * mydummy) << endl; 
    366391        lightProj = lightProj * matLispSM; 
    367392 
Note: See TracChangeset for help on using the changeset viewer.