Changeset 3305 for GTP


Ignore:
Timestamp:
02/12/09 14:38:14 (15 years ago)
Author:
mattausch
Message:

removed filter radius

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

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp

    r3295 r3305  
    298298                                        ++ mNumShapes; 
    299299 
    300                                         if (!currentMat) cout << "here3" << endl; 
    301300                                        LoadShape(faceVertices, faceNormals, faceTexcoords, currentMat); 
    302301 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3296 r3305  
    820820                        </File> 
    821821                        <File 
    822                                 RelativePath=".\src\shaders\combineSsao.cg" 
    823                                 > 
    824                         </File> 
    825                         <File 
    826822                                RelativePath=".\src\shaders\combineSsaoSep.cg" 
    827823                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3297 r3305  
    144144# ssao temporal coherence factor 
    145145tempCohFactor=2000.0f 
    146 # ssao filter radius 
    147 ssaoFilterRadius=12.0f 
    148146 
    149147 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3301 r3305  
    248248        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    249249        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    250  
    251250        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    252251        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     
    300299mSortSamples(true), 
    301300mKernelRadius(1e-8f), 
    302 mSsaoFilterRadius(12.0f), 
    303301mSampleIntensity(0.2f), 
    304302mSunVisiblePixels(0), 
     
    309307mUseToneMapping(false), 
    310308mUseAntiAliasing(false), 
    311 mUseDepthOfField(false) 
     309mUseDepthOfField(false), 
     310mSsaoUseFullResolution(ssaoUseFullResolution) 
    312311{ 
    313312        /////////// 
     
    316315        int downSampledWidth, downSampledHeight; 
    317316 
    318         if (ssaoUseFullResolution) 
     317        if (mSsaoUseFullResolution) 
    319318        { 
    320319                downSampledWidth = w; downSampledHeight = h; 
     
    327326        } 
    328327 
    329         /////// 
     328 
     329        ///////// 
    330330        //-- the illumination fbo is either half size or full size 
    331331 
    332332        mIllumFbo = new FrameBufferObject(downSampledWidth, downSampledHeight, FrameBufferObject::DEPTH_NONE); 
    333  
    334333        mFBOs.push_back(mIllumFbo); 
    335334 
     
    343342        /////////////// 
    344343        //-- the downsampled ssao + color bleeding textures:  
    345         //-- as GI is mostly low frequency, we can use lower resolution toimprove performance 
     344        //-- as GI is mostly low frequency, we can use lower resolution to improve performance 
    346345 
    347346        mDownSampleFbo = new FrameBufferObject(downSampledWidth, downSampledHeight, FrameBufferObject::DEPTH_NONE); 
     
    358357 
    359358        mFBOs.push_back(mDownSampleFbo); 
     359 
     360 
     361        ///////// 
     362        //-- temporal buffer 
     363 
     364        mTempFbo = new FrameBufferObject(mWidth, mHeight, FrameBufferObject::DEPTH_NONE); 
     365        mFBOs.push_back(mTempFbo); 
     366 
     367        mTempFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
     368        FrameBufferObject::InitBuffer(mTempFbo, 0); 
     369         
    360370 
    361371        // create noise texture for ssao 
     
    397407        sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "GiFrag"); 
    398408        sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "CombineGi"); 
    399         //sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao"); 
    400         sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "CombineSsaoFullRes", "CombineSsao"); 
    401         sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoFullRes", "FilterSsao"); 
     409 
     410        if (mSsaoUseFullResolution) 
     411        { 
     412                sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoFullRes", "FilterSsao"); 
     413        } 
     414        else 
     415        { 
     416                sCgFilterSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "FilterSsaoHalfRes", "FilterSsao"); 
     417        } 
     418         
     419        sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsaoSep", "CombineSsao", "CombineSsao"); 
    402420        sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "AntiAliasing"); 
    403421        sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "ToneMap"); 
     
    446464        //////////////// 
    447465 
    448         /*string combineSsaoParams[] =  
    449                 {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights",  
    450                 "ssaoFilterRadius", "modelViewProj", "bl", "br", "tl",  
    451                 "tr", "w", "h"}; 
    452         */ 
    453466        string combineSsaoParams[] =  
    454                 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "xyStep"}; 
     467        {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"}; 
    455468 
    456469        //sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13); 
     
    461474 
    462475        string filterSsaoParams[] =  
    463                 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "xyStep"}; 
     476                {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res"}; 
    464477 
    465478        sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 7); 
     
    515528 
    516529        sCgDOFProgram->AddParameters(dofParams, 0, 4); 
    517  
    518  
    519         //////////////// 
    520         //-- prepare filter for ssao 
    521  
    522         PrepareSsaoFilter(); 
    523530 
    524531 
     
    642649} 
    643650 
    644 #if 0 
    645  
    646 void DeferredRenderer::PrepareSsaoFilter() 
    647 { 
    648         const float filterWidth = 1.0f; 
    649  
    650         PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
    651         poisson.Generate((float *)ssaoFilterOffsets); 
    652  
    653         const float xoffs = (float)filterWidth / mWidth; 
    654         const float yoffs = (float)filterWidth / mHeight; 
    655  
    656         for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    657         { 
    658                 float x = ssaoFilterOffsets[2 * i + 0]; 
    659                 float y = ssaoFilterOffsets[2 * i + 1]; 
    660  
    661                 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    662                 //ssaoFilterWeights[i] = 1.0f; 
    663  
    664                 ssaoFilterOffsets[2 * i + 0] *= xoffs; 
    665                 ssaoFilterOffsets[2 * i + 1] *= yoffs; 
    666         } 
    667 } 
    668  
    669 #else 
    670  
    671 /** star filter 
    672 */ 
    673 void DeferredRenderer::PrepareSsaoFilter() 
    674 { 
    675         const float filterWidth = 1.0f; 
    676  
    677         PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
    678         poisson.Generate((float *)ssaoFilterOffsets); 
    679  
    680         const float xoffs = (float)filterWidth / mWidth; 
    681         const float yoffs = (float)filterWidth / mHeight; 
    682  
    683         const int n = NUM_SSAO_FILTER_SAMPLES / 2 + 1; 
    684  
    685         for (int i = 0; i < n; ++ i) 
    686         { 
    687                 const int idx = i - NUM_SSAO_FILTER_SAMPLES / 4; 
    688  
    689                 const float x = xoffs * (float)idx; 
    690                 const float y = 0; 
    691  
    692                 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    693                  
    694                 ssaoFilterOffsets[2 * i + 0] = x; 
    695                 ssaoFilterOffsets[2 * i + 1] = y; 
    696         } 
    697  
    698         int j = 2 * n; 
    699  
    700         for (int i = 0; i < n; ++ i) 
    701         {  
    702                 const int idx = i - NUM_SSAO_FILTER_SAMPLES / 4; 
    703  
    704                 if (idx) 
    705                 { 
    706                         const float x = 0; 
    707                         const float y = yoffs * (float)idx; 
    708  
    709                         ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    710                         //ssaoFilterWeights[i] = 1.0f; 
    711                          
    712                         ssaoFilterOffsets[j + 0] = x; 
    713                         ssaoFilterOffsets[j + 1] = y; 
    714  
    715                         j += 2; 
    716                 } 
    717         } 
    718  
    719         for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    720         { 
    721                 cout << "samples " << i << ": " << ssaoFilterOffsets[i * 2] << " " << ssaoFilterOffsets[i * 2 + 1] << endl; 
    722         } 
    723 } 
    724  
    725 #endif 
    726  
    727651 
    728652static inline float SqrMag(const Sample2 &s) 
     
    1045969        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    1046970         
    1047         mIllumFbo->Bind(); 
    1048         glDrawBuffers(1, mrt + mIllumFboIndex + 1); 
    1049          
    1050  
     971        //mIllumFbo->Bind(); 
     972        //glDrawBuffers(1, mrt + mIllumFboIndex + 1); 
     973        mTempFbo->Bind(); 
     974        glDrawBuffers(1, mrt); 
     975         
    1051976        int i = 0; 
    1052977 
     
    1059984        } 
    1060985 
    1061         sCgFilterSsaoProgram->SetValue2f(i ++, 1.0f / (float)mWidth, 0); 
     986        sCgFilterSsaoProgram->SetValue2f(i ++, (float)mWidth, (float)mHeight); 
    1062987 
    1063988        DrawQuad(sCgFilterSsaoProgram); 
    1064          
    1065989        PrintGLerror("combine ssao"); 
    1066990} 
     
    1071995        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    1072996        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    1073         GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
     997        //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
     998        GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 
    1074999         
    10751000        FlipFbos(fbo); 
     
    10801005        sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 
    10811006 
    1082         //sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 
    1083         //sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 
    1084         //sCgCombineSsaoProgram->SetValue1f(i ++, mSsaoFilterRadius); 
    1085         //sCgCombineSsaoProgram->SetMatrix(i ++, mProjViewMatrix); 
    1086  
    10871007        for (int j = 0; j < 4; ++ j, ++ i) 
    10881008        { 
     
    10901010        } 
    10911011 
    1092         //float xOffs, yOffs; 
    1093  
    1094         //sCgCombineSsaoProgram->SetValue2f(i ++, 1.0f / (float)mWidth, 1.0f / (float)mHeight); 
    1095         sCgCombineSsaoProgram->SetValue2f(i ++, 0, 1.0f / (float)mHeight); 
     1012        sCgCombineSsaoProgram->SetValue2f(i ++, mWidth, mHeight); 
    10961013 
    10971014        DrawQuad(sCgCombineSsaoProgram); 
     
    15451462 
    15461463 
    1547 void DeferredRenderer::SetSsaoFilterRadius(float ssaoFilterRadius) 
    1548 { 
    1549         mSsaoFilterRadius = ssaoFilterRadius; 
    1550         mRegenerateSamples = true; 
    1551 } 
    1552  
    1553  
    15541464/*void DeferredRenderer::SetSortSamples(bool sortSamples)  
    15551465{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3301 r3305  
    6363        */ 
    6464        void SetKernelRadius(float kernelRadius); 
    65         /** Sets ssao filter radius. 
    66         */ 
    67         void SetSsaoFilterRadius(float radius); 
    6865        /** Passes the number of pixels that are visible from the sun. 
    6966        */ 
     
    161158 
    162159        void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light); 
    163   
    164         void PrepareSsaoFilter(); 
    165160 
    166161        void SaveFrame(FrameBufferObject *fbo); 
     
    196191 
    197192        FrameBufferObject *mDownSampleFbo; 
     193        FrameBufferObject *mTempFbo; 
    198194 
    199195        FBOContainer mFBOs; 
     
    211207 
    212208        float mKernelRadius; 
    213         float mSsaoFilterRadius; 
    214209        float mSampleIntensity; 
    215210 
     
    224219        bool mUseToneMapping; 
    225220        bool mUseAntiAliasing; 
    226         bool mUseDepthOfField;     
     221        bool mUseDepthOfField; 
     222 
     223        bool mSsaoUseFullResolution; 
    227224}; 
    228225 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3297 r3305  
    204204float ssaoKernelRadius = 1e-8f; 
    205205float ssaoSampleIntensity = 0.2f; 
    206 float ssaoFilterRadius = 12.0f; 
     206float ssaoFilterRadius = 3.0f; 
    207207float ssaoTempCohFactor = 255.0; 
    208208bool sortSamples = true; 
     
    13831383                        deferredShader->SetKernelRadius(ssaoKernelRadius); 
    13841384                        deferredShader->SetSampleIntensity(ssaoSampleIntensity); 
    1385                         deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 
    13861385                } 
    13871386 
     
    15741573                cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 
    15751574                break; 
    1576         case 'o': 
    1577                 ssaoFilterRadius *= 0.9f; 
     1575        /*case 'o': 
     1576                if (ssaoFilterRadius >= 0.0f) ssaoFilterRadius -= 1.0f; 
    15781577                if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 
    15791578                cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 
    15801579                break; 
    15811580        case 'O': 
    1582                 ssaoFilterRadius *= 1.0f / 0.9f; 
     1581                ssaoFilterRadius += 1.0f; 
    15831582                if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 
    15841583                cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 
    1585                 break; 
     1584                break;*/ 
    15861585        /*      case 'o': 
    15871586        case 'O': 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3304 r3305  
    107107                                                 uniform float3 tl, 
    108108                                                 uniform float3 tr, 
    109                                                  uniform float2 resolution 
     109                                                 uniform float2 res 
    110110                                                 ) 
    111111{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3304 r3305  
    1919        float4 illum_col: COLOR0; 
    2020}; 
     21 
     22 
     23float ComputeConvergenceHalfRes(uniform sampler2D ssaoTex, 
     24                                                                float2 texCoord,  
     25                                                                float2 halfres) 
     26{ 
     27    // the following has to be done for half resolution ssao: 
     28        // get the minimum convergence by exactly sampling the 4 surrounding 
     29        // texels in the old texture, otherwise flickering because convergence 
     30        // will be interpolated when upsampling and filter size does not match! 
     31 
     32        float4 texelCenterConv; 
     33        const float xoffs = .5f / halfres.x; const float yoffs = .5f / halfres.y; 
     34 
     35        // get position exactly between old texel centers 
     36        float2 center; 
     37        center.x = (floor(texCoord.x * halfres.x - .5f) + 1.0f) / halfres.x; 
     38        center.y = (floor(texCoord.y * halfres.y - .5f) + 1.0f) / halfres.y; 
     39 
     40        texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2( xoffs,  yoffs), 0, 0)).y; 
     41        texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 
     42        texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
     43        texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y; 
     44 
     45        const float m1 = min(texelCenterConv.x, texelCenterConv.y); 
     46        const float m2 = min(texelCenterConv.z, texelCenterConv.w); 
     47 
     48        const float minConvergence = min(m1, m2); 
     49        return minConvergence; 
     50} 
    2151 
    2252 
     
    4575        // combine the weights 
    4676        float w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor; 
    47  
    4877        float average = aoSample.x * w; 
    4978 
     
    94123                                                uniform float3 tl, 
    95124                                                uniform float3 tr, 
    96                                                 uniform float2 xyStep 
    97                                                  ) 
     125                                                uniform float2 res 
     126                                                ) 
    98127{ 
    99128        pixel OUT; 
     
    108137        // afterwards we do not use the filter anymore 
    109138 
     139        float2 xyStep = float2(1.0f / res.x, 0); 
     140 
    110141        // filter up to a certain convergance value and leave out background (sky) by checking depth 
    111142        if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 
     
    118149} 
    119150 
     151/** In between step that only filters in one direction 
     152*/ 
     153pixel FilterSsaoHalfRes(fragment IN,  
     154                                                uniform sampler2D colorsTex, 
     155                                                uniform sampler2D ssaoTex, 
     156                                                uniform float3 bl, 
     157                                                uniform float3 br, 
     158                                                uniform float3 tl, 
     159                                                uniform float3 tr, 
     160                                                uniform float2 res 
     161                                                 ) 
     162{ 
     163        pixel OUT; 
     164 
     165        const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 
     166 
     167        OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
     168        // just take unfiltered convergence in current pixel 
     169        const float convergence = ComputeConvergenceHalfRes(ssaoTex, IN.texCoord, res * 0.5f); 
     170 
     171        const float2 xyStep = float2(1.0f / res.x, 0); 
     172 
     173        // filter reaches size 1 pixel when sample size reaches threshold  
     174        // afterwards we do not use the filter anymore 
     175 
     176        // filter up to a certain convergance value and leave out background (sky) by checking depth 
     177        if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 
     178        { 
     179                // the filtered ssao value 
     180                OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 
     181        } 
     182 
     183        return OUT; 
     184} 
    120185 
    121186/** Function combining image and indirect illumination buffer using a  
    122187    depth and convergence aware discontinuity filter. 
    123188*/ 
    124 pixel CombineSsaoFullRes(fragment IN,  
    125                                                 uniform sampler2D colorsTex, 
    126                                                 uniform sampler2D ssaoTex, 
    127                                                 uniform float3 bl, 
    128                                                 uniform float3 br, 
    129                                                 uniform float3 tl, 
    130                                                 uniform float3 tr, 
    131                                                  uniform float2 xyStep 
    132                                                 ) 
     189pixel CombineSsao(fragment IN,  
     190                                  uniform sampler2D colorsTex, 
     191                                  uniform sampler2D ssaoTex, 
     192                                  uniform float3 bl, 
     193                                  uniform float3 br, 
     194                                  uniform float3 tl, 
     195                                  uniform float3 tr, 
     196                                  uniform float2 res 
     197                                  ) 
    133198{ 
    134199        pixel OUT; 
     
    141206        const float convergence = ao.y; 
    142207 
     208        const float2 xyStep = float2(0, 1.0f / res.y); 
     209         
    143210        // filter reaches size 1 pixel when sample size reaches threshold  
    144211        // afterwards we do not use the filter anymore 
Note: See TracChangeset for help on using the changeset viewer.