Changeset 3123 for GTP


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

working on ssao for dynamic objects, found error with tight bounds

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

Legend:

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

    r3119 r3123  
    1212# triangles per bvh leaf (influences hierarchy depth vs. occlusion power) 
    1313trianglesPerVirtualLeaf=300 
     14 
     15maxDepthForTestingChildren=3 
    1416 
    1517################ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3075 r3123  
    158158         
    159159        if (!numEntities) 
    160         { 
    161                 // no box=> just initialize 
     160        {       // no box=> just initialize 
    162161                box.Initialize(); 
    163162        } 
     
    202201                mGeometry[mStaticGeometrySize + i] = dynamicEntities[i]; 
    203202        } 
     203} 
     204 
     205 
     206Bvh::Bvh(const SceneEntityContainer &staticEntities,  
     207                 const SceneEntityContainer &dynamicEntities, 
     208                 int maxDepthForTestingChildren) 
     209{ 
     210        Init(); 
     211 
     212        mGeometrySize = staticEntities.size() + dynamicEntities.size(); 
     213        mGeometry = new SceneEntity*[mGeometrySize]; 
     214 
     215        mStaticGeometrySize = staticEntities.size(); 
     216        mDynamicGeometrySize = dynamicEntities.size(); 
     217 
     218        for (size_t i = 0; i < mStaticGeometrySize; ++ i) 
     219        { 
     220                mGeometry[i] = staticEntities[i]; 
     221        } 
     222 
     223        for (size_t i = 0; i < mDynamicGeometrySize; ++ i) 
     224        { 
     225                mGeometry[mStaticGeometrySize + i] = dynamicEntities[i]; 
     226        } 
     227 
     228        mMaxDepthForTestingChildren = maxDepthForTestingChildren; 
    204229} 
    205230 
     
    232257        // nodes are tested using the subnodes from 3 levels below 
    233258        mMaxDepthForTestingChildren = 3; 
     259        mMaxDepthForTestingChildren = 0; 
    234260        //mMaxDepthForTestingChildren = 4; 
    235261 
     
    567593        return numNodes; 
    568594} 
     595 
     596#if TODO 
     597void Bvh::RenderBoundsImmediate(const BvhNodeContainer &nodes, RenderState *state) 
     598{ 
     599        ///////// 
     600        //-- Render the tight bounds in immediate mode 
     601        BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 
     602 
     603        for (nit = nodes.begin(); nit != nit_end; ++ nit) 
     604        { 
     605                BvhNode *node = *nit; 
     606 
     607                for (int size_t i = 0; i < node->mNumTestNodes; ++ i) 
     608                { 
     609                        BvhNode *testNode = node->mTestNodesIdx 
     610                        RenderBoundingBoxImmediate((*nit)->GetBox()); 
     611                } 
     612        } 
     613} 
     614#endif 
    569615 
    570616 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r3102 r3123  
    665665        const Bvh(const SceneEntityContainer &staticEntities,  
    666666                      const SceneEntityContainer &dynamicEntities); 
     667        /** Protected constructor taking scene geometry into account 
     668                Sets the static and dynamic objects for the hierarchy. 
     669        */ 
     670        const Bvh(const SceneEntityContainer &staticEntities,  
     671                      const SceneEntityContainer &dynamicEntities, 
     672                          int maxDepthForTestingChildren); 
    667673        /** Called by the constructor. Initializes important members. 
    668674        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3074 r3123  
    6464Bvh *BvhLoader::Load(const string &filename,   
    6565                                         const SceneEntityContainer &staticEntities, 
    66                                          const SceneEntityContainer &dynamicEntities) 
     66                                         const SceneEntityContainer &dynamicEntities, 
     67                                         int maxDepthForTestingChildren) 
    6768{ 
    6869        queue<BvhNode *> tQueue; 
     
    7374        cout << "loading bvh" << endl; 
    7475 
    75         Bvh *bvh = new Bvh(staticEntities, dynamicEntities); 
     76        Bvh *bvh = new Bvh(staticEntities, dynamicEntities, maxDepthForTestingChildren); 
    7677 
    7778        BvhNode *root = LoadNextNode(stream, NULL); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.h

    r3072 r3123  
    2323        Bvh *Load(const std::string &filename,  
    2424                          const SceneEntityContainer &staticEntities, 
    25                           const SceneEntityContainer &dynamicEntities); 
     25                          const SceneEntityContainer &dynamicEntities, 
     26                          int maxDepthForTestingChildren); 
    2627 
    2728protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3122 r3123  
    409409 
    410410                ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 
     411                //ssaoFilterWeights[i] = 1.0f; 
    411412 
    412413                ssaoFilterOffsets[2 * i + 0] *= xoffs; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3077 r3123  
    137137 
    138138        if (!scaleToRange) 
    139         {        
     139        { 
    140140                // use tone mapping 
    141141                vtxParams->SetValue1f(8, 1.0f); 
     
    143143        else 
    144144        { 
    145                 // no tone mapping => scale to range 
     145                // no tone mapping => scale to range  
    146146                vtxParams->SetValue1f(8, 8e-5f); 
    147147        } 
     
    275275        // diffuse color: sun color 
    276276        pair<float, float> sun_theta; 
     277 
    277278        Vector3 zenithColor; 
    278279        vector<Vector3> ABCDE; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3120 r3123  
    107107MotionPath *motionPath = NULL; 
    108108 
     109int maxDepthForTestingChildren = 3; 
     110 
    109111 
    110112/// the technique used for rendering 
     
    358360                env.GetIntParam(string("maxBatchSize"), maxBatchSize); 
    359361                env.GetIntParam(string("trianglesPerVirtualLeaf"), trianglesPerVirtualLeaf); 
     362                env.GetIntParam(string("winWidth"), winWidth); 
     363                env.GetIntParam(string("winHeight"), winHeight); 
     364                env.GetIntParam(string("shadowSize"), shadowSize); 
     365                env.GetIntParam(string("maxDepthForTestingChildren"), maxDepthForTestingChildren); 
    360366 
    361367                env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 
    362368                env.GetFloatParam(string("keyRotation"), keyRotation); 
    363  
    364                 env.GetIntParam(string("winWidth"), winWidth); 
    365                 env.GetIntParam(string("winHeight"), winHeight); 
    366369                env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor); 
     370 
     371                 
     372                 
    367373                env.GetVectorParam(string("camPosition"), camPos); 
    368374                env.GetVectorParam(string("camDirection"), camDir); 
    369375                env.GetVectorParam(string("lightDirection"), lightDir); 
    370                 env.GetIntParam(string("shadowSize"), shadowSize); 
    371376 
    372377                env.GetBoolParam(string("useFullScreen"), useFullScreen); 
     
    467472 
    468473        //LoadModel("fisch.dem", dynamicObjects); 
    469         LoadModel("hbuddha.dem", dynamicObjects); 
     474        /*LoadModel("hbuddha.dem", dynamicObjects); 
    470475        buddha = dynamicObjects.back(); 
    471476         
     
    492497                ent->SetTransform(transform); 
    493498                dynamicObjects.push_back(ent); 
    494         } 
     499        }*/ 
    495500 
    496501 
     
    501506 
    502507        BvhLoader bvhLoader; 
    503         bvh = bvhLoader.Load(bvh_filename, sceneEntities, dynamicObjects); 
     508        bvh = bvhLoader.Load(bvh_filename, sceneEntities, dynamicObjects, maxDepthForTestingChildren); 
    504509 
    505510        if (!bvh) 
     
    908913void MainLoop()  
    909914{        
     915#if 0 
    910916        GPUProgramParameters *vtxParams =  
    911917                buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 
     
    931937        Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 
    932938        dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
    933  
     939#endif 
    934940 
    935941 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3122 r3123  
    1212//#define SAMPLE_INTENSITY 0.1f 
    1313//#define SAMPLE_INTENSITY 0.07f 
    14 #define SAMPLE_INTENSITY 0.03f 
     14#define SAMPLE_INTENSITY 0.015f 
    1515 
    1616#define SAMPLE_RADIUS 8e-1f 
     
    5858#define NUM_DOWNSAMPLES 9 
    5959 
    60 #define NUM_SSAO_FILTERSAMPLES 20 
     60#define NUM_SSAO_FILTERSAMPLES 50 
    6161//#define NUM_SSAO_FILTERSAMPLES 40 
    6262//#define NUM_SSAO_FILTERSAMPLES 100 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3122 r3123  
    5757 
    5858 
    59 float BilateralFilter(float2 texCoord, 
    60                                           float4 ao, 
    61                                           uniform sampler2D ssaoTex, 
    62                                           uniform sampler2D normalsTex, 
    63                                           uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    64                                           uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    65                                           float scale) 
     59float DiscontinuityFilter(float2 texCoord, 
     60                                                  float4 ao, 
     61                                                  uniform sampler2D ssaoTex, 
     62                                                  uniform sampler2D normalsTex, 
     63                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     64                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     65                                                  float scale) 
    6666{ 
    6767        float average = .0f; 
     
    7676        float4 offs; 
    7777        float depthFactor; 
     78        float normalFactor; 
    7879 
    7980        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     
    8384                 
    8485                sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
    85                 depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    86                 //sampleNorm = tex2Dlod(normalsTex, offs).xyz; 
    8786 
    88                 w = filterWeights[i] * max(dot(sampleNorm, norm), 1e-3f) * depthFactor; 
     87                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
     88                 
     89                depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
     90                normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
     91 
     92                w = filterWeights[i] * normalFactor * depthFactor; 
     93                //w = filterWeights[i] * depthFactor; 
    8994 
    9095                average += aoSample.x * w; 
     
    111116        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    112117 
    113         if ((ao.y < 60.0f) && (col.w < 1e10f)) 
     118        //if ((ao.y < 60.0f) && (col.w < 1e10f)) 
     119        if (col.w < 1e10f) 
    114120        { 
    115                 const static float scaleFactor = 20.0f; 
     121                //const static float scaleFactor = 10.0f; 
     122                const static float scaleFactor = 50.0f; 
    116123 
    117124                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    118125                //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)); 
     126                ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
    120127                //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
    121128        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3122 r3123  
    66 
    77#define USE_EYESPACE_DEPTH 1 
    8 //#extension GL_EXT_gpu_shader4 : enable 
    9  
    108 
    119 
     
    110108        const float projectedEyeSpaceDepth = invlen * length(translatedPos); 
    111109 
    112         float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 3.0f) ?  
     110        float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 1.0f) ?  
    113111                0 : abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 
    114112 
     
    183181 
    184182        float notValid = 0.5f; 
    185         //float overallDepth = 0; 
     183        float overallDepth = 0; 
     184 
    186185        const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 
    187186 
     
    209208#endif 
    210209 
    211         //const float clampedOldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 
    212         const float oldWeight = oldPixel.y; 
     210        const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 
     211        //const float oldWeight = oldPixel.y; 
    213212 
    214213        float newWeight; 
     
    225224                // increase the weight for convergence 
    226225                newWeight = oldWeight + 1.0f; 
    227                 //if (notValid > 1.0f) newWeight = 2.0f; 
     226                //if (notValid > 1.0f) newWeight = 10.0f; 
     227                //if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f); 
    228228        } 
    229229        else 
     
    234234        //if (oldPixel.y >= 2000) 
    235235        //      newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 
    236         if (newWeight >= 2000) newWeight = 1000; 
     236        //if (newWeight >= 2000) newWeight = 1000; 
    237237 
    238238        return float3(oldPixel.x, newWeight, eyeSpaceDepth); 
     
    397397        } 
    398398 
    399         const float clampedWeight = clamp(newWeight, 1, temporalCoherence); 
    400  
    401         OUT.illum_col.x = (ao.x + oldSsao * (clampedWeight - 1.0f)) / clampedWeight; 
     399        OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 
    402400        OUT.illum_col.y = newWeight; 
    403401        OUT.illum_col.z = invw; 
Note: See TracChangeset for help on using the changeset viewer.