Changeset 3120


Ignore:
Timestamp:
11/12/08 01:47:27 (16 years ago)
Author:
mattausch
Message:

worked on filtering now trying to reduce flickering (have to reorder ssao function quite much

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

Legend:

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

    r3119 r3120  
    9797                           &tangent.x, &tangent.y, &tangent.z); 
    9898 
    99                 vtx.x *= 0.07f; 
    100                 vtx.y *= 0.07f; 
    101                 vtx.z *= 0.07f; 
     99                const float scale = 0.05f; 
     100                vtx.x *= scale; 
     101                vtx.y *= scale; 
     102                vtx.z *= scale; 
    102103 
    103104                geom->mVertices[line] = vtx; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3118 r3120  
    321321        sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag"); 
    322322        sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 
    323         //sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 
    324         sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 
     323        sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 
     324        //sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 
    325325        sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 
    326326        sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); 
     
    364364        //////////////// 
    365365 
    366         string combineSsaoParams[] = {"colorsTex", "ssaoTex", "filterOffs", "filterWeights"}; 
    367         sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 4); 
     366        string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 
     367        sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 5); 
    368368 
    369369        ////////////// 
     
    395395 
    396396        //const float filterWidth = 10.0f; 
    397         const float filterWidth = 5.0f; 
    398         //const float filterWidth = 60.0f; 
     397        //const float filterWidth = 6.0f; 
     398        const float filterWidth = 20.0f; 
    399399 
    400400        //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); 
     
    408408                float y = ssaoFilterOffsets[2 * i + 1]; 
    409409 
     410                ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
     411 
    410412                ssaoFilterOffsets[2 * i + 0] *= xoffs; 
    411413                ssaoFilterOffsets[2 * i + 1] *= yoffs; 
    412  
    413                 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
    414414        } 
    415415 
     
    747747        int i = 0; 
    748748        sCgCombineSsaoProgram->SetTexture(i ++, colorsTex); 
    749         //sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); 
     749        sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); 
    750750        sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 
    751751 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3114 r3120  
    164164{ 
    165165        if (mTransform->IsIdentity()) return mCenter; 
    166         return mTransform->GetMatrix() *  mCenter; 
     166        return mTransform->GetMatrix() * mCenter; 
    167167} 
    168168 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r3110 r3120  
    8989        */ 
    9090        int GetNumLODLevels() const { return (int)mLODLevels.size(); } 
     91        /** Returns center point of this shape. 
     92        */ 
     93        Vector3 GetCenter() const {return mCenter; } 
    9194        /** Returns transformed center point of this shape. 
    9295        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3119 r3120  
    301301void CreateAnimation(); 
    302302 
    303  
    304 // the new and the old viewProjection matrix of the current camera 
     303SceneQuery *GetOrCreateSceneQuery(); 
     304 
     305 
     306// new view projection matrix of the camera 
    305307static Matrix4x4 viewProjMat = IdentityMatrix(); 
     308// the old view projection matrix of the camera 
    306309static Matrix4x4 oldViewProjMat = IdentityMatrix(); 
    307310 
     
    463466        //-- load some dynamic stuff 
    464467 
    465         LoadModel("fisch.dem", dynamicObjects); 
    466         //LoadModel("hbuddha.dem", dynamicObjects); 
     468        //LoadModel("fisch.dem", dynamicObjects); 
     469        LoadModel("hbuddha.dem", dynamicObjects); 
    467470        buddha = dynamicObjects.back(); 
    468471         
     
    482485                offs.y = RandomValue(.0f, 50.0f); 
    483486 
    484                 transl = TranslationMatrix(sceneCenter + offs); 
     487                Vector3 newPos = sceneCenter + offs; 
     488 
     489                transl = TranslationMatrix(newPos); 
    485490                Transform3 *transform = resourceManager->CreateTransform(transl); 
    486491 
     
    912917        buddha->GetTransform()->SetMatrix(trafo); 
    913918 
     919        /*for (int i = 0; i < 10; ++ i) 
     920        { 
     921                SceneEntity *ent = dynamicObjects[i]; 
     922                Vector3 newPos = ent->GetWorldCenter(); 
     923 
     924                if (GetOrCreateSceneQuery()->CalcIntersection(newPos)) 
     925                { 
     926                        Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter());// + Vector3(0, 0, ent->GetBoundingBox().Size(2) * 0.5f)); 
     927                        ent->GetTransform()->SetMatrix(mat); 
     928                } 
     929        }*/ 
     930 
    914931        Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 
    915  
    916932        dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
     933 
    917934 
    918935 
     
    20072024 
    20082025 
     2026SceneQuery *GetOrCreateSceneQuery() 
     2027{ 
     2028        if (!sceneQuery) 
     2029                sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState); 
     2030 
     2031        return sceneQuery; 
     2032} 
     2033 
     2034 
    20092035void PlaceViewer(const Vector3 &oldPos) 
    20102036{ 
    2011         if (!sceneQuery) 
    2012         { 
    2013                 sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState); 
    2014         } 
    2015  
    20162037        Vector3 playerPos = camera->GetPosition(); 
    2017         bool validIntersect = sceneQuery->CalcIntersection(playerPos); 
     2038        bool validIntersect = GetOrCreateSceneQuery()->CalcIntersection(playerPos); 
    20182039 
    20192040        if (validIntersect)  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3115 r3120  
    2929//-- reprojection 
    3030 
    31 #define MIN_DEPTH_DIFF 2e-2f 
     31//#define MIN_DEPTH_DIFF 2e-2f 
     32#define MIN_DEPTH_DIFF 5e-3f 
    3233#define PRECISION_SCALE 1e-1f 
    3334 
     
    5758#define NUM_DOWNSAMPLES 9 
    5859 
    59 //#define NUM_SSAO_FILTERSAMPLES 28 
     60#define NUM_SSAO_FILTERSAMPLES 20 
    6061//#define NUM_SSAO_FILTERSAMPLES 40 
    61 #define NUM_SSAO_FILTERSAMPLES 100 
     62//#define NUM_SSAO_FILTERSAMPLES 100 
    6263 
    6364 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3109 r3120  
    3636 
    3737 
     38float Filter(float2 texCoord,  
     39                         uniform sampler2D ssaoTex, 
     40                         uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     41                         uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     42                         float scale) 
     43{ 
     44        float average = .0f; 
     45        float w = .0f; 
     46 
     47        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     48        {        
     49                average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 
     50                w += filterWeights[i]; 
     51        } 
     52 
     53        average *= 1.0f / (float)w; 
     54 
     55        return average; 
     56} 
     57 
     58 
    3859float BilateralFilter(float2 texCoord, 
    3960                                          float4 ao, 
     
    4162                                          uniform sampler2D normalsTex, 
    4263                                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    43                                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 
     64                                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     65                                          float scale) 
    4466{ 
    4567        float average = .0f; 
    4668        float total_w = .0f; 
    4769 
    48         //const float eyeSpaceDepth = ao.w; 
     70        const float eyeSpaceDepth = ao.w; 
    4971        const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
    5072 
     
    5274        float3 sampleNorm; 
    5375        float w; 
     76        float4 offs; 
     77        float depthFactor; 
    5478 
    5579        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    5680        { 
    57                 float4 offs = float4(texCoord + filterOffs[i], 0, 0); 
     81                offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
    5882                aoSample = tex2Dlod(ssaoTex, offs); 
    59                 //aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]); 
    60                 //float sampleEyeSpaceDepth = aoSample.w; 
    61                 //factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth; 
     83                 
    6284                sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
     85                depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    6386                //sampleNorm = tex2Dlod(normalsTex, offs).xyz; 
    6487 
    65                 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f); 
     88                w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) * depthFactor; 
    6689 
    67                 average += w * aoSample.x; 
     90                average += aoSample.x * w; 
    6891                total_w += w; 
    6992        } 
    7093 
    71         average *= 1.0f / max(total_w, 1e-5f); 
     94        average *= 1.0f / max(total_w, 1e-6f); 
    7295 
    7396        return average; 
     
    88111        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    89112 
    90         //if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    91         //if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights); 
     113        if ((ao.y < 60.0f) && (col.w < 1e10f)) 
     114        { 
     115                const static float scaleFactor = 10.0f; 
    92116 
    93         //OUT.illum_col = col * ao.x; 
    94         //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 
    95         OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
     117                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
     118                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
     119                ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
     120                //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
     121        } 
     122 
     123        OUT.illum_col = col * ao.x; 
     124        //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    96125        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    97         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    98126        OUT.illum_col.w = col.w; 
    99127 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3119 r3120  
    189189        //float overallDepth = 0; 
    190190        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
    191  
     191#if 1 
    192192        if (squaredLen < 1e-8f) // object not dynamic 
    193193        { 
     
    210210                } 
    211211        } 
    212  
     212#endif 
    213213        const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 
    214214        float newWeight; 
     
    220220                // if visibility changed in the surrounding area we have to recompute 
    221221                //&& (oldNumSamples > 0.8f * newNumSamples) 
    222                 && (notValid < 1.0f) 
     222                //&& (notValid < 1.0f) 
    223223                ) 
    224224        { 
     
    226226                newWeight = oldWeight + 1.0f; 
    227227                illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight; 
    228                 //if (notValid > 1.0f) newWeight = 2.0f; 
     228                if (notValid > 1.0f) newWeight = 2.0f; 
    229229        } 
    230230        else 
     
    292292 
    293293                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
     294 
    294295                const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 
    295296 
     
    378379        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    379380 
     381 
    380382        ///////////////// 
    381383        //-- compute temporal reprojection 
     
    393395                                                                          diffVec); 
    394396 
    395         //OUT.illum_col.xyz = id; 
    396         //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 
    397397        return OUT; 
    398398} 
    399  
    400  
    401 float Filter(float2 texCoord,  
    402                          uniform sampler2D ssaoTex, 
    403                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    404                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    405                          float scale) 
    406 { 
    407         float average = .0f; 
    408         float w = .0f; 
    409  
    410         for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
    411         {        
    412                 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x; 
    413                 w += filterWeights[i]; 
    414         } 
    415  
    416         average *= 1.0f / (float)w; 
    417  
    418         return average; 
    419 } 
    420  
    421  
    422 pixel combine(fragment IN,  
    423                           uniform sampler2D colorsTex, 
    424                           uniform sampler2D ssaoTex, 
    425                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    426                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
    427                           ) 
    428 { 
    429         pixel OUT; 
    430  
    431         const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
    432         float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    433  
    434         //if ((ao.y < 10.0f) && (col.w < 1e10f)) 
    435         //      ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 
    436  
    437         OUT.illum_col = col * ao.x; 
    438         //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 
    439         //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 
    440         //OUT.illum_col = float4(ao.x, 0, 0, col.w); 
    441         //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    442         //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    443         OUT.illum_col.w = col.w; 
    444  
    445         return OUT; 
    446 } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt

    r3098 r3120  
    7676to compare the depth of the current pixel, but the depth of the 
    7777samples taken for ao 
     78 
     79 
     80idea for incorporation of dynamic objects: 
     81 
     82store object id with render target 
     83for each object we know the trafo 
     84when doing the back projection => 
     85 
     86as usual: 
     87we have the world space position of the current pixel 
     88find pixel from last frame using the old projection view trafo 
     89 
     90but now we first apply the inverse transformation that brought the 
     91last pixel to the current pixel and then the old projection view!! 
     92 
     93=> now we do the equality comparison as usual 
     94 
     95 
     96for reducing flickering: 
     97 
     98 
Note: See TracChangeset for help on using the changeset viewer.