Ignore:
Timestamp:
09/12/08 22:02:41 (16 years ago)
Author:
mattausch
Message:

lispsm working for standard case (light dir perpendicular to scene), but not even uniform working for all other cases

File:
1 edited

Legend:

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

    r2938 r2939  
    6060        } 
    6161 
     62        // first create near plane because of precision issues 
     63        clipPlanes.push_back(frustum.mClipPlanes[4]); 
     64 
    6265        clipPlanes.push_back(frustum.mClipPlanes[0]); 
    6366        clipPlanes.push_back(frustum.mClipPlanes[1]); 
     
    6568        clipPlanes.push_back(frustum.mClipPlanes[3]); 
    6669        clipPlanes.push_back(frustum.mClipPlanes[5]); 
    67  
    68         clipPlanes.push_back(frustum.mClipPlanes[4]); 
    6970 
    7071        return Polyhedron::CreatePolyhedron(clipPlanes, sceneBox); 
     
    226227                                                                                 ) 
    227228{ 
    228         //return IdentityMatrix(); 
     229        return IdentityMatrix(); 
    229230 
    230231        AxisAlignedBox3 bounds_ls = GetExtremalPoints(lightSpace, body); 
     
    235236 
    236237        //const float n = 1e2f; 
    237         const float n = 1e2f; 
    238         //const float n = ComputeN(bounds_ls) * 100; 
     238        const float n = 1e6f; 
     239        //const float n = ComputeN(bounds_ls); 
    239240 
    240241        cout << "n: " << n << endl; 
     
    245246        const Vector3 lsNear = lightSpace * nearPt; 
    246247 
    247         //c start has the x and y coordinate of e, the z coord of the near plane of the light volume 
     248        // the start point has the x and y coordinate of e, the z coord of the near plane of the light volume 
    248249        const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 
    249250        //const Vector3 schas = lightSpace * mCamera->GetPosition(); 
     
    278279        Matrix4x4 matLispSM; 
    279280         
    280         matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d * 1e10f); 
     281        matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 
    281282 
    282283        //cout << "lispsm\n" << matLispSM << endl; 
     
    405406 
    406407        VertexArray frustumPoints; 
    407         IncludeLightVolume(*polyhedron, frustumPoints, mShadowCam->GetDirection(), mSceneBox); 
     408        //Vector3 lightDir = Vector3(0, 0, -1); 
     409        IncludeLightVolume(*polyhedron, frustumPoints, mLight->GetDirection(), mSceneBox); 
    408410 
    409411 
     
    445447        lightProj *= frame; 
    446448 
    447         cout << "here9\n" << lightProj << endl; 
    448  
    449         //Matrix4x4 refl2 = ScaleMatrix(-1, -1, 1);  
    450         //lightProj = refl2 * lightProj; 
    451  
    452449        const Matrix4x4 matLispSM =  
    453450                CalcLispSMTransform(lightView * lightProj, extremalPoints, frustumPoints); 
     
    464461 
    465462        lightProj *= transformToGL; 
    466         //cout << "here4 \n" << lightProj << endl; 
    467463 
    468464        AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 
    469465 
    470         //cout << "max2: " << lightPts.Max() << endl; 
    471         //cout << "min2: " << lightPts.Min() << endl; 
    472  
    473         AxisAlignedBox3 dummyBox = GetExtremalPoints(IdentityMatrix(), frustumPoints); 
    474  
     466        cout << "max: " << lightPts.Max() << " min: " << lightPts.Min() << endl; 
    475467        // focus projection matrix on the extremal points => scale to unit cube 
    476         //Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(extremalPoints); 
    477468        Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 
    478         lightProj = scaleTranslate * lightProj; 
    479  
    480         cout << "max: " << lightView * lightProj * dummyBox.Max() << endl; 
    481         cout << "min: " << lightView * lightProj * dummyBox.Min() << endl; 
     469 
     470        cout << "scaleTranslate:\n" << scaleTranslate << endl; 
     471 
     472        lightProj = lightProj * scaleTranslate; 
     473 
     474        Matrix4x4 mymat = lightView * lightProj; 
     475 
     476        AxisAlignedBox3 lightPtsNew = GetExtremalPoints(mymat, frustumPoints); 
     477 
     478        cout << "newmax: " << lightPtsNew.Max() << endl; 
     479        cout << "newmin: " << lightPtsNew.Min() << endl; 
    482480 
    483481        // we have to flip the signs in order to tranform to opengl right handed system 
     
    554552                frustumPoints.push_back(v); 
    555553                 
    556                 // hack: get point surely outside of box 
     554                // hack: start at point which is guaranteed to be outside of box 
    557555                v -= Magnitude(mSceneBox.Diagonal()) * lightDir; 
    558556 
     
    575573        const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    576574         
    577         //const Vector3 dir = mLight->GetDirection(); 
    578         const Vector3 dir(0, 0, -1); 
     575        const Vector3 dir = mLight->GetDirection(); 
     576        //const Vector3 dir(0, 0, -1); 
    579577 
    580578        // set position so that we can see the whole scene 
     
    627625 
    628626        mLightProjView = lightView * lightProj; 
    629 ; 
     627 
    630628        cout << "here3" << endl; 
    631629        DEL_PTR(lightPoly); 
     
    690688void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView) 
    691689{ 
    692         //const Vector3 dir = mLight->GetDirection(); 
    693         const Vector3 dir(0, 0, -1); 
    694  
     690        const Vector3 dir = mLight->GetDirection(); 
     691        //const Vector3 dir(0, 0, -1); 
     692 
     693        cout << "dir: " << dir << endl; 
    695694        mShadowCam->SetDirection(dir); 
    696695 
     
    735734        lightPoly = CreatePolyhedron(mLightProjView, mSceneBox); 
    736735 
     736        Frustum frustum(mLightProjView); 
     737        cout << "near: " << Normalize(frustum.mClipPlanes[4].mNormal) << endl; 
     738        cout << "far: " << Normalize(frustum.mClipPlanes[5].mNormal) << endl; 
     739 
    737740        glMatrixMode(GL_MODELVIEW); 
    738741        glPushMatrix(); 
Note: See TracChangeset for help on using the changeset viewer.