Ignore:
Timestamp:
08/26/08 13:30:31 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2866 r2867  
    6464 
    6565 
    66 SsaoShader::SsaoShader(int w, int h,  
    67                                            Camera *cam, 
    68                                            float scaleFactor 
    69                                            ): 
     66SsaoShader::SsaoShader(int w, int h, Camera *cam, float scaleFactor): 
    7067mWidth(w), mHeight(h),  
    7168mCamera(cam), 
     
    7875        mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    7976        // the diffuse color buffer 
    80         mNewFbo->AddColorBuffer(w, h, ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
     77        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    8178         
    8279        mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    8380        // the diffuse color buffer 
    84         mOldFbo->AddColorBuffer(w, h, ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
     81        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    8582         
    8683 
     
    167164        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
    168165 
     166        glPushAttrib(GL_VIEWPORT_BIT); 
     167        glViewport(0, 0, mWidth, mHeight); 
     168 
     169        glDrawBuffers(1, mymrt); 
     170 
     171        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     172 
     173        glDisable(GL_ALPHA_TEST); 
     174        glDisable(GL_TEXTURE_2D); 
     175        glDisable(GL_LIGHTING); 
     176 
     177        glMatrixMode(GL_PROJECTION); 
     178        glPushMatrix(); 
     179        glLoadIdentity(); 
     180 
     181        glMatrixMode(GL_MODELVIEW); 
     182        glPushMatrix(); 
     183        glLoadIdentity(); 
     184 
     185        const float offs = 0.5f; 
     186        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     187 
    169188        // switch roles of old and new fbo 
    170189        // the algorihm uses two input fbos, where the one 
     
    177196        //DisplayTexture(); 
    178197        AntiAliasing(fbo); 
     198 
     199        glEnable(GL_LIGHTING); 
     200        glDisable(GL_TEXTURE_2D); 
     201 
     202        glMatrixMode(GL_PROJECTION); 
     203        glPopMatrix(); 
     204 
     205        glMatrixMode(GL_MODELVIEW); 
     206        glPopMatrix(); 
     207 
     208        glPopAttrib(); 
     209 
     210        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    179211} 
    180212 
     
    186218        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    187219 
     220        if (1) 
     221        { 
     222                // generate mip map levels for position texture 
     223                glBindTexture(GL_TEXTURE_2D, positionsTex); 
     224                glGenerateMipmapEXT(GL_TEXTURE_2D); 
     225        } 
     226 
     227 
    188228        // read the second buffer, write to the first buffer 
    189229        mNewFbo->Bind(); 
    190230        GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 
    191231 
    192         glPushAttrib(GL_VIEWPORT_BIT); 
    193         glViewport(0, 0, mWidth, mHeight); 
    194  
    195232        glDrawBuffers(1, mymrt); 
    196233 
    197         glDisable(GL_ALPHA_TEST); 
    198         glDisable(GL_TEXTURE_2D); 
    199         glDisable(GL_LIGHTING); 
    200  
    201         glMatrixMode(GL_PROJECTION); 
    202         glPushMatrix(); 
    203         glLoadIdentity(); 
    204  
    205         glMatrixMode(GL_MODELVIEW); 
    206         glPushMatrix(); 
    207         glLoadIdentity(); 
    208  
    209         const float offs = 0.5f; 
    210  
    211         glOrtho(-offs, offs, -offs, offs, 0, 1); 
    212  
    213234        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    214  
    215         cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    216235 
    217236        cgGLBindProgram(sCgSsaoProgram); 
     
    265284        cgGLDisableTextureParameter(sOldTexParam); 
    266285 
    267         cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    268  
    269         glEnable(GL_LIGHTING); 
    270         glDisable(GL_TEXTURE_2D); 
    271  
    272         glMatrixMode(GL_PROJECTION); 
    273         glPopMatrix(); 
    274  
    275         glMatrixMode(GL_MODELVIEW); 
    276         glPopMatrix(); 
    277  
    278         glPopAttrib(); 
    279  
    280286        FrameBufferObject::Release(); 
    281287 
     
    316322void SsaoShader::CreateNoiseTex2D() 
    317323{ 
    318         GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 
     324        //GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 
     325        float *randomNormals = new float[mWidth * mHeight * 3]; 
    319326 
    320327        for (int i = 0; i < mWidth * mHeight * 3; i += 3) 
     
    324331                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    325332 
    326                 randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
    327                 randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
     333                //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
     334                //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
     335                randomNormals[i + 0] = cos(theta); 
     336                randomNormals[i + 1] = sin(theta); 
    328337                randomNormals[i + 2] = 0; 
    329338        } 
     
    338347        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    339348 
    340         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     349        //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     350        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mWidth, mHeight, 0, GL_RGB, GL_FLOAT, randomNormals); 
    341351 
    342352        glBindTexture(GL_TEXTURE_2D, 0); 
     
    371381        GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
    372382        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    373  
    374         glPushAttrib(GL_VIEWPORT_BIT); 
    375         glViewport(0, 0, mWidth, mHeight); 
    376  
    377         glDisable(GL_ALPHA_TEST); 
    378         glDisable(GL_TEXTURE_2D); 
    379         glDisable(GL_LIGHTING); 
    380          
    381         glMatrixMode(GL_PROJECTION); 
    382         glPushMatrix(); 
    383         glLoadIdentity(); 
    384  
    385         glMatrixMode(GL_MODELVIEW); 
    386         glPushMatrix(); 
    387         glLoadIdentity(); 
    388  
    389         const float offs = 0.5f; 
    390          
    391         glOrtho(-offs, offs, -offs, offs, 0, 1); 
     383         
    392384        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    393385 
     
    422414        cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 
    423415 
    424         cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    425          
    426         glEnable(GL_LIGHTING); 
    427         glDisable(GL_TEXTURE_2D); 
    428          
    429         glMatrixMode(GL_PROJECTION); 
    430         glPopMatrix(); 
    431  
    432         glMatrixMode(GL_MODELVIEW); 
    433         glPopMatrix(); 
    434  
    435         glPopAttrib(); 
    436  
    437         PrintGLerror("deferred shading"); 
     416        PrintGLerror("antialiasing"); 
    438417} 
    439418 
Note: See TracChangeset for help on using the changeset viewer.