- Timestamp:
- 07/10/08 15:57:47 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2806 r2829 182 182 const Vector3 fc = mPosition + view * z_far; 183 183 184 const Vector3 up = GetUpVector();184 const Vector3 up = -GetUpVector(); 185 185 186 186 const Vector3 right = GetRightVector(); … … 218 218 mYaw += angle; 219 219 CalculateFromPitchAndYaw(); 220 /*221 Matrix4x4 viewOrientation(mRight, mUp, mDirection);222 Matrix4x4 rot = RotationYMatrix(angle);223 224 viewOrientation = viewOrientation * rot;225 226 mDirection = Vector3(viewOrientation.x[2][0], viewOrientation.x[2][1], viewOrientation.x[2][2]);227 mRight = Vector3(viewOrientation.x[0][0], viewOrientation.x[0][1], viewOrientation.x[0][2]);228 mUp = Vector3(viewOrientation.x[1][0], viewOrientation.x[1][1], viewOrientation.x[1][2]);*/229 220 } 230 221 … … 237 228 238 229 230 void Camera::SetDirection(const Vector3 &direction) 231 { 232 Vector3 h1 = direction; h1.z = 0; h1.Normalize(); 233 Vector3 h2 = direction; h1.x = 0; h2.Normalize(); 234 235 mYaw = acos(DotProd(h1, Vector3(0, 1, 0))); 236 mPitch = acos(DotProd(h2, Vector3(0, 1, 0))); 237 238 CalculateFromPitchAndYaw(); 239 } 240 241 239 242 void Camera::CalculateFromPitchAndYaw() 240 243 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2826 r2829 78 78 float GetPitch() const { return mPitch; } 79 79 float GetYaw() const { return mYaw; } 80 /** Sets the camera direction. 81 */ 82 void SetDirection(const Vector3 &direction); 80 83 81 84 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.cpp
r2828 r2829 58 58 return false; 59 59 60 // parse vector values 60 61 Tokenize((*it).second, tokens); 61 62 62 val.x = (float)atof(tokens[ 1].c_str());63 val.y = (float)atof(tokens[ 2].c_str());64 val.z = (float)atof(tokens[ 3].c_str());63 val.x = (float)atof(tokens[0].c_str()); 64 val.y = (float)atof(tokens[1].c_str()); 65 val.z = (float)atof(tokens[2].c_str()); 65 66 66 67 return true; … … 78 79 while (fgets(str, 256, file) != NULL) 79 80 { 81 // this line is empty or a comment 82 if ((strlen(str) <= 1) || (str[0] == '#')) 83 continue; 84 80 85 static vector<string> tokens; 81 86 tokens.clear(); … … 83 88 Tokenize(str, tokens, "="); 84 89 85 // this line is a comment 86 if (tokens[0][0] == '#') 87 continue; 88 90 if (tokens.size() == 1) 91 cerr << "parsing failed at: " << tokens[0] << endl; 89 92 // store parameter 90 93 mParams[tokens[0]] = tokens[1]; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp
r2828 r2829 67 67 glLoadIdentity(); 68 68 69 glTranslatef(0.6 8f, 0.68f, 0.0f);70 glScalef(0.3 f, 0.3f, 1.0f);69 glTranslatef(0.668f, 0.668f, 0.0f); 70 glScalef(0.33f, 0.33f, 1.0f); 71 71 72 72 DrawBackGround(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2828 r2829 298 298 299 299 env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 300 env.GetFloatParam(string("key ForwardMotion"), keyRotation);300 env.GetFloatParam(string("keyRotation"), keyRotation); 301 301 302 302 env.GetIntParam(string("winWidth"), winWidth); … … 305 305 env.GetBoolParam(string("useFullScreen"), useFullScreen); 306 306 307 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 308 309 Vector3 camPos; 310 env.GetVectorParam(string("camPosition"), camPos); 311 312 cout << "read values: " << endl; 313 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 314 cout << "maxBatchSize: " << maxBatchSize << endl; 315 cout << "trianglesPerVirtualLeaf: " << trianglesPerVirtualLeaf << endl; 316 317 cout << "keyForwardMotion: " << keyForwardMotion << endl; 318 cout << "keyRotation: " << keyRotation << endl; 319 cout << "winWidth: " << winWidth << endl; 320 cout << "winHeight: " << winHeight << endl; 321 cout << "useFullScreen: " << useFullScreen << endl; 322 cout << "camPosition: " << camPos << endl; 307 323 308 324 … … 312 328 camera->SetNear(nearDist); 313 329 330 camera->Pitch(-M_PI * 0.5); 331 camera->SetPosition(camPos); 332 314 333 visCamera = new Camera(winWidth, winHeight, fov); 315 334 … … 341 360 glutIgnoreKeyRepeat(true); 342 361 362 // initialise gl graphics 363 343 364 InitExtensions(); 344 365 InitGLstate(); 345 366 346 //InitRenderTexture();347 367 InitFBO(); 348 368 … … 350 370 MiddleMotion(0, 0); 351 371 352 perfGraph = new PerformanceGraph( 500);372 perfGraph = new PerformanceGraph(1000); 353 373 354 374 loader = new ResourceManager(); … … 382 402 BvhLoader bvhLoader; 383 403 bvh = bvhLoader.Load(bvh_filename, sceneEntities); 384 //bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities);385 386 myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal());387 404 388 405 if (!bvh) … … 393 410 } 394 411 412 // set far plane based on scene extent 413 myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 414 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 415 416 bvh->SetCamera(camera); 417 395 418 InitCg(); 396 419 … … 398 421 CreateNoiseTex2D(); 399 422 400 bvh->SetCamera(camera);401 402 423 // init render traverser 403 424 ResetTraverser(); 404 425 405 camera->Pitch(-M_PI * 0.5);406 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f));407 426 408 427 visualization = new Visualization(bvh, camera, NULL, &state); … … 692 711 glGenTextures(1, &fontTex); 693 712 glBindTexture(GL_TEXTURE_2D, fontTex); 694 if (!myfont.Create("data/fonts/ myfont.glf", fontTex))713 if (!myfont.Create("data/fonts/verdana.glf", fontTex)) 695 714 return false; 696 715 … … 790 809 glColor3f(1.0f, 1.0f, 1.0f); 791 810 811 glEnable(GL_TEXTURE_2D); 792 812 myfont.Begin(); 793 813 … … 806 826 } 807 827 } 828 glDisable(GL_TEXTURE_2D); 808 829 } 809 830 … … 995 1016 glDrawBuffers(1, mrt); 996 1017 1018 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1019 997 1020 break; 998 1021 … … 1006 1029 cgGLDisableProfile(RenderState::sCgVertexProfile); 1007 1030 1031 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1032 1033 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 1034 1008 1035 glDrawBuffers(1, mrt); 1009 1036 … … 1026 1053 glDrawBuffers(3, mrt); 1027 1054 1028 break; 1029 } 1030 1031 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1055 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1056 1057 break; 1058 } 1059 1032 1060 1033 1061 glDepthFunc(GL_LESS); … … 1056 1084 if (renderType == RenderState::DEPTH_PASS) 1057 1085 { 1086 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 1058 1087 RenderVisibleObjects(); 1059 1088 } … … 1191 1220 upKeyPressed = true; 1192 1221 break; 1193 case ' x':1194 case ' X':1222 case 's': 1223 case 'S': 1195 1224 downKeyPressed = true; 1196 1225 break; … … 1266 1295 upKeyPressed = false; 1267 1296 break; 1268 case ' X':1269 case ' x':1297 case 'S': 1298 case 's': 1270 1299 downKeyPressed = false; 1271 1300 break; … … 1389 1418 else if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) 1390 1419 { 1420 xEyeBegin = x; 1391 1421 yEyeBegin = y; 1392 1422 yMotionBegin = y; … … 1436 1466 void RightMotion(int x, int y) 1437 1467 { 1468 float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0; 1438 1469 float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0; 1439 1470 1440 1471 camera->Yaw(eyeYAngle); 1441 1472 camera->Pitch(eyeXAngle); 1473 1474 xEyeBegin = x; 1442 1475 yEyeBegin = y; 1476 1443 1477 glutPostRedisplay(); 1444 1478 } … … 1497 1531 glLoadIdentity(); 1498 1532 gluOrtho2D(0, winWidth, 0, winHeight); 1499 1500 int w = winWidth / 2;1501 int h = winHeight / 2;1502 1503 //glOrtho(-w, w, -h, h, 0, 10);1504 1533 1505 1534 glMatrixMode(GL_MODELVIEW); … … 1625 1654 1626 1655 // this function inserts a dezimal point after each 1000 1627 void CalcDecimalPoint(string &str, int d )1656 void CalcDecimalPoint(string &str, int d, int len) 1628 1657 { 1629 1658 static vector<int> numbers; 1630 1659 numbers.clear(); 1631 1660 1632 char hstr[100]; 1661 static string shortStr; 1662 shortStr.clear(); 1663 1664 static char hstr[100]; 1633 1665 1634 1666 while (d != 0) … … 1642 1674 { 1643 1675 sprintf(hstr, "%d", numbers.back()); 1644 s tr.append(hstr);1676 shortStr.append(hstr); 1645 1677 } 1646 1678 … … 1648 1680 { 1649 1681 sprintf(hstr, ",%03d", numbers[i]); 1650 str.append(hstr); 1651 } 1682 shortStr.append(hstr); 1683 } 1684 1685 int dif = len - (int)shortStr.size(); 1686 1687 for (int i = 0; i < dif; ++ i) 1688 { 1689 str += " "; 1690 } 1691 1692 str.append(shortStr); 1652 1693 } 1653 1694 … … 1696 1737 Begin2D(); 1697 1738 1698 float top_color[3] = {1.0F, 1.0F, 1.0F};1699 float bottom_color[3] = {0.0F, 0.0F, 1.0F};1700 1701 glEnable(GL_TEXTURE_2D);1702 1739 glEnable(GL_BLEND); 1703 1740 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1704 1741 1705 1706 //DrawFont();1707 1742 if (showHelp) 1708 1743 { … … 1711 1746 else 1712 1747 { 1713 myfont.Begin();1714 1715 glColor3f(0.0f, 1.0f, 0.0f);1716 1717 1748 if (showOptions) 1718 1749 { 1750 glColor4f(0.0f, 0.0f, 0.0f, 0.5f); 1751 glRecti(5, winHeight - 95, winWidth * 2 / 3 - 5, winHeight - 5); 1752 } 1753 1754 if (showStatistics) 1755 { 1756 glColor4f(0.0f, 0.0f, 0.0f, 0.5f); 1757 glRecti(5, winHeight - 165, winWidth * 2 / 3 - 5, winHeight - 100); 1758 } 1759 1760 glEnable(GL_TEXTURE_2D); 1761 1762 myfont.Begin(); 1763 1764 if (showOptions) 1765 { 1766 glColor3f(0.0f, 1.0f, 0.0f); 1767 1719 1768 int i = 0; 1720 1769 … … 1732 1781 1733 1782 for (int j = 0; j < 4; ++ j) 1734 myfont.DrawString(msg[j], 20.0f, 760 - j * 30);1783 myfont.DrawString(msg[j], 10.0f, winHeight - 5 - j * 20); 1735 1784 } 1736 1737 glColor3f(0.0f, 1.0f, 1.0f);1738 1785 1739 1786 if (showStatistics) 1740 1787 { 1788 glColor3f(1.0f, 1.0f, 0.0f); 1789 1741 1790 string str; 1742 1791 string str2; 1743 1792 1744 CalcDecimalPoint(str, renderedTriangles); 1745 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 1793 int len = 10; 1794 CalcDecimalPoint(str, renderedTriangles, len); 1795 CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles, len); 1746 1796 1747 1797 int i = 4; 1748 1798 1749 sprintf(msg[i ++], "rendered: %6d nodes (of %6d), %s triangles (of %s)",1799 sprintf(msg[i ++], "rendered: %6d of %6d nodes, %s of %s triangles", 1750 1800 renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 1751 1801 … … 1757 1807 1758 1808 for (int j = 4; j < 7; ++ j) 1759 myfont.DrawString(msg[j], 20.0f, 760 - j * 30);1809 myfont.DrawString(msg[j], 10.0f, winHeight - (j + 1) * 20); 1760 1810 } 1761 1811 … … 1772 1822 } 1773 1823 1774 myfont.DrawString(msg[7], 720.0f, 760.0f);//, top_color, bottom_color);1824 myfont.DrawString(msg[7], 1.3f, 690.0f, 760.0f);//, top_color, bottom_color); 1775 1825 1776 1826 //sprintf(msg[8], "algorithm time: %6.1f ms", rTime); … … 1832 1882 void DisplayRenderTexture() 1833 1883 { 1884 glDisable(GL_ALPHA_TEST); 1834 1885 glDisable(GL_TEXTURE_2D); 1835 1836 1886 glDisable(GL_LIGHTING); 1837 1887 … … 1889 1939 glBegin(GL_QUADS); 1890 1940 1891 // slightly larger than screen size in order to hide ambient occlusion errors1941 // note: slightly larger texture hides ambient occlusion error on border but costs resolution 1892 1942 //float offs2 = 0.55f; 1893 1943 float offs2 = 0.5f; … … 1900 1950 glEnd(); 1901 1951 1952 cgGLDisableTextureParameter(sColorsTexParamSsao); 1953 cgGLDisableTextureParameter(sPositionsTexParamSsao); 1954 cgGLDisableTextureParameter(sNormalsTexParamSsao); 1955 1902 1956 if (useSsao) 1903 {1904 cgGLDisableTextureParameter(sColorsTexParamSsao);1905 cgGLDisableTextureParameter(sPositionsTexParamSsao);1906 cgGLDisableTextureParameter(sNormalsTexParamSsao);1907 1908 1957 cgGLDisableTextureParameter(sNoiseTexParamSsao); 1909 //cgGLDisableTextureParameter(sSamplesParamSsao);1910 }1911 else1912 {1913 cgGLDisableTextureParameter(sColorsTexParam);1914 cgGLDisableTextureParameter(sPositionsTexParam);1915 cgGLDisableTextureParameter(sNormalsTexParam);1916 }1917 1958 1918 1959 cgGLDisableProfile(RenderState::sCgFragmentProfile); … … 1932 1973 1933 1974 1934 1935 1975 void GenerateSamples() 1936 1976 { 1937 1977 float scale = 1.0f / (float)NUM_SAMPLES; 1938 1978 1939 // fill an array with uniformly distributed spherical samples 1979 //////// 1980 //-- generate uniformly distributed spherical samples 1981 1940 1982 for (int i = 0; i < NUM_SAMPLES; ++ i) 1941 1983 { … … 1949 1991 Vector3 unit = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 1950 1992 1951 // project 1993 ////// 1994 //-- we sample in texture space => store 2D component 1995 1996 // q: project to plane or just drop z? 1952 1997 Vector3 proj = unit / (1.0f + fabs(unit.z)); 1998 //Vector3 proj = unit; 1953 1999 1954 2000 samples[i + 0] = proj.x; 1955 2001 samples[i + 1] = proj.y; 1956 1957 cout << samples[i] << " " << samples[i + 1] << endl; 1958 } 1959 } 1960 1961 1962 /*void GenerateSamples() 1963 { 1964 float scale = 1.0f / (float)NUM_SAMPLES; 1965 1966 // fill an array with uniformly distributed spherical samples 1967 for (int i = 0; i < NUM_SAMPLES; ++ i) 1968 { 1969 // create stratified samples over sphere 1970 const float rx = ((float)i + RandomValue(0, 1)) * scale; 1971 1972 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1973 1974 samples[i + 0] = cos(theta); 1975 samples[i + 1] = sin(theta); 1976 1977 cout << samples[i] << " " << samples[i + 1] << endl; 1978 } 1979 } 1980 */ 2002 //cout << samples[i] << " " << samples[i + 1] << endl; 2003 } 2004 } 2005 1981 2006 1982 2007 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/default.env
r2828 r2829 9 9 winWidth=1024 10 10 winHeight=768 11 position=483.398f 242.364f 186.078f11 camPosition=483.398f 242.364f 186.078f 12 12 useFullScreen=false 13 13 numSsaoSamples=8 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2826 r2829 1 //////////////////// 2 // Screen Spaced Ambient Occlusion shader 3 // mainly based on Kustls shader 4 1 5 #define NUM_SAMPLES 8 2 6 #define SAMPLE_INTENSITY 0.5f … … 180 184 float ao = ssao(IN, positions, noiseTexture, samples, normal); 181 185 182 //OUT.color = tex2D(positions, IN.texCoord.xy); 183 //OUT.color = ao; 184 //OUT.color = col; 185 OUT.color = ao * col; 186 //OUT.color = ao; 187 OUT.color = ao * col; 186 188 187 189 return OUT;
Note: See TracChangeset
for help on using the changeset viewer.