Changeset 2879


Ignore:
Timestamp:
08/28/08 21:17:15 (16 years ago)
Author:
mattausch
Message:

improved performance

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

Legend:

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

    r2877 r2879  
    308308                        </File> 
    309309                        <File 
     310                                RelativePath=".\src\ShadowMapping.cpp" 
     311                                > 
     312                        </File> 
     313                        <File 
     314                                RelativePath=".\src\ShadowMapping.h" 
     315                                > 
     316                        </File> 
     317                        <File 
    310318                                RelativePath=".\src\SsaoShader.cpp" 
    311319                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp

    r2868 r2879  
    2424 
    2525 
     26static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT,  GL_COLOR_ATTACHMENT3_EXT}; 
     27 
    2628 
    2729static CGprogram sCgDeferredProgram; 
     
    4042mWidth(w), mHeight(h) 
    4143{ 
    42         mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    43         // the diffuse color buffer 
    44         mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
     44        //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     45        //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    4546} 
    4647 
     
    5051        if (sCgDeferredProgram) 
    5152                cgDestroyProgram(sCgDeferredProgram); 
     53 
     54        //DEL_PTR(mFbo); 
    5255} 
    5356 
     
    111114        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    112115 
    113         mFbo->Bind(); 
     116        fbo->Bind(); 
     117        glDrawBuffers(1, mymrt + 3); 
     118 
    114119 
    115120        glPushAttrib(GL_VIEWPORT_BIT); 
     
    199204void DeferredShader::AntiAliasing(FrameBufferObject *fbo) 
    200205{ 
    201         GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 
     206        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
    202207        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    203208 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h

    r2865 r2879  
    4444        int mHeight; 
    4545 
    46         FrameBufferObject *mFbo; 
     46        //FrameBufferObject *mFbo; 
    4747}; 
    4848 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp

    r2878 r2879  
    1616        { 
    1717        case GL_FRAMEBUFFER_COMPLETE_EXT: 
    18                 cout << "frame buffer object complete" << endl; 
     18                //cout << "frame buffer object complete" << endl; 
    1919                break; 
    2020        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 
     
    6868        } 
    6969 
     70 
    7071        glGenRenderbuffersEXT(1, &mId); 
    7172        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId); 
     73         
    7274        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, w, h); 
    73          
    7475        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, color_attachment[attachment_idx], GL_RENDERBUFFER_EXT, mId); 
     76 
    7577 
    7678        glGenTextures(1, &mTexId); 
     
    141143        Bind(); 
    142144 
    143         cout << "creating fbo" << endl; 
    144  
    145145        /////////// 
    146146        //-- create depth buffer 
     
    150150                glGenRenderbuffersEXT(1, &mDepthId);     
    151151                glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthId); 
    152  
    153                 cout << "adding depth buffer" << endl; 
    154152 
    155153                GLuint depthFormat; 
     
    167165                } 
    168166 
    169                 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, mWidth, mHeight); 
     167                glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, w, h); 
     168                 
     169 
    170170                glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthId); 
    171171 
    172172                if (useDepthTex) 
    173173                { 
    174                         //cout << "adding depth texture" << endl; 
    175  
    176174                        glGenTextures(1, &mDepthTexId); 
    177175                        glBindTexture(GL_TEXTURE_2D, mDepthTexId); 
     
    210208                                                                          bool useMipMap) 
    211209{ 
    212         cout << "adding color buffer" << endl; 
    213  
    214210        Bind(); 
    215211 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2878 r2879  
    143143        fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    144144 
    145         PrintGLerror("here667"); 
    146145 
    147146        fbo->Bind(); 
     
    152151        glPushAttrib(GL_VIEWPORT_BIT); 
    153152 
    154         glClearColor(1, 1, 1, 1); 
    155153        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    156154 
     
    188186 
    189187        GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 
    190          
    191188        //ExportDepthBuffer(mDepth); PrintGLerror("grab"); 
    192189 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2875 r2879  
    99using namespace std; 
    1010 
    11 static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 
     11static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 
    1212 
    1313namespace CHCDemoEngine 
     
    7272static CGparameter sNormalsTexAntiAliasingParam; 
    7373 
    74  
    75 static GLuint noiseTex; 
     74static GLuint noiseTex = 0; 
    7675 
    7776// ssao random spherical samples 
     
    9897        static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
    9998        poisson.Generate((Sample2 *)samples); 
     99} 
     100 
     101 
     102static void CreateNoiseTex2D(int w, int h) 
     103{ 
     104        // hack: should be able to recalc noise texture 
     105        //if (noiseTex > 0) return; 
     106 
     107        //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 
     108        float *randomNormals = new float[w * h * 3]; 
     109 
     110        for (int i = 0; i < w * h * 3; i += 3) 
     111        { 
     112                // create random samples on a circle 
     113                const float rx = RandomValue(0, 1); 
     114                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
     115 
     116                //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
     117                //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
     118                randomNormals[i + 0] = cos(theta); 
     119                randomNormals[i + 1] = sin(theta); 
     120                randomNormals[i + 2] = 0; 
     121        } 
     122 
     123        glEnable(GL_TEXTURE_2D); 
     124        glGenTextures(1, &noiseTex); 
     125        glBindTexture(GL_TEXTURE_2D, noiseTex); 
     126                 
     127        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     128        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     129        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
     130        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
     131 
     132        //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     133        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, randomNormals); 
     134 
     135        glBindTexture(GL_TEXTURE_2D, 0); 
     136        glDisable(GL_TEXTURE_2D); 
     137 
     138        delete [] randomNormals; 
     139 
     140        cout << "created noise texture" << endl; 
     141 
     142        PrintGLerror("noisetexture"); 
    100143} 
    101144 
     
    108151mUseGlobIllum(false) 
    109152{ 
     153        // create noise texture for ssao 
     154        CreateNoiseTex2D(w, h); 
     155 
    110156        /////////// 
    111157        //-- the flip-flop fbos 
    112158 
    113159        mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    114         // the diffuse color buffer 
    115160        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    116161        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
     
    118163         
    119164        mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    120         // the diffuse color buffer 
    121165        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    122166        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    123167        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    124168         
    125         mFbo3 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    126         // the diffuse color buffer 
    127         mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    128                  
    129  
    130         // create noise texture for ssao 
    131         CreateNoiseTex2D(); 
     169        //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     170        //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);*/ 
    132171} 
    133172 
    134173 
    135174SsaoShader::~SsaoShader()  
    136 { 
    137         if (sCgSsaoProgram) 
    138                 cgDestroyProgram(sCgSsaoProgram); 
     175 
     176{ 
     177        if (sCgSsaoProgram)     cgDestroyProgram(sCgSsaoProgram); 
     178        if (sCgDeferredProgram) cgDestroyProgram(sCgDeferredProgram); 
     179        if (sCgSsaoProgram)     cgDestroyProgram(sCgSsaoProgram); 
     180        if (sCgGiProgram) cgDestroyProgram(sCgGiProgram); 
     181        if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 
    139182 
    140183        DEL_PTR(mNewFbo); 
    141184        DEL_PTR(mOldFbo); 
     185        //DEL_PTR(mFbo); 
    142186 
    143187        glDeleteTextures(1, &noiseTex); 
     
    295339        FrameBufferObject::Release(); 
    296340 
    297         glDrawBuffers(1, mymrt); 
    298  
    299341        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    300342 
     
    345387        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
    346388 
    347         GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 
     389//      GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 
     390        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
    348391        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    349392        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     
    462505 
    463506 
    464 void SsaoShader::CreateNoiseTex2D() 
    465 { 
    466         //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 
    467         float *randomNormals = new float[mWidth * mHeight * 3]; 
    468  
    469         for (int i = 0; i < mWidth * mHeight * 3; i += 3) 
    470         { 
    471                 // create random samples on a circle 
    472                 const float rx = RandomValue(0, 1); 
    473                 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    474  
    475                 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
    476                 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
    477                 randomNormals[i + 0] = cos(theta); 
    478                 randomNormals[i + 1] = sin(theta); 
    479                 randomNormals[i + 2] = 0; 
    480         } 
    481  
    482         glEnable(GL_TEXTURE_2D); 
    483         glGenTextures(1, &noiseTex); 
    484         glBindTexture(GL_TEXTURE_2D, noiseTex); 
    485                  
    486         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    487         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    488         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    489         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    490  
    491         //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
    492         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mWidth, mHeight, 0, GL_RGB, GL_FLOAT, randomNormals); 
    493  
    494         glBindTexture(GL_TEXTURE_2D, 0); 
    495         glDisable(GL_TEXTURE_2D); 
    496  
    497         delete [] randomNormals; 
    498  
    499         cout << "created noise texture" << endl; 
    500  
    501         PrintGLerror("noisetexture"); 
    502 } 
    503  
    504  
    505507 
    506508static void SetVertex(float x, float y, float x_offs, float y_offs) 
     
    521523void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 
    522524{ 
    523         //GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture(); 
    524525        GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 
    525526        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     
    566567        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    567568 
    568         mFbo3->Bind(); 
    569         //mNewFbo->Bind(); 
     569        fbo->Bind(); 
     570 
     571        glDrawBuffers(1, mymrt + 3); 
    570572 
    571573        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    572574         
    573         glDrawBuffers(1, mymrt); 
    574  
    575575        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    576576 
     
    618618        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixGiParam, (const float *)oldProjViewMatrix.x); 
    619619 
    620         GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 
     620        //GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture(); 
     621        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
    621622        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    622623        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2875 r2879  
    5858        void AntiAliasing(FrameBufferObject *fbo); 
    5959 
    60         void CreateNoiseTex2D(); 
    6160        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 
    6261 
     
    7473        FrameBufferObject *mOldFbo; 
    7574        FrameBufferObject *mNewFbo; 
    76         FrameBufferObject *mFbo3; 
     75        //FrameBufferObject *mFbo; 
    7776 
    7877        bool mUseGlobIllum; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2878 r2879  
    4747//-- fbos 
    4848 
    49 FrameBufferObject *fbo; 
     49FrameBufferObject *fbo = NULL; 
    5050 
    5151bool isFirstTexture = true; 
     
    376376        glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); 
    377377 
    378         InitFBO(); 
    379          
    380378        LeftMotion(0, 0); 
    381379        MiddleMotion(0, 0); 
     
    432430        SsaoShader::Init(sCgContext); 
    433431 
    434         deferredShader = new DeferredShader(texWidth, texHeight); 
    435         ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
     432        //deferredShader = new DeferredShader(texWidth, texHeight); 
     433        //ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
    436434 
    437435        // initialize the render traverser 
     
    539537        // this fbo basicly stores the scene information we get from standard rendering of a frame 
    540538        // we store colors, normals, positions (for the ssao) 
    541         fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_24); 
     539        fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32); 
    542540 
    543541        // the diffuse color buffer 
     
    551549        // the normals buffer 
    552550        //fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
     551        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
     552 
     553        // another color buffer 
    553554        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false); 
    554555 
     
    574575void InitGLstate()  
    575576{ 
    576         glClearColor(0.5f, 0.5f, 0.8f, 0.0f); 
     577        glClearColor(0.0f, 0.0, 0.2f, 0.0f); 
    577578         
    578579        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     
    871872         
    872873                glEnable(GL_MULTISAMPLE_ARB); 
    873                 fbo->Release(); 
    874  
     874                 
    875875                state.SetRenderType(RenderState::FIXED); 
    876876                glEnable(GL_LIGHTING); 
     
    888888 
    889889                glEnable(GL_MULTISAMPLE_ARB); 
    890                 fbo->Release(); 
    891  
     890                 
    892891                cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    893892                cgGLDisableProfile(RenderState::sCgVertexProfile); 
     
    907906         
    908907        case RenderState::DEFERRED: 
     908 
     909                if (!fbo) InitFBO(); 
    909910 
    910911                // multisampling does not work with deferred shading 
     
    987988 
    988989                if (useSsao) 
     990                { 
     991                        if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
     992                        //DEL_PTR(deferredShader); 
     993                         
    989994                        ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor); 
     995 
     996                } 
    990997                else 
     998                { 
     999                        if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight); 
     1000                        //DEL_PTR(ssaoShader); 
     1001 
    9911002                        deferredShader->Render(fbo); 
     1003                } 
     1004        } 
     1005        else 
     1006        { 
     1007                /*DEL_PTR(fbo); 
     1008                DEL_PTR(ssaoShader); 
     1009                DEL_PTR(deferredShader); 
     1010                */ 
    9921011        } 
    9931012         
     
    11741193        switch (c)  
    11751194        { 
     1195 
    11761196        case 'A': 
    11771197        case 'a': 
     
    15311551        DEL_PTR(renderQueue); 
    15321552        DEL_PTR(perfGraph); 
     1553 
     1554        DEL_PTR(fbo); 
     1555        DEL_PTR(ssaoShader); 
     1556        DEL_PTR(deferredShader); 
    15331557 
    15341558        if (sCgMrtVertexProgram) 
Note: See TracChangeset for help on using the changeset viewer.