Changeset 2943


Ignore:
Timestamp:
09/13/08 15:00:11 (16 years ago)
Author:
mattausch
Message:

shadows working nicely

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

Legend:

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

    r2936 r2943  
    268268        planePoly = SplitPolygon(planePoly); 
    269269 
    270         // something is wrong, probably some numerical error 
    271         if (!planePoly)  
    272         {  
    273                 cerr << "should not happen" << endl;  
     270        if (planePoly)  
     271        { 
     272                // we can now savely add the new polygon 
     273                clippedPolyhedron->Add(planePoly); 
     274        } 
     275        else if (0) 
     276        { 
     277                // something is wrong, probably some numerical error 
     278                cerr << "no polygon: should not happen" << endl;  
    274279                return new Polyhedron(*this);  
    275280        } 
    276  
     281         
    277282 
    278283        ///////////// 
     
    317322        } 
    318323 
    319         // we can now savely add the new polygon 
    320         clippedPolyhedron->Add(planePoly); 
    321  
    322324        return clippedPolyhedron; 
    323325} 
     
    357359                                break; 
    358360                        case Polygon3::FRONT_SIDE: 
    359                                 cerr << "SplitPolygon: should not come here" << endl; 
     361                                //cerr << "SplitPolygon: should not come here" << endl; 
    360362                                DEL_PTR(polygon); 
    361363                break; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r2934 r2943  
    2222mTexturesEnabled(false),  
    2323mMode(RENDER), 
    24 mRenderType(FIXED) 
     24mRenderType(FIXED), 
     25mUseAlphaToCoverage(true) 
    2526{ 
    2627        Reset();  
     
    9697                mAlphaTestEnabled = false; 
    9798                 
    98                 // not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 
    99                 //glDisable(GL_ALPHA_TEST); 
    100                 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 
     99                if (mUseAlphaToCoverage) 
     100                        glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 
     101                else 
     102                        glDisable(GL_ALPHA_TEST); 
    101103        } 
    102104        else if (!mAlphaTestEnabled && alphaTest) 
     
    104106                mAlphaTestEnabled = true; 
    105107                 
    106                 // not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 
    107                 //glEnable(GL_ALPHA_TEST); 
    108                 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 
     108                if (mUseAlphaToCoverage) 
     109                        glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 
     110                else 
     111                        glEnable(GL_ALPHA_TEST); 
    109112        } 
    110113 
     
    146149 
    147150 
     151void RenderState::SetUseAlphaToCoverage(bool useAlphaToCoverage) 
     152{ 
     153        mUseAlphaToCoverage = useAlphaToCoverage; 
    148154} 
     155 
     156 
     157} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r2854 r2943  
    5757        */ 
    5858        inline int GetCurrentVboId() const { return mCurrentVboId; } 
     59        /** If alpha to coverage is instead of alpha testing 
     60        */ 
     61        void SetUseAlphaToCoverage(bool useAlphaToCoverage); 
    5962 
    6063        void SetRenderType(RenderType type) { mRenderType = type; } 
     
    8689 
    8790        RenderType mRenderType; 
     91 
     92        bool mUseAlphaToCoverage; 
    8893}; 
    8994 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2942 r2943  
    2323static Polyhedron *polyhedron = NULL; 
    2424static Polyhedron *lightPoly = NULL; 
    25 static Vector3 dummyPt; 
    26 static Matrix4x4 dummyMat; 
    2725 
    2826 
     
    159157 
    160158 
    161 void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2) 
     159static void DrawPoly(Polyhedron *poly, const Vector3 &color) 
    162160{ 
    163161        if (!poly) return; 
     
    167165                glColor3f(color.x, color.y, color.z); 
    168166 
    169                 if (i == poly->NumPolygons() - 1) // hack: different color for near 
    170                 { 
    171                         //glLineWidth(2); 
    172                         glColor3f(color2.x, color2.y, color2.z); 
    173                  
    174                 } 
    175167                glBegin(GL_LINE_LOOP); 
    176168 
     
    184176 
    185177                glEnd(); 
    186                  
    187                 //if (i == poly->NumPolygons() - 1) glLineWidth(1); 
    188178        } 
    189179} 
     
    192182void ShadowMap::DrawPolys() 
    193183{ 
    194         DrawPoly(lightPoly, Vector3(1, 0, 1), Vector3(1, 1, 1)); 
    195         DrawPoly(polyhedron, Vector3(0, 1, 0), Vector3(0, 1, 1)); 
    196  
    197         glPointSize(10.0f); 
    198  
    199         Vector3 pt = Vector3::ZERO(); 
    200         //Vector3 pt = dummyPt; 
    201  
    202         Matrix4x4 myMat = Invert(dummyMat); 
    203         pt = myMat * pt; 
    204  
    205         glBegin(GL_POINTS); 
    206         glVertex3f(pt.x, pt.y, pt.z); 
    207         glEnd(); 
     184        DrawPoly(lightPoly, Vector3(1, 0, 1)); 
     185        DrawPoly(polyhedron, Vector3(0, 1, 0)); 
    208186} 
    209187 
     
    235213        //-- first find the free parameter values n, and P (the projection center), and the projection depth 
    236214 
    237         //const float n = 1e2f; 
    238         //const float n = 1e6f; 
    239215        const float n = ComputeN(bounds_ls); 
    240216 
    241         cout << "n: " << n << endl; 
     217        //cout << "n: " << n << endl; 
    242218 
    243219        const Vector3 nearPt = GetNearCameraPointE(body); 
     
    248224        // the start point has the x and y coordinate of e, the z coord of the near plane of the light volume 
    249225        const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z); 
    250         //const Vector3 schas = lightSpace * mCamera->GetPosition(); 
    251         //const Vector3 startPt = Vector3(schas.x, schas.y, bounds_ls.Max().z); 
    252  
    253         cout << "mx: " <<  bounds_ls.Max() << endl; 
    254         cout << "mn: " << bounds_ls.Min() << endl; 
    255  
     226         
    256227        // the new projection center 
    257228        const Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
    258229 
    259         cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 
    260  
    261         dummyPt = startPt; 
    262  
    263230        //construct a translation that moves to the projection center 
    264231        const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter); 
     
    270237        const float dx = fabs(bounds_ls.Max()[0] - bounds_ls.Min()[0]); 
    271238 
    272         cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl; 
    273  
    274239         
    275240 
     
    281246        matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d); 
    282247 
    283         //cout << "lispsm\n" << matLispSM << endl; 
    284  
    285248        // translate to the projection center 
    286249        matLispSM = projectionCenter * matLispSM; 
    287  
    288         //cout << "new\n" << matLispSM << endl; 
    289250 
    290251        // transform into OpenGL right handed system 
     
    314275                Vector3 pt = *it; 
    315276                Vector3 ptE = eyeView * pt; 
    316 //cout<<"i"<< pt.z; 
     277                 
    317278                if (ptE.z > 0) cerr <<"should not happen " << ptE.z << endl; 
    318279                else 
     
    376337        Vector3 projDir(b_lp - e_lp); 
    377338 
    378         Matrix4x4 dummy = Invert(lightSpace); 
    379         Invert(dummy); 
    380         Vector3 dummyVec = dummy * e_lp; 
    381         Vector3 dummyVec2 = dummy * b_lp; 
    382  
    383         //projDir.z = -projDir.z; 
    384  
    385         cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl; 
    386339        //project the view direction into the shadow map plane 
    387340        projDir.y = .0f; 
    388341 
    389342        return Normalize(projDir); 
    390         //return projDir; 
    391343} 
    392344 
     
    435387        const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints); 
    436388 
    437         cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl; 
    438                                                                  
    439389        //do Light Space Perspective shadow mapping 
    440390        //rotate the lightspace so that the projected light view always points upwards 
     
    444394        const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y()); 
    445395 
    446         cout << "frame\n " << frame << endl; 
    447396        lightProj *= frame; 
    448397 
     
    464413        AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints); 
    465414 
    466         cout << "max: " << lightPts.Max() << " min: " << lightPts.Min() << endl; 
    467415        // focus projection matrix on the extremal points => scale to unit cube 
    468416        Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts); 
    469417 
    470         cout << "scaleTranslate:\n" << scaleTranslate << endl; 
    471  
    472418        lightProj = lightProj * scaleTranslate; 
    473419 
     
    475421 
    476422        AxisAlignedBox3 lightPtsNew = GetExtremalPoints(mymat, frustumPoints); 
    477  
    478         cout << "newmax: " << lightPtsNew.Max() << endl; 
    479         cout << "newmin: " << lightPtsNew.Min() << endl; 
    480423 
    481424        // we have to flip the signs in order to tranform to opengl right handed system 
     
    578521 
    579522        glDisable(GL_LIGHTING); 
    580         glDisable(GL_TEXTURE_2D); 
     523        //glDisable(GL_TEXTURE_2D); 
    581524        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    582525 
     
    602545        glPopAttrib(); 
    603546         
     547        glShadeModel(GL_SMOOTH); 
    604548        glEnable(GL_LIGHTING); 
    605549        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     
    623567{ 
    624568        glEnable(GL_LIGHTING); 
    625         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    626  
     569         
    627570        _Render(renderer); 
    628571         
     572        /*glDisable(GL_LIGHTING); 
     573        glDisable(GL_DEPTH_TEST); 
     574 
     575        //glLineWidth(2); 
     576        Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 
     577        DrawPoly(hpoly, Vector3(1, 1, 1)); 
     578 
     579        DEL_PTR(hpoly); 
     580 
     581        glEnable(GL_LIGHTING); 
     582        glEnable(GL_DEPTH_TEST);*/ 
     583 
    629584        glDisable(GL_POLYGON_OFFSET_FILL); 
    630         glDisable(GL_LIGHTING); 
    631585} 
    632586 
     
    637591        //const Vector3 dir(0, 0, -1); 
    638592 
    639         cout << "dir: " << dir << endl; 
    640593        mShadowCam->SetDirection(dir); 
    641594 
     
    664617 
    665618        mLightProjView = lightView * lightProj; 
    666         dummyMat = mLightProjView; 
    667619 
    668620        DEL_PTR(lightPoly); 
     
    682634        renderer->RenderScene(); 
    683635 
     636 
    684637        glMatrixMode(GL_MODELVIEW); 
    685638        glPopMatrix(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2942 r2943  
    8787        Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; 
    8888 
    89         static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2); 
    9089 
    9190        /** Internal shador render method. 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2942 r2943  
    100100static int winHeight = 768; 
    101101 
    102 const float shadowSize = 4096; 
     102//const float shadowSize = 4096; 
     103const float shadowSize = 2048; 
    103104 
    104105static float winAspectRatio = 1.0f; 
     
    922923 
    923924                // the scene is rendered withouth any shading    
     925                glShadeModel(GL_FLAT); 
     926         
    924927                glDisable(GL_LIGHTING); 
    925928         
     
    934937                { 
    935938                        shadowChanged = false; 
     939 
     940                        //glEnable(GL_MULTISAMPLE_ARB); 
    936941 
    937942                        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     
    944949                        BvhNode::SetCurrentState(1); 
    945950 
     951                        state.SetUseAlphaToCoverage(false); 
     952 
    946953                        // the scene is rendered withouth any shading    
    947954                        shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 
     955 
     956                        state.SetUseAlphaToCoverage(true); 
    948957 
    949958                        // change back state 
     
    10251034        { 
    10261035                glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     1036                glShadeModel(GL_SMOOTH); 
     1037 
    10271038                RenderVisibleObjects(); 
    10281039        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2942 r2943  
    137137        if (amb < 0.9f) // hack: prevent shadowing the sky       
    138138        { 
    139                 const float x = 0.1f; 
     139                // base lighting 
     140                const float x = 0.4f; 
    140141                OUT.color *= x + (1.0f - x) * (1.0f - d); 
    141142        } 
Note: See TracChangeset for help on using the changeset viewer.