Changeset 3059
- Timestamp:
- 10/21/08 20:41:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3012 r3059 70 70 if (indices.size() > 2) 71 71 { 72 #if 072 #if 1 73 73 int idx1 = 0; 74 74 int idx2 = (int)indices.size() - 2; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r3053 r3059 155 155 */ 156 156 inline int CountPrimitives() const; 157 157 /** This is an imporantent function once you have one or more 158 view point changes within a frame (e.g., camera view and shadow view for 159 shadow mapping), because each camera needs its own state in 160 order to not break temporal coherency. 161 */ 158 162 static void SetCurrentState(int _state) { sCurrentState = _state; } 159 163 … … 170 174 171 175 ////////////// 172 //-- members that define the current state 176 //-- members that define the current state. There is one state for each camera 177 178 /// the currently used state 179 static int sCurrentState; 173 180 174 181 /// stores the visibility related info 175 182 VisibilityInfo mVisibility[NUM_STATES]; 176 183 177 /// used for view frustum culling 184 // members used to speed up view frustum culling 185 /// masks out planes of the frustum that do not have to be tested against 178 186 int mPlaneMask[NUM_STATES]; 187 /// the plane that is usually responsible for culling this node. 188 /** if our educated guess was right, we save up to 5 comparisons. 189 */ 179 190 int mPreferredPlane[NUM_STATES]; 180 181 191 /// when the node was last rendered 182 192 int mLastRenderedFrame[NUM_STATES]; 183 184 185 // the current state186 static int sCurrentState;187 188 193 189 194 //////////////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3057 r3059 75 75 Bvh *bvh = NULL; 76 76 /// handles scene loading 77 ResourceManager * loader = NULL;77 ResourceManager *resourceManager = NULL; 78 78 /// handles scene loading 79 79 ShaderManager *shaderManager = NULL; … … 121 121 int renderMethod = RENDER_FORWARD; 122 122 123 static int winWidth = 1024; 124 static int winHeight = 768; 125 static float winAspectRatio = 1.0f; 123 126 124 127 /// these values get scaled with the frame rate … … 127 130 128 131 /// elapsed time in milliseconds 129 double elapsedTime = 1000.0f; 130 double algTime = 1000.0f; 131 132 static int winWidth = 1024; 133 static int winHeight = 768; 132 double elapsedTime = 1000.0; 133 double algTime = 1000.0; 134 double accumulatedTime = 1000.0; 135 float fps = 1e3f; 134 136 135 137 int shadowSize = 2048; 136 138 137 static float winAspectRatio = 1.0f; 138 139 double accumulatedTime = 1000; 140 float fps = 1e3f; 141 139 /// the hud font 142 140 glfont::GLFont myfont; 143 141 … … 157 155 int numBatches = 0; 158 156 159 160 157 // mouse navigation state 161 158 int xEyeBegin = 0; … … 200 197 201 198 PerfTimer frameTimer, algTimer; 202 199 /// the performance window 203 200 PerformanceGraph *perfGraph = NULL; 204 201 … … 217 214 DeferredRenderer *ssaoShader = NULL; 218 215 219 SceneEntity *cube = NULL;220 SceneEntity * aeroplane= NULL;216 //SceneEntity *cube = NULL; 217 SceneEntity *buddha = NULL; 221 218 SceneEntity *skyDome = NULL; 222 219 223 220 224 225 // function forward declarations 221 //////////////////// 222 //--- function forward declarations 223 226 224 void InitExtensions(); 225 void InitGLstate(); 226 227 227 void DisplayVisualization(); 228 void InitGLstate(); 229 void InitRenderTexture(); 228 /// destroys all allocated resources 230 229 void CleanUp(); 231 230 void SetupEyeView(); 232 void UpdateEyeMtx();233 231 void SetupLighting(); 234 232 void DisplayStats(); 235 void Output(int x, int y, const char *string); 233 /// draw the help screen 236 234 void DrawHelpMessage(); 235 /// render the sky dome 237 236 void RenderSky(); 237 /// render the objects found visible in the depth pass 238 238 void RenderVisibleObjects(); 239 239 240 240 void Begin2D(); 241 241 void End2D(); 242 /// the main loop 243 void MainLoop(); 244 242 245 void KeyBoard(unsigned char c, int x, int y); 243 void DrawStatistics();244 void Display();245 246 void Special(int c, int x, int y); 246 247 void KeyUp(unsigned char c, int x, int y); … … 251 252 void RightMotion(int x, int y); 252 253 void MiddleMotion(int x, int y); 253 void CalcDecimalPoint(string &str, int d);254 255 RenderTraverser *CreateTraverser(Camera *cam);256 257 254 void KeyHorizontalMotion(float shift); 258 255 void KeyVerticalMotion(float shift); 259 256 /// returns the string representation of a number with the decimal points 257 void CalcDecimalPoint(string &str, int d); 258 /// Creates the traversal method (vfc, stopandwait, chc, chc++) 259 RenderTraverser *CreateTraverser(Camera *cam); 260 261 /// place the viewer on the floor plane 260 262 void PlaceViewer(const Vector3 &oldPos); 263 // initialise the frame buffer objects 264 void InitFBO(); 265 /// changes the sunlight direction 266 void RightMotionLight(int x, int y); 267 /// render the shader map 268 void RenderShadowMap(float newfar); 269 /// function that touches each material once in order to accelarate render queue 270 void PrepareRenderQueue(); 271 /// loads the specified model 272 void LoadModel(const string &model); 261 273 262 274 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 263 275 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 264 // initialise the frame buffer objects 265 void InitFBO(); 266 267 void RightMotionLight(int x, int y); 268 269 void RenderShadowMap(float newfar); 270 271 276 277 // the new and the old viewProjection matrix of the current camera 272 278 static Matrix4x4 viewProjMat = IdentityMatrix(); 273 279 static Matrix4x4 oldViewProjMat = IdentityMatrix(); … … 291 297 { 292 298 #ifdef _CRT_SET 293 294 299 //Now just call this function at the start of your program and if you're 295 300 //compiling in debug mode (F5), any leaks will be displayed in the Output … … 399 404 } 400 405 401 glutDisplayFunc( Display);406 glutDisplayFunc(MainLoop); 402 407 glutKeyboardFunc(KeyBoard); 403 408 glutSpecialFunc(Special); 404 409 glutReshapeFunc(Reshape); 405 410 glutMouseFunc(Mouse); 406 glutIdleFunc( Display);411 glutIdleFunc(MainLoop); 407 412 glutKeyboardUpFunc(KeyUp); 408 413 glutSpecialUpFunc(SpecialKeyUp); … … 421 426 perfGraph = new PerformanceGraph(1000); 422 427 423 loader = ResourceManager::GetSingleton();428 resourceManager = ResourceManager::GetSingleton(); 424 429 shaderManager = ShaderManager::GetSingleton(); 425 430 426 const string filename = string(model_path + "city.dem"); 427 428 if (loader->Load(filename, sceneEntities)) 429 cout << "model " << filename << " loaded" << endl; 430 else 431 { 432 cerr << "loading model " << filename << " failed" << endl; 433 CleanUp(); 434 exit(0); 435 } 436 431 /////////// 432 //-- load the static scene geometry 433 434 LoadModel("city.dem"); 435 436 437 /////////// 438 //-- load the associated static bvh 437 439 438 440 const string bvh_filename = string(model_path + "city.bvh"); … … 447 449 } 448 450 451 /// set the depth of the bvh depending on the triangles per leaf node 452 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 453 449 454 // set far plane based on scene extent 450 455 farDist = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 451 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 452 453 camera->SetFar(Magnitude(bvh->GetBox().Diagonal())); 454 455 Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 456 457 Matrix4x4 transl = TranslationMatrix(cubeCenter); 458 459 string skyDomeStr(model_path + "sky.dem"); 460 461 if (loader->Load(skyDomeStr, sceneEntities)) 462 { 463 cout << "successfully loaded " << sceneEntities.size() << " scene entities" << endl; 464 } 465 else 466 { 467 cerr << "loading file " << skyDomeStr << " failed" << endl; 468 CleanUp(); 469 exit(0); 470 } 471 456 camera->SetFar(farDist); 457 458 459 ////////////////// 460 //-- setup the skydome model 461 462 LoadModel("sky.dem"); 472 463 skyDome = sceneEntities.back(); 473 464 465 /// the turbitity of the sky (from clear to hazy, use <3 for clear sky) 474 466 const float turbitiy = 5.0f; 475 467 preetham = new SkyPreetham(turbitiy, skyDome); 476 468 477 // initialize the render traverser 469 470 ////////// 471 //-- initialize the traversal algorithm 472 478 473 traverser = CreateTraverser(camera); 479 474 475 // the bird-eye visualization 480 476 visualization = new Visualization(bvh, camera, NULL, &state); 481 482 for (int i = 0; i < 3; ++ i) 483 { 484 state.SetRenderTechnique((RenderState::RenderTechnique)i); 485 486 // fill all shapes into the render queue once so we can establish the buckets 487 ShapeContainer::const_iterator sit, sit_end = (*loader->GetShapes()).end(); 488 489 for (sit = (*loader->GetShapes()).begin(); sit != sit_end; ++ sit) 490 { 491 renderQueue->Enqueue(*sit); 492 } 493 494 //renderQueue->Apply(); 495 // just clear queue again 496 renderQueue->Clear(); 497 } 498 477 478 479 LoadModel("hbuddha.dem"); 480 buddha = sceneEntities.back(); 481 482 Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 483 Matrix4x4 transl = TranslationMatrix(sceneCenter); 484 485 buddha->GetTransform()->SetMatrix(transl); 486 487 // this function assign the render queue bucket ids of the materials in beforehand 488 // => probably a little less overhead for new parts of the scene that are not yet assigned 489 PrepareRenderQueue(); 490 491 /// forward rendering is the default 499 492 state.SetRenderTechnique(RenderState::FORWARD); 500 493 501 494 // frame time is restarted every frame 502 495 frameTimer.Start(); 496 503 497 // the rendering loop 504 498 glutMainLoop(); 499 505 500 // clean up 506 501 CleanUp(); … … 709 704 } 710 705 711 706 /** Setup sunlight 707 */ 712 708 void SetupLighting() 713 709 { … … 773 769 // set up the camera view 774 770 camera->SetupCameraView(); 775 776 771 777 772 ///////////////// 773 //-- compute view projection matrix and store for later use 778 774 779 775 Matrix4x4 matViewing, matProjection; … … 782 778 camera->GetProjectionMatrix(matProjection); 783 779 784 // store matrix for later use785 780 viewProjMat = matViewing * matProjection; 786 781 } … … 810 805 811 806 812 static void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) 813 { 814 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 815 816 camera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 817 818 bl = Normalize(nbl - fbl); 819 br = Normalize(nbr - fbr); 820 tl = Normalize(ntl - ftl); 821 tr = Normalize(ntr - ftr); 822 } 823 824 807 /** Initialize the deferred rendering pass. 808 */ 825 809 void InitDeferredRendering() 826 810 { … … 856 840 857 841 858 // the main rendering loop 859 void Display() 842 /** the main rendering loop 843 */ 844 void MainLoop() 860 845 { 861 846 Vector3 oldPos = camera->GetPosition(); … … 896 881 // bring eye modelview matrix up-to-date 897 882 SetupEyeView(); 898 899 // set GPU related parameters 883 // set frame related parameters for GPU programs 900 884 GPUProgramParameters::InitFrame(camera, light); 901 885 902 903 // hack 886 // hack: store current rendering method and restore later 904 887 int oldRenderMethod = renderMethod; 905 888 // for rendering the light view, we use forward rendering … … 907 890 renderMethod = RenderState::FORWARD; 908 891 892 /// enable vbo vertex array 909 893 glEnableClientState(GL_VERTEX_ARRAY); 910 911 894 912 895 // render with the specified method (forward rendering, forward + depth, deferred) … … 980 963 981 964 glDepthFunc(GL_LESS); 982 983 965 glDisable(GL_TEXTURE_2D); 984 966 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 985 967 986 968 987 // reset lod levels for current frame969 // set proper lod levels for current frame using current eye point 988 970 LODLevel::InitFrame(camera->GetPosition()); 989 990 // set up lights 971 // set up sunlight 991 972 SetupLighting(); 992 973 … … 994 975 if (renderLightView) 995 976 { 996 // change CHC++ set of state variables (must be done for each change of camera because 997 // otherwise the temporal coherency is broken 977 // change CHC++ set of state variables: 978 // must be done for each change of camera because otherwise 979 // the temporal coherency is broken 998 980 BvhNode::SetCurrentState(LIGHT_PASS); 999 981 shadowMap->RenderShadowView(shadowTraverser, viewProjMat); … … 1661 1643 ShaderManager::DelSingleton(); 1662 1644 1663 loader = NULL;1645 resourceManager = NULL; 1664 1646 shaderManager = NULL; 1665 1647 } … … 1822 1804 int len = 10; 1823 1805 CalcDecimalPoint(objStr, renderedObjects, len); 1824 CalcDecimalPoint(totalObjStr, (int) loader->GetNumEntities(), len);1806 CalcDecimalPoint(totalObjStr, (int)resourceManager->GetNumEntities(), len); 1825 1807 1826 1808 CalcDecimalPoint(triStr, renderedTriangles, len); … … 1873 1855 void RenderSky() 1874 1856 { 1857 buddha->Render(&state); 1858 1875 1859 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 1876 1860 state.SetRenderTechnique(RenderState::DEFERRED); … … 1879 1863 ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 1880 1864 (renderMethod == RENDER_DEFERRED)) && useHDR; 1881 1865 1882 1866 preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping); 1883 1867 /// once again reset the state … … 1995 1979 BvhNode::SetCurrentState(CAMERA_PASS); 1996 1980 } 1981 1982 /** Toach each material once in order to preload the render queue 1983 bucket id of each material 1984 */ 1985 void PrepareRenderQueue() 1986 { 1987 for (int i = 0; i < 3; ++ i) 1988 { 1989 state.SetRenderTechnique((RenderState::RenderTechnique)i); 1990 1991 // fill all shapes into the render queue once so we can establish the buckets 1992 ShapeContainer::const_iterator sit, sit_end = (*resourceManager->GetShapes()).end(); 1993 1994 for (sit = (*resourceManager->GetShapes()).begin(); sit != sit_end; ++ sit) 1995 { 1996 renderQueue->Enqueue(*sit); 1997 } 1998 1999 // just clear queue again 2000 renderQueue->Clear(); 2001 } 2002 } 2003 2004 2005 void LoadModel(const string &model) 2006 { 2007 const string filename = string(model_path + model); 2008 2009 if (resourceManager->Load(filename, sceneEntities)) 2010 cout << "model " << filename << " loaded" << endl; 2011 else 2012 { 2013 cerr << "loading model " << filename << " failed" << endl; 2014 CleanUp(); 2015 exit(0); 2016 } 2017 }
Note: See TracChangeset
for help on using the changeset viewer.