Changeset 3219


Ignore:
Timestamp:
12/10/08 03:31:07 (15 years ago)
Author:
mattausch
Message:
 
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  
    332332mSsaoFilterRadius(12.0f), 
    333333mSampleIntensity(0.2f), 
    334 mSunVisiblePixels(0) 
     334mSunVisiblePixels(0), 
     335mSavedFrameNumber(-1) 
    335336{ 
    336337        /////////// 
     
    590591        LenseFlare(fbo, light); 
    591592 
     593        const bool saveFrame = (mSavedFrameNumber != -1); 
     594        const bool displayAfterAA = !saveFrame; 
     595 
    592596        // multisampling is difficult / costly with deferred shading 
    593597        // 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);  
    596606 
    597607        glEnable(GL_LIGHTING); 
     
    795805 
    796806 
    797 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light) 
     807void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo,  
     808                                                                        DirectionalLight *light,  
     809                                                                        bool displayFrame) 
    798810{ 
    799811        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
     
    802814 
    803815        // 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(); 
    807821 
    808822        // the neighbouring texels 
     
    12921306 
    12931307 
     1308void 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 
    12941357 
    12951358void DeferredRenderer::SetUseTemporalCoherence(bool temporal) 
     
    13591422 
    13601423 
     1424void DeferredRenderer::SetSaveFrame(int frameNumber) 
     1425{ 
     1426        mSavedFrameNumber = frameNumber; 
     1427} 
     1428 
    13611429 
    13621430} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3216 r3219  
    8383        */ 
    8484        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); 
    8589 
    8690 
     
    111115        void CombineSsao(FrameBufferObject *fbo); 
    112116        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); 
    115124        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the 
    116125                resolution of fbo. 
     
    144153        void PrepareSsaoFilter(); 
    145154 
     155        void SaveFrame(FrameBufferObject *fbo); 
     156 
    146157 
    147158        //////////// 
     
    189200 
    190201        int mSunVisiblePixels; 
     202 
     203        int mSavedFrameNumber; 
    191204}; 
    192205 
     
    194207} // namespace  
    195208 
    196 #endif // _SsaoShader_H__ 
     209#endif // _SSAOSHADER_H__ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r3103 r3219  
    9191        } 
    9292 
     93        ilEnable(IL_FILE_OVERWRITE); 
     94 
    9395        if (!ilSaveImage(filename)) 
    9496        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r3068 r3219  
    101101        } 
    102102 
     103        ilEnable(IL_FILE_OVERWRITE); 
    103104        if (!ilSaveImage(filename)) 
    104105        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Vector3.h

    r2920 r3219  
    514514        // read "(x, y, z)" 
    515515        return s >> a >> A.x >> a >> A.y >> a >> A.z >> a; 
     516        //return s >> A.x >> A.y >> A.z; 
    516517} 
    517518 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.cpp

    r3211 r3219  
    11#include "WalkThroughRecorder.h" 
    22#include "Camera.h" 
    3  
     3#include "Vector3.h" 
     4#include <sstream> 
    45 
    56using namespace std; 
     
    910{ 
    1011 
    11 WalkThroughRecorder::WalkThroughRecorder(const std::string &filename) 
    12 {} 
     12 
     13WalkThroughRecorder::WalkThroughRecorder(const std::string &filename): 
     14mFile(filename.c_str()) 
     15{ 
     16} 
    1317 
    1418 
    1519void WalkThroughRecorder::WriteFrame(Camera *cam) 
    1620{ 
    17         mFile << cam->GetDirection() << "" << cam->GetPosition() << endl; 
     21        FrameInfo info(cam->GetPosition(), cam->GetDirection()); 
     22        mFile << info << endl; 
    1823} 
    1924 
    2025 
    21 WalkThroughPlayer::WalkThroughPlayer(const std::string &filename) 
    22 {} 
     26WalkThroughPlayer::WalkThroughPlayer(const std::string &filename): 
     27mFrame(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} 
    2343 
    2444 
    25 void WalkThroughPlayer::ReadNextFrame(Camera *cam) 
     45bool WalkThroughPlayer::ReadNextFrame(Camera *cam) 
    2646{ 
    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; 
    2853} 
    2954 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/WalkThroughRecorder.h

    r3210 r3219  
    44#include "common.h" 
    55#include <fstream> 
     6#include "Vector3.h" 
     7 
    68 
    79namespace CHCDemoEngine 
     
    911 
    1012class Camera; 
     13 
     14struct 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 
     34inline 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 
     41inline std::istream& operator>> (std::istream &s, FrameInfo &A) 
     42{ 
     43        return s >> A.mPosition >> A.mDirection; 
     44} 
     45 
    1146 
    1247 
     
    2257        */ 
    2358        void WriteFrame(Camera *cam); 
    24         /** Reads next frame 
    25         */ 
    26         void ReadNextFrame(Camera *cam); 
    27  
     59         
    2860protected: 
    2961 
     
    3971        */ 
    4072        WalkThroughPlayer(const std::string &filename); 
    41         /** Reads next frame 
     73        /** Reads next frame. returns false if end of recorded frames is reached. 
    4274        */ 
    43         void ReadNextFrame(Camera *cam); 
     75        bool ReadNextFrame(Camera *cam); 
     76 
    4477 
    4578protected: 
    4679 
    47         std::ifstream mFile; 
     80        std::vector<FrameInfo> mFrameInfos; 
     81 
     82        int mFrame; 
    4883}; 
    4984 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3216 r3219  
    5656#include "ShaderProgram.h" 
    5757#include "Shape.h" 
     58#include "WalkThroughRecorder.h" 
    5859 
    5960 
     
    112113bool ssaoUseFullResolution = false; 
    113114 
     115/// store the frames as tga 
     116bool recordFrames = false; 
     117/// record the taken path 
     118bool recordPath = false; 
     119/// replays the recorded path 
     120bool replayPath = false; 
     121 
     122int currentReplayFrame = -1; 
     123 
     124/// the walkThroughRecorder 
     125WalkThroughRecorder *walkThroughRecorder = NULL; 
     126WalkThroughPlayer *walkThroughPlayer = NULL; 
     127 
    114128 
    115129/// the technique used for rendering 
     
    581595        CreateAnimation(); 
    582596 
     597 
    583598        ////////////////////////// 
    584         //-- a bounding box representing the sun position 
    585         //-- in order to test sun visibility 
     599        //-- a bounding box representing the sun pos in order to test visibility 
     600 
    586601        Transform3 *trafo = resourceManager->CreateTransform(IdentityMatrix()); 
    587602 
     
    653668 
    654669        for (int i = 0; i < 4; ++ i) 
     670        { 
    655671                FrameBufferObject::InitBuffer(fbo, i); 
    656          
     672        } 
     673 
    657674        PrintGLerror("init fbo"); 
    658675} 
     
    9871004void MainLoop()  
    9881005{        
    989 #if 1 
     1006#if TODO 
    9901007        GPUProgramParameters *vtxParams =  
    9911008                buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 
     
    10231040        ///////////// 
    10241041 
    1025         Vector3 oldPos = camera->GetPosition(); 
     1042        static Vector3 oldPos = camera->GetPosition(); 
     1043        static Vector3 oldDir = camera->GetDirection(); 
    10261044 
    10271045        if (leftKeyPressed) 
     
    10521070        } 
    10531071         
     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        } 
    10541086 
    10551087        if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) 
     
    10651097        // bring eye modelview matrix up-to-date 
    10661098        SetupEyeView(); 
     1099         
    10671100        // set frame related parameters for GPU programs 
    10681101        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        } 
    10691114 
    10701115        // hack: store current rendering method and restore later 
     
    12161261                deferredShader->SetUseTemporalCoherence(useTemporalCoherence); 
    12171262                deferredShader->SetSortSamples(sortSamples); 
     1263                deferredShader->SetSaveFrame((recordFrames && replayPath) ? -1 : currentReplayFrame); 
    12181264 
    12191265                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
     
    12571303 
    12581304        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) 
    12631312void KeyBoard(unsigned char c, int x, int y)  
    12641313{ 
     
    13591408                cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 
    13601409                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': 
    13851411        case 'O': 
    13861412                useOptimization = !useOptimization; 
     
    13891415                traverser->SetUseOptimization(useOptimization); 
    13901416                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; 
    13911440        case 'a': 
    13921441        case 'A': 
     
    14391488                useLenseFlare = !useLenseFlare; 
    14401489                break; 
    1441          
     1490        case 'u': 
     1491        case 'U': 
     1492                moveLight = !moveLight; 
     1493                break; 
    14421494        default: 
    14431495                return; 
     
    15501602        case GLUT_KEY_F8: 
    15511603                useAdvancedShading = !useAdvancedShading; 
    1552  
    15531604                break; 
    15541605        case GLUT_KEY_F9: 
     
    15561607                break; 
    15571608        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; 
    15591644                break; 
    15601645        case GLUT_KEY_LEFT: 
     
    18781963        DEL_PTR(shadowTraverser); 
    18791964        DEL_PTR(motionPath); 
     1965        DEL_PTR(walkThroughRecorder); 
     1966        DEL_PTR(walkThroughPlayer); 
    18801967 
    18811968        ResourceManager::DelSingleton(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt

    r3212 r3219  
    113113adaptive number of samples instead of size? 
    1141142) fix color bleeding 
    115 3) fix ssao2 so that ssao contribution stays constant 
     1153) fix ssao2 so that ssao contribution stays constant for both methods 
    1161164) find physical expressions for constants in ssao 
    1171175) retry normal discontinuity for ssao filter 
     
    133133sun disc 
    134134environment lighting 
     135 
     1361) antialiasing very slow: try separable filter and one direction at a time 
     1372) try cross filter for ssao without tempcoh 
     1383) fix model directory => clean up structure (city/model => models ?) 
     1394) fix namespaces: one main namespace for core functions + math functions? 
     140   one util namespace 
     141 
     1425) clean up hacks:  
     143 
     144normalmapping 
     145render target flipflopping for tone mapping 
     146scenequery 
     147 
     148fix walk speed 
Note: See TracChangeset for help on using the changeset viewer.