Ignore:
Timestamp:
08/25/08 17:34:34 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2863 r2865  
    3030static CGparameter sNoiseMultiplierParam; 
    3131static CGparameter sExpFactorParam; 
     32static CGprogram sCgAntiAliasingProgram; 
     33 
     34static CGparameter sColorsTexAntiAliasingParam; 
     35static CGparameter sNormalsTexAntiAliasingParam; 
     36 
    3237 
    3338static GLuint noiseTex; 
     
    133138                cerr << "ssao program failed to load" << endl; 
    134139 
     140        sCgAntiAliasingProgram =  
     141                cgCreateProgramFromFile(context,  
     142                                                                CG_SOURCE, 
     143                                                                "src/shaders/antialiasing.cg",  
     144                                                                RenderState::sCgFragmentProfile, 
     145                                                                "main", 
     146                                                                NULL); 
     147 
     148        if (sCgAntiAliasingProgram != NULL) 
     149        { 
     150                cgGLLoadProgram(sCgAntiAliasingProgram); 
     151 
     152                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
     153                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     154        } 
     155        else 
     156                cerr << "antialiasing program failed to load" << endl; 
     157 
     158 
    135159        PrintGLerror("init"); 
    136160} 
     
    151175        ComputeSsao(fbo, expFactor); 
    152176        // the second pass just renders the combined solution 
    153         DisplayTexture(); 
     177        //DisplayTexture(); 
     178        AntiAliasing(fbo); 
    154179} 
    155180 
     
    213238 
    214239 
    215         GenerateSamples();  
     240        //GenerateSamples();  
    216241        cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
    217242 
     
    259284 
    260285 
    261 void SsaoShader::DisplayTexture() 
     286/*void SsaoShader::DisplayTexture() 
    262287{ 
    263288        glEnable(GL_TEXTURE_2D); 
     
    300325 
    301326        PrintGLerror("ssao second pass"); 
    302 } 
     327}*/ 
    303328 
    304329 
     
    370395 
    371396 
     397 
     398static void SetVertex(float x, float y, float x_offs, float y_offs) 
     399{ 
     400        glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center 
     401        glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top 
     402        glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom 
     403        glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top 
     404        glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom 
     405 
     406        glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right 
     407        glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 
     408 
     409        glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 
     410} 
     411 
     412 
     413void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 
     414{ 
     415        GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     416        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     417 
     418        glPushAttrib(GL_VIEWPORT_BIT); 
     419        glViewport(0, 0, mWidth, mHeight); 
     420 
     421        glDisable(GL_ALPHA_TEST); 
     422        glDisable(GL_TEXTURE_2D); 
     423        glDisable(GL_LIGHTING); 
     424         
     425        glMatrixMode(GL_PROJECTION); 
     426        glPushMatrix(); 
     427        glLoadIdentity(); 
     428 
     429        glMatrixMode(GL_MODELVIEW); 
     430        glPushMatrix(); 
     431        glLoadIdentity(); 
     432 
     433        const float offs = 0.5f; 
     434         
     435        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     436        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     437 
     438        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     439 
     440        cgGLBindProgram(sCgAntiAliasingProgram); 
     441 
     442        cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex); 
     443        cgGLEnableTextureParameter(sColorsTexAntiAliasingParam); 
     444 
     445        cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 
     446        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
     447         
     448        glColor3f(1.0f, 1.0f, 1.0f); 
     449 
     450        float offs2 = 0.5f; 
     451 
     452        glBegin(GL_QUADS); 
     453 
     454        // the neighbouring texels 
     455        float x_offs = 1.0f / mWidth; 
     456        float y_offs = 1.0f / mHeight; 
     457 
     458        SetVertex(0, 0, x_offs, y_offs); 
     459        SetVertex(1, 0, x_offs, y_offs); 
     460        SetVertex(1, 1, x_offs, y_offs); 
     461        SetVertex(0, 1, x_offs, y_offs); 
     462 
     463        glEnd(); 
     464 
     465        cgGLDisableTextureParameter(sColorsTexAntiAliasingParam); 
     466        cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam); 
     467 
     468        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     469         
     470        glEnable(GL_LIGHTING); 
     471        glDisable(GL_TEXTURE_2D); 
     472         
     473        glMatrixMode(GL_PROJECTION); 
     474        glPopMatrix(); 
     475 
     476        glMatrixMode(GL_MODELVIEW); 
     477        glPopMatrix(); 
     478 
     479        glPopAttrib(); 
     480 
     481        PrintGLerror("deferred shading"); 
     482} 
     483 
     484 
    372485} // namespace 
Note: See TracChangeset for help on using the changeset viewer.