Changeset 3103


Ignore:
Timestamp:
11/06/08 10:41:02 (16 years ago)
Author:
mattausch
Message:

still some error with ssao on edges
bilateral filter slow

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

Legend:

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

    r3102 r3103  
    244244                        </File> 
    245245                        <File 
     246                                RelativePath=".\src\SceneQuery.cpp" 
     247                                > 
     248                        </File> 
     249                        <File 
     250                                RelativePath=".\src\SceneQuery.h" 
     251                                > 
     252                        </File> 
     253                        <File 
    246254                                RelativePath=".\src\SkyPreetham.cpp" 
    247255                                > 
     
    495503                                </File> 
    496504                                <File 
    497                                         RelativePath=".\src\SceneQuery.h" 
    498                                         > 
    499                                 </File> 
    500                                 <File 
    501505                                        RelativePath=".\src\ShaderManager.h" 
    502506                                        > 
     
    679683                                </File> 
    680684                                <File 
    681                                         RelativePath=".\src\SceneQuery.cpp" 
    682                                         > 
    683                                 </File> 
    684                                 <File 
    685685                                        RelativePath=".\src\ShaderManager.cpp" 
    686686                                        > 
     
    753753                        <File 
    754754                                RelativePath=".\src\shaders\antialiasing.cg" 
     755                                > 
     756                        </File> 
     757                        <File 
     758                                RelativePath=".\src\shaders\combineSsao.cg" 
    755759                                > 
    756760                        </File> 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3095 r3103  
    6464// ssao random spherical samples 
    6565static Sample2 samples2[NUM_SAMPLES]; 
    66 // default sequence of samples 
    67 //static Sample2 defaultSamples2[NUM_SAMPLES]; 
    6866// number of pcf tabs 
    69 Sample2 pcfSamples[NUM_PCF_TABS]; 
     67static Sample2 pcfSamples[NUM_PCF_TABS]; 
     68 
     69 
     70static float ssaoFilterOffsets[NUM_SSAO_FILTERSAMPLES * 2]; 
     71static float ssaoFilterWeights[NUM_SSAO_FILTERSAMPLES]; 
    7072 
    7173 
     
    7880{ 
    7981        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
    80  
    8182        cam->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
    8283 
     
    257258        //-- the flip-flop fbos 
    258259 
    259         mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
     260        const int dsw = w / 2; 
     261        const int dsh = h / 2; 
     262 
     263        mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
    260264        //mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    261265 
     
    268272        } 
    269273 
    270         mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 
     274        mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 
    271275        //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    272276        mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
     
    277281 
    278282        // create noise texture for ssao 
    279         CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
     283        //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
     284        CreateNoiseTex2D(mWidth / 8, mHeight / 8); 
    280285 
    281286        mProjViewMatrix = IdentityMatrix(); 
     
    316321        sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag"); 
    317322        sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 
    318         sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 
     323        sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 
    319324        sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 
    320325        sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); 
     
    391396        sCgCombineIllumProgram->AddParameter("illumTex", 2); 
    392397 
    393         sCgCombineSsaoProgram->AddParameter("colors", 0); 
    394         sCgCombineSsaoProgram->AddParameter("ssaoTex", 1); 
    395         sCgCombineSsaoProgram->AddParameter("filterOffs", 2); 
    396         sCgCombineSsaoProgram->AddParameter("filterWeights", 3); 
     398        sCgCombineSsaoProgram->AddParameter("colorsTex", 0); 
     399        sCgCombineSsaoProgram->AddParameter("normalsTex", 1); 
     400        sCgCombineSsaoProgram->AddParameter("ssaoTex", 2); 
     401        sCgCombineSsaoProgram->AddParameter("filterOffs", 3); 
     402        sCgCombineSsaoProgram->AddParameter("filterWeights", 4); 
     403 
     404        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
     405        poisson.Generate((float *)ssaoFilterOffsets); 
     406 
     407        //const float filterWidth = 10.0f; 
     408        const float filterWidth = 5.0f; 
     409 
     410        //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); 
     411        //const float yoffs = filterWidth / mDownSampleFbo->GetHeight(); 
     412        const float xoffs = (float)filterWidth / 1024.0f; 
     413        const float yoffs = (float)filterWidth / 768.0f; 
     414 
     415        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     416        { 
     417                float x = ssaoFilterOffsets[2 * i + 0]; 
     418                float y = ssaoFilterOffsets[2 * i + 1]; 
     419 
     420                ssaoFilterOffsets[2 * i + 0] *= xoffs; 
     421                ssaoFilterOffsets[2 * i + 1] *= yoffs; 
     422 
     423                ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
     424        } 
    397425 
    398426 
    399427        float filterWeights[NUM_PCF_TABS]; 
    400         PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 
    401         poisson.Generate((float *)pcfSamples); 
     428        PoissonDiscSampleGenerator2 poisson2(NUM_PCF_TABS, 1.0f); 
     429        poisson2.Generate((float *)pcfSamples); 
    402430 
    403431        for (int i = 0; i < NUM_PCF_TABS; ++ i) 
     
    427455                FirstPass(fbo, light); 
    428456 
     457 
     458        if (mShadingMethod != 0) 
     459        { 
     460                // downsample fbo buffers for colors 
     461                DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 
     462                // normals 
     463                DownSample(fbo, 1, mDownSampleFbo, 1); 
     464        } 
     465 
    429466        switch (mShadingMethod) 
    430467        { 
    431468        case SSAO: 
    432                 // downsample fbo buffers for colors, normals 
    433                 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 
    434                 DownSample(fbo, 1, mDownSampleFbo, 1); 
    435469 
    436470                ComputeSsao(fbo, tempCohFactor); 
     
    438472                break; 
    439473        case GI: 
    440                 // downsample fbo buffers for colors, normals 
    441                 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 
    442                 DownSample(fbo, 1, mDownSampleFbo, 1); 
    443  
    444474                ComputeGlobIllum(fbo, tempCohFactor); 
    445475                CombineIllum(fbo); 
     
    707737 
    708738        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    709          
     739        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    710740        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    711741 
     
    714744        glDrawBuffers(1, mrt + colorBufferIdx); 
    715745 
    716         float filterOffsets[NUM_SSAO_FILTERSAMPLES * 2]; 
    717         float filterWeights[NUM_SSAO_FILTERSAMPLES]; 
    718  
    719         PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
    720         poisson.Generate((float *)filterOffsets); 
    721  
    722         //const float filterWidth = 10.0f; 
    723         const float filterWidth = 7.0f; 
    724         const float xoffs = filterWidth / fbo->GetWidth(); 
    725         const float yoffs = filterWidth / fbo->GetHeight(); 
    726  
    727         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    728         { 
    729                 float x = filterOffsets[2 * i + 0]; 
    730                 float y = filterOffsets[2 * i + 1]; 
    731  
    732                 filterOffsets[2 * i + 0] *= xoffs; 
    733                 filterOffsets[2 * i + 1] *= yoffs; 
    734  
    735                 filterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    736         } 
    737  
    738          
    739746        sCgCombineSsaoProgram->SetTexture(0, colorsTex); 
    740         sCgCombineSsaoProgram->SetTexture(1, ssaoTex); 
    741  
    742         sCgCombineSsaoProgram->SetArray2f(2, (float *)filterOffsets, NUM_SSAO_FILTERSAMPLES); 
    743         sCgCombineSsaoProgram->SetArray1f(3, (float *)filterWeights, NUM_SSAO_FILTERSAMPLES); 
     747        sCgCombineSsaoProgram->SetTexture(1, normalsTex); 
     748        sCgCombineSsaoProgram->SetTexture(2, ssaoTex); 
     749 
     750        sCgCombineSsaoProgram->SetArray2f(3, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 
     751        sCgCombineSsaoProgram->SetArray1f(4, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
    744752         
    745753        DrawQuad(sCgCombineSsaoProgram); 
     
    874882 
    875883 
    876 void DeferredRenderer::DownSample(FrameBufferObject *fbo, int bufferIdx, 
     884void DeferredRenderer::DownSample(FrameBufferObject *fbo,  
     885                                                                  int bufferIdx, 
    877886                                                                  FrameBufferObject *downSampleFbo,  
    878887                                                                  int downSampleBufferIdx) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp

    r3102 r3103  
    776776        m.x[2][3] = .0f; 
    777777         
    778         m.x[3][0] = (right + left) * xDif; 
    779         m.x[3][1] = (top + bottom) * yDif; 
    780         m.x[3][2] = (far + near)   * zDif; 
     778        m.x[3][0] = -(right + left) * xDif; 
     779        m.x[3][1] = -(top + bottom) * yDif; 
     780        m.x[3][2] = -(far + near)   * zDif; 
    781781        m.x[3][3] = 1.0f; 
    782782 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r2955 r3103  
    6868 
    6969                        // check if in disk, else exit early 
    70                         if (rx * rx + ry * ry > mRadius * mRadius) 
     70                        const float distanceSquared = rx * rx + ry * ry; 
     71 
     72                        if ((rx * rx + ry * ry > mRadius * mRadius)  
     73                                // also test if sample exactly in center => avoid that                           
     74                                || (distanceSquared <= 1e-3f) 
     75                                ) 
    7176                                continue; 
    7277 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r3102 r3103  
    162162        glMatrixMode(GL_MODELVIEW); 
    163163        glPushMatrix(); 
    164         //glLoadIdentity(); 
     164        glLoadIdentity(); 
    165165 
    166166        glMatrixMode(GL_PROJECTION); 
    167167        glPushMatrix(); 
    168         //glLoadIdentity(); 
     168        glLoadIdentity(); 
    169169 
    170170        OrthoCamera *orthoCam = new OrthoCamera(xlen, -xlen, ylen, -ylen, .0f, mSceneBox.Size().z); 
    171171         
    172         orthoCam->Yaw(.5 * M_PI); 
    173172        orthoCam->SetDirection(Vector3(0, 0, -1)); 
    174173        orthoCam->SetPosition(pos); 
     
    177176 
    178177        //glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);  
    179         //glMatrixMode(GL_MODELVIEW); 
     178        glMatrixMode(GL_MODELVIEW); 
    180179        //orthoCam->SetupCameraView(); 
    181180 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3102 r3103  
    458458        //-- load some dynamic stuff 
    459459 
    460         /*LoadModel("hbuddha.dem", dynamicObjects); 
     460        LoadModel("hbuddha.dem", dynamicObjects); 
    461461        //LoadModel("hbuddha2.dem", dynamicObjects); 
    462462        buddha = dynamicObjects.back(); 
     
    484484        } 
    485485 
    486 */ 
    487486 
    488487        /////////// 
     
    884883 
    885884        Matrix4x4 mat = TranslationMatrix(planepos); 
    886         //buddha->GetTransform()->SetMatrix(mat); 
     885        buddha->GetTransform()->SetMatrix(mat); 
    887886 
    888887        Vector3 oldPos = camera->GetPosition(); 
     
    933932        /// enable vbo vertex array 
    934933        glEnableClientState(GL_VERTEX_ARRAY); 
    935  
    936934 
    937935        // render with the specified method (forward rendering, forward + depth, deferred) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3100 r3103  
    1818//#define DISTANCE_SCALE 1e-1f 
    1919#define DISTANCE_SCALE 5e-2f 
     20//#define DISTANCE_SCALE 0.2f 
    2021 
    2122//#define ILLUM_INTENSITY 8e-2f 
     
    4243#define MAX_LOD_LEVEL 10 
    4344 
    44 #define MIN_DEPTH_DIFF 1e-2f 
    45 //#define MIN_DEPTH_DIFF 5e-1f 
     45//#define MIN_DEPTH_DIFF 1e-2f 
     46#define MIN_DEPTH_DIFF 0.1f 
    4647#define PRECISION_SCALE 1e-1f 
    4748 
     
    5253/////////////////// 
    5354 
    54 #define NUM_DOWNSAMPLES 16 
     55#define NUM_DOWNSAMPLES 9 
    5556 
    56 #define NUM_SSAO_FILTERSAMPLES 100 
     57#define NUM_SSAO_FILTERSAMPLES 28 
    5758 
    5859 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r3094 r3103  
    104104                //-- reconstruct world space position from sample 
    105105 
    106                 //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
    107                 const float4 sample = tex2D(colors, texcoord); 
     106                const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 
     107                //const float4 sample = tex2D(colors, texcoord); 
    108108 
    109109                const float eyeSpaceDepth = sample.w; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3101 r3103  
    44// Screen Spaced Ambient Occlusion shader 
    55// based on shader of Alexander Kusternig 
    6  
    7  
    8 #define USE_EYE_SPACE_DEPTH 1 
    9  
    106 
    117struct fragment 
     
    8278                                                           ) 
    8379{ 
    84         const float2 mynoise = tex2D(noiseTex, texcoord0).xy; 
     80        const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy; 
    8581 
    8682        const float2 offsetTransformed = myreflect(offset, mynoise); 
     
    151147        //else trafo = inverseModelTrafo * oldModelViewProj; 
    152148 
    153         float3 dummyPt = worldPos.xyz - oldEyePos; 
     149        float3 translatedPt = worldPos.xyz - oldEyePos; 
    154150 
    155151        // reproject into old frame and calculate texture position of sample in old frame 
    156         float4 backProjPos = mul(oldModelViewProj, float4(dummyPt, 1.0f)); 
     152        float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 
    157153        backProjPos /= backProjPos.w; 
    158154        // fit from unit cube into 0 .. 1 
     
    169165         
    170166        const float invlen = 1.0f / length(viewVec); 
    171         const float projectedEyeSpaceDepth = length(dummyPt) * invlen; 
     167        const float projectedEyeSpaceDepth = length(translatedPt) * invlen; 
    172168         
    173169        const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 
     170        //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 
    174171         
    175172        float notValid = 0.5f; 
    176173 
     174        /* 
    177175        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    178176        { 
     
    191189                if (sampleDif >= 5e-2f) ++ notValid; 
    192190        } 
     191        */ 
    193192 
    194193        // the number of valid samples in this frame 
     
    202201                && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 
    203202                && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 
    204                 && (abs(depthDif) <= MIN_DEPTH_DIFF)  
     203                && (depthDif <= MIN_DEPTH_DIFF)  
    205204                // if visibility changed in the surrounding area we have to recompute 
    206205                //&& (oldNumSamples > 0.8f * newNumSamples) 
     
    259258                //-- add random noise: reflect around random normal vector (rather slow!) 
    260259 
    261                 float2 mynoise = tex2D(noiseTex, IN.texCoord).xy; 
     260                float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    262261                const float2 offsetTransformed = myreflect(offset, mynoise); 
    263262#else 
     
    275274 
    276275                float3 dirSample = samplePos - centerPosition; 
    277                 const float lengthToSample = length(dirSample); 
     276                const float lengthToSample = max(length(dirSample), 1e-6f); 
    278277 
    279278                dirSample /= lengthToSample; // normalize 
    280279 
    281280                // angle between current normal and direction to sample controls AO intensity. 
    282                 const float cosAngle = max(dot(dirSample, normal), .0f); 
    283  
     281                float cosAngle = max(dot(dirSample, normal), .0f); 
     282         
    284283                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    285284                // the distance to a sample approaches zero 
     
    291290                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    292291 
    293                 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, normal); 
     292                const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 
    294293                total_ao += cosAngle * aoContrib * viewCorrection; 
    295294#else 
     
    352351                                                                          oldbl, oldbr, oldtl, oldtr); 
    353352 
     353        //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 
    354354        return OUT; 
    355355} 
    356  
    357  
    358 float Filter(float2 texCoord,  
    359                          uniform sampler2D ssaoTex, 
    360                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    361                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 
    362 { 
    363         float average = .0f; 
    364         float w = .0f; 
    365  
    366         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    367         { 
    368                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x; 
    369                 w += filterWeights[i]; 
    370         } 
    371  
    372         average *= 1.0f / (float)w; 
    373  
    374         return average; 
    375 } 
    376  
    377  
    378 pixel combine(fragment IN,  
    379                           uniform sampler2D colors, 
    380                           uniform sampler2D ssaoTex, 
    381                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    382                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    383                           ) 
    384 { 
    385         pixel OUT; 
    386  
    387         float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
    388         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    389  
    390         if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    391  
    392         OUT.illum_col = col * ao.x; 
    393         //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 
    394         //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    395         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    396         OUT.illum_col.w = col.w; 
    397  
    398         return OUT; 
    399 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3017 r3103  
    9191        { 
    9292                color = tex2D(colors, downSampleOffs[i]); 
    93  
    9493                const float intensity = dot(cols[i].rgb, w); 
    9594 
     
    146145         
    147146        // obtain new image key from highest mipmap level 
    148         float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w; 
     147        float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, MAX_LOD_LEVEL)).w; 
    149148        float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 
    150149 
     
    153152        // adjust to middle gray 
    154153        const float lum = middleGrey * pixLum / newImageKey; 
    155           
    156154        // map to range and calc burnout 
    157155        const float scaleLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 
     
    170168 
    171169        pixel OUT; 
    172          
     170 
    173171        const float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    174  
    175172        OUT.col = color; 
    176173 
     
    187184        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    188185 
    189         if (oldLogLum > 1e-5f) // too bright 
     186        // exponential smoothing of tone mapping over time 
     187        if (oldLogLum > 1e-5f) // loglum from last frame too bright 
    190188                OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    191189        else 
Note: See TracChangeset for help on using the changeset viewer.