Changeset 3219 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 12/10/08 03:31:07 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3216 r3219 332 332 mSsaoFilterRadius(12.0f), 333 333 mSampleIntensity(0.2f), 334 mSunVisiblePixels(0) 334 mSunVisiblePixels(0), 335 mSavedFrameNumber(-1) 335 336 { 336 337 /////////// … … 590 591 LenseFlare(fbo, light); 591 592 593 const bool saveFrame = (mSavedFrameNumber != -1); 594 const bool displayAfterAA = !saveFrame; 595 592 596 // multisampling is difficult / costly with deferred shading 593 597 // at least do some edge blurring 594 if (useAntiAliasing) AntiAliasing(fbo, light); else 595 Output(fbo); // just output the latest buffer 598 if (useAntiAliasing) AntiAliasing(fbo, light, displayAfterAA); 599 600 /// store the current frame 601 if (saveFrame) SaveFrame(fbo); 602 603 // if it hasn't been done yet => just output the latest buffer 604 if (!useAntiAliasing || !displayAfterAA) 605 Output(fbo); 596 606 597 607 glEnable(GL_LIGHTING); … … 795 805 796 806 797 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light) 807 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, 808 DirectionalLight *light, 809 bool displayFrame) 798 810 { 799 811 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); … … 802 814 803 815 // read the second buffer, write to the first buffer 804 //FlipFbos(fbo); 805 // end of the pipeline => just draw image to screen 806 FrameBufferObject::Release(); 816 if (!displayFrame) 817 FlipFbos(fbo); 818 else 819 // end of the pipeline => just draw image to screen 820 FrameBufferObject::Release(); 807 821 808 822 // the neighbouring texels … … 1292 1306 1293 1307 1308 void DeferredRenderer::SaveFrame(FrameBufferObject *fbo) 1309 { 1310 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 1311 GLuint colorsTex = colorBuffer->GetTexture(); 1312 1313 GLubyte *data = new GLubyte[mWidth * mHeight * 4]; 1314 1315 // grab texture data 1316 glEnable(GL_TEXTURE_2D); 1317 glBindTexture(GL_TEXTURE_2D, colorsTex); 1318 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 1319 1320 glBindTexture(GL_TEXTURE_2D, 0); 1321 glDisable(GL_TEXTURE_2D); 1322 1323 ///////////////// 1324 1325 startil(); 1326 1327 static char imageName[200]; 1328 sprintf(imageName, "myframe%05d.bmp", mSavedFrameNumber); 1329 1330 ILstring fileName = ILstring(imageName); 1331 ilRegisterType(IL_FLOAT); 1332 1333 const int depth = 1; 1334 const int bpp = 4; 1335 1336 if (!ilTexImage(mWidth, mHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data)) 1337 { 1338 cerr << "IL error " << ilGetError() << endl; 1339 stopil(); 1340 return; 1341 } 1342 1343 ilEnable(IL_FILE_OVERWRITE); 1344 1345 if (!ilSaveImage(fileName)) 1346 { 1347 cerr << "TGA write error " << ilGetError() << endl; 1348 } 1349 1350 delete [] data; 1351 1352 stopil(); 1353 1354 PrintGLerror("Store frame"); 1355 } 1356 1294 1357 1295 1358 void DeferredRenderer::SetUseTemporalCoherence(bool temporal) … … 1359 1422 1360 1423 1424 void DeferredRenderer::SetSaveFrame(int frameNumber) 1425 { 1426 mSavedFrameNumber = frameNumber; 1427 } 1428 1361 1429 1362 1430 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3216 r3219 83 83 */ 84 84 void SetUseTemporalCoherence(bool temporal); 85 /** if set to something other than -1 the current frame is stored on disc 86 using the specified frame number 87 */ 88 void SetSaveFrame(int frameNumber); 85 89 86 90 … … 111 115 void CombineSsao(FrameBufferObject *fbo); 112 116 void CombineIllum(FrameBufferObject *fbo); 113 114 void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); 117 /** Does some basic antialiasing (searches for edges using a edge detector, 118 smoothes these edges. 119 This function is usually the last function in the pipeline, 120 so one can specify if the frame should be put out directly or stored to 121 another texture. 122 */ 123 void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light, bool displayFrame = true); 115 124 /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the 116 125 resolution of fbo. … … 144 153 void PrepareSsaoFilter(); 145 154 155 void SaveFrame(FrameBufferObject *fbo); 156 146 157 147 158 //////////// … … 189 200 190 201 int mSunVisiblePixels; 202 203 int mSavedFrameNumber; 191 204 }; 192 205 … … 194 207 } // namespace 195 208 196 #endif // _S saoShader_H__209 #endif // _SSAOSHADER_H__ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3103 r3219 91 91 } 92 92 93 ilEnable(IL_FILE_OVERWRITE); 94 93 95 if (!ilSaveImage(filename)) 94 96 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3068 r3219 101 101 } 102 102 103 ilEnable(IL_FILE_OVERWRITE); 103 104 if (!ilSaveImage(filename)) 104 105 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h
r2920 r3219 514 514 // read "(x, y, z)" 515 515 return s >> a >> A.x >> a >> A.y >> a >> A.z >> a; 516 //return s >> A.x >> A.y >> A.z; 516 517 } 517 518 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.cpp
r3211 r3219 1 1 #include "WalkThroughRecorder.h" 2 2 #include "Camera.h" 3 3 #include "Vector3.h" 4 #include <sstream> 4 5 5 6 using namespace std; … … 9 10 { 10 11 11 WalkThroughRecorder::WalkThroughRecorder(const std::string &filename) 12 {} 12 13 WalkThroughRecorder::WalkThroughRecorder(const std::string &filename): 14 mFile(filename.c_str()) 15 { 16 } 13 17 14 18 15 19 void WalkThroughRecorder::WriteFrame(Camera *cam) 16 20 { 17 mFile << cam->GetDirection() << "" << cam->GetPosition() << endl; 21 FrameInfo info(cam->GetPosition(), cam->GetDirection()); 22 mFile << info << endl; 18 23 } 19 24 20 25 21 WalkThroughPlayer::WalkThroughPlayer(const std::string &filename) 22 {} 26 WalkThroughPlayer::WalkThroughPlayer(const std::string &filename): 27 mFrame(0) 28 { 29 ifstream file(filename.c_str()); 30 FrameInfo info; 31 int i=0; 32 33 std::string token; 34 35 while(std::getline(file, token)) 36 { 37 std::stringstream line(token); 38 39 line >> info; 40 mFrameInfos.push_back(info); 41 } 42 } 23 43 24 44 25 voidWalkThroughPlayer::ReadNextFrame(Camera *cam)45 bool WalkThroughPlayer::ReadNextFrame(Camera *cam) 26 46 { 27 //mFile >> cam->GetDirection() >> "" >> cam->GetPosition() << endl; 47 cam->SetDirection(mFrameInfos[mFrame].mDirection); 48 cam->SetPosition(mFrameInfos[mFrame].mPosition); 49 50 mFrame = (mFrame + 1) % (int)mFrameInfos.size(); 51 52 return mFrame != 0; 28 53 } 29 54 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.h
r3210 r3219 4 4 #include "common.h" 5 5 #include <fstream> 6 #include "Vector3.h" 7 6 8 7 9 namespace CHCDemoEngine … … 9 11 10 12 class Camera; 13 14 struct FrameInfo 15 { 16 FrameInfo(const Vector3 &pos, const Vector3 &dir): 17 mPosition(pos), mDirection(dir) 18 {} 19 20 FrameInfo() {} 21 22 23 ///////////// 24 25 Vector3 mPosition; 26 Vector3 mDirection; 27 28 friend std::ostream& operator<< (std::ostream &s, const FrameInfo &A); 29 friend std::istream& operator>> (std::istream &s, FrameInfo &A); 30 }; 31 32 33 // Overload << operator for C++-style output 34 inline std::ostream& operator<< (std::ostream &s, const FrameInfo &A) 35 { 36 return s << A.mPosition << " " << A.mDirection; 37 } 38 39 40 // Overload >> operator for C++-style input 41 inline std::istream& operator>> (std::istream &s, FrameInfo &A) 42 { 43 return s >> A.mPosition >> A.mDirection; 44 } 45 11 46 12 47 … … 22 57 */ 23 58 void WriteFrame(Camera *cam); 24 /** Reads next frame 25 */ 26 void ReadNextFrame(Camera *cam); 27 59 28 60 protected: 29 61 … … 39 71 */ 40 72 WalkThroughPlayer(const std::string &filename); 41 /** Reads next frame 73 /** Reads next frame. returns false if end of recorded frames is reached. 42 74 */ 43 void ReadNextFrame(Camera *cam); 75 bool ReadNextFrame(Camera *cam); 76 44 77 45 78 protected: 46 79 47 std::ifstream mFile; 80 std::vector<FrameInfo> mFrameInfos; 81 82 int mFrame; 48 83 }; 49 84 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3216 r3219 56 56 #include "ShaderProgram.h" 57 57 #include "Shape.h" 58 #include "WalkThroughRecorder.h" 58 59 59 60 … … 112 113 bool ssaoUseFullResolution = false; 113 114 115 /// store the frames as tga 116 bool recordFrames = false; 117 /// record the taken path 118 bool recordPath = false; 119 /// replays the recorded path 120 bool replayPath = false; 121 122 int currentReplayFrame = -1; 123 124 /// the walkThroughRecorder 125 WalkThroughRecorder *walkThroughRecorder = NULL; 126 WalkThroughPlayer *walkThroughPlayer = NULL; 127 114 128 115 129 /// the technique used for rendering … … 581 595 CreateAnimation(); 582 596 597 583 598 ////////////////////////// 584 //-- a bounding box representing the sun pos ition585 //-- in order to test sun visibility 599 //-- a bounding box representing the sun pos in order to test visibility 600 586 601 Transform3 *trafo = resourceManager->CreateTransform(IdentityMatrix()); 587 602 … … 653 668 654 669 for (int i = 0; i < 4; ++ i) 670 { 655 671 FrameBufferObject::InitBuffer(fbo, i); 656 672 } 673 657 674 PrintGLerror("init fbo"); 658 675 } … … 987 1004 void MainLoop() 988 1005 { 989 #if 11006 #if TODO 990 1007 GPUProgramParameters *vtxParams = 991 1008 buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); … … 1023 1040 ///////////// 1024 1041 1025 Vector3 oldPos = camera->GetPosition(); 1042 static Vector3 oldPos = camera->GetPosition(); 1043 static Vector3 oldDir = camera->GetDirection(); 1026 1044 1027 1045 if (leftKeyPressed) … … 1052 1070 } 1053 1071 1072 // don't allow replay on record 1073 if (replayPath && !recordPath) 1074 { 1075 if (!walkThroughPlayer) 1076 walkThroughPlayer = new WalkThroughPlayer("frames.log"); 1077 1078 ++ currentReplayFrame; 1079 1080 if (!walkThroughPlayer->ReadNextFrame(camera)) 1081 { 1082 currentReplayFrame = -1; 1083 replayPath = false; 1084 } 1085 } 1054 1086 1055 1087 if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) … … 1065 1097 // bring eye modelview matrix up-to-date 1066 1098 SetupEyeView(); 1099 1067 1100 // set frame related parameters for GPU programs 1068 1101 GPUProgramParameters::InitFrame(camera, light); 1102 1103 if (recordPath) 1104 { 1105 if (!walkThroughRecorder) 1106 walkThroughRecorder = new WalkThroughRecorder("frames.log"); 1107 1108 if ((Distance(oldPos, camera->GetPosition()) > 1e-6f) || 1109 (DotProd(oldDir, camera->GetDirection()) < 1.0f - 1e-6f)) 1110 { 1111 walkThroughRecorder->WriteFrame(camera); 1112 } 1113 } 1069 1114 1070 1115 // hack: store current rendering method and restore later … … 1216 1261 deferredShader->SetUseTemporalCoherence(useTemporalCoherence); 1217 1262 deferredShader->SetSortSamples(sortSamples); 1263 deferredShader->SetSaveFrame((recordFrames && replayPath) ? -1 : currentReplayFrame); 1218 1264 1219 1265 ShadowMap *sm = showShadowMap ? shadowMap : NULL; … … 1257 1303 1258 1304 glutSwapBuffers(); 1259 } 1260 1261 1262 #pragma warning( disable : 4100 ) 1305 1306 oldPos = camera->GetPosition(); 1307 oldDir = camera->GetDirection(); 1308 } 1309 1310 1311 #pragma warning(disable : 4100) 1263 1312 void KeyBoard(unsigned char c, int x, int y) 1264 1313 { … … 1359 1408 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1360 1409 break; 1361 case 'l': 1362 case 'L': 1363 useLODs = !useLODs; 1364 SceneEntity::SetUseLODs(useLODs); 1365 cout << "using LODs: " << useLODs << endl; 1366 break; 1367 case 'P': 1368 case 'p': 1369 samplingMethod = DeferredRenderer::SAMPLING_METHOD((samplingMethod + 1) % 3); 1370 cout << "ssao sampling method: " << samplingMethod << endl; 1371 break; 1372 case 'Y': 1373 case 'y': 1374 showShadowMap = !showShadowMap; 1375 break; 1376 case 'g': 1377 case 'G': 1378 useGlobIllum = !useGlobIllum; 1379 break; 1380 case 't': 1381 case 'T': 1382 useTemporalCoherence = !useTemporalCoherence; 1383 break; 1384 /* case 'o': 1410 /* case 'o': 1385 1411 case 'O': 1386 1412 useOptimization = !useOptimization; … … 1389 1415 traverser->SetUseOptimization(useOptimization); 1390 1416 break;*/ 1417 case 'l': 1418 case 'L': 1419 useLODs = !useLODs; 1420 SceneEntity::SetUseLODs(useLODs); 1421 cout << "using LODs: " << useLODs << endl; 1422 break; 1423 case 'P': 1424 case 'p': 1425 samplingMethod = DeferredRenderer::SAMPLING_METHOD((samplingMethod + 1) % 3); 1426 cout << "ssao sampling method: " << samplingMethod << endl; 1427 break; 1428 case 'Y': 1429 case 'y': 1430 showShadowMap = !showShadowMap; 1431 break; 1432 case 'g': 1433 case 'G': 1434 useGlobIllum = !useGlobIllum; 1435 break; 1436 case 't': 1437 case 'T': 1438 useTemporalCoherence = !useTemporalCoherence; 1439 break; 1391 1440 case 'a': 1392 1441 case 'A': … … 1439 1488 useLenseFlare = !useLenseFlare; 1440 1489 break; 1441 1490 case 'u': 1491 case 'U': 1492 moveLight = !moveLight; 1493 break; 1442 1494 default: 1443 1495 return; … … 1550 1602 case GLUT_KEY_F8: 1551 1603 useAdvancedShading = !useAdvancedShading; 1552 1553 1604 break; 1554 1605 case GLUT_KEY_F9: … … 1556 1607 break; 1557 1608 case GLUT_KEY_F10: 1558 moveLight = !moveLight; 1609 replayPath = !replayPath; 1610 1611 if (replayPath) 1612 { 1613 cout << "replaying path" << endl; 1614 currentReplayFrame = -1; 1615 } 1616 else 1617 { 1618 cout << "finished replaying path" << endl; 1619 } 1620 1621 break; 1622 case GLUT_KEY_F11: 1623 recordPath = !recordPath; 1624 1625 if (recordPath) 1626 { 1627 cout << "recording path" << endl; 1628 } 1629 else 1630 { 1631 cout << "finished recording path" << endl; 1632 // start over with new frame recording next time 1633 DEL_PTR(walkThroughRecorder); 1634 } 1635 1636 break; 1637 case GLUT_KEY_F12: 1638 recordFrames = !recordFrames; 1639 1640 if (recordFrames) 1641 cout << "recording frames on replaying" << endl; 1642 else 1643 cout << "finished recording frames on replaying" << endl; 1559 1644 break; 1560 1645 case GLUT_KEY_LEFT: … … 1878 1963 DEL_PTR(shadowTraverser); 1879 1964 DEL_PTR(motionPath); 1965 DEL_PTR(walkThroughRecorder); 1966 DEL_PTR(walkThroughPlayer); 1880 1967 1881 1968 ResourceManager::DelSingleton(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
r3212 r3219 113 113 adaptive number of samples instead of size? 114 114 2) fix color bleeding 115 3) fix ssao2 so that ssao contribution stays constant 115 3) fix ssao2 so that ssao contribution stays constant for both methods 116 116 4) find physical expressions for constants in ssao 117 117 5) retry normal discontinuity for ssao filter … … 133 133 sun disc 134 134 environment lighting 135 136 1) antialiasing very slow: try separable filter and one direction at a time 137 2) try cross filter for ssao without tempcoh 138 3) fix model directory => clean up structure (city/model => models ?) 139 4) fix namespaces: one main namespace for core functions + math functions? 140 one util namespace 141 142 5) clean up hacks: 143 144 normalmapping 145 render target flipflopping for tone mapping 146 scenequery 147 148 fix walk speed
Note: See TracChangeset
for help on using the changeset viewer.