- Timestamp:
- 10/24/08 16:39:24 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3066 r3068 419 419 if (!mDynamicEntities.empty()) 420 420 { 421 //UpdateDynamicBranch();421 UpdateDynamicBranch(); 422 422 } 423 423 } … … 427 427 { 428 428 // q: should we use distance to center rather than the distance to the near plane? 429 430 // because otherwise problems with big object penetrating the near plane 431 // (e.g., big objects in the distance which are then always visible) 432 // especially annoying is this problem when using the frustum 433 // fitting on the visible objects for shadow mapping 434 // on the other hand, distance to near plane can also be used 435 // for near plane intersection 436 node->mDistance = sNearPlane.Distance(node->GetBox().Center()); 437 //node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 429 // distance to near plane can also be used for checking near plane intersection 430 //node->mDistance = sNearPlane.Distance(node->GetBox().Center()); 431 node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 438 432 } 439 433 … … 441 435 float Bvh::CalcMaxDistance(BvhNode *node) const 442 436 { 437 #if 1 443 438 return node->GetBox().GetMaxDistance(sNearPlane); 444 439 440 #else 441 // use bounding boxes of geometry to determine max dist 445 442 float maxDist = .0f; 446 443 … … 457 454 458 455 return maxDist; 456 #endif 459 457 } 460 458 … … 932 930 933 931 mNumVirtualNodes = 0; 934 935 932 // assign new virtual leaves based on specified #triangles per leaf 936 933 std::stack<BvhNode *> nodeStack; 937 938 934 nodeStack.push(mRoot); 939 935 … … 1273 1269 void Bvh::UpdateDynamicBranch() 1274 1270 { 1275 BvhNode *dynamicRoot = static_cast<BvhInterior *>(mRoot)->mBack;1276 1277 1271 // delete old branch 1278 if (! dynamicRoot->IsLeaf())1272 if (!mDynamicRoot->IsLeaf()) 1279 1273 { 1280 1274 cout << "deleting old branch" << endl; 1281 1275 1282 DEL_PTR(dynamicRoot); 1283 1284 dynamicRoot = new BvhLeaf(mRoot); 1285 dynamicRoot->mBox = mRoot->mBox; 1276 DEL_PTR(mDynamicRoot); 1277 1278 mDynamicRoot = new BvhLeaf(mRoot); 1279 mDynamicRoot->mBox = mRoot->mBox; 1280 1281 mDynamicRoot->mFirst = 0; 1282 mDynamicRoot->mLast = 0; 1283 mDynamicRoot->mArea = mDynamicRoot->mBox.SurfaceArea(); 1286 1284 } 1287 1285 1288 1286 cout << "updating dynamic branch" << endl; 1289 1287 1290 dynamicRoot = SubdivideLeaf(static_cast<BvhLeaf *>(dynamicRoot), 0, mDynamicEntities);1288 mDynamicRoot = SubdivideLeaf(static_cast<BvhLeaf *>(mDynamicRoot), 0, mDynamicEntities); 1291 1289 1292 1290 cout << "finished updating dynamic branch" << endl; … … 1302 1300 bool Bvh::IntersectsNearPlane(BvhNode *node) const 1303 1301 { 1304 float distanceToNearPlane = node->GetBox().GetMinDistance(sNearPlane); 1302 // note: we have problems with large scale object penetrating the near plane 1303 // (e.g., objects in the distance which are always handled to be visible) 1304 // especially annoying is this problem when using the frustum 1305 // fitting on the visible objects for shadow mapping 1306 // but don't see how to solve this issue without using much costlier calculations 1307 1305 1308 // we stored the near plane distance => we can use it also here 1306 //float distanceToNearPlane = node->GetDistance(); 1307 1308 return distanceToNearPlane < sNear; 1309 } 1310 1311 1312 } 1309 float distanceToNearPlane = node->GetDistance(); 1310 //float distanceToNearPlane = node->GetBox().GetMinDistance(sNearPlane); 1311 1312 return (distanceToNearPlane < sNear); 1313 } 1314 1315 1316 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
r3065 r3068 76 76 BvhNode *root = LoadNextNode(stream, NULL); 77 77 78 #if 179 80 78 bvh->mRoot = root; 81 79 80 #if 0 81 82 //bvh->mRoot = bvh->mStaticRoot; 83 bvh->mNumNodes = 1; 84 82 85 #else 83 // copy root and set new one for dynamic objects 84 BvhInterior *newRoot = new BvhInterior(NULL); 86 // we are setting a new root node 87 // and adds one level of indirection to the bvh 88 // It allows us to use dynamic objects 89 90 // the new bvh has two main branches 91 // a static branch (the old root), and adynamic branch 92 // we create a 'dynamic' leaf which basically is a container 93 // for all dynamic objects underneath 94 95 // the bounding boxes of the dynamic tree must be updated 96 // once each frame in order to be able to incorporate 97 // the movements of the objects within 98 99 // create new root 100 /*BvhInterior *newRoot = new BvhInterior(NULL); 101 bvh->mRoot = newRoot; 102 103 // the separation is a purely logical one 104 // the bounding boxes of the child nodes are 105 // identical to those of the root node 106 107 newRoot->mBox = bvh->mStaticRoot->mBox; 108 newRoot->mArea = newRoot->mBox.SurfaceArea(); 109 110 newRoot->mFirst = bvh->mStaticRoot->mFirst; 111 newRoot->mLast = bvh->mStaticRoot->mLast; 112 113 // add static root on left subtree 114 newRoot->mFront = bvh->mStaticRoot; 115 bvh->mStaticRoot->mParent = newRoot; 116 */ 117 // create and add dynamic root 118 BvhLeaf *dynamicRoot = new BvhLeaf(NULL); 85 119 86 newRoot->mBox = root->mBox; 87 newRoot->mFirst = root->mFirst; 88 newRoot->mLast = root->mLast; 120 dynamicRoot->mFirst = 0; 121 dynamicRoot->mLast = 0; 89 122 90 // create 'dynamic' leaf which basically is a container 91 // for all dynamic objects 92 BvhLeaf *dynamicLeaf = new BvhLeaf(newRoot); 93 dynamicLeaf->mBox = root->mBox; 123 //dynamicRoot->mBox = bvh->mStaticRoot->mBox; 124 dynamicRoot->mBox = bvh->mRoot->mBox; 125 dynamicRoot->mArea = dynamicRoot->mBox.SurfaceArea(); 94 126 95 newRoot->mFront = root;96 root->mParent = newRoot;127 bvh->mDynamicRoot = dynamicRoot; 128 //newRoot->mBack = dynamicRoot; 97 129 98 newRoot->mBack = dynamicLeaf; 99 100 bvh->mRoot = newRoot; 130 bvh->mNumNodes = 1; 101 131 #endif 102 132 103 133 tQueue.push(bvh->mRoot); 104 bvh->mNumNodes = 1; 105 134 106 135 while(!tQueue.empty()) 107 136 { … … 139 168 //-- post process nodes 140 169 170 /// this function must be called once after creation 141 171 bvh->PostProcess(); 142 172 143 173 // set virtual leaves for specified number of triangles 144 174 bvh->SetVirtualLeaves(INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES); 145 175 /// update the numleaves parameter of the bvh nodes 146 176 bvh->UpdateNumLeaves(bvh->mRoot); 147 177 // compute unique ids -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3063 r3068 222 222 glDrawBuffers(1, mrt + index); 223 223 224 //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);225 224 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 226 225 227 glEnd();228 229 226 FrameBufferObject::Release(); 230 227 } 231 228 232 229 233 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam , float scaleFactor):230 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam): 234 231 mWidth(w), mHeight(h), 235 232 mCamera(cam), -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3062 r3068 30 30 public: 31 31 /** Constructor for a deferred shader taking the requested output image size, 32 the current camera, and a scaling factor. 33 34 The parameter scaleFactor must be reciprocal value of the 35 scale factor used for creating the world space position texture. It is used recover the 36 exact scene size that was scaled in order to improve floating point precision. 32 the current camera; 37 33 */ 38 DeferredRenderer(int w, int h, PerspectiveCamera *cam , float scaleFactor);34 DeferredRenderer(int w, int h, PerspectiveCamera *cam); 39 35 /** The algorithm renders the scene given an fbo consists of 1 color buffer, 40 36 1 position buffer, and 1 normal buffer. … … 59 55 enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT}; 60 56 enum SHADING_METHOD {DEFAULT, SSAO, GI}; 61 57 /** Set the samplig method for the indirect illumination 58 */ 62 59 void SetSamplingMethod(SAMPLING_METHOD s); 63 60 /** Set the shading method (SSAO, SSAO + color bleeding 61 */ 64 62 void SetShadingMethod(SHADING_METHOD s); 65 63 66 // hack: store the color buffer idx for the first flipflip-mrthere64 // hack: store the color buffer idx for the currently used flip flop-MRT here 67 65 // TODO matt: make this less hacky 68 66 static int colorBufferIdx; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r3065 r3068 96 96 void Material::Render(RenderState *state) 97 97 { 98 mTechniques[state->GetRenderTechnique()]->Render(state); 98 // set technique if available 99 int idx = min((int)mTechniques.size() - 1 , state->GetRenderTechnique()); 100 mTechniques[idx]->Render(state); 99 101 } 100 102 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3066 r3068 17 17 18 18 RenderState::RenderState(): 19 mRenderTechnique( FORWARD),19 mRenderTechnique(0), 20 20 mUseAlphaToCoverage(true), 21 21 mLockCullFaceEnabled(false), … … 320 320 321 321 322 void RenderState::SetRenderTechnique( RenderTechniquet)322 void RenderState::SetRenderTechnique(int t) 323 323 { 324 324 mRenderTechnique = t; … … 326 326 327 327 328 RenderState::RenderTechniqueRenderState::GetRenderTechnique() const328 int RenderState::GetRenderTechnique() const 329 329 { 330 330 return mRenderTechnique; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r3066 r3068 23 23 QUERY, 24 24 RENDER 25 };26 27 /// the used render technique28 enum RenderTechnique29 {30 FORWARD,31 DEFERRED,32 DEPTH_PASS33 25 }; 34 26 … … 59 51 */ 60 52 inline int GetCurrentVboId() const { return mCurrentVboId; } 61 /** Sets the render technique (foreward, depth pass, deferred) 53 /** Sets the index of the render technique that is used to render a material. 54 Initially we use foreward = 0, deferred = 1, depth pass = 1 62 55 */ 63 void SetRenderTechnique( RenderTechniquet);56 void SetRenderTechnique(int t); 64 57 /** See Set 65 58 */ 66 RenderTechniqueGetRenderTechnique() const;59 int GetRenderTechnique() const; 67 60 /** If alpha to coverage is instead of alpha testing 68 61 */ … … 87 80 int mCurrentVboId; 88 81 /// the current render technique 89 RenderTechniquemRenderTechnique;82 int mRenderTechnique; 90 83 91 84 bool mUseAlphaToCoverage; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3067 r3068 596 596 glViewport(0, 0, mSize, mSize); 597 597 598 glDisable(GL_LIGHTING); 599 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 598 // turn off colors + lighting (should be handled by the render state) 600 599 glShadeModel(GL_FLAT); 601 600 … … 607 606 608 607 glPopAttrib(); 609 610 608 glShadeModel(GL_SMOOTH); 611 glEnable(GL_LIGHTING);612 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);613 609 614 610 #if 0 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3067 r3068 62 62 63 63 64 /// the environment for the program parameter 64 65 static Environment env; 65 66 66 #define MAX_DEPTH_CONST 10.0f67 68 67 69 68 GLuint fontTex; 70 /// fbo69 /// the fbo used for MRT 71 70 FrameBufferObject *fbo = NULL; 72 71 /// the renderable scene geometry … … 91 90 int renderMode = RenderTraverser::CHCPLUSPLUS; 92 91 /// eye near plane distance 93 float nearDist = 0.2f;92 const float nearDist = 0.2f; 94 93 /// eye far plane distance 95 94 float farDist = 1e6f; 96 95 /// the field of view 97 float fov = 50.0f; 98 /// the pixel threshold where a node is still considered invisible 99 int threshold; 100 101 int assumedVisibleFrames = 10; 102 int maxBatchSize = 50; 103 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 96 const float fov = 50.0f; 97 104 98 SceneQuery *sceneQuery = NULL; 105 99 RenderQueue *renderQueue = NULL; 106 // traverses and renders the hierarchy100 /// traverses and renders the hierarchy 107 101 RenderTraverser *shadowTraverser = NULL; 108 102 /// the skylight + skydome model 109 103 SkyPreetham *preetham = NULL; 104 105 106 107 /// the technique used for rendering 108 enum RenderTechnique 109 { 110 FORWARD, 111 DEFERRED, 112 DEPTH_PASS 113 }; 110 114 111 115 … … 170 174 bool descendKeyPressed = false; 171 175 bool ascendKeyPressed = false; 172 173 176 bool altKeyPressed = false; 174 177 … … 207 210 208 211 209 #define CAMERA_PASS 0 210 #define LIGHT_PASS 1 212 ////////////// 213 //-- algorithm parameters 214 215 /// the pixel threshold where a node is still considered invisible 216 /// (should be zero for conservative visibility) 217 int threshold; 218 int assumedVisibleFrames = 10; 219 int maxBatchSize = 50; 220 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 221 222 ////////////// 223 224 enum {CAMERA_PASS = 0, LIGHT_PASS = 1}; 225 226 211 227 212 228 //DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; … … 495 511 496 512 /// forward rendering is the default 497 state.SetRenderTechnique( RenderState::FORWARD);513 state.SetRenderTechnique(FORWARD); 498 514 499 515 // frame time is restarted every frame … … 814 830 // multisampling does not work with deferred shading 815 831 glDisable(GL_MULTISAMPLE_ARB); 816 817 state.SetRenderTechnique(RenderState::DEFERRED); 818 819 shaderManager->EnableVertexProfile(); 820 shaderManager->EnableFragmentProfile(); 821 822 const Vector3 pos = camera->GetPosition(); 832 state.SetRenderTechnique(DEFERRED); 823 833 824 834 … … 887 897 int oldRenderMethod = renderMethod; 888 898 // for rendering the light view, we use forward rendering 889 if (renderLightView) renderMethod = RenderState::FORWARD;899 if (renderLightView) renderMethod = FORWARD; 890 900 891 901 /// enable vbo vertex array … … 899 909 glEnable(GL_MULTISAMPLE_ARB); 900 910 901 state.SetRenderTechnique( RenderState::FORWARD);911 state.SetRenderTechnique(FORWARD); 902 912 glEnable(GL_LIGHTING); 903 913 … … 913 923 state.SetUseAlphaToCoverage(false); 914 924 915 state.SetRenderTechnique( RenderState::DEPTH_PASS);925 state.SetRenderTechnique(DEPTH_PASS); 916 926 917 927 if (!fbo) InitFBO(); fbo->Bind(); … … 921 931 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 922 932 923 // the scene is rendered withouth any shading 933 // the scene is rendered withouth any shading 934 // (should be handled by render state) 924 935 glShadeModel(GL_FLAT); 925 glDisable(GL_LIGHTING);926 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);927 936 928 937 … … 933 942 glEnable(GL_MULTISAMPLE_ARB); 934 943 935 state.SetRenderTechnique( RenderState::DEPTH_PASS);944 state.SetRenderTechnique(DEPTH_PASS); 936 945 937 946 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 938 947 939 // the scene is rendered withouth any shading 948 // the scene is rendered withouth any shading 949 // (should be handled by render state) 940 950 glShadeModel(GL_FLAT); 941 glDisable(GL_LIGHTING); 942 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 943 951 944 952 945 953 break; … … 1014 1022 1015 1023 if (!ssaoShader) ssaoShader = 1016 new DeferredRenderer(texWidth, texHeight, camera , farDist / MAX_DEPTH_CONST);1024 new DeferredRenderer(texWidth, texHeight, camera); 1017 1025 1018 1026 DeferredRenderer::SHADING_METHOD shadingMethod; … … 1038 1046 1039 1047 1040 state.SetRenderTechnique( RenderState::FORWARD);1048 state.SetRenderTechnique(FORWARD); 1041 1049 state.Reset(); 1042 1050 … … 1855 1863 1856 1864 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 1857 state.SetRenderTechnique( RenderState::DEFERRED);1865 state.SetRenderTechnique(DEFERRED); 1858 1866 1859 1867 const bool useToneMapping = … … 1874 1882 if (showShadowMap && !renderLightView) 1875 1883 { 1876 state.Reset(); 1877 1878 float minVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 1879 RenderShadowMap(minVisibleDist); 1884 // usethe maximal visible distance to focus shadow map 1885 float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 1886 RenderShadowMap(maxVisibleDist); 1880 1887 } 1881 1888 1882 glViewport(0, 0, texWidth, texHeight); 1883 // rese the state before the final visible objects pass 1884 state.Reset(); 1889 //glViewport(0, 0, texWidth, texHeight); 1890 // initialize deferred rendering 1885 1891 InitDeferredRendering(); 1886 1892 } 1887 1893 else 1888 1894 { 1889 state.SetRenderTechnique(RenderState::FORWARD); 1890 // rese the state before the final visible objects pass 1891 state.Reset(); 1892 } 1895 state.SetRenderTechnique(FORWARD); 1896 } 1897 1898 ///////////////// 1899 //-- reset gl state before the final visible objects pass 1900 1901 state.Reset(); 1893 1902 1894 1903 glEnableClientState(GL_NORMAL_ARRAY); 1895 1904 /// switch back to smooth shading 1896 1905 glShadeModel(GL_SMOOTH); 1897 // draw all objects that have exactly the same depth as the current sample 1898 glDepthFunc(GL_LEQUAL); 1899 1900 //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1906 /// reset alpha to coverage flag 1901 1907 state.SetUseAlphaToCoverage(true); 1902 1908 // clear color 1903 1909 glClear(GL_COLOR_BUFFER_BIT); 1904 1910 1911 // draw only objects having exactly the same depth as the current sample 1912 glDepthFunc(GL_EQUAL); 1905 1913 1906 1914 //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 1907 1915 1908 SceneEntityContainer::const_iterator sit, 1916 SceneEntityContainer::const_iterator sit, 1909 1917 sit_end = traverser->GetVisibleObjects().end(); 1910 1918 … … 1913 1921 renderQueue->Enqueue(*sit); 1914 1922 } 1915 1923 /// now render out everything in one giant pass 1916 1924 renderQueue->Apply(); 1917 1925 1926 // switch back to standard depth func 1918 1927 glDepthFunc(GL_LESS); 1919 1928 state.Reset(); … … 1941 1950 void RenderShadowMap(float newfar) 1942 1951 { 1943 shaderManager->DisableVertexProfile();1944 shaderManager->DisableFragmentProfile();1945 1946 1952 glDisableClientState(GL_NORMAL_ARRAY); 1947 1948 state.SetRenderTechnique(RenderState::DEPTH_PASS); 1953 state.SetRenderTechnique(DEPTH_PASS); 1949 1954 1950 1955 // hack: disable cull face because of alpha textured balconies 1951 1956 glDisable(GL_CULL_FACE); 1952 1957 state.LockCullFaceEnabled(true); 1953 /// don't use alphatocoverage 1958 1959 /// don't use alpha to coverage for the depth map (problems with fbo rendering) 1954 1960 state.SetUseAlphaToCoverage(false); 1955 1961 … … 1974 1980 } 1975 1981 1982 1976 1983 /** Toach each material once in order to preload the render queue 1977 1984 bucket id of each material … … 1981 1988 for (int i = 0; i < 3; ++ i) 1982 1989 { 1983 state.SetRenderTechnique( (RenderState::RenderTechnique)i);1990 state.SetRenderTechnique(i); 1984 1991 1985 1992 // fill all shapes into the render queue once so we can establish the buckets
Note: See TracChangeset
for help on using the changeset viewer.