Changeset 2939


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

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

Legend:

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

    r2936 r2939  
    569569        ret.y = v.x * M.x[0][1] + v.y * M.x[1][1] + v.z * M.x[2][1] + M.x[3][1]; 
    570570        ret.z = v.x * M.x[0][2] + v.y * M.x[1][2] + v.z * M.x[2][2] + M.x[3][2]; 
    571         denom = M.x[0][3] + M.x[1][3] + M.x[2][3] + M.x[3][3]; 
     571        denom = v.x * M.x[0][3] + v.y * M.x[1][3] + v.z * M.x[2][3] + M.x[3][3]; 
     572        //denom = M.x[0][3] + M.x[1][3] + M.x[2][3] + M.x[3][3]; 
     573 
    572574        if (denom != 1.0) 
    573575                ret /= denom; 
     
    677679        return m; 
    678680} 
     681/* 
     682 
     683template<class REAL> 
     684Matrix4<REAL>& scaleTranslateToFit(Matrix4<REAL>& output, const Vector3<REAL>& vMin, const Vector3<REAL>& vMax) { 
     685        const REAL diffX = vMax.x()-vMin.x(); 
     686        output[ 0] = 2/diffX; 
     687        output[ 4] = 0; 
     688        output[ 8] = 0; 
     689        output[12] = -(vMax.x()+vMin.x())/diffX; 
     690 
     691        const REAL diffY = vMax.y()-vMin.y(); 
     692        output[ 1] = 0; 
     693        output[ 5] = 2/diffY; 
     694        output[ 9] = 0; 
     695        output[13] = -(vMax.y()+vMin.y())/diffY; 
     696 
     697        const REAL diffZ = vMax.z()-vMin.z(); 
     698        output[ 2] = 0; 
     699        output[ 6] = 0; 
     700        output[10] = 2/diffZ; 
     701        output[14] = -(vMax.z()+vMin.z())/diffZ; 
     702 
     703        output[ 3] = 0; 
     704        output[ 7] = 0; 
     705        output[11] = 0; 
     706        output[15] = 1; 
     707        return output; 
     708} 
     709*/ 
     710 
    679711 
    680712 
  • 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(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2936 r2939  
    7070int renderMode = RenderTraverser::CHCPLUSPLUS; 
    7171// eye near plane distance 
    72 float nearDist = 0.1f; 
     72float nearDist = 0.5f; 
    7373float farDist = 1e6f; 
    7474/// the field of view 
Note: See TracChangeset for help on using the changeset viewer.