Changeset 2869


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

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

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

Legend:

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

    r2868 r2869  
    799799                                > 
    800800                        </File> 
    801                         <File 
    802                                 RelativePath=".\src\shaders\temporal.cg" 
    803                                 > 
    804                         </File> 
    805801                </Filter> 
    806802                <File 
  • 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 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2868 r2869  
    5353 
    5454        void AntiAliasing(FrameBufferObject *fbo); 
     55        void Combine(FrameBufferObject *fbo); 
    5556 
    5657        void CreateNoiseTex2D(); 
     
    7172        FrameBufferObject *mNewFbo; 
    7273        FrameBufferObject *mFbo3; 
     74        FrameBufferObject *mFbo4; 
    7375}; 
    7476 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2868 r2869  
    181181        return float4(total_color, 1.0f - total_ao); 
    182182} 
     183 
     184 
     185float ComputeSmoothedColor(float4 centerPosition,  
     186                                                   uniform sampler2D oldTex, 
     187                                                   uniform float maxDepth,   
     188                                                   uniform float expFactor, 
     189                                                   const uniform float4x4 oldModelViewProj, 
     190                                                   float4 currentCol 
     191                                                   ) 
     192{ 
     193        float4 realPos = centerPosition * maxDepth; 
     194        realPos.w = 1.0f; 
     195 
     196        float4 oldPos = mul(oldModelViewProj, realPos); 
     197 
     198        float newDepth = oldPos.z / oldPos.w; 
     199 
     200        float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     201        float4 oldCol = tex2D(oldTex, tex); 
     202 
     203        float oldDepth = oldCol.w; 
     204        float depthDif = 1.0f - newDepth / oldDepth; 
     205 
     206        float4 col; 
     207 
     208        if ((tex.x >= 0.0f) && (tex.x < 1.0f) &&  
     209                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
     210                (abs(depthDif)  < 1e-4f)) 
     211        { 
     212                col = currentCol * expFactor + oldCol * float4(1.0f - expFactor); 
     213        } 
     214        else 
     215        { 
     216                col = currentCol; 
     217        } 
     218 
     219        return col; 
     220 } 
    183221 
    184222 
     
    217255 
    218256        float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
    219         float4 attenuated_color = ao * col; 
     257        //float4 attenuated_color = ao * col; 
    220258        //float4 attenuated_color = ao; 
    221259 
     
    223261        //float4 attenuated_color = ao * col + new_col; 
    224262         
    225         const float x = expFactor; 
    226  
    227         float4 dummy = centerPosition * maxDepth; 
    228         dummy.w = 1.0f; 
    229  
    230         float4 oldPos = mul(oldModelViewProj, dummy); 
    231  
    232         float newDepth = oldPos.z / oldPos.w; 
    233   
    234         float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
    235         float4 col1 = tex2D(oldTex, tex); 
    236  
    237         float oldDepth = col1.w; 
    238         float depthDif = 1.0f - newDepth / oldDepth; 
    239  
    240         if ((tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    241                 (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    242                 (abs(depthDif)  < 1e-4f)) 
    243         { 
    244                 OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor); 
    245         } 
    246         else 
    247         { 
    248                 OUT.color = attenuated_color; 
    249         } 
     263        // compute temporally smoothed color 
     264        OUT.color = ComputeSmoothedColor(centerPosition, oldTex, maxDepth, expFactor, oldModelViewProj, float4(ao)); 
    250265 
    251266        //OUT.color.xyz = viewDir; 
     
    256271        return OUT; 
    257272} 
     273 
     274 
     275pixel combined(fragment IN,  
     276                           uniform sampler2D colors, 
     277                           uniform sampler2D ssaoTex 
     278                   ) 
     279{ 
     280        pixel OUT; 
     281 
     282        float4 col = tex2D(colors, IN.texCoord.xy); 
     283        float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 
     284 
     285        OUT.color = float4(1,0,0,0); 
     286        OUT.color = col * ao; 
     287 
     288        return OUT; 
     289} 
Note: See TracChangeset for help on using the changeset viewer.