Changeset 2948 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 09/15/08 16:57:20 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r2943 r2948 28 28 FIXED, 29 29 DEPTH_PASS, 30 DEFERRED 30 DEFERRED, 31 DEPTH_PASS_DEFERRED, 32 NUM_RENDER_TYPES 31 33 }; 32 34 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r2946 r2948 35 35 bool Load(const std::string &filename, SceneEntityContainer &geometry); 36 36 37 int GetNumEntities() const { return (int)mSceneEntities.size(); } 38 37 39 protected: 38 40 … … 60 62 //////// 61 63 64 /// the scene entities 62 65 SceneEntityContainer mSceneEntities; 63 66 }; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
r2840 r2948 24 24 if (!mMatrix) return; 25 25 26 if ( state->GetRenderType() == RenderState::DEFERRED)26 if ((state->GetRenderType() == RenderState::DEFERRED) || (state->GetRenderType() == RenderState::DEPTH_PASS_DEFERRED)) 27 27 { 28 28 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x); … … 40 40 if (!mMatrix) return; 41 41 42 if ( state->GetRenderType() == RenderState::DEFERRED)42 if ((state->GetRenderType() == RenderState::DEFERRED) || (state->GetRenderType() == RenderState::DEPTH_PASS_DEFERRED)) 43 43 { 44 44 static Matrix4x4 identity = IdentityMatrix(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2946 r2948 113 113 static int texHeight = 768; 114 114 115 116 115 int renderedObjects = 0; 117 116 int renderedNodes = 0; … … 172 171 bool useLODs = true; 173 172 174 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; 173 //DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON; 174 DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_QUADRATIC; 175 175 176 176 bool useAdvancedShading = false; … … 183 183 bool renderLightView = false; 184 184 185 186 187 185 ShadowMap *shadowMap = NULL; 188 186 Light *light = NULL; 187 DeferredRenderer *ssaoShader = NULL; 189 188 190 189 … … 227 226 void PlaceViewer(const Vector3 &oldPos); 228 227 229 230 231 228 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 232 229 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 233 234 230 void InitFBO(); 235 236 DeferredRenderer *ssaoShader = NULL; 231 void RenderShadowMap(); 232 233 234 237 235 238 236 … … 555 553 // we store colors, normals, positions (for the ssao) 556 554 fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32); 555 //fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_24); 557 556 558 557 // the diffuse color buffer … … 592 591 void InitGLstate() 593 592 { 594 glClearColor(0. 0f, 0.0, 0.2f, 0.0f);593 glClearColor(0.7f, 0.0f, 0.2f, 0.0f); 595 594 596 595 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 737 736 tr->SetUseMultiQueries(useMultiQueries); 738 737 tr->SetUseTightBounds(useTightBounds); 739 tr->SetUseDepthPass( renderType == RenderState::DEPTH_PASS);738 tr->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS_DEFERRED)); 740 739 tr->SetRenderQueue(renderQueue); 741 740 … … 826 825 matProjectionView = matViewing * matProjection; 827 826 828 if ( renderType == RenderState::DEFERRED)827 if ((renderType == RenderState::DEFERRED) || (renderType == RenderState::DEPTH_PASS_DEFERRED)) 829 828 { 830 829 // set modelview matrix for shaders … … 859 858 860 859 camera->SetPosition(pos); 860 } 861 862 863 void InitDeferredRendering() 864 { 865 if (!fbo) InitFBO(); 866 fbo->Bind(); 867 868 // multisampling does not work with deferred shading 869 glDisable(GL_MULTISAMPLE_ARB); 870 871 state.SetRenderType(RenderState::DEFERRED); 872 873 cgGLEnableProfile(RenderState::sCgVertexProfile); 874 cgGLBindProgram(sCgMrtVertexProgram); 875 876 cgGLEnableProfile(RenderState::sCgFragmentProfile); 877 cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 861 878 } 862 879 … … 925 942 break; 926 943 927 case RenderState::DEPTH_PASS: 928 929 glEnable(GL_MULTISAMPLE_ARB); 930 944 case RenderState::DEPTH_PASS_DEFERRED: 945 946 state.Reset(); 947 948 if (!fbo) InitFBO(); fbo->Bind(); 949 glDrawBuffers(1, mrt); 950 931 951 cgGLDisableProfile(RenderState::sCgFragmentProfile); 932 952 cgGLDisableProfile(RenderState::sCgVertexProfile); 933 953 954 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 955 956 glDisable(GL_MULTISAMPLE_ARB); 957 934 958 state.SetRenderType(RenderState::DEPTH_PASS); 935 959 state.SetUseAlphaToCoverage(false); 960 961 962 state.Reset(); 936 963 // the scene is rendered withouth any shading 937 964 glShadeModel(GL_FLAT); 938 965 glDisable(GL_LIGHTING); 966 967 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 968 969 break; 970 971 case RenderState::DEPTH_PASS: 972 973 glEnable(GL_MULTISAMPLE_ARB); 974 975 cgGLDisableProfile(RenderState::sCgFragmentProfile); 976 cgGLDisableProfile(RenderState::sCgVertexProfile); 977 978 state.SetRenderType(RenderState::DEPTH_PASS); 979 980 // the scene is rendered withouth any shading 981 glShadeModel(GL_FLAT); 939 982 glDisable(GL_LIGHTING); 940 983 … … 946 989 case RenderState::DEFERRED: 947 990 948 if (showShadowMap && !renderLightView) // && shadowChanged)991 if (showShadowMap && !renderLightView) 949 992 { 950 shadowChanged = false; 951 952 //glEnable(GL_MULTISAMPLE_ARB); 953 954 cgGLDisableProfile(RenderState::sCgFragmentProfile); 955 cgGLDisableProfile(RenderState::sCgVertexProfile); 956 957 state.SetRenderType(RenderState::DEPTH_PASS); 958 959 // change CHC++ set of state variables (must be done for each change of camera because 960 // otherwise the temporal coherency is broken 961 BvhNode::SetCurrentState(1); 962 963 state.SetUseAlphaToCoverage(false); 964 965 // the scene is rendered withouth any shading 966 shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 967 968 state.SetUseAlphaToCoverage(true); 969 970 // change back state 971 BvhNode::SetCurrentState(0); 972 993 RenderShadowMap(); 973 994 } 974 995 975 if (!fbo) InitFBO(); 976 977 978 // multisampling does not work with deferred shading 979 glDisable(GL_MULTISAMPLE_ARB); 980 981 state.SetRenderType(RenderState::DEFERRED); 982 983 fbo->Bind(); 984 985 glPushAttrib(GL_VIEWPORT_BIT); 996 //glPushAttrib(GL_VIEWPORT_BIT); 986 997 glViewport(0, 0, texWidth, texHeight); 987 998 988 cgGLEnableProfile(RenderState::sCgFragmentProfile); 989 cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 990 991 cgGLEnableProfile(RenderState::sCgVertexProfile); 992 cgGLBindProgram(sCgMrtVertexProgram); 993 994 /// draw to 3 color buffers 999 InitDeferredRendering(); 1000 1001 // draw to 3 color buffers 995 1002 glDrawBuffers(3, mrt); 996 1003 … … 1032 1039 } 1033 1040 else 1041 { 1034 1042 // actually render the scene geometry using the specified algorithm 1035 1043 traverser->RenderScene(); 1044 } 1036 1045 1037 1046 … … 1044 1053 1045 1054 // reset depth pass and render visible objects 1046 if (renderType == RenderState::DEPTH_PASS) 1047 { 1048 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1049 glShadeModel(GL_SMOOTH); 1050 1055 if ((renderType == RenderState::DEPTH_PASS) || 1056 (renderType == RenderState::DEPTH_PASS_DEFERRED)) 1057 { 1051 1058 RenderVisibleObjects(); 1052 1059 } 1060 1053 1061 1054 1062 … … 1059 1067 // this would conveniently solves some issues (e.g, skys without shadows) 1060 1068 1061 RenderSky(); 1062 1063 1064 1065 if (renderType == RenderState::DEFERRED) 1066 { 1069 //RenderSky(); 1070 1071 1072 1073 if ((renderType == RenderState::DEFERRED))// || (renderType == RenderState::DEPTH_PASS_DEFERRED)) 1074 { 1075 //glPopAttrib(); 1067 1076 FrameBufferObject::Release(); 1068 1077 … … 1070 1079 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1071 1080 1072 if (!ssaoShader) ssaoShader = new DeferredRenderer(texWidth, texHeight, camera, farDist / MAX_DEPTH_CONST); 1081 if (!ssaoShader) ssaoShader = 1082 new DeferredRenderer(texWidth, texHeight, camera, farDist / MAX_DEPTH_CONST); 1073 1083 1074 1084 DeferredRenderer::SHADING_METHOD shadingMethod; … … 1141 1151 exit(0); 1142 1152 break; 1143 case 32: // space1153 case 32: // space 1144 1154 renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES; 1145 1155 … … 1149 1159 if (shadowTraverser) 1150 1160 { 1151 // shadow traverser has to be recomputed (this is done on demand)1161 // shadow traverser has to be recomputed 1152 1162 DEL_PTR(shadowTraverser); 1163 shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 1153 1164 } 1154 1165 … … 1355 1366 case GLUT_KEY_F7: 1356 1367 1357 renderType = (renderType + 1) % 3;1358 traverser->SetUseDepthPass( renderType == RenderState::DEPTH_PASS);1368 renderType = (renderType + 1) % RenderState::NUM_RENDER_TYPES; 1369 traverser->SetUseDepthPass((renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS) || (renderType == RenderState::DEPTH_PASS_DEFERRED)); 1359 1370 1360 1371 break; … … 1590 1601 // hack: set far plane for viz 1591 1602 //camera->SetFar(0.35f * Magnitude(box.Diagonal())); 1592 //camera->SetFar(1000); 1593 1594 //const float offs = box.Size().x * 0.3f; 1595 const float offs = box.Size().x * 0.6f; 1603 1604 const float offs = box.Size().x * 0.3f; 1605 //const float offs = box.Size().x * 0.6f; 1596 1606 1597 1607 Vector3 vizpos = Vector3(box.Min().x, box.Min().y - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50); … … 1744 1754 1745 1755 rTime = renderTime; 1746 renderedObjects = traverser->GetStats().mNumRenderedGeometry; 1747 renderedNodes = traverser->GetStats().mNumRenderedNodes; 1748 renderedTriangles = traverser->GetStats().mNumRenderedTriangles; 1756 1757 if (renderLightView && shadowTraverser) 1758 { 1759 renderedTriangles = shadowTraverser->GetStats().mNumRenderedTriangles; 1760 renderedObjects = shadowTraverser->GetStats().mNumRenderedGeometry; 1761 renderedNodes = shadowTraverser->GetStats().mNumRenderedNodes; 1762 } 1763 else if (showShadowMap && shadowTraverser) 1764 { 1765 renderedNodes = traverser->GetStats().mNumRenderedNodes + shadowTraverser->GetStats().mNumRenderedNodes; 1766 renderedObjects = traverser->GetStats().mNumRenderedGeometry + shadowTraverser->GetStats().mNumRenderedGeometry; 1767 renderedTriangles = traverser->GetStats().mNumRenderedTriangles + shadowTraverser->GetStats().mNumRenderedTriangles; 1768 } 1769 else 1770 { 1771 renderedTriangles = traverser->GetStats().mNumRenderedTriangles; 1772 renderedObjects = traverser->GetStats().mNumRenderedGeometry; 1773 renderedNodes = traverser->GetStats().mNumRenderedNodes; 1774 } 1749 1775 1750 1776 traversedNodes = traverser->GetStats().mNumTraversedNodes; … … 1790 1816 int i = 0; 1791 1817 1792 static char *renderTypeStr[] = {"f ixed function", "fixed function + depth pass", "deferred shading"};1818 static char *renderTypeStr[] = {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"}; 1793 1819 1794 1820 sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", … … 1810 1836 glColor3f(1.0f, 1.0f, 0.0f); 1811 1837 1812 string str;1813 string str2;1838 string objStr, totalObjStr; 1839 string triStr, totalTriStr; 1814 1840 1815 1841 int len = 10; 1816 CalcDecimalPoint(str, renderedTriangles, len); 1817 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles, len); 1842 CalcDecimalPoint(objStr, renderedObjects, len); 1843 CalcDecimalPoint(totalObjStr, (int)loader->GetNumEntities(), len); 1844 1845 CalcDecimalPoint(triStr, renderedTriangles, len); 1846 CalcDecimalPoint(totalTriStr, bvh->GetBvhStats().mTriangles, len); 1818 1847 1819 1848 int i = 4; 1820 1849 1821 sprintf(msg[i ++], "rendered: %6d of %6d nodes, %s of %s triangles", 1822 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 1850 sprintf(msg[i ++], "rendered: %s of %s objects, %s of %s triangles", 1851 objStr.c_str(), totalObjStr.c_str(), triStr.c_str(), totalTriStr.c_str()); 1852 1853 //sprintf(msg[i ++], "rendered: %6d of %6d nodes, %s of %s triangles", 1854 // renderedNodes, bvh->GetNumVirtualNodes(), triStr.c_str(), totalTriStr.c_str()); 1823 1855 1824 1856 sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d", … … 1865 1897 } 1866 1898 1899 1867 1900 // render visible object from depth pass 1868 1901 void RenderVisibleObjects() 1869 1902 { 1870 state.SetRenderType(RenderState::FIXED); 1903 /*if ((renderType == RenderState::DEPTH_PASS_DEFERRED)) 1904 { 1905 //glDisable(GL_LIGHTING); 1906 state.SetUseAlphaToCoverage(false); 1907 //FrameBufferObject::Release(); 1908 InitDeferredRendering(); 1909 1910 glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT); 1911 // draw to 3 color buffers 1912 glDrawBuffers(3, mrt); 1913 } 1914 else*/ 1915 state.SetRenderType(RenderState::FIXED); 1916 1871 1917 state.Reset(); 1872 1918 1919 glShadeModel(GL_SMOOTH); 1873 1920 glEnable(GL_LIGHTING); 1921 1922 glDisable(GL_ALPHA); 1923 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB); 1924 1925 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1926 1927 // draw all objects that have exactly the same depth as the current sample 1928 //glDisable(GL_DEPTH_TEST); 1874 1929 glDepthFunc(GL_LEQUAL); 1875 1876 //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 1930 cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 1877 1931 1878 1932 SceneEntityContainer::const_iterator sit, … … 1880 1934 1881 1935 for (sit = traverser->GetVisibleObjects().begin(); sit != sit_end; ++ sit) 1936 { 1882 1937 renderQueue->Enqueue(*sit); 1883 1938 } 1939 1884 1940 renderQueue->Apply(); 1885 1941 1886 1942 glDepthFunc(GL_LESS); 1943 state.SetUseAlphaToCoverage(true); 1887 1944 } 1888 1945 … … 1900 1957 } 1901 1958 } 1959 1960 1961 void RenderShadowMap() 1962 { 1963 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1964 cgGLDisableProfile(RenderState::sCgVertexProfile); 1965 1966 state.SetRenderType(RenderState::DEPTH_PASS); 1967 1968 // change CHC++ set of state variables (must be done for each change of camera because 1969 // otherwise the temporal coherency is broken 1970 BvhNode::SetCurrentState(1); 1971 state.SetUseAlphaToCoverage(false); 1972 1973 // hack: temporarily change camera far plane 1974 //camera->SetFar(0.2f * Magnitude(bvh->GetBox().Diagonal())); 1975 1976 // the scene is rendered withouth any shading 1977 shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 1978 1979 camera->SetFar(farDist); 1980 1981 state.SetUseAlphaToCoverage(true); 1982 1983 // change back state 1984 BvhNode::SetCurrentState(0); 1985 }
Note: See TracChangeset
for help on using the changeset viewer.