Changeset 2951


Ignore:
Timestamp:
09/16/08 12:38:36 (16 years ago)
Author:
mattausch
Message:

strted to implement animation

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r2946 r2951  
    268268                        </File> 
    269269                        <File 
     270                                RelativePath=".\src\MotionPath.cpp" 
     271                                > 
     272                        </File> 
     273                        <File 
     274                                RelativePath=".\src\MotionPath.h" 
     275                                > 
     276                        </File> 
     277                        <File 
    270278                                RelativePath=".\src\PerformanceGraph.cpp" 
    271279                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp

    r2947 r2951  
    33#include "Polygon3.h" 
    44#include "Polyhedron.h" 
     5#include "Triangle3.h" 
    56 
    67#include <cassert> 
     
    14001401} 
    14011402 
    1402 } 
    1403  
     1403 
     1404void AxisAlignedBox3::Triangulate(std::vector<Triangle3> &triangles) const 
     1405{ 
     1406        Triangle3 tri; 
     1407 
     1408        tri.mVertices[0] = Vector3(mMin.x, mMax.y ,mMin.z); 
     1409        tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 
     1410        tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z); 
     1411 
     1412        triangles.push_back(tri); 
     1413 
     1414    tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 
     1415        tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 
     1416        tri.mVertices[2] = Vector3(mMin.x, mMax.y ,mMin.z); 
     1417 
     1418        triangles.push_back(tri); 
     1419 
     1420        ////////////////////////////////////// 
     1421 
     1422    tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 
     1423    tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 
     1424        tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z); 
     1425 
     1426        triangles.push_back(tri); 
     1427 
     1428        tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z); 
     1429        tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 
     1430    tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 
     1431 
     1432        triangles.push_back(tri); 
     1433 
     1434 
     1435        ////////////////////////////////////// 
     1436 
     1437        tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 
     1438        tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 
     1439    tri.mVertices[2] = Vector3(mMax.x, mMin.y ,mMin.z); 
     1440 
     1441        triangles.push_back(tri); 
     1442 
     1443    tri.mVertices[0] = Vector3(mMax.x, mMin.y ,mMin.z); 
     1444        tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 
     1445        tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z);      
     1446 
     1447        triangles.push_back(tri); 
     1448 
     1449 
     1450        ////////////////////////////////////// 
     1451 
     1452        tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 
     1453        tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 
     1454        tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z); 
     1455 
     1456        triangles.push_back(tri); 
     1457 
     1458        tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z); 
     1459        tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 
     1460        tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 
     1461     
     1462        triangles.push_back(tri); 
     1463 
     1464 
     1465        ////////////////////////////////////// 
     1466 
     1467    tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z); 
     1468        tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z); 
     1469        tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z); 
     1470            
     1471        triangles.push_back(tri); 
     1472 
     1473        tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z); 
     1474        tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z); 
     1475    tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z); 
     1476            
     1477        triangles.push_back(tri); 
     1478 
     1479 
     1480        ////////////////////////////////////// 
     1481 
     1482    tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z); 
     1483        tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z); 
     1484    tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z); 
     1485 
     1486        triangles.push_back(tri); 
     1487 
     1488    tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z); 
     1489    tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z); 
     1490    tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z); 
     1491            
     1492        triangles.push_back(tri); 
     1493} 
     1494 
     1495 
     1496} 
     1497 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h

    r2947 r2951  
    149149 
    150150        // Six faces are distuinguished by their name. 
    151         enum EFaces {ID_Back = 0,  
    152                 ID_Left = 1,  
    153                 ID_Bottom = 2,  
    154                 ID_Front = 3, 
    155                 ID_Right = 4,  
    156                 ID_Top = 5}; 
     151        enum EFaces {ID_Back = 0, 
     152                                 ID_Left = 1,  
     153                                 ID_Bottom = 2,  
     154                                 ID_Front = 3, 
     155                                 ID_Right = 4,  
     156                                 ID_Top = 5}; 
    157157 
    158158        // Writes a brief description of the object, indenting by the given 
     
    217217        */ 
    218218        void ExtractPolygons(PolygonContainer &polys) const; 
     219        /** Returns triangle representation of this box. 
     220        */ 
     221        void Triangulate(std::vector<Triangle3> &triangles) const; 
     222 
    219223 
    220224 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2947 r2951  
    290290                } 
    291291                else 
    292                 { 
     292                {  
    293293                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
    294294 
     
    300300 
    301301 
    302 SceneEntity **Bvh::GetGeometry(BvhNode *node, int &geometrySize) 
     302SceneEntity **Bvh::GetGeometry(BvhNode *node, int &geometrySize) const 
    303303{ 
    304304        geometrySize = node->CountPrimitives(); 
     
    398398{ 
    399399        return node->GetBox().GetMaxDistance(sNearPlane); 
     400 
     401        float maxDist = .0f; 
     402 
     403        int geometrySize; 
     404        SceneEntity **entities = GetGeometry(node, geometrySize); 
     405 
     406        for (int i = 0; i < geometrySize; ++ i) 
     407        { 
     408                SceneEntity *ent = entities[i]; 
     409                float dist = ent->GetTransformedBoundingBox().GetMaxDistance(sNearPlane); 
     410 
     411                if (dist > maxDist) maxDist = dist; 
     412        } 
     413 
     414        return maxDist; 
    400415} 
    401416 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2947 r2951  
    492492        /** Returns geometry by reference (faster). 
    493493        */ 
    494         SceneEntity **GetGeometry(BvhNode *node, int &size); 
     494        SceneEntity **GetGeometry(BvhNode *node, int &size) const; 
    495495 
    496496 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h

    r2842 r2951  
    2020public: 
    2121        /** Constructor taking an array of triangles. 
     22                If delData is true, the vertex / normal / texture is deleted when 
     23                after it was transferred into a vbo 
    2224        */ 
    2325        Geometry(Vector3 *vertices,  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2947 r2951  
    120120 
    121121                        // store the visible entities for rendering in the second pass 
    122                         if (mUseDepthPass) 
    123                                 mVisibleObjects.push_back(ent); 
     122                        if (mUseDepthPass) mVisibleObjects.push_back(ent); 
    124123                } 
    125124 
     
    148147{ 
    149148        mVisibleObjects.clear(); 
     149        mMaxVisibleDistance = .0f; 
    150150 
    151151        glEnableClientState(GL_VERTEX_ARRAY); 
    152          
    153         if (!mUseDepthPass) 
    154                 glEnableClientState(GL_NORMAL_ARRAY); 
     152        if (!mUseDepthPass) glEnableClientState(GL_NORMAL_ARRAY); 
    155153 
    156154        ++ mFrameId; 
     
    160158        mStats.Reset(); 
    161159        mQueryHandler.ResetQueries(); 
    162          
     160        // add root node to queue 
    163161        EnqueueNode(mBvh->GetRoot()); 
    164162 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2947 r2951  
    190190        /// the objects found visible in current frame 
    191191        SceneEntityContainer mVisibleObjects; 
    192  
    193192        /// the maximal visible distance in the scene 
    194193        float mMaxVisibleDistance; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp

    r2946 r2951  
    11#include "SceneEntityConverter.h" 
     2#include "SceneEntity.h" 
     3#include "Geometry.h" 
     4#include "Shape.h" 
    25 
    36 
     
    710namespace CHCDemoEngine  
    811{ 
     12 
     13SceneEntity *SceneEntityConverter::ConvertBox(const AxisAlignedBox3 &box,  
     14                                                                                          Material *mat,  
     15                                                                                          Transform3 *trafo) 
     16{ 
     17        SceneEntity *ent = new SceneEntity(trafo); 
     18 
     19        vector<Triangle3> triangles; 
     20 
     21        box.Triangulate(triangles); 
     22 
     23        Vector3 *vertices = new Vector3[12]; 
     24        Vector3 *normals = new Vector3[12]; 
     25 
     26        for (size_t i = 0; i < triangles.size(); ++ i) 
     27        { 
     28                Triangle3 tri = triangles[i]; 
     29 
     30                vertices[i * 3 + 0] = tri.mVertices[0]; 
     31                vertices[i * 3 + 1] = tri.mVertices[1]; 
     32                vertices[i * 3 + 2] = tri.mVertices[2]; 
     33 
     34                Vector3 normal = tri.GetNormal(); 
     35 
     36                normals[i * 3 + 0] = normal; 
     37                normals[i * 3 + 1] = normal; 
     38                normals[i * 3 + 2] = normal; 
     39        } 
     40 
     41 
     42        Geometry *geom = new Geometry(vertices, normals, NULL, 12, true); 
     43 
     44        Shape *shape = new Shape(geom, mat, ent); 
     45        ent->AddShape(shape); 
     46 
     47        return ent; 
    948} 
     49 
     50 
     51} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2947 r2951  
    590590 
    591591        glDisable(GL_LIGHTING); 
    592         //glDisable(GL_TEXTURE_2D); 
    593592        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    594593 
     
    658657{ 
    659658        const Vector3 dir = mLight->GetDirection(); 
    660         //const Vector3 dir(0, 0, -1); 
    661659 
    662660        mShadowCam->SetDirection(dir); 
     
    692690        glMatrixMode(GL_MODELVIEW); 
    693691        glPushMatrix(); 
    694         glLoadIdentity(); 
    695  
    696         //glDisable(GL_CULL_FACE); 
     692         
    697693        mShadowCam->SetupCameraView(); 
    698694 
     
    704700 
    705701 
     702 
     703        glMatrixMode(GL_PROJECTION); 
     704        glPopMatrix(); 
     705 
    706706        glMatrixMode(GL_MODELVIEW); 
    707707        glPopMatrix(); 
    708708 
    709         glMatrixMode(GL_PROJECTION); 
    710         glPopMatrix(); 
    711  
    712709         
    713710        glDisable(GL_POLYGON_OFFSET_FILL); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r2950 r2951  
    2828                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); 
    2929        } 
    30         else 
    31         { 
     30//      else 
     31//      { 
    3232                glPushMatrix(); 
    3333                glMultMatrixf((float *)mMatrix->x); 
    34         } 
     34//      } 
    3535} 
    3636 
     
    4545                cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 
    4646        } 
    47         else 
    48         { 
     47//      else 
     48//      { 
    4949                glPopMatrix(); 
    50         } 
     50//      } 
    5151} 
    5252 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2950 r2951  
    228228inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 
    229229inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 
     230 
    230231void InitFBO(); 
    231 void RenderShadowMap(); 
    232  
    233  
     232 
     233void RenderShadowMap(float newfar); 
    234234 
    235235 
     
    516516 
    517517                cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); 
    518                 //Debug << "maxdepth: " << MAX_DEPTH_CONST / myfar << endl; 
    519518        } 
    520519        else 
     
    557556 
    558557        // the diffuse color buffer 
    559         //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 
    560         fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
     558        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 
     559        //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    561560 
    562561        // the positions buffer 
    563562        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_MIPMAP_LINEAR, true); 
    564563        //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    565          
     564 
    566565        // the normals buffer 
    567         //fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    568566        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    569567 
     
    592590void InitGLstate()  
    593591{ 
    594         glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
     592        glClearColor(0.2f, 0.2f, 0.8f, 1.0f); 
    595593         
    596594        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     
    608606        glEnable(GL_NORMALIZE); 
    609607                 
    610         //glEnable(GL_ALPHA_TEST); 
    611608        glDisable(GL_ALPHA_TEST); 
    612         glAlphaFunc(GL_GEQUAL, 0.8f); 
     609        glAlphaFunc(GL_GEQUAL, 0.5f); 
    613610 
    614611        glFrontFace(GL_CCW); 
     
    616613        glEnable(GL_CULL_FACE); 
    617614 
    618         //glDisable(GL_CULL_FACE); 
    619615        glDisable(GL_TEXTURE_2D); 
    620616 
     
    810806 
    811807        glMatrixMode(GL_MODELVIEW); 
    812         glLoadIdentity(); 
    813  
     808         
    814809        // set up the camera view 
    815810        camera->SetupCameraView(); 
     
    877872        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    878873        cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 
     874 
     875        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    879876} 
    880877 
     
    919916        } 
    920917 
     918         
     919        // bring eye modelview matrix up-to-date 
     920        SetupEyeView(); 
     921 
    921922        // hack 
    922923        int oldRenderType = renderType; 
     
    957958                cgGLDisableProfile(RenderState::sCgVertexProfile); 
    958959 
    959                 glClear(GL_DEPTH_BUFFER_BIT); 
    960                 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     960                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    961961 
    962962                // the scene is rendered withouth any shading    
     
    988988 
    989989                if (showShadowMap && !renderLightView) 
    990                         RenderShadowMap(); 
    991                  
     990                        RenderShadowMap(camera->GetFar()); 
     991 
    992992                //glPushAttrib(GL_VIEWPORT_BIT); 
    993993                glViewport(0, 0, texWidth, texHeight); 
    994994 
    995995                InitDeferredRendering(); 
     996                 
    996997                // draw to 3 color buffers 
    997998                glDrawBuffers(3, mrt); 
    998  
    999                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1000999 
    10011000                break; 
     
    10111010        // reset lod levels for current frame 
    10121011        LODLevel::InitFrame(camera->GetPosition()); 
    1013  
    1014  
    1015         // bring eye modelview matrix up-to-date 
    1016         SetupEyeView(); 
    10171012 
    10181013        // set up lights 
     
    13621357 
    13631358                renderType = (renderType + 1) % RenderState::NUM_RENDER_TYPES; 
    1364                 traverser->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS_DEFERRED)); 
     1359                traverser->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS_DEFERRED)); 
    13651360                 
    13661361                break; 
    13671362        case GLUT_KEY_F8: 
    1368  
    13691363                useAdvancedShading = !useAdvancedShading; 
    1370                 //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2); 
    13711364 
    13721365                break; 
     
    18991892        { 
    19001893                if (showShadowMap && !renderLightView) 
    1901                         RenderShadowMap(); 
     1894                { 
     1895                        float minVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 
     1896                        RenderShadowMap(minVisibleDist); 
     1897                        //cout << "far: " << camera->GetFar() << " min: " << traverser->GetMaxVisibleDistance() << endl; 
     1898                } 
     1899                glEnableClientState(GL_VERTEX_ARRAY); 
     1900                glEnableClientState(GL_NORMAL_ARRAY); 
    19021901 
    19031902                glDisable(GL_LIGHTING); 
    19041903                glViewport(0, 0, texWidth, texHeight); 
     1904 
    19051905                InitDeferredRendering(); 
    19061906 
    19071907                // draw to 3 color buffers 
    19081908                glDrawBuffers(3, mrt); 
     1909                glClear(GL_COLOR_BUFFER_BIT); 
    19091910        } 
    19101911        else 
     
    19121913                glShadeModel(GL_SMOOTH); 
    19131914                glEnable(GL_LIGHTING); 
     1915 
    19141916                state.SetRenderType(RenderState::FIXED); 
    19151917        } 
     
    19211923        state.SetUseAlphaToCoverage(true); 
    19221924        state.Reset(); 
    1923          
    1924          
     1925 
    19251926        //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 
    19261927 
     
    19361937 
    19371938        glDepthFunc(GL_LESS); 
    1938         state.SetUseAlphaToCoverage(true); 
    19391939 
    19401940        PrintGLerror("visibleobjects"); 
     
    19561956 
    19571957 
    1958 void RenderShadowMap() 
     1958void RenderShadowMap(float newfar) 
    19591959{ 
    19601960        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     
    19691969 
    19701970        // hack: temporarily change camera far plane 
    1971         //camera->SetFar(0.2f * Magnitude(bvh->GetBox().Diagonal())); 
     1971        camera->SetFar(newfar); 
    19721972 
    19731973        // the scene is rendered withouth any shading    
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2949 r2951  
    3434 
    3535        float4 mypos: TEXCOORD3; 
    36         //float DEPTH; 
    3736}; 
    3837 
     
    4544}; 
    4645 
     46#pragma position_invariant vtx 
    4747 
    4848vtxout vtx(vtxin IN,  
     
    5959 
    6060   // transform the vertex position into eye space 
    61    OUT.position = mul(ModelViewProj, OUT.worldPos); 
     61   //OUT.position = mul(ModelViewProj, OUT.worldPos); 
     62   OUT.position = mul(glstate.matrix.mvp, IN.position); 
    6263 
    6364   OUT.normal = IN.normal; 
    6465 
    6566   OUT.mypos = OUT.position; 
     67 
    6668   return OUT; 
    6769} 
     
    7981        pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy); 
    8082         
    81         // save world position in second rt 
     83        // save world position in second render target 
    8284        pix.pos = IN.worldPos * maxDepth; 
    8385        // save normal in third rt 
    84         //pix.norm.xyz = IN.normal * 0.5f + 0.5f; 
    8586        pix.norm.xyz = IN.normal; 
    8687 
Note: See TracChangeset for help on using the changeset viewer.