Ignore:
Timestamp:
01/04/09 21:48:45 (15 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r3245 r3246  
    113113/// max depth where candidates for tighter bounds are searched 
    114114int maxDepthForTestingChildren = 3; 
    115  
     115/// use full resolution for ssao or half 
    116116bool ssaoUseFullResolution = false; 
    117117 
     
    140140 
    141141ViewCellsTree *viewCellsTree = NULL; 
     142ViewCell *viewCell = NULL; 
    142143 
    143144static int globalVisibleId = 0; 
    144145 
    145 ViewCell *viewCell = NULL; 
    146146 
    147147 
     
    255255bool useLenseFlare = true; 
    256256 
     257bool usePvs = false; 
     258 
     259 
    257260PerfTimer frameTimer, algTimer; 
    258261/// the performance graph window 
     
    263266static Matrix4x4 invTrafo = IdentityMatrix(); 
    264267 
     268float mouseMotion = 0.2f; 
     269 
    265270 
    266271////////////// 
    267 //-- algorithm parameters 
     272//-- chc++ algorithm parameters 
    268273 
    269274/// the pixel threshold where a node is still considered invisible  
     
    356361SceneQuery *GetOrCreateSceneQuery(); 
    357362 
    358 void RenderPvs(); 
     363void LoadPvs(); 
     364 
     365void LoadVisibilitySolution(); 
     366 
     367void RenderViewCell(); 
    359368 
    360369 
     
    419428                env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 
    420429                env.GetFloatParam(string("keyRotation"), keyRotation); 
     430                env.GetFloatParam(string("mouseMotion"), mouseMotion); 
    421431                env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor); 
    422432                env.GetFloatParam(string("turbitity"), turbitity); 
     
    443453                env.GetStringParam(string("filename"), filename); 
    444454                env.GetStringParam(string("visibilitySolution"), visibilitySolution); 
     455 
     456                env.GetBoolParam(string("usePvs"), usePvs); 
    445457 
    446458                //env.GetStringParam(string("modelPath"), model_path); 
     
    474486                cout << "stats filename: " << statsFilename << endl; 
    475487                cout << "filename: " << filename << endl; 
     488                cout << "use PVS: " << usePvs << endl; 
    476489                cout << "visibilitySolution: " << visibilitySolution << endl; 
    477490                 
     
    558571 
    559572        //LoadModel("fisch.dem", dynamicObjects); 
    560         LoadModel("hbuddha.dem", dynamicObjects); 
     573        //LoadModel("hbuddha.dem", dynamicObjects); 
    561574 
    562575        //LoadModel("venusm.dem", dynamicObjects); 
     
    568581        resourceManager->mUseSpecialColors = false; 
    569582 
     583        /* 
    570584        buddha = dynamicObjects.back(); 
    571585         
     
    594608                dynamicObjects.push_back(ent); 
    595609        } 
    596  
     610        */ 
    597611 
    598612/*      int cityEntities = LoadModel("vienna_full_hp.dem", dynamicObjects); 
     
    619633        /// set the depth of the bvh depending on the triangles per leaf node 
    620634        bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 
    621  
    622         /////////// 
    623         //-- load the visibility solution 
    624  
    625         const string vis_filename =  
    626                 string(model_path + visibilitySolution + ".vis"); 
    627  
    628         VisibilitySolutionLoader visLoader; 
    629  
    630         viewCellsTree = visLoader.Load(vis_filename, bvh); 
    631  
    632635 
    633636        // set far plane based on scene extent 
     
    753756void InitGLstate()  
    754757{ 
    755         glClearColor(0.4f, 0.4f, 0.4f, 1.0f); 
     758        glClearColor(0.4f, 0.4f, 0.4f, 1e20f); 
    756759         
    757760        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     
    10631066void MainLoop()  
    10641067{        
    1065         Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 
    1066         Vector3 buddhaPos = motionPath->GetCurrentPosition(); 
    1067         Matrix4x4 trafo = TranslationMatrix(buddhaPos); 
    1068          
    1069         buddha->GetTransform()->SetMatrix(trafo); 
    1070  
    1071 #if TODO 
    1072         /*for (int i = 0; i < 10; ++ i) 
    1073         { 
    1074                 SceneEntity *ent = dynamicObjects[i]; 
    1075                 Vector3 newPos = ent->GetWorldCenter(); 
    1076  
    1077                 if (GetOrCreateSceneQuery()->CalcIntersection(newPos)) 
     1068        if (buddha) 
     1069        { 
     1070                Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 
     1071                Vector3 buddhaPos = motionPath->GetCurrentPosition(); 
     1072                Matrix4x4 trafo = TranslationMatrix(buddhaPos); 
     1073 
     1074                buddha->GetTransform()->SetMatrix(trafo); 
     1075 
     1076#if TODO // drop objects on ground floor 
     1077                for (int i = 0; i < 10; ++ i) 
    10781078                { 
    1079                         Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter()); 
    1080                         ent->GetTransform()->SetMatrix(mat); 
     1079                        SceneEntity *ent = dynamicObjects[i]; 
     1080                        Vector3 newPos = ent->GetWorldCenter(); 
     1081 
     1082                        if (GetOrCreateSceneQuery()->CalcIntersection(newPos)) 
     1083                        { 
     1084                                Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter()); 
     1085                                ent->GetTransform()->SetMatrix(mat); 
     1086                        } 
    10811087                } 
    1082         }*/ 
    10831088#endif 
    10841089 
    10851090 
    1086         ///////////////////////// 
    1087         //-- update animations 
    1088  
    1089         //const float rotAngle = M_PI * 1e-3f; 
    1090         const float rotAngle = 1.0f * M_PI / 180.0f; 
    1091  
    1092         Matrix4x4 rotMatrix = RotationZMatrix(rotAngle); 
    1093         dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
    1094  
    1095         motionPath->Move(0.01f); 
    1096  
     1091                ///////////////////////// 
     1092                //-- update animations 
     1093 
     1094                //const float rotAngle = M_PI * 1e-3f; 
     1095                const float rotAngle = 1.0f * M_PI / 180.0f; 
     1096 
     1097                Matrix4x4 rotMatrix = RotationZMatrix(rotAngle); 
     1098                dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
     1099 
     1100                motionPath->Move(0.01f); 
     1101        } 
    10971102 
    10981103 
     
    11811186        glEnableClientState(GL_VERTEX_ARRAY); 
    11821187 
     1188        if (usePvs) 
     1189        { 
     1190                if (!viewCellsTree) LoadVisibilitySolution(); 
     1191                LoadPvs();       
     1192        } 
     1193 
    11831194        // render with the specified method (forward rendering, forward + depth, deferred) 
    11841195        switch (renderMethod) 
     
    12601271        else 
    12611272        { 
    1262                 RenderPvs(); 
    1263  
    12641273                // actually render the scene geometry using the specified algorithm 
    12651274                traverser->RenderScene(); 
     
    12831292        const int sunVisiblePixels = useLenseFlare  &&  useDeferred ? TestSunVisible() : 0; 
    12841293 
     1294         
    12851295 
    12861296        /////////////// 
     
    15741584                // make a snapshot of the current frame 
    15751585                makeSnapShot = true; 
     1586                break; 
     1587        case '.': 
     1588                // enable / disable view cells 
     1589                usePvs = !usePvs; 
     1590                if (!usePvs) SceneEntity::SetGlobalVisibleId(-1); 
    15761591                break; 
    15771592        default: 
     
    18291844        camera->Pitch(eyeXAngle); 
    18301845 
    1831         pos += horView * (yMotionBegin - y) * 0.2f; 
     1846        pos += horView * (yMotionBegin - y) * mouseMotion; 
    18321847         
    18331848        camera->SetPosition(pos); 
     
    18971912        rVec = rot * rVec; 
    18981913         
    1899         pos -= rVec * (x - horizontalMotionBegin) * 0.1f; 
    1900         pos[2] += (verticalMotionBegin - y) * 0.1f; 
     1914        pos -= rVec * (x - horizontalMotionBegin) * mouseMotion; 
     1915        pos[2] += (verticalMotionBegin - y) * mouseMotion; 
    19011916 
    19021917        camera->SetPosition(pos); 
     
    19601975void DisplayVisualization() 
    19611976{ 
     1977        // render current view cell 
     1978        if (usePvs) RenderViewCell(); 
     1979         
     1980        visualization->SetViewCell(usePvs ? viewCell : NULL); 
    19621981        visualization->SetFrameId(traverser->GetCurrentFrameId()); 
    1963         visualization->SetViewCell(viewCell); 
     1982         
    19641983 
    19651984        Begin2D(); 
     
    22292248                        sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d",  
    22302249                                        useMultiQueries, useTightBounds, useRenderQueue); 
    2231                         sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderMethodStr[renderMethod], useAdvancedShading); 
     2250                        sprintf(msg[i ++], "render technique: %s, use pvss: %d", renderMethodStr[renderMethod], usePvs); 
    22322251                        sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 
    22332252                        sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d",  
     
    22672286                        sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d", 
    22682287                                traversedNodes, frustumCulledNodes, queryCulledNodes); 
    2269                         sprintf(msg[i ++], "issued queries: %5d, renderState changes: %5d, render batches: %5d",  
     2288                        sprintf(msg[i ++], "issued queries: %5d, renderstate changes: %5d, render batches: %5d",  
    22702289                                issuedQueries, stateChanges, numBatches); 
    22712290 
     
    25312550        tech.Init(); 
    25322551 
    2533         //tech.SetLightingEnabled(false); 
    2534         //tech.SetDepthWriteEnabled(false); 
    2535  
    25362552        tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
    25372553        tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     
    25422558 
    25432559 
    2544 void RenderPvs() 
     2560void LoadPvs() 
    25452561{ 
    25462562        viewCell = viewCellsTree->GetViewCell(camera->GetPosition()); 
     
    25512567        { 
    25522568                SceneEntity *ent = viewCell->mPvs.GetEntry(i); 
    2553                 //ent->Render(&renderState); 
    25542569                ent->SetVisibleId(globalVisibleId); 
    25552570 
     
    25582573 
    25592574        SceneEntity::SetGlobalVisibleId(globalVisibleId ++); 
    2560  
     2575} 
     2576 
     2577 
     2578void LoadVisibilitySolution() 
     2579{ 
     2580        /////////// 
     2581        //-- load the visibility solution 
     2582 
     2583        const string vis_filename =  
     2584                string(model_path + visibilitySolution + ".vis"); 
     2585 
     2586        VisibilitySolutionLoader visLoader; 
     2587 
     2588        viewCellsTree = visLoader.Load(vis_filename, bvh); 
     2589} 
     2590 
     2591 
     2592void RenderViewCell() 
     2593{ 
    25612594        // render current view cell 
    25622595        static Technique vcTechnique = GetVizTechnique(); 
     
    25642597        vcTechnique.Render(&renderState); 
    25652598        Visualization::RenderBoxForViz(viewCell->GetBox()); 
    2566  
    2567         visualization->SetViewCell(viewCell); 
    2568  
    2569         //cout << "pvs: " << vc->mPvs.Size() << " triangles: " << numTriangles << endl; 
    2570 } 
     2599} 
Note: See TracChangeset for help on using the changeset viewer.