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

computing ao in nice function ... but slow!!

File:
1 edited

Legend:

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

    r2868 r2869  
    2121static CGprogram sCgDeferredProgram2 = NULL; 
    2222static CGprogram sCgAntiAliasingProgram = NULL; 
     23static CGprogram sCgCombineProgram = NULL; 
     24 
     25static CGparameter sColorsTexCombineParam; 
     26static CGparameter sSsaoTexCombineParam; 
    2327 
    2428static CGparameter sColorsTexDeferredParam; 
     
    9195        // the diffuse color buffer 
    9296        mFbo3->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    93          
     97                 
     98        mFbo4 = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     99        // the diffuse color buffer 
     100        mFbo4->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    94101 
    95102        // create noise texture for ssao 
     
    131138        else 
    132139                cerr << "deferred program failed to load" << endl; 
     140 
     141 
     142        sCgCombineProgram =  
     143                cgCreateProgramFromFile(context,  
     144                                                                CG_SOURCE, 
     145                                                                "src/shaders/ssao.cg",  
     146                                                                RenderState::sCgFragmentProfile, 
     147                                                                "combined", 
     148                                                                NULL); 
     149 
     150        if (sCgCombineProgram != NULL) 
     151        { 
     152                cgGLLoadProgram(sCgCombineProgram); 
     153 
     154                // we need size of texture for scaling 
     155                sColorsTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "colors");   
     156                sSsaoTexCombineParam = cgGetNamedParameter(sCgCombineProgram, "ssaoTex");  
     157        } 
     158        else 
     159                cerr << "combined program failed to load" << endl; 
    133160 
    134161 
     
    230257        FirstPass(fbo); 
    231258        ComputeSsao(fbo, expFactor); 
     259        Combine(fbo); 
    232260        AntiAliasing(fbo); 
    233261 
     
    415443void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 
    416444{ 
    417         GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     445        GLuint colorsTex = mFbo4->GetColorBuffer(0)->GetTexture(); 
     446        //GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
    418447        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    419448         
     
    503532} 
    504533 
     534 
     535void SsaoShader::Combine(FrameBufferObject *fbo) 
     536{ 
     537        GLuint colorsTex = mFbo3->GetColorBuffer(0)->GetTexture(); 
     538        GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     539 
     540        mFbo4->Bind(); 
     541        //mNewFbo->Bind(); 
     542 
     543        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     544         
     545        glDrawBuffers(1, mymrt); 
     546 
     547        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     548 
     549        cgGLBindProgram(sCgCombineProgram); 
     550 
     551        cgGLSetTextureParameter(sColorsTexCombineParam, colorsTex); 
     552        cgGLEnableTextureParameter(sColorsTexCombineParam); 
     553 
     554        cgGLSetTextureParameter(sSsaoTexCombineParam, ssaoTex); 
     555        cgGLEnableTextureParameter(sSsaoTexCombineParam); 
     556 
     557        glColor3f(1.0f, 1.0f, 1.0f); 
     558 
     559        const float offs = 0.5f; 
     560 
     561        glBegin(GL_QUADS); 
     562 
     563        glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 
     564        glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 
     565        glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f); 
     566        glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f); 
     567 
     568        glEnd(); 
     569 
     570        cgGLDisableTextureParameter(sColorsTexCombineParam); 
     571        cgGLDisableTextureParameter(sSsaoTexCombineParam); 
     572 
     573        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     574 
     575        FrameBufferObject::Release(); 
     576 
     577        PrintGLerror("deferred shading"); 
     578} 
     579 
     580 
    505581} // namespace 
Note: See TracChangeset for help on using the changeset viewer.