Changeset 2826 for GTP/trunk/App
- Timestamp:
- 07/09/08 20:12:00 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2825 r2826 224 224 </File> 225 225 <File 226 RelativePath=".\src\glfont2.cpp" 227 > 228 </File> 229 <File 230 RelativePath=".\src\glfont2.h" 231 > 232 </File> 233 <File 226 234 RelativePath=".\src\glInterface.h" 227 235 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2806 r2826 38 38 39 39 inline float GetFov() const { return mFovy; } 40 inline void GetSize(int &width, int &height) const { width = mWidth; height = mHeight; }41 40 inline float GetAspect() const { return (float) mWidth / mHeight; } 41 inline int GetWidth() const { return mWidth; } 42 inline int GetHeight() const { return mHeight; } 42 43 43 44 /** Sets up viewing in gl 44 45 */ 45 46 void SetupCameraView(); 47 /** Returns the current projection matrix. 48 */ 46 49 void GetProjectionMatrix(Matrix4x4 &mat); 50 /** Returns the current model view matrix. 51 */ 47 52 void GetModelViewMatrix(Matrix4x4 &mat); 48 53 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.cpp
r2825 r2826 13 13 } 14 14 15 16 void Environment::Init() 17 { 18 /*mAssumedVisibleFrames; 19 mMaxBatchSize; 20 21 mTrianglesPerVirtualLeaf; 22 23 mKeyForwardMotion; 24 mKeyRotation; 25 26 mWinWidth; 27 mWinHeight; 28 29 mPosition; 30 */ 31 mUseFullScreen = false; 15 32 } 33 34 35 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.h
r2825 r2826 23 23 */ 24 24 bool Read(const std::string &filename); 25 /** Initialises the environment file with default values. 26 */ 27 void Init(); 28 25 29 26 30 ////////// … … 40 44 41 45 Vector3 mPosition; 42 Vector3 mPitch; 43 Vector3 mYaw; 46 Vector3 mDirection; 47 48 bool mUseFullScreen; 44 49 }; 45 50 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r2819 r2826 62 62 Material *mat = ent->GetMaterial(); 63 63 64 // test if entity 65 //if (mat->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) return false; 64 // test if entity belongs to this bucket 65 // note: rather slows down the application for some reason!! 66 if (0 && mat->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) 67 return false; 66 68 67 69 const bool hasTexture = (mat->GetTexture() != NULL); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2825 r2826 26 26 #include <Cg/cg.h> 27 27 #include <Cg/cgGL.h> 28 #include "glfont2.h" 28 29 29 30 … … 47 48 GLuint noiseTex; 48 49 50 GLuint fontTex; 49 51 50 52 /// the renderable scene geometry … … 85 87 const static float keyRotation = 1.5f; 86 88 87 /// elapsed time in seconds88 double elapsedTime = 1 .0f;89 double algTime = 1 .0f;89 /// elapsed time in milliseconds 90 double elapsedTime = 1000.0f; 91 double algTime = 1000.0f; 90 92 91 93 static int winWidth = 1024; … … 97 99 98 100 float myfar = 0; 101 102 glfont::GLFont myfont; 99 103 100 104 // rendertexture … … 116 120 117 121 bool showHelp = false; 118 bool showStatistics = true;119 bool showOptions = true;122 bool showStatistics = false; 123 bool showOptions = false; 120 124 bool showBoundingVolumes = false; 121 125 bool visMode = false; … … 145 149 bool useSsao = false; 146 150 151 bool showAlgorithmTime = false; 152 147 153 GLubyte *randomNormals = NULL; 148 154 … … 152 158 153 159 154 #define NUM_SAMPLES 12160 #define NUM_SAMPLES 8 155 161 156 162 static float samples[NUM_SAMPLES * 2]; … … 196 202 197 203 198 inline float KeyRotationAngle() { return keyRotation * elapsedTime ; }199 inline float KeyShift() { return keyForwardMotion * elapsedTime ; }204 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 205 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 200 206 201 207 void InitFBO(); … … 647 653 648 654 649 void InitGLstate(void) 655 bool Initfont(void) 656 { 657 //Initialize OpenGL 658 //Texture mapping and blending must be enabled for glFont to work 659 glClearColor(0.0, 0.0, 0.0, 1.0); 660 glEnable(GL_TEXTURE_2D); 661 glEnable(GL_BLEND); 662 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 663 664 glGenTextures(1, &fontTex); 665 glBindTexture(GL_TEXTURE_2D, fontTex); 666 if (!myfont.Create("myfont.glf", fontTex)) 667 return false; 668 669 glDisable(GL_TEXTURE_2D); 670 //Return successfully 671 return true; 672 } 673 674 675 void InitGLstate() 650 676 { 651 677 glClearColor(0.5f, 0.5f, 0.8f, 0.0f); … … 684 710 685 711 glDepthFunc(GL_LESS); 712 713 if (!Initfont()) 714 cerr << "font creation failed" << endl; 715 else 716 cout << "successfully created font" << endl; 717 } 718 719 720 void DrawFont() 721 { 722 float top_color[3] = {1.0F, 1.0F, 1.0F}; 723 float bottom_color[3] = {0.0F, 0.0F, 1.0F}; 724 725 glEnable(GL_TEXTURE_2D); 726 glEnable(GL_BLEND); 727 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 728 729 730 //Clear back buffer 731 glClear(GL_DEPTH_BUFFER_BIT); 732 733 //Draw some stuff 734 glMatrixMode(GL_MODELVIEW); 735 glPushMatrix(); 736 glLoadIdentity(); 737 738 //Draw a string 739 glColor3f(1.0F, 1.0F, 1.0F); 740 myfont.Begin(); 741 myfont.DrawString("Hello World!", 1.0F, 0.0F, 480.0F); 742 /*myfont.DrawString(L"Hello World!", 2.0F, 0.0F, 743 400.0F, top_color, bottom_color); 744 myfont.DrawString(std::string("Hello World!"), 0.0F, 320.0F); 745 myfont.DrawString(std::wstring(L"Hello World!"), 0.0F, 280.F, 746 top_color, bottom_color); 747 glTranslatef(0.0F, 200.F, 0.0F); 748 glRotatef(15.0F, 0.0F, 0.0F, 1.0F); 749 myfont.DrawString("Hello World!", 2.0F, 0.0F, 0.F, 750 top_color, bottom_color); 751 */ 752 glPopMatrix(); 753 754 glDisable(GL_BLEND); 755 glDisable(GL_TEXTURE_2D); 686 756 } 687 757 … … 699 769 "'F5', - shows/hides parameters", 700 770 "'F6', - toggles between fly / walkmode", 701 "'F7', - depth pass",702 "'F8', - enable /disable glFinish for more accurate timings",703 "'F9', - enables/disables ambient occlusion",771 "'F7', - cycles throw render modes", 772 "'F8', - enables/disables ambient occlusion (only deferred)", 773 "'F9', - shows pure algorithm render time (using glFinish)", 704 774 "'SPACE' - cycles through occlusion culling algorithms", 705 775 "", … … 900 970 void Display() 901 971 { 972 glFlush(); 973 elapsedTime = frameTimer.Elapsedms(); 974 902 975 // take time from last frame 903 elapsedTime = frameTimer.Elapsed();904 976 frameTimer.Start(); 905 977 … … 922 994 if (!flyMode) PlaceViewer(oldPos); 923 995 924 algTimer.Start(); 925 996 if (showAlgorithmTime) 997 { 998 glFinish(); 999 algTimer.Start(); 1000 } 926 1001 927 1002 // render without shading … … 990 1065 991 1066 1067 992 1068 ///////// 993 1069 //-- do the rest of the rendering … … 1013 1089 glDisableClientState(GL_VERTEX_ARRAY); 1014 1090 glDisableClientState(GL_NORMAL_ARRAY); 1015 1016 1091 1017 1092 if (renderType == RenderState::DEFERRED) … … 1028 1103 } 1029 1104 1030 1031 algTime = algTimer.Elapsedms(); 1032 1105 if (showAlgorithmTime) 1106 { 1107 glFinish(); 1108 algTime = algTimer.Elapsedms(); 1109 } 1033 1110 1034 1111 /////////// … … 1037 1114 1038 1115 if (visMode) DisplayVisualization(); 1039 1116 1040 1117 DisplayStats(); 1041 1118 … … 1233 1310 useSsao = !useSsao; 1234 1311 break; 1312 case GLUT_KEY_F9: 1313 showAlgorithmTime = !showAlgorithmTime; 1314 break; 1315 1235 1316 case GLUT_KEY_LEFT: 1236 1317 { … … 1400 1481 1401 1482 1402 void Begin2D( void)1483 void Begin2D() 1403 1484 { 1404 1485 glDisable(GL_LIGHTING); 1405 1486 glDisable(GL_DEPTH_TEST); 1406 1407 glPushMatrix();1408 glLoadIdentity();1409 1487 1410 1488 glMatrixMode(GL_PROJECTION); 1411 1489 glPushMatrix(); 1412 1490 glLoadIdentity(); 1413 gluOrtho2D(0, winWidth, winHeight, 0); 1414 } 1415 1416 1417 void End2D(void) 1491 gluOrtho2D(0, winWidth, 0, winHeight); 1492 1493 glMatrixMode(GL_MODELVIEW); 1494 glPushMatrix(); 1495 glLoadIdentity(); 1496 } 1497 1498 1499 void End2D() 1418 1500 { 1419 1501 glPopMatrix(); … … 1569 1651 void DisplayStats() 1570 1652 { 1571 static char msg[7][300]; 1572 1573 static double renderTime = elapsedTime;//algTime; 1653 static char msg[9][300]; 1654 1655 static double frameTime = elapsedTime; 1656 static double renderTime = algTime; 1657 1574 1658 const float expFactor = 0.1f; 1575 1659 1576 1660 // if some strange render time spike happened in this frame => don't count 1577 if (algTime < 500) renderTime = algTime * expFactor + (1.0f - expFactor) * algTime; 1578 1579 accumulatedTime += elapsedTime * 1e3f; 1661 if (elapsedTime < 500) frameTime = elapsedTime * expFactor + (1.0f - expFactor) * elapsedTime; 1662 1663 static float rTime = 1000.0f; 1664 1665 if (showAlgorithmTime) 1666 { 1667 if (algTime < 500) renderTime = algTime * expFactor + (1.0f - expFactor) * renderTime; 1668 } 1669 1670 accumulatedTime += elapsedTime; 1580 1671 1581 1672 if (accumulatedTime > 500) // update every fraction of a second 1582 1673 { 1583 1674 accumulatedTime = 0; 1584 if (renderTime) fps = 1e3f / (float)renderTime; 1585 1675 1676 if (frameTime) fps = 1e3f / (float)frameTime; 1677 1678 rTime = renderTime; 1586 1679 renderedObjects = traverser->GetStats().mNumRenderedGeometry; 1587 1680 renderedNodes = traverser->GetStats().mNumRenderedNodes; … … 1596 1689 } 1597 1690 1598 string str;1599 string str2;1600 1601 int i = 0;1602 1603 CalcDecimalPoint(str, renderedTriangles);1604 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles);1605 1606 sprintf(msg[i ++], "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)",1607 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str());1608 1609 sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d",1610 traversedNodes, frustumCulledNodes, queryCulledNodes);1611 1612 sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d",1613 issuedQueries, stateChanges, numBatches);1614 1615 sprintf(msg[i ++], "fps: %6.1f", fps);1616 1617 1618 sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d",1619 assumedVisibleFrames, maxBatchSize);1620 1621 static char *renderTypeStr[] = {"fixed function", "fixed function + depth pass", "deferred shading"};1622 1623 sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d, render technique: %s",1624 useMultiQueries, useTightBounds, useRenderQueue, renderTypeStr[renderType]);1625 1626 sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf);1627 1628 1691 1629 1692 Begin2D(); 1630 1631 if(showHelp) 1693 1694 float top_color[3] = {1.0F, 1.0F, 1.0F}; 1695 float bottom_color[3] = {0.0F, 0.0F, 1.0F}; 1696 1697 glEnable(GL_TEXTURE_2D); 1698 glEnable(GL_BLEND); 1699 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1700 1701 1702 1703 glClear(GL_DEPTH_BUFFER_BIT); 1704 //Draw a string 1705 glColor3f(1.0f, 1.0f, 1.0f); 1706 myfont.Begin(); 1707 1708 //DrawFont(); 1709 if (showHelp) 1632 1710 { 1633 1711 DrawHelpMessage(); … … 1635 1713 else 1636 1714 { 1637 static char *alg_str[] = {"Frustum Culling", "Stop and Wait", "CHC", "CHC ++"}; 1638 1639 glColor3f(1.0f, 1.0f, 1.0f); 1640 Output(850, 30, alg_str[renderMode]); 1715 glColor3f(1.0f, 0.5f, 0.5f); 1716 1717 if (showOptions) 1718 { 1719 int i = 0; 1720 1721 static char *renderTypeStr[] = {"fixed function", "fixed function + depth pass", "deferred shading"}; 1722 1723 sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", 1724 useMultiQueries, useTightBounds, useRenderQueue); 1725 1726 sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderTypeStr[renderType], useSsao); 1727 1728 sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 1729 1730 sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 1731 assumedVisibleFrames, maxBatchSize); 1732 1733 for (int j = 0; j < 4; ++ j) 1734 myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30); 1735 } 1736 1737 glColor3f(0.5f, 1.0f, 0.5f); 1641 1738 1642 1739 if (showStatistics) 1643 1740 { 1644 for (int i = 0; i < 4; ++ i) 1645 Output(20, (i + 1) * 30, msg[i]); 1741 string str; 1742 string str2; 1743 1744 CalcDecimalPoint(str, renderedTriangles); 1745 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 1746 1747 int i = 4; 1748 1749 sprintf(msg[i ++], "rendered: %6d nodes (of %6d), %s triangles (of %s)", 1750 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 1751 1752 sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d", 1753 traversedNodes, frustumCulledNodes, queryCulledNodes); 1754 1755 sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d", 1756 issuedQueries, stateChanges, numBatches); 1757 1758 for (int j = 4; j < 7; ++ j) 1759 myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30); 1646 1760 } 1647 1761 1648 if (showOptions) 1649 { 1650 for (int i = 4; i < 8; ++ i) 1651 Output(20, (i + 1) * 30, msg[i]); 1652 } 1653 } 1762 //glTranslatef(200, 200, 0); 1763 //glScalef(1, -1, 1); 1764 1765 glColor3f(1.0f, 1.0f, 1.0f); 1766 static char *alg_str[] = {"Frustum Cull", "Stop and Wait", "CHC", "CHC ++"}; 1767 sprintf(msg[7], "%s: %6.1f fps", alg_str[renderMode], fps); 1768 1769 myfont.DrawString(msg[7], 1.0F, 720.0F, 760.0F);//, top_color, bottom_color); 1770 1771 //glDisable(GL_CULL_FACE); 1772 //Output(780, 30, msg[7]); 1773 1774 if (showAlgorithmTime) 1775 { 1776 //sprintf(msg[8], "algorithm time: %6.1f ms", rTime); 1777 //Output(780, 60, msg[8]); 1778 } 1779 } 1780 1781 glDisable(GL_BLEND); 1782 glDisable(GL_TEXTURE_2D); 1654 1783 1655 1784 End2D(); … … 1814 1943 // create stratified samples over sphere 1815 1944 const float rx = ((float)i + RandomValue(0, 1)) * scale; 1945 const float ry = ((float)i + RandomValue(0, 1)) * scale; 1946 1947 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1948 const float phi = 2.0f * M_PI * ry; 1949 1950 Vector3 unit = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 1951 1952 // project 1953 Vector3 proj = unit / (1.0f + fabs(unit.z)); 1954 1955 samples[i + 0] = proj.x; 1956 samples[i + 1] = proj.y; 1957 1958 cout << samples[i] << " " << samples[i + 1] << endl; 1959 } 1960 } 1961 1962 1963 /*void GenerateSamples() 1964 { 1965 float scale = 1.0f / (float)NUM_SAMPLES; 1966 1967 // fill an array with uniformly distributed spherical samples 1968 for (int i = 0; i < NUM_SAMPLES; ++ i) 1969 { 1970 // create stratified samples over sphere 1971 const float rx = ((float)i + RandomValue(0, 1)) * scale; 1816 1972 1817 1973 const float theta = 2.0f * acos(sqrt(1.0f - rx)); … … 1823 1979 } 1824 1980 } 1825 1981 */ 1826 1982 1827 1983 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2825 r2826 1 #define NUM_SAMPLES 122 #define SAMPLE_INTENSITY 1.2f1 #define NUM_SAMPLES 8 2 #define SAMPLE_INTENSITY 0.5f 3 3 //#define SAMPLE_INTENSITY 0.7f 4 4 #define AREA_SIZE 5e-1f … … 88 88 float total_ao = 0.0; 89 89 90 //const float areaSize = 5e-1f;90 const float areaSize = 5e-1f; 91 91 //const float areaSize = 3e-1f; 92 92 //const float sampleIntensity = 0.2f; … … 118 118 119 119 // distance between current position and sample position controls AO intensity. 120 //const float maxdist = 4e-1f;121 const float maxdist = 5e-1f;122 123 float distance_intensity = maxdist - length_to_sample;124 //float distance_intensity = 0.5f / (1.0f+ length_to_sample * length_to_sample);125 distance_intensity = max(distance_intensity, 0.0f);120 //const float maxdist = 2e-1f; 121 //const float maxdist = 5e-1f; 122 const float distanceScale = 1e-6f; 123 //float distance_intensity = maxdist - length_to_sample; 124 float distance_intensity = (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample); 125 //distance_intensity = max(distance_intensity, 0.0f); 126 126 // quadratic influence 127 distance_intensity *= distance_intensity;128 129 total_ao += cos_angle * SAMPLE_INTENSITY *distance_intensity;127 //distance_intensity *= distance_intensity; 128 129 total_ao += cos_angle * distance_intensity; 130 130 } 131 131
Note: See TracChangeset
for help on using the changeset viewer.