Changeset 3101
- Timestamp:
- 11/05/08 15:14:22 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3089 r3101 101 101 102 102 for (; sit != sit_end; ++ sit) 103 {104 103 (*sit)->Render(state); 105 }106 104 107 105 mTransform->Unload(state); … … 143 141 144 142 if (lodLevel == -1) 145 {146 143 lodLevel = GetCurrentLODLevel(); 147 }148 144 149 145 return mLODLevels[lodLevel].GetNumTriangles(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3089 r3101 6 6 #include "RenderTraverser.h" 7 7 #include "FrameBufferObject.h" 8 #include "RenderState.h" 8 9 9 10 #include <IL/il.h> … … 75 76 startil(); 76 77 77 ILstring filename = ILstring(" depth.tga");78 ILstring filename = ILstring("sceneQuery.tga"); 78 79 ilRegisterType(IL_FLOAT); 79 80 … … 100 101 101 102 SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, 102 RenderTraverser *renderer ):103 mSceneBox(sceneBox), mDepth(NULL) 103 RenderTraverser *renderer, RenderState *state): 104 mSceneBox(sceneBox), mDepth(NULL), mRenderState(state) 104 105 { 105 106 Prepare(renderer); … … 112 113 const int py = (mSceneBox.Max(1) - pt.y) * (texHeight - 1) / mSceneBox.Size(1); 113 114 114 float d = mDepth[px + py * texHeight];115 const float d = mDepth[px + py * texHeight]; 115 116 116 117 static float depth = d; 117 118 118 if (d > 0)119 if (d > .0f) 119 120 { 120 121 // temporal smoothing of depth values … … 136 137 cout << "Preparing scene queries" << endl; 137 138 138 const float xlen = mSceneBox.Size().x * 0.5f;139 const float ylen = mSceneBox.Size().y * 0.5f;139 const float xlen = mSceneBox.Size().x * .5f; 140 const float ylen = mSceneBox.Size().y * .5f; 140 141 141 142 PerspectiveCamera *orthoCam = new PerspectiveCamera(xlen / ylen); … … 165 166 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 166 167 168 // hack: disable cull face because of alpha textured balconies 167 169 glDisable(GL_CULL_FACE); 168 glEnable(GL_DEPTH_TEST); 170 mRenderState->LockCullFaceEnabled(true); 171 172 //glDisable(GL_CULL_FACE); 173 //glEnable(GL_DEPTH_TEST); 169 174 170 175 glMatrixMode(GL_MODELVIEW); … … 177 182 178 183 glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 184 //glOrtho(xlen, .0f, ylen, .0f, .0f, mSceneBox.Size().z); 179 185 180 186 glMatrixMode(GL_MODELVIEW); … … 190 196 glEnableClientState(GL_NORMAL_ARRAY); 191 197 198 // forward rendering 199 mRenderState->SetRenderTechnique(0); 200 192 201 renderer->RenderScene(); 193 202 … … 197 206 renderer->SetCamera(oldCam); 198 207 199 200 glEnable(GL_CULL_FACE);208 mRenderState->LockCullFaceEnabled(false); 209 //glEnable(GL_CULL_FACE); 201 210 202 211 glMatrixMode(GL_MODELVIEW); … … 211 220 212 221 GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 213 //ExportDepthBuffer(mDepth); PrintGLerror("grab");222 ExportDepthBuffer(mDepth); PrintGLerror("grab depth"); 214 223 215 224 DEL_PTR(fbo); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.h
r2848 r3101 10 10 11 11 class RenderTraverser; 12 class RenderState; 12 13 13 14 /** A simple class that computes the first intersection of a horizontal ray with … … 18 19 public: 19 20 20 SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *traverser); 21 SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *traverser, 22 RenderState *state); 21 23 22 24 ~SceneQuery() { DEL_ARRAY_PTR(mDepth); } … … 38 40 //unsigned char *mDepth; 39 41 float *mDepth; 42 43 RenderState *mRenderState; 40 44 }; 41 45 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3089 r3101 86 86 /// the visualization 87 87 Visualization *visualization = NULL; 88 /// the current render state89 RenderState state;88 /// the current render renderState 89 RenderState renderState; 90 90 /// the rendering algorithm 91 91 int renderMode = RenderTraverser::CHCPLUSPLUS; … … 162 162 int numBatches = 0; 163 163 164 // mouse navigation state164 // mouse navigation renderState 165 165 int xEyeBegin = 0; 166 166 int yEyeBegin = 0; … … 267 267 void SpecialKeyUp(int c, int x, int y); 268 268 void Reshape(int w, int h); 269 void Mouse(int button, int state, int x, int y);269 void Mouse(int button, int renderState, int x, int y); 270 270 void LeftMotion(int x, int y); 271 271 void RightMotion(int x, int y); … … 404 404 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1)); 405 405 // the render queue for material sorting 406 renderQueue = new RenderQueue(& state);406 renderQueue = new RenderQueue(&renderState); 407 407 408 408 glutInitWindowSize(winWidth, winHeight); … … 527 527 528 528 // the bird-eye visualization 529 visualization = new Visualization(bvh, camera, NULL, & state);529 visualization = new Visualization(bvh, camera, NULL, &renderState); 530 530 531 531 // this function assign the render queue bucket ids of the materials in beforehand … … 533 533 PrepareRenderQueue(); 534 534 /// forward rendering is the default 535 state.SetRenderTechnique(FORWARD);535 renderState.SetRenderTechnique(FORWARD); 536 536 // frame time is restarted every frame 537 537 frameTimer.Start(); … … 729 729 tr->SetHierarchy(bvh); 730 730 tr->SetRenderQueue(renderQueue); 731 tr->SetRenderState(& state);731 tr->SetRenderState(&renderState); 732 732 tr->SetUseOptimization(useOptimization); 733 733 tr->SetUseRenderQueue(useRenderQueue); … … 853 853 // multisampling does not work with deferred shading 854 854 glDisable(GL_MULTISAMPLE_ARB); 855 state.SetRenderTechnique(DEFERRED);855 renderState.SetRenderTechnique(DEFERRED); 856 856 857 857 … … 940 940 941 941 glEnable(GL_MULTISAMPLE_ARB); 942 state.SetRenderTechnique(FORWARD);942 renderState.SetRenderTechnique(FORWARD); 943 943 //glEnable(GL_LIGHTING); 944 944 … … 950 950 951 951 glDisable(GL_MULTISAMPLE_ARB); 952 state.SetUseAlphaToCoverage(false);953 state.SetRenderTechnique(DEPTH_PASS);952 renderState.SetUseAlphaToCoverage(false); 953 renderState.SetRenderTechnique(DEPTH_PASS); 954 954 955 955 if (!fbo) InitFBO(); fbo->Bind(); … … 960 960 961 961 // the scene is rendered withouth any shading 962 // (should be handled by render state)962 // (should be handled by render renderState) 963 963 glShadeModel(GL_FLAT); 964 964 break; … … 967 967 968 968 glEnable(GL_MULTISAMPLE_ARB); 969 state.SetRenderTechnique(DEPTH_PASS);969 renderState.SetRenderTechnique(DEPTH_PASS); 970 970 971 971 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 972 972 973 973 // the scene is rendered withouth any shading 974 // (should be handled by render state)974 // (should be handled by render renderState) 975 975 glShadeModel(GL_FLAT); 976 976 break; … … 1004 1004 if (renderLightView) 1005 1005 { 1006 // change CHC++ set of state variables:1006 // change CHC++ set of renderState variables: 1007 1007 // must be done for each change of camera because otherwise 1008 1008 // the temporal coherency is broken … … 1068 1068 1069 1069 1070 state.SetRenderTechnique(FORWARD);1071 state.Reset();1070 renderState.SetRenderTechnique(FORWARD); 1071 renderState.Reset(); 1072 1072 1073 1073 … … 1406 1406 1407 1407 1408 void Mouse(int button, int state, int x, int y)1409 { 1410 if ((button == GLUT_LEFT_BUTTON) && ( state == GLUT_DOWN))1408 void Mouse(int button, int renderState, int x, int y) 1409 { 1410 if ((button == GLUT_LEFT_BUTTON) && (renderState == GLUT_DOWN)) 1411 1411 { 1412 1412 xEyeBegin = x; … … 1415 1415 glutMotionFunc(LeftMotion); 1416 1416 } 1417 else if ((button == GLUT_RIGHT_BUTTON) && ( state == GLUT_DOWN))1417 else if ((button == GLUT_RIGHT_BUTTON) && (renderState == GLUT_DOWN)) 1418 1418 { 1419 1419 xEyeBegin = x; … … 1426 1426 glutMotionFunc(RightMotionLight); 1427 1427 } 1428 else if ((button == GLUT_MIDDLE_BUTTON) && ( state == GLUT_DOWN))1428 else if ((button == GLUT_MIDDLE_BUTTON) && (renderState == GLUT_DOWN)) 1429 1429 { 1430 1430 horizontalMotionBegin = x; … … 1808 1808 static char *renderMethodStr[] = 1809 1809 {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"}; 1810 1811 1810 sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", 1812 1811 useMultiQueries, useTightBounds, useRenderQueue); 1813 1814 1812 sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderMethodStr[renderMethod], useAdvancedShading); 1815 1816 1813 sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 1817 1818 1814 sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 1819 1815 assumedVisibleFrames, maxBatchSize); … … 1852 1848 sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d", 1853 1849 traversedNodes, frustumCulledNodes, queryCulledNodes); 1854 1855 sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d", 1850 sprintf(msg[i ++], "issued queries: %5d, renderState changes: %5d, render batches: %5d", 1856 1851 issuedQueries, stateChanges, numBatches); 1857 1852 … … 1884 1879 { 1885 1880 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 1886 state.SetRenderTechnique(DEFERRED);1881 renderState.SetRenderTechnique(DEFERRED); 1887 1882 1888 1883 const bool useToneMapping = … … 1890 1885 (renderMethod == RENDER_DEFERRED)) && useHDR; 1891 1886 1892 preetham->RenderSkyDome(-light->GetDirection(), camera, & state, !useToneMapping);1893 /// once again reset the state1894 state.Reset();1887 preetham->RenderSkyDome(-light->GetDirection(), camera, &renderState, !useToneMapping); 1888 /// once again reset the renderState 1889 renderState.Reset(); 1895 1890 } 1896 1891 … … 1914 1909 else 1915 1910 { 1916 state.SetRenderTechnique(FORWARD);1911 renderState.SetRenderTechnique(FORWARD); 1917 1912 } 1918 1913 1919 1914 ///////////////// 1920 //-- reset gl state before the final visible objects pass1921 1922 state.Reset();1915 //-- reset gl renderState before the final visible objects pass 1916 1917 renderState.Reset(); 1923 1918 1924 1919 glEnableClientState(GL_NORMAL_ARRAY); … … 1926 1921 glShadeModel(GL_SMOOTH); 1927 1922 /// reset alpha to coverage flag 1928 state.SetUseAlphaToCoverage(true);1923 renderState.SetUseAlphaToCoverage(true); 1929 1924 // clear color 1930 1925 glClear(GL_COLOR_BUFFER_BIT); … … 1947 1942 // switch back to standard depth func 1948 1943 glDepthFunc(GL_LESS); 1949 state.Reset();1944 renderState.Reset(); 1950 1945 1951 1946 PrintGLerror("visibleobjects"); … … 1956 1951 { 1957 1952 if (!sceneQuery) 1958 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 1953 { 1954 sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState); 1955 } 1959 1956 1960 1957 Vector3 playerPos = camera->GetPosition(); … … 1972 1969 { 1973 1970 glDisableClientState(GL_NORMAL_ARRAY); 1974 state.SetRenderTechnique(DEPTH_PASS);1971 renderState.SetRenderTechnique(DEPTH_PASS); 1975 1972 1976 1973 // hack: disable cull face because of alpha textured balconies 1977 1974 glDisable(GL_CULL_FACE); 1978 state.LockCullFaceEnabled(true);1975 renderState.LockCullFaceEnabled(true); 1979 1976 1980 1977 /// don't use alpha to coverage for the depth map (problems with fbo rendering) 1981 state.SetUseAlphaToCoverage(false);1982 1983 // change CHC++ set of state variables1978 renderState.SetUseAlphaToCoverage(false); 1979 1980 // change CHC++ set of renderState variables 1984 1981 // this must be done for each change of camera because 1985 1982 // otherwise the temporal coherency is broken … … 1993 1990 camera->SetFar(farDist); 1994 1991 1995 state.SetUseAlphaToCoverage(true);1996 state.LockCullFaceEnabled(false);1992 renderState.SetUseAlphaToCoverage(true); 1993 renderState.LockCullFaceEnabled(false); 1997 1994 1998 1995 glEnableClientState(GL_NORMAL_ARRAY); 1999 // change back state1996 // change back renderState 2000 1997 BvhNode::SetCurrentState(CAMERA_PASS); 2001 1998 } … … 2009 2006 for (int i = 0; i < 3; ++ i) 2010 2007 { 2011 state.SetRenderTechnique(i);2008 renderState.SetRenderTechnique(i); 2012 2009 2013 2010 // fill all shapes into the render queue once so we can establish the buckets -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3100 r3101 88 88 89 89 const float sampleEyeSpaceDepth = tex2Dlod(colors, float4(texCoord, 0, 0)).w; 90 //float3 viewVec = normalize(Interpol(texcoord, bl, br, tl, tr));90 91 91 const float3 viewVec = Interpol(texCoord, bl, br, tl, tr); 92 92 const float3 samplePos = -viewVec * sampleEyeSpaceDepth; … … 158 158 // fit from unit cube into 0 .. 1 159 159 const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 160 //const float2 oldTexCoords = texcoord0;160 161 161 162 162 // retrieve the sample from the last frame … … 166 166 167 167 // vector from eye pos to old sample 168 //const float3 viewVec = normalize(Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr));169 168 const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 170 //const float3 oldWorldPos = oldEyePos - oldEyeSpaceDepth * viewVec; 171 //const float3 oldWorldPos = - viewVec * eyeSpaceDepth; 172 //const float3 dummy14 = Interpol(texcoord0, bl, br, tl, tr); 173 174 // the euclidian world space distance 175 //const float depthDif = length(oldWorldPos - worldPos.xyz); 176 //const float depthDif = length(dummy14 - viewVec); 177 //const float projectedEyeSpaceDepth = length(worldPos + oldEyePos); 169 178 170 const float invlen = 1.0f / length(viewVec); 179 171 const float projectedEyeSpaceDepth = length(dummyPt) * invlen; 180 172 181 173 const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 182 //const float depthDif = length(oldEyePos); 183 174 184 175 float notValid = 0.5f; 185 176
Note: See TracChangeset
for help on using the changeset viewer.