Changeset 2880


Ignore:
Timestamp:
08/28/08 22:37:40 (16 years ago)
Author:
mattausch
Message:

downsampling not working yet

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r2879 r2880  
    2323static CGprogram sCgDeferredProgram = NULL; 
    2424static CGprogram sCgAntiAliasingProgram = NULL; 
    25 static CGprogram sCgCombineProgram = NULL; 
    2625 
    2726static CGparameter sColorsTexCombineParam; 
     
    3231static CGparameter sNormalsTexDeferredParam; 
    3332 
     33 
     34static CGprogram sCgCombinedSsaoProgram = NULL; 
     35static CGprogram sCgCombinedIllumProgram = NULL; 
    3436 
    3537///////////////////////////////////////7 
     
    6769 
    6870 
     71static CGparameter sColorsTexCombinedIllumParam; 
     72static CGparameter sSsaoTexCombinedIllumParam; 
     73static CGparameter sIllumTexCombinedIllumParam; 
     74 
     75static CGparameter sColorsTexCombinedSsaoParam; 
     76static CGparameter sSsaoTexCombinedSsaoParam; 
     77 
     78 
    6979//////////// 
    7080 
     
    157167        //-- the flip-flop fbos 
    158168 
     169        w = 256; h = 256; 
    159170        mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     171         
    160172        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    161173        mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    162         mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    163174         
    164175        mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    165         mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
     176         
    166177        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    167178        mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
     
    299310                cerr << "globillum program failed to load" << endl; 
    300311 
     312        sCgCombinedIllumProgram =  
     313                cgCreateProgramFromFile(context,  
     314                                                                CG_SOURCE, 
     315                                                                "src/shaders/globillum.cg",  
     316                                                                RenderState::sCgFragmentProfile, 
     317                                                                "combine", 
     318                                                                NULL); 
     319 
     320        if (sCgCombinedIllumProgram != NULL) 
     321        { 
     322                cgGLLoadProgram(sCgCombinedIllumProgram); 
     323 
     324                sColorsTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "colors");   
     325                sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 
     326                sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 
     327        } 
     328        else 
     329                cerr << "combined illum program failed to load" << endl; 
     330 
     331 
     332        sCgCombinedSsaoProgram =  
     333                cgCreateProgramFromFile(context,  
     334                                                                CG_SOURCE, 
     335                                                                "src/shaders/ssao.cg",  
     336                                                                RenderState::sCgFragmentProfile, 
     337                                                                "combine", 
     338                                                                NULL); 
     339 
     340        if (sCgCombinedSsaoProgram != NULL) 
     341        { 
     342                cgGLLoadProgram(sCgCombinedSsaoProgram); 
     343 
     344                sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors");   
     345                sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex"); 
     346        } 
     347        else 
     348                cerr << "combied illum program failed to load" << endl; 
     349 
     350         
    301351        sCgAntiAliasingProgram =  
    302352                cgCreateProgramFromFile(context,  
     
    317367                cerr << "antialiasing program failed to load" << endl; 
    318368 
    319  
    320369        PrintGLerror("init"); 
    321370} 
     
    333382        swap(mNewFbo, mOldFbo);  
    334383 
    335  
    336         glPushAttrib(GL_VIEWPORT_BIT); 
    337         glViewport(0, 0, mWidth, mHeight); 
    338  
    339384        FrameBufferObject::Release(); 
    340385 
     
    345390        glDisable(GL_LIGHTING); 
    346391 
     392        glPushAttrib(GL_VIEWPORT_BIT); 
     393        glViewport(0, 0, mWidth, mHeight); 
     394 
    347395        glMatrixMode(GL_PROJECTION); 
    348396        glPushMatrix(); 
     
    359407         
    360408        if (!mUseGlobIllum) 
     409        { 
    361410                ComputeSsao(fbo, expFactor, oldProjViewMatrix); 
     411                CombineSsao(fbo); 
     412        } 
    362413        else 
     414        { 
    363415                ComputeGlobIllum(fbo, expFactor, oldProjViewMatrix); 
    364  
     416                CombineIllum(fbo); 
     417        } 
    365418        AntiAliasing(fbo); 
    366419 
     
    402455        // read the second buffer, write to the first buffer 
    403456        mNewFbo->Bind(); 
    404         glDrawBuffers(2, mymrt); 
     457        glDrawBuffers(1, mymrt); 
     458 
     459        glPushAttrib(GL_VIEWPORT_BIT); 
     460        glViewport(0, 0, 256, 256); 
     461 
     462        glMatrixMode(GL_PROJECTION); 
     463        glPushMatrix(); 
     464        glLoadIdentity(); 
     465 
     466        glMatrixMode(GL_MODELVIEW); 
     467        glPushMatrix(); 
     468        glLoadIdentity(); 
     469 
     470        const float offs = 0.5f; 
     471        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     472 
    405473 
    406474        GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 
     
    469537        cgGLDisableTextureParameter(sOldTexParam); 
    470538 
     539        glMatrixMode(GL_PROJECTION); 
     540        glPopMatrix(); 
     541 
     542        glMatrixMode(GL_MODELVIEW); 
     543        glPopMatrix(); 
     544 
     545        glPopAttrib(); 
     546 
    471547        FrameBufferObject::Release(); 
    472548 
     
    523599void SsaoShader::AntiAliasing(FrameBufferObject *fbo) 
    524600{ 
    525         GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 
     601        //GLuint colorsTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 
     602        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    526603        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    527604         
     
    637714        // read the second buffer, write to the first buffer 
    638715        mNewFbo->Bind(); 
    639         glDrawBuffers(3, mymrt); 
     716        glDrawBuffers(2, mymrt); 
    640717 
    641718        GLuint oldSsaoTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 
    642         GLuint oldIllumTex = mOldFbo->GetColorBuffer(2)->GetTexture(); 
     719        GLuint oldIllumTex = mOldFbo->GetColorBuffer(1)->GetTexture(); 
    643720 
    644721        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    716793 
    717794 
     795void SsaoShader::CombineIllum(FrameBufferObject *fbo) 
     796{ 
     797        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
     798        GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     799        GLuint illumTex = mNewFbo->GetColorBuffer(1)->GetTexture(); 
     800 
     801        // 
     802        fbo->Bind(); 
     803 
     804        // write into old color texture (not needed anymore) 
     805        glDrawBuffers(1, mymrt); 
     806 
     807        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     808         
     809        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     810 
     811        cgGLBindProgram(sCgCombinedIllumProgram); 
     812 
     813        cgGLSetTextureParameter(sColorsTexCombinedIllumParam, colorsTex); 
     814        cgGLEnableTextureParameter(sColorsTexCombinedIllumParam); 
     815 
     816        cgGLSetTextureParameter(sSsaoTexCombinedIllumParam, ssaoTex); 
     817        cgGLEnableTextureParameter(sSsaoTexCombinedIllumParam); 
     818 
     819        cgGLSetTextureParameter(sIllumTexCombinedIllumParam, illumTex); 
     820        cgGLEnableTextureParameter(sIllumTexCombinedIllumParam); 
     821         
     822        glColor3f(1.0f, 1.0f, 1.0f); 
     823 
     824        const float offs = 0.5f; 
     825 
     826        glBegin(GL_QUADS); 
     827 
     828        glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 
     829        glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 
     830        glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f); 
     831        glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f); 
     832 
     833        glEnd(); 
     834 
     835        cgGLDisableTextureParameter(sColorsTexCombinedIllumParam); 
     836        cgGLDisableTextureParameter(sSsaoTexCombinedIllumParam); 
     837        cgGLDisableTextureParameter(sIllumTexCombinedIllumParam); 
     838 
     839        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     840 
     841        FrameBufferObject::Release(); 
     842 
     843        PrintGLerror("combine"); 
     844} 
     845 
     846 
     847void SsaoShader::CombineSsao(FrameBufferObject *fbo) 
     848{ 
     849        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
     850        GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
     851 
     852        // 
     853        fbo->Bind(); 
     854 
     855        // write into old color texture (not needed anymore) 
     856        glDrawBuffers(1, mymrt); 
     857 
     858        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     859         
     860        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     861 
     862        cgGLBindProgram(sCgCombinedSsaoProgram); 
     863 
     864        cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex); 
     865        cgGLEnableTextureParameter(sColorsTexCombinedSsaoParam); 
     866 
     867        cgGLSetTextureParameter(sSsaoTexCombinedSsaoParam, ssaoTex); 
     868        cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam); 
     869 
     870         
     871        glColor3f(1.0f, 1.0f, 1.0f); 
     872 
     873        const float offs = 0.5f; 
     874 
     875        glBegin(GL_QUADS); 
     876 
     877        glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 
     878        glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 
     879        glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f); 
     880        glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f); 
     881 
     882        glEnd(); 
     883 
     884        cgGLDisableTextureParameter(sColorsTexCombinedSsaoParam); 
     885        cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam); 
     886 
     887        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     888 
     889        FrameBufferObject::Release(); 
     890 
     891        PrintGLerror("combine ssao"); 
     892} 
     893 
     894 
     895 
    718896} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2879 r2880  
    5656        void FirstPass(FrameBufferObject *fbo); 
    5757 
     58        void CombineSsao(FrameBufferObject *fbo); 
     59        void CombineIllum(FrameBufferObject *fbo); 
     60 
    5861        void AntiAliasing(FrameBufferObject *fbo); 
    5962 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2876 r2880  
    3232{ 
    3333        float4 ssao_col: COLOR0; 
    34         float4 combined_col: COLOR1; 
    35         float4 illum_col: COLOR2; 
     34        float4 illum_col: COLOR1; 
    3635}; 
    3736 
     
    185184        } 
    186185 
    187         OUT.combined_col = (currentCol + OUT.illum_col) * OUT.ssao_col.x; 
    188         //OUT.combined_col = float4(newDepth, oldDepth, 1, 1) ; 
    189  
    190186        OUT.ssao_col.w = currentDepth; 
    191187 
    192188        return OUT; 
    193189} 
     190 
     191 
     192pixel combine(fragment IN,  
     193                          uniform sampler2D colors, 
     194                          uniform sampler2D ssaoTex, 
     195                          uniform sampler2D illumTex 
     196                   ) 
     197{ 
     198        pixel OUT; 
     199 
     200        float4 col = tex2D(colors, IN.texCoord.xy); 
     201        float ao = tex2D(ssaoTex, IN.texCoord.xy).x; 
     202        float4 illum = tex2D(illumTex, IN.texCoord.xy); 
     203         
     204        OUT.illum_col = (col + illum) * ao; 
     205 
     206        return OUT; 
     207} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2876 r2880  
    2929{ 
    3030        float4 illum_col: COLOR0; 
    31         float4 combined_col: COLOR1; 
    3231}; 
    3332 
     
    173172        } 
    174173 
    175         OUT.combined_col = currentCol * OUT.illum_col.x; 
    176174        OUT.illum_col.w = currentDepth; 
    177175 
    178176        return OUT; 
    179177} 
     178 
     179 
     180 
     181pixel combine(fragment IN,  
     182                          uniform sampler2D colors, 
     183                          uniform sampler2D ssaoTex) 
     184{ 
     185        pixel OUT; 
     186 
     187        float4 col = tex2D(colors, IN.texCoord.xy); 
     188        float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 
     189 
     190        OUT.illum_col = col * ao.x; 
     191 
     192        return OUT; 
     193} 
Note: See TracChangeset for help on using the changeset viewer.