Changeset 3019


Ignore:
Timestamp:
10/09/08 18:36:03 (16 years ago)
Author:
mattausch
Message:

detected memory leaks mainly in shadowmapping!!
strange problems with deferred rendering, seems to be uninitialized sometimes (solved?)

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln

    r3017 r3019  
    77EndProject 
    88Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MainApp", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}" 
    9         ProjectSection(ProjectDependencies) = postProject 
    10                 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} 
    11         EndProjectSection 
    12 EndProject 
    13 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}" 
    149        ProjectSection(ProjectDependencies) = postProject 
    1510                {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} 
     
    3429                {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.ActiveCfg = Release|Win32 
    3530                {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.Build.0 = Release|Win32 
    36                 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win32 
    37                 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win32 
    38                 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32 
    39                 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32 
    4031        EndGlobalSection 
    4132        GlobalSection(SolutionProperties) = preSolution 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3016 r3019  
    1818                <Configuration 
    1919                        Name="Debug|Win32" 
    20                         OutputDirectory="$(SolutionDir)/bin/$(ConfigurationName)" 
     20                        OutputDirectory="$(SolutionDir)/lib/$(ConfigurationName)" 
    2121                        IntermediateDirectory="obj/$(ConfigurationName)" 
    22                         ConfigurationType="1" 
     22                        ConfigurationType="4" 
    2323                        CharacterSet="1" 
    2424                        > 
     
    6262                        /> 
    6363                        <Tool 
    64                                 Name="VCLinkerTool" 
    65                                 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib" 
    66                                 LinkIncremental="2" 
    67                                 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib;&quot;$(CG_LIB_PATH)&quot;" 
    68                                 IgnoreDefaultLibraryNames="LIBCMT" 
    69                                 GenerateDebugInformation="true" 
    70                                 SubSystem="1" 
    71                                 TargetMachine="1" 
     64                                Name="VCLibrarianTool" 
    7265                        /> 
    7366                        <Tool 
     
    7568                        /> 
    7669                        <Tool 
    77                                 Name="VCManifestTool" 
    78                         /> 
    79                         <Tool 
    8070                                Name="VCXDCMakeTool" 
    8171                        /> 
     
    8575                        <Tool 
    8676                                Name="VCFxCopTool" 
    87                         /> 
    88                         <Tool 
    89                                 Name="VCAppVerifierTool" 
    90                         /> 
    91                         <Tool 
    92                                 Name="VCWebDeploymentTool" 
    9377                        /> 
    9478                        <Tool 
     
    128112                                EnableFiberSafeOptimizations="true" 
    129113                                AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;" 
    130                                 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS" 
     114                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 
    131115                                StringPooling="true" 
    132116                                RuntimeLibrary="2" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj

    r3012 r3019  
    4141                                Name="VCCLCompilerTool" 
    4242                                Optimization="0" 
    43                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" 
     43                                AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;" 
     44                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SET" 
    4445                                MinimalRebuild="true" 
    4546                                BasicRuntimeChecks="3" 
     
    6162                        <Tool 
    6263                                Name="VCLinkerTool" 
     64                                AdditionalDependencies="DemoEngine.lib glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib" 
     65                                OutputFile="$(OutDir)\FriendlyCulling.exe" 
    6366                                LinkIncremental="2" 
     67                                AdditionalLibraryDirectories="&quot;lib/$(ConfigurationName)&quot;;libs;&quot;$(CG_LIB_PATH)&quot;;libs/GL;libs/Devil/lib;libs/Zlib/lib" 
    6468                                GenerateDebugInformation="true" 
    6569                                SubSystem="1" 
     
    122126                                EnableFiberSafeOptimizations="true" 
    123127                                AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;" 
    124                                 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS" 
     128                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 
    125129                                RuntimeLibrary="2" 
    126130                                EnableEnhancedInstructionSet="2" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3018 r3019  
    6161 
    6262 
     63ShaderContainer DeferredRenderer::sShaders; 
    6364 
    6465/////////////////////////////////////// 
     
    296297 
    297298 
     299static void InitBuffer(FrameBufferObject *fbo, int index) 
     300{ 
     301        // read the second buffer, write to the first buffer 
     302        fbo->Bind(); 
     303        glDrawBuffers(1, mrt + index); 
     304 
     305        //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
     306        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     307 
     308        glEnd(); 
     309 
     310        FrameBufferObject::Release(); 
     311} 
     312 
     313 
    298314DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor): 
    299315mWidth(w), mHeight(h),  
     
    303319mSamplingMethod(SAMPLING_POISSON), 
    304320mShadingMethod(DEFAULT), 
    305 mFboIndex(0) 
     321mIllumFboIndex(0) 
    306322{ 
    307323        // create noise texture for ssao 
     
    312328        //-- the flip-flop fbos 
    313329 
    314         mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
    315         //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    316  
    317         mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    318         mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    319         mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    320         mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
     330        mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
     331        mFBOs.push_back(mIllumFbo); 
     332 
     333        for (int i = 0; i < 4; ++ i) 
     334        { 
     335                mIllumFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
     336                InitBuffer(mIllumFbo, i); 
     337        } 
    321338 
    322339        mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
    323  
    324340        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    325341        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    326 } 
    327  
     342 
     343        mFBOs.push_back(mDownSampleFbo); 
     344} 
    328345 
    329346 
    330347DeferredRenderer::~DeferredRenderer()  
    331348{ 
    332         if (sCgSsaoProgram)     cgDestroyProgram(sCgSsaoProgram); 
    333         if (sCgDeferredProgram) cgDestroyProgram(sCgDeferredProgram); 
    334         if (sCgSsaoProgram)     cgDestroyProgram(sCgSsaoProgram); 
    335         if (sCgGiProgram) cgDestroyProgram(sCgGiProgram); 
    336         if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 
    337  
    338         DEL_PTR(mFbo); 
     349        CLEAR_CONTAINER(sShaders); 
     350        CLEAR_CONTAINER(mFBOs); 
    339351 
    340352        glDeleteTextures(1, &noiseTex); 
     
    350362void DeferredRenderer::Init(CGcontext context) 
    351363{        
     364        ShaderProgram *pr; 
     365 
     366 
    352367        sCgDeferredProgram =  
    353368                cgCreateProgramFromFile(context,  
     
    368383                 
    369384                sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 
     385 
     386                pr = new ShaderProgram(sCgDeferredProgram); 
     387                sShaders.push_back(pr); 
    370388        } 
    371389        else 
     
    407425                sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br");  
    408426                sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl");  
     427 
     428                pr = new ShaderProgram(sCgSsaoProgram); 
     429                sShaders.push_back(pr); 
    409430        } 
    410431        else 
     
    443464 
    444465                sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 
     466 
     467                pr = new ShaderProgram(sCgGiProgram); 
     468                sShaders.push_back(pr); 
    445469        } 
    446470        else 
     
    462486                sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 
    463487                sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 
     488 
     489                pr = new ShaderProgram(sCgCombinedIllumProgram); 
     490                sShaders.push_back(pr); 
    464491        } 
    465492        else 
     
    484511                sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 
    485512                sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 
     513 
     514                pr = new ShaderProgram(sCgCombinedSsaoProgram); 
     515                sShaders.push_back(pr); 
    486516        } 
    487517        else 
     
    503533                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
    504534                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     535 
     536                pr = new ShaderProgram(sCgAntiAliasingProgram); 
     537                sShaders.push_back(pr); 
    505538        } 
    506539        else 
     
    538571 
    539572                cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 
     573 
     574                pr = new ShaderProgram(sCgDeferredShadowProgram); 
     575                sShaders.push_back(pr); 
    540576        } 
    541577        else 
     
    553589        { 
    554590                cgGLLoadProgram(sCgLogLumProgram); 
    555                 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");   
     591                sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");  
     592 
     593                pr = new ShaderProgram(sCgLogLumProgram); 
     594                sShaders.push_back(pr); 
    556595        } 
    557596        else 
     
    576615 
    577616                sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors");   
     617 
     618                pr = new ShaderProgram(sCgToneProgram); 
     619                sShaders.push_back(pr); 
    578620        } 
    579621        else 
     
    596638                sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors");  
    597639                sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs"); 
     640 
     641                pr = new ShaderProgram(sCgDownSampleProgram); 
     642                sShaders.push_back(pr); 
    598643        } 
    599644        else 
     
    618663        // the other one will be written 
    619664 
    620         mFboIndex = 2 - mFboIndex; 
     665        mIllumFboIndex = 2 - mIllumFboIndex; 
    621666         
    622667 
     
    726771#endif 
    727772 
    728         GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 
     773        GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    729774 
    730775        glPushAttrib(GL_VIEWPORT_BIT); 
    731         glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight()); 
     776        glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    732777 
    733778        // read the second buffer, write to the first buffer 
    734         mFbo->Bind(); 
    735         glDrawBuffers(1, mrt + mFboIndex); 
     779        mIllumFbo->Bind(); 
     780        glDrawBuffers(1, mrt + mIllumFboIndex); 
    736781 
    737782         
     
    850895        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
    851896 
    852  
     897        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    853898        glColor3f(1.0f, 1.0f, 1.0f); 
    854899 
     
    939984 
    940985        glPushAttrib(GL_VIEWPORT_BIT); 
    941         glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight()); 
     986        glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
    942987 
    943988        // read the second buffer, write to the first buffer 
    944         mFbo->Bind(); 
    945  
    946         glDrawBuffers(2, mrt + mFboIndex); 
    947  
    948         GLuint oldSsaoTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 
    949         GLuint oldIllumTex = mFbo->GetColorBuffer(2 - mFboIndex + 1)->GetTexture(); 
     989        mIllumFbo->Bind(); 
     990 
     991        glDrawBuffers(2, mrt + mIllumFboIndex); 
     992 
     993        GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
     994        GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 
    950995         
    951996        cgGLBindProgram(sCgGiProgram); 
     
    10241069        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    10251070 
    1026         GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 
    1027         GLuint illumTex = mFbo->GetColorBuffer(mFboIndex + 1)->GetTexture(); 
     1071        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     1072        GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
    10281073 
    10291074 
     
    10841129        GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    10851130         
    1086         GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 
     1131        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    10871132 
    10881133        // overwrite old color texture 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3016 r3019  
    1919class DirectionalLight; 
    2020 
     21 
     22class ShaderProgram 
     23{ 
     24public: 
     25 
     26        ShaderProgram(CGprogram program): mProgram(program) {} 
     27 
     28        ~ShaderProgram() { cgDestroyProgram(mProgram); } 
     29 
     30        CGprogram mProgram; 
     31}; 
     32 
     33 
     34typedef  std::vector<ShaderProgram *> ShaderContainer; 
     35typedef  std::vector<FrameBufferObject *> FBOContainer; 
    2136 
    2237/** This class implements a deferred shading algorithm that takes 
     
    108123 
    109124        int mSamplingMethod; 
    110         int mFboIndex; 
    111125 
    112126        int mShadingMethod; 
     
    114128        bool mRegenerateSamples; 
    115129 
    116         // the main fbo we are working with 
    117         FrameBufferObject *mFbo; 
     130        int mIllumFboIndex; 
     131        // the fbo for indirect illumination (ssao + color bleeding) 
     132        FrameBufferObject *mIllumFbo; 
    118133 
    119134        FrameBufferObject *mDownSampleFbo; 
     135 
     136        FBOContainer mFBOs; 
     137 
     138        static ShaderContainer sShaders; 
    120139}; 
    121140 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r2982 r3019  
    2929        CLEAR_CONTAINER(mTrafos); 
    3030        CLEAR_CONTAINER(mShapes); 
     31        CLEAR_CONTAINER(mLODs); 
    3132} 
    3233 
     
    7374                str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 
    7475 
    75                  
    7676                LODLevel *lodLevel = new LODLevel(dist); 
    7777 
     
    9393                } 
    9494 
     95                mLODs.push_back(lodLevel); 
    9596                sceneGeom->AddLODLevel(lodLevel); 
    9697        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h

    r2981 r3019  
    99#include "common.h" 
    1010 
     11 
     12#define _CRTDBG_MAP_ALLOC 
    1113 
    1214class igzstream; 
     
    6062        ShapeContainer mShapes; 
    6163 
     64        LODContainer mLODs; 
    6265 
    6366        //////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r3011 r3019  
    160160        DEL_PTR(mFbo); 
    161161        DEL_PTR(mShadowCam); 
     162 
     163        DEL_PTR(lightPoly); 
     164        DEL_PTR(polyhedron); 
    162165} 
    163166 
     
    649652        glDisable(GL_DEPTH_TEST); 
    650653 
    651         //glLineWidth(2); 
    652654        Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 
    653655        DrawPoly(hpoly, Vector3(1, 1, 1)); 
    654  
    655656        DEL_PTR(hpoly); 
    656657 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3018 r3019  
    11// chcdemo.cpp : Defines the entry point for the console application. 
    22// 
    3 #include "glInterface.h" 
     3 
     4#ifdef _CRT_SET 
     5        #define _CRTDBG_MAP_ALLOC 
     6        #include <stdlib.h> 
     7        #include <crtdbg.h> 
     8#endif 
     9 
     10#include "common.h" 
     11 
     12#ifdef _CRT_SET 
     13        // redefine new operator 
     14        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     15        #define new DEBUG_NEW 
     16#endif 
     17 
     18 
    419#include <math.h> 
    520#include <time.h> 
    6 #include "common.h" 
     21#include "glInterface.h" 
     22 
     23#include <Cg/cg.h> 
     24#include <Cg/cgGL.h> 
     25 
     26 
    727#include "RenderTraverser.h" 
    828#include "SceneEntity.h" 
     
    4060#include "EntityMerger.h" 
    4161 
    42 #include <Cg/cg.h> 
    43 #include <Cg/cgGL.h> 
    44  
    45  
    4662using namespace std; 
    4763using namespace CHCDemoEngine; 
     
    5975/// the renderable scene geometry 
    6076SceneEntityContainer sceneEntities; 
    61 SceneEntityContainer sceneEntities2; 
    6277 
    6378// traverses and renders the hierarchy 
     
    255270inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 
    256271inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 
    257  
     272// initialise the frame buffer objects 
    258273void InitFBO(); 
    259274 
     
    309324int main(int argc, char* argv[]) 
    310325{ 
     326#ifdef _CRT_SET 
     327 
     328        //Now just call this function at the start of your program and if you're 
     329        //compiling in debug mode (F5), any leaks will be displayed in the Output 
     330        //window when the program shuts down. If you're not in debug mode this will 
     331        //be ignored. Use it as you will! 
     332        //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 
     333 
     334        _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 
     335        _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 
     336        _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);  
     337#endif 
     338 
     339        cout << "=== reading environment file ===" << endl << endl; 
     340 
    311341        int returnCode = 0; 
    312342 
     
    317347        cout << "=== reading environment file ===" << endl << endl; 
    318348 
    319         string envFileName = "default.env"; 
     349        const string envFileName = "default.env"; 
    320350        if (!env.Read(envFileName)) 
    321351        { 
     
    347377                //env.GetStringParam(string("modelPath"), model_path); 
    348378                //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 
    349  
    350379 
    351380                cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl;  
     
    395424        SceneEntity::SetUseLODs(useLODs); 
    396425 
    397  
    398426        if (!useFullScreen) 
    399427        { 
     
    420448        InitGLstate(); 
    421449 
    422  
    423450        glEnable(GL_MULTISAMPLE_ARB); 
    424451        glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); 
     
    432459 
    433460        const string filename = string(model_path + "city.dem"); 
     461         
    434462 
    435463        if (loader->Load(filename, sceneEntities)) 
     
    441469                exit(0); 
    442470        } 
     471         
    443472 
    444473        const string bvh_filename = string(model_path + "city.bvh"); 
     
    452481                exit(0); 
    453482        } 
    454          
    455483 
    456484        // set far plane based on scene extent 
     
    468496         
    469497        Matrix4x4 transl = TranslationMatrix(cubeCenter); 
    470          
    471498 
    472499        SceneEntityContainer dummy; 
     
    474501        string skyDomeStr(model_path + "sky.dem"); 
    475502 
    476         if (loader->Load(skyDomeStr, dummy)) 
    477                 cout << "successfully loaded " << dummy.size() << " scene entities" << endl; 
     503        if (loader->Load(skyDomeStr, sceneEntities)) 
     504                cout << "successfully loaded " << sceneEntities.size() << " scene entities" << endl; 
    478505        else 
    479506        { 
     
    484511        } 
    485512 
    486         skyDome = dummy[0]; 
     513        skyDome = sceneEntities.back(); 
    487514 
    488515 
     
    506533        // clean up 
    507534        CleanUp(); 
    508  
     535         
    509536        return 0; 
    510537} 
     
    572599                cgGLLoadProgram(RenderState::sCgMrtFragmentProgram); 
    573600 
    574                 sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos"); 
     601                sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "eyePos"); 
    575602        } 
    576603        else 
     
    613640        glGenTextures(1, &fontTex); 
    614641        glBindTexture(GL_TEXTURE_2D, fontTex); 
     642 
    615643        if (!myfont.Create("data/fonts/verdana.glf", fontTex)) 
    616644                return false; 
     
    17471775        DEL_PTR(ssaoShader); 
    17481776 
     1777        DEL_PTR(light); 
     1778        DEL_PTR(visCamera); 
     1779 
     1780        DEL_PTR(preetham); 
     1781 
    17491782        if (sCgMrtVertexProgram) 
    17501783                cgDestroyProgram(sCgMrtVertexProgram); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp

    r2784 r3019  
    276276} 
    277277 
    278 char * 
    279 strdup(char *a) 
    280 { 
    281         if (a) { 
    282                 char *s = new char[strlen(a)+1]; 
    283                 strcpy(s, a); 
    284                 return s; 
    285         } else 
    286                 return NULL; 
    287 } 
    288278 
    289279bool 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h

    r2980 r3019  
    3232class Vector3; 
    3333class Geometry; 
    34  
     34struct LODLevel; 
    3535 
    3636 
     
    445445 
    446446 
    447 char * 
    448 GetAbsPath(char *path); 
    449  
    450 char * 
    451 strdup(char *a); 
     447char *GetAbsPath(char *path); 
     448 
    452449 
    453450std::string 
     
    495492typedef std::vector<LODLevel *> LODLevelContainer; 
    496493typedef std::vector<Polygon3 *> PolygonContainer; 
     494typedef std::vector<LODLevel *> LODContainer; 
    497495 
    498496typedef std::vector<Vector3> VertexArray; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r3017 r3019  
    8585        for (int i = 0; i < NUM_SAMPLES; i ++)  
    8686        { 
    87                 float2 offset = samples[i]; 
     87                const float2 offset = samples[i]; 
    8888 
    8989#if 1 
     
    104104                //-- reconstruct world space position from sample 
    105105 
    106                 const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     106                //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     107                const float4 sample = tex2D(colors, texcoord); 
    107108 
    108109                const float eyeSpaceDepth = sample.w; 
    109                 //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
    110110                float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
    111111                 
    112                 const float3 sample_position = - rotView * eyeSpaceDepth; 
    113                 const float3 sample_color = sample.xyz; 
     112                const float3 samplePos = - rotView * eyeSpaceDepth; 
     113                const float3 sampleCol = sample.xyz; 
    114114 
    115115                // distance between current position and sample position controls AO intensity. 
    116116 
    117                 float3 vector_to_sample = sample_position - centerPosition.xyz; 
    118                 const float length_to_sample = length(vector_to_sample); 
    119  
    120                 float3 direction_to_sample = vector_to_sample / length_to_sample; 
     117                float3 dirSample = samplePos - centerPosition.xyz; 
     118                const float magSample = length(dirSample); 
     119                // normalize 
     120                dirSample /= magSample; 
    121121 
    122122                // use angle between current normal and direction to sample controls AO intensity. 
    123                 float cos_angle = max(dot(direction_to_sample, currentNormal), 0); 
    124  
    125                 const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample); 
    126  
    127                 const float ssao_intensity = SAMPLE_INTENSITY / denom; 
    128                 const float illum_intensity = ILLUM_INTENSITY / denom; 
     123                float cosAngle = max(dot(dirSample, currentNormal), 0); 
     124 
     125                const float denom = (DISTANCE_SCALE + magSample * magSample); 
     126 
     127                float2 intensity = float2(SAMPLE_INTENSITY, ILLUM_INTENSITY); 
     128                intensity /= denom; 
    129129 
    130130                // if normal perpenticular to view dir, only the samples approx count half 
    131131#if 1 
    132                 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 
    133          
    134                 total_ao += cos_angle * ssao_intensity * view_correction; 
    135                 total_color += cos_angle * illum_intensity * sample_color * view_correction; 
     132                const float viewCorrect = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 
     133         
     134                total_ao += cosAngle * intensity.x * viewCorrect; 
     135                total_color += cosAngle * intensity.y * sampleCol * viewCorrect; 
    136136#else 
    137                 total_ao += cos_angle * ssao_intensity; 
    138                 total_color += cos_angle * illum_intensity * sample_color; 
     137                total_ao += cos_angle * intensity.x; 
     138                total_color += cos_angle * intensity.y * sampleCol; 
    139139#endif 
    140140        } 
     
    143143        gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 
    144144 
    145         //return saturate(total_color); 
    146145        return gi; 
    147146} 
     
    211210 
    212211        // retrieve the sample from the last frame 
    213         float4 oldSsao = tex2D(oldSsaoTex, tex); 
    214         float4 oldIllum = tex2D(oldIllumTex, tex); 
     212        float3 oldSsao = tex2D(oldSsaoTex, tex); 
     213        float3 oldIllum = tex2D(oldIllumTex, tex); 
    215214 
    216215        const float oldDepth = oldSsao.z; 
     
    218217        const float depthDif = projDepth - oldDepth; 
    219218 
    220         float oldWeight = clamp(oldSsao.y, 0, temporalCoherence); 
    221  
     219        // the weights that indicate the state of convergence 
     220        const float oldWeight = clamp(oldSsao.y, .0f, temporalCoherence); 
    222221        float newWeight; 
    223222 
     
    234233                newWeight = oldWeight + 1; 
    235234 
    236                 OUT.ssao_col.x = (gi.ao + oldSsao.x * oldWeight) / newWeight; 
    237                 OUT.illum_col.xyz  = (gi.illum + oldIllum.xyz * oldWeight) / newWeight; 
     235                float4 tmp = float4(gi.ao.x, gi.illum); 
     236                float4 oldTmp = float4(oldSsao.x, oldIllum); 
     237 
     238                float4 interpol = (tmp + oldTmp * oldWeight) / newWeight; 
     239 
     240                OUT.ssao_col.x = interpol.x; 
     241                OUT.illum_col.xyz = interpol.yzw; 
    238242        } 
    239243        else 
     
    261265 
    262266        float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
    263         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x; 
    264         float4 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0)); 
    265  
    266         OUT.illum_col = (col + illum) * ao; 
     267        float ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x; 
     268 
     269        float3 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0)).xyz; 
     270 
     271        OUT.illum_col.xyz = (col.xyz + illum) * ao; 
     272        //OUT.illum_col.xyz = col.xyz * ao; 
     273 
    267274        OUT.illum_col.w = col.w; 
    268275 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3017 r3019  
    4848                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
    4949{ 
    50         const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 
     50        //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 
     51        const float eyeSpaceDepth = tex2D(colors, texcoord).w; 
    5152        float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 
    5253        float3 samplePos = -viewVec * eyeSpaceDepth; 
     
    9495#endif 
    9596                // weight with projected coordinate to reach similar kernel size for near and far 
    96                 float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
    97  
    98                 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f))++ numSamples; 
     97                const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 
     98 
     99                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    99100 
    100101                const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
     
    105106 
    106107                float3 dirSample = samplePos - centerPosition; 
    107                 const float lengthSample = length(dirSample); 
    108  
    109                 float3 nDirSample = dirSample / lengthSample; 
     108                const float magSample = length(dirSample); 
     109                // normalize 
     110                dirSample /= magSample; 
    110111 
    111112                // angle between current normal and direction to sample controls AO intensity. 
    112                 const float cosAngle = max(dot(nDirSample, currentNormal), 0.0f); 
     113                const float cosAngle = max(dot(dirSample, currentNormal), 0.0f); 
    113114 
    114115                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    115116                // the distance to a sample approaches zero 
    116                 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample); 
     117                const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample); 
    117118 
    118119#if 1 
Note: See TracChangeset for help on using the changeset viewer.