Ignore:
Timestamp:
11/25/08 18:14:48 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
9 edited

Legend:

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

    r3166 r3167  
    7171 
    7272 
    73 static float ssaoFilterOffsets[NUM_SSAO_FILTERSAMPLES * 2]; 
    74 static float ssaoFilterWeights[NUM_SSAO_FILTERSAMPLES]; 
     73static float ssaoFilterOffsets[NUM_SSAO_FILTER_SAMPLES * 2]; 
     74static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 
    7575 
    7676 
     
    445445         
    446446        string prepareSsaoParams[] =  
    447                 {"colorsTex", "oldTex", "oldEyePos", "modelViewProj", "oldModelViewProj", 
    448                  "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"}; 
    449  
    450         sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 
     447                {"colorsTex", "normalsTex", "diffVals", "oldTex",  
     448                 "oldEyePos", "modelViewProj", "oldModelViewProj", 
     449                 "oldbl", "oldbr", "oldtl", "oldtr"}; 
     450 
     451        sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11); 
    451452 
    452453 
    453454        //////////////// 
    454455 
    455  
    456         //const float filterWidth = 100.0f; 
    457         const float filterWidth = 30.0f; 
    458         //const float filterWidth = 15.0f; 
    459  
    460         PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 
     456        const float filterWidth = 1.0f; 
     457 
     458        PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 
    461459        poisson.Generate((float *)ssaoFilterOffsets); 
    462460 
     
    464462        const float yoffs = (float)filterWidth / mHeight; 
    465463 
    466         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     464        for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    467465        { 
    468466                float x = ssaoFilterOffsets[2 * i + 0]; 
     
    516514                //DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 
    517515                PrepareSsao(fbo); 
    518                 DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 
    519                 DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 
     516                //DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 
     517                //DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 
    520518        } 
    521519 
     
    570568 
    571569 
     570 
     571static inline float SqrMag(const Sample2 &s) 
     572{ 
     573        return (s.x * s.x + s.y * s.y); 
     574} 
     575 
     576 
     577static inline float SqrDist(const Sample2 &a, const Sample2 &b) 
     578{ 
     579        float x = a.x - b.x; 
     580        float y = a.y - b.y; 
     581         
     582        return x * x + y * y; 
     583} 
     584 
     585 
     586static inline bool lt(const Sample2 &a, const Sample2 &b) 
     587{ 
     588        return SqrMag(a) < SqrMag(b); 
     589} 
     590 
     591 
     592void DeferredRenderer::SortSamples() 
     593{ 
     594        //for (int i = 0; i < NUM_SAMPLES; ++ i)cout << SqrDist(samples2[i-1], samples2[i]) << "|"; 
     595        float dist = 0; 
     596        for (int i = 1; i < NUM_SAMPLES; ++ i) 
     597                dist += SqrDist(samples2[i-1], samples2[i]); 
     598                //cout << samples2[i].x << " " << samples2[i].y  
     599 
     600        //cout << "\nbefore: " << dist << endl; 
     601 
     602        //sort(samples2, samples2 + sizeof(samples2) / sizeof(Sample2), lt2); 
     603 
     604 
     605        static Sample2 tempSamples[NUM_SAMPLES]; 
     606        static bool checked[NUM_SAMPLES]; 
     607 
     608        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     609                checked[i] = false; 
     610 
     611        Sample2 currentSample; 
     612        currentSample.x = 0; currentSample.y = 0; 
     613        int ns = 0; // the next sample index 
     614 
     615        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     616        { 
     617                float minLen = 1e20f; 
     618 
     619                for (int j = 0; j < NUM_SAMPLES; ++ j) 
     620                { 
     621                        if (checked[j]) continue; 
     622 
     623                        Sample2 s = samples2[j]; 
     624                        const float len = SqrDist(s, currentSample); 
     625 
     626                        if (len < minLen)  
     627                        { 
     628                                minLen = len; 
     629                                ns = j; 
     630                        } 
     631                } 
     632 
     633                tempSamples[i] = samples2[ns]; 
     634                currentSample = samples2[ns]; 
     635                checked[ns] = true; 
     636        } 
     637 
     638        for (int i = 0; i < NUM_SAMPLES; ++ i) 
     639                samples2[i] = tempSamples[i]; 
     640 
     641        dist = 0; 
     642        for (int i = 1; i < NUM_SAMPLES; ++ i) 
     643                dist += SqrDist(samples2[i-1], samples2[i]); 
     644                //cout << samples2[i].x << " " << samples2[i].y << " " << SqrDist(samples2[i-1], samples2[i]) << "|"; 
     645 
     646        //cout << "after:  " << dist << endl; 
     647} 
     648 
     649 
    572650void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo,  
    573651                                                                   float tempCohFactor) 
     
    616694                // needs longer to converge 
    617695                GenerateSamples(mSamplingMethod); 
     696 
     697                SortSamples(); 
    618698                sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
    619699        } 
     
    821901        sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 
    822902 
    823         sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 
    824         sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
     903        sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 
     904        sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 
    825905         
    826906        sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); 
     
    9571037void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 
    9581038{ 
    959         GLuint colorsTex, diffVals, oldTex; 
     1039        GLuint colorsTex, normalsTex, diffVals, oldTex; 
    9601040 
    9611041        colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    962         //normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     1042        normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    9631043        diffVals = fbo->GetColorBuffer(2)->GetTexture(); 
    9641044        //diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); 
     
    9701050 
    9711051        sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 
    972         //sCgSsaoProgram->SetTexture(i ++, normalsTex); 
     1052        sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex); 
     1053        sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    9731054        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 
    9741055 
     
    9861067                sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 
    9871068 
    988         sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    989  
    990  
    9911069        glPushAttrib(GL_VIEWPORT_BIT); 
    9921070        glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 
     
    9941072        mDownSampleFbo->Bind(); 
    9951073 
    996         glDrawBuffers(1, mrt + 0); 
     1074        glDrawBuffers(3, mrt + 0); 
    9971075 
    9981076        DrawQuad(sCgPrepareSsaoProgram); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3155 r3167  
    109109        void PrepareSsao(FrameBufferObject *fbo); 
    110110 
     111        void SortSamples(); 
    111112 
    112113 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3155 r3167  
    587587        //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
    588588        // buffer holding the difference vector to the old frame 
    589         fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     589        fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    590590        // another color buffer 
    591591        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3166 r3167  
    66//-- ssao + gi parameters 
    77 
    8 //#define NUM_SAMPLES 8 
    9 #define NUM_SAMPLES 24 
     8#define NUM_SAMPLES 8 
     9//#define NUM_SAMPLES 24 
    1010 
    1111// for quadratic falloff 
    1212//#define SAMPLE_INTENSITY 0.2f 
    13 //#define SAMPLE_INTENSITY 0.07f 
    14 #define SAMPLE_INTENSITY 0.01f 
     13#define SAMPLE_INTENSITY 0.07f 
     14//#define SAMPLE_INTENSITY 0.01f 
    1515 
    1616//#define SAMPLE_INTENSITY 0.075f 
     
    2727 
    2828#define VIEW_CORRECTION_SCALE 1.0f 
     29 
     30//#define NUM_SSAO_FILTERSAMPLES 80 
     31#define NUM_SSAO_FILTER_SAMPLES 16 
     32#define NUM_SSAO_FILTER_WIDTH 10.0f 
     33#define SSAO_CONVERGENCE_WEIGHT 25.0f 
    2934 
    3035 
     
    6065#define NUM_DOWNSAMPLES 9 
    6166 
    62 //#define NUM_SSAO_FILTERSAMPLES 25 
    63 //#define NUM_SSAO_FILTERSAMPLES 50 
    64 //#define NUM_SSAO_FILTERSAMPLES 80 
    65 #define NUM_SSAO_FILTERSAMPLES 80 
    66  
    6767 
    6868#define DYNAMIC_OBJECTS_THRESHOLD 1e-8f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r3154 r3167  
    9191 
    9292 
    93         //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 
    94         float4 col = (s0 + s1 + s2 + s3) * 0.25f; 
     93        float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 
     94        //float4 col = (s0 + s1 + s2 + s3) * 0.25f; 
    9595        //float4 col = float4(ne.x, ne.x, ne.x, 0); 
    9696        //float4 col = float4(de.x, de.x, de.x, 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3164 r3167  
    3030                                                  uniform sampler2D normalsTex, 
    3131                                                  uniform sampler2D colorsTex, 
    32                                                   uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    33                                                   uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     32                                                  uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 
     33                                                  uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 
    3434                                                  float scale 
    3535                                                  ) 
     
    4040        const float eyeSpaceDepth = color.w; 
    4141 
    42         const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    43         //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 
     42        const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 
    4443 
    4544        float4 aoSample; 
     
    5352        float sampleDepth; 
    5453 
    55         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     54        for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    5655        { 
    5756                sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    5857 
    5958                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
    60                 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 
    61                 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
     59                sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    6260 
    6361                // check depth discontinuity 
     
    9694                                                   uniform sampler2D normalsTex, 
    9795                                                   uniform sampler2D colorsTex, 
    98                                                    uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     96                                                   uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 
    9997                                                   float scale, 
    10098                                                   float3 bl, 
     
    107105 
    108106        const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 
    109         const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    110         //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 
     107        const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 
    111108 
    112109        float4 aoSample; 
     
    118115        float normalFactor; 
    119116        float convergenceFactor; 
    120         float sampleDepth; 
    121  
    122         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     117        float len; 
     118 
     119        for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 
    123120        { 
    124121                sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    125122 
    126123                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
    127                 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 
    128                 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
     124                sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
    129125 
    130126                // check spatial discontinuity 
    131127                samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 
    132                 float len = SqrLen(centerPos - samplePos); 
     128                len = min(SqrLen(centerPos - samplePos), 1e2f); 
    133129 
    134130                spatialFactor = 1.0f / max(len, 1e-3f); 
     
    159155                          uniform sampler2D ssaoTex, 
    160156                          uniform sampler2D normalsTex, 
    161                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    162                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     157                          uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 
     158                          uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 
    163159                          uniform float4x4 modelViewProj, 
    164160                          uniform float3 bl, 
     
    180176*/ 
    181177 
     178        // filter up to a certain convergance value and leave out background (sky) by checking depth 
    182179        if ((ao.y < 100.0f) && (col.w < 1e10f)) 
    183180        //if (col.w < 1e10f) 
     
    189186 
    190187                const float convergence = ao.y; 
    191                 const float adaptWeight = 5.0f; 
    192                 const float convergenceScale = adaptWeight / (convergence + adaptWeight); 
    193  
    194                 const float scale = convergenceScale * distanceScale; 
    195  
    196  
     188                const float adaptWeight = 25.0f; 
     189                const float convergenceScale = SSAO_CONVERGENCE_WEIGHT / (convergence + SSAO_CONVERGENCE_WEIGHT); 
     190 
     191                const float scale = NUM_SSAO_FILTER_WIDTH * convergenceScale * distanceScale; 
     192 
     193                // the filtered ssao value 
    197194                ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 
    198195        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3164 r3167  
    1414{ 
    1515        float4 color: COLOR0; 
     16        float3 normal: COLOR1; 
     17        float3 diffVal: COLOR2; 
    1618}; 
    1719 
     
    230232        valid in the current frame 
    231233        */ 
    232 inline float PixelValid(sampler2D diffVals, 
    233                                                 sampler2D oldTex, 
     234inline float PixelValid(sampler2D oldTex, 
    234235                                                float4 color, 
     236                                                float3 diffVec, 
    235237                                                float2 texCoord, 
    236238                                                float3 viewDir, 
     
    248250        const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 
    249251 
    250         float3 diffVec = tex2Dlod(diffVals, float4(texCoord, 0, 0)).xyz; 
    251252         
    252253 
     
    308309 
    309310 
    310 float4 PrepareSsao(fragment IN, 
     311pixel PrepareSsao(fragment IN, 
    311312                                   uniform sampler2D colorsTex, 
     313                                   uniform sampler2D normalsTex, 
     314                                   uniform sampler2D diffVals, 
    312315                                   uniform sampler2D oldTex, 
    313316                                   uniform float4x4 modelViewProj, 
     
    317320                                   uniform float3 oldtl, 
    318321                                   uniform float3 oldtr, 
    319                                    uniform float3 oldEyePos, 
    320                                    uniform sampler2D diffVals 
    321                                    ): COLOR 
     322                                   uniform float3 oldEyePos 
     323                                   ) 
    322324{    
    323         //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     325        pixel pix; 
     326 
     327        const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz); 
     328        const float3 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0 ,0)).xyz; 
     329 
    324330        const float3 viewDir = IN.view; 
    325331        float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
     
    330336 
    331337        // do reprojection and filter out the pixels that are not save 
    332         float pValid = PixelValid(diffVals, 
     338        float pValid = PixelValid( 
    333339                oldTex, 
    334340                color,  
     341                difVec.xyz, 
    335342                IN.texCoord, 
    336343                viewDir, 
     
    341348                ); 
    342349 
    343         color.x = pValid; 
    344         return color; 
     350        pix.color = color; 
     351        pix.color.x = pValid; 
     352 
     353        pix.normal = normal; 
     354        pix.diffVal = difVec; 
     355 
     356        return pix; 
    345357} 
    346358 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3161 r3167  
    213213                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
    214214                // the normal of the current sample 
    215                 const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
     215                //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 
     216                const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 
    216217 
    217218 
     
    357358        pixel OUT; 
    358359 
    359         const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     360        //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 
     361        const float3 normal = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz; 
    360362 
    361363        // reconstruct position from the eye space depth 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg

    r3017 r3167  
    127127         
    128128        // the ambient term 
    129         const float amb = norm.w; 
    130  
     129        //const float amb = norm.w; 
    131130        // expand normal 
    132131        float3 normal = normalize(norm.xyz); 
    133          
    134132        /// the current view direction 
    135133        float3 viewDir;// = normalize(IN.view); 
Note: See TracChangeset for help on using the changeset viewer.