Changeset 3361 for GTP


Ignore:
Timestamp:
04/20/09 09:11:32 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
9 edited

Legend:

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

    r3359 r3361  
    4444                for (size_t j = 0; j < face.indices.size(); ++ j) 
    4545                { 
    46                         geom->mVertices.push_back(vertices[faces[i].indices[j]]); 
     46                        SimpleVec h = vertices[faces[i].indices[j]]; 
     47                        SimpleVec v; 
     48                         
     49                        v.x = h.x * 14; 
     50                        v.y = h.z * 14; 
     51                        v.z = h.y * 14; 
     52         
     53                        geom->mVertices.push_back(v); 
    4754 
    4855                        /*if (!normals.empty()) 
     
    6976 
    7077                // no face normals? => create normals 
    71                 const SimpleTri tri(geom->mVertices[idx], 
     78                const SimpleTri tri(geom->mVertices[idx + 2], 
    7279                                        geom->mVertices[idx + 1],  
    73                                                         geom->mVertices[idx + 2]); 
     80                                                        geom->mVertices[idx + 0]); 
    7481 
    7582                const SimpleVec n = tri.GetNormal(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r3360 r3361  
    1 #include "ObjConverter.h" 
    2 //#include "PlyConverter.h" 
     1//#include "ObjConverter.h" 
     2#include "PlyConverter.h" 
    33#include <iostream> 
    44#include <time.h> 
     
    1212 
    1313        //ObjConverter2 converter; 
    14         ObjConverter converter; 
    15         //PlyConverter converter; 
     14        //ObjConverter converter; 
     15        PlyConverter converter; 
    1616 
    1717        cout << "converting obj to dem format" << endl; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj

    r3342 r3361  
    156156                                IgnoreAllDefaultLibraries="false" 
    157157                                IgnoreDefaultLibraryNames="LIBCMT" 
    158                                 GenerateDebugInformation="false" 
     158                                GenerateDebugInformation="true" 
    159159                                SubSystem="1" 
    160160                                LargeAddressAware="2" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3360 r3361  
    407407                cout << "using half resolution ssao" << endl; 
    408408        } 
    409  
     409#if 1 
    410410 
    411411        ///////// 
     
    467467 
    468468        PrepareLenseFlare(); 
    469  
     469#endif 
    470470        InitCg(); 
    471471} 
     
    660660        */ 
    661661 
    662         if (mShadingMethod != 0) 
     662        if (mShadingMethod != DEFAULT) 
    663663        { 
    664664                PrepareSsao(fbo); // downsample fbo buffers 
     
    966966        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    967967        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     968        //GLuint aoTex = fbo->GetColorBuffer(1)->GetTexture(); 
    968969        GLuint aoTex = mTempFbo->GetColorBuffer(1)->GetTexture(); 
    969970 
     
    11031104        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    11041105        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     1106        //GLuint ssaoTex = fbo->GetColorBuffer(1)->GetTexture(); 
    11051107        GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 
    11061108         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3360 r3361  
    149149 
    150150bool useSkylightForIllum = true; 
    151  
    152151bool showFPS = true; 
    153  
    154152static int globalVisibleId = 0; 
    155  
    156153PerfTimer applicationTimer; 
    157154 
     
    203200// ssao parameters 
    204201float ssaoKernelRadius = 1e-8f; 
    205 float ssaoSampleIntensity = 0.2f; 
     202float ssaoSampleIntensity = .2f; 
    206203float ssaoFilterRadius = 3.0f; 
    207204float ssaoTempCohFactor = 255.0; 
     
    647644         
    648645        // for buddha (lowres) 
    649         /*positions.push_back(Vector3(6.07307, 8.20723, 6.62)); 
     646        positions.push_back(Vector3(6.07307, 8.20723, 6.62)); 
    650647        positions.push_back(Vector3(-17.1935, 11.1687, 8.8781)); 
    651         positions.push_back(Vector3(1.50032, 31.1943, 19.1f));*/ 
     648        positions.push_back(Vector3(1.50032, 31.1943, 19.1f)); 
    652649 
    653650        // for happy buddha 
     
    658655        // for dragon 
    659656        //positions.push_back(Vector3(6.07307, 8.20723, 5.0f)); 
    660         positions.push_back(Vector3(0, 0, -0.8)); 
     657        //positions.push_back(Vector3(0, 0, -0.8)); 
    661658 
    662659#endif 
     
    666663         
    667664        //LoadModel("hbuddha.dem", dynamicObjects); 
    668         LoadModel("horse.dem", dynamicObjects); 
    669         //LoadModel("happy.dem", dynamicObjects); 
     665        //LoadModel("horse.dem", dynamicObjects); 
     666        LoadModel("happy.dem", dynamicObjects); 
    670667        //LoadModel("dragon.dem", dynamicObjects); 
    671668        //LoadModel("torus.dem", dynamicObjects); 
     
    681678        } 
    682679 
     680        /* 
    683681        const float rotAngle = M_PI / 2.0f; 
    684682        const Matrix4x4 rotMatrix = RotationXMatrix(rotAngle); 
     
    689687        dynamicObjects[0]->GetTransform()->MultMatrix(scaleMatrix); 
    690688 
    691         //dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
    692         //dynamicObjects[1]->GetTransform()->MultMatrix(scaleMatrix); 
    693  
    694         //dynamicObjects[2]->GetTransform()->MultMatrix(rotMatrix); 
    695         //dynamicObjects[2]->GetTransform()->MultMatrix(scaleMatrix); 
     689        dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
     690        dynamicObjects[1]->GetTransform()->MultMatrix(scaleMatrix); 
     691 
     692        dynamicObjects[2]->GetTransform()->MultMatrix(rotMatrix); 
     693        dynamicObjects[2]->GetTransform()->MultMatrix(scaleMatrix); 
    696694 
    697695        cout << "dynamic objects: " << (int)dynamicObjects.size() << endl; 
    698  
     696        */ 
    699697        CreateAnimation(positions[0]); 
     698 
    700699#endif 
    701700 
     
    827826        // buffer holding the difference vector to the old frame 
    828827        fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
     828        //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 
    829829        // another color buffer 
    830830        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 
     
    11721172                dynamicObjects[i]->GetTransform()->InitFrame(); 
    11731173 
    1174         if (0)//buddha) 
     1174        if (buddha) 
    11751175        { 
    11761176                Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 
     
    11941194#endif 
    11951195 
    1196 #if 0 
     1196#if 1 
    11971197                ///////////////////////// 
    11981198                //-- update animations 
    11991199 
    12001200                //const float rotAngle = M_PI * 1e-3f; 
    1201                 //const float rotAngle = 0.3f * M_PI / 180.0f; 
    1202                 const float rotAngle = 0.6f * M_PI / 180.0f; 
     1201                const float rotAngle = 0.3f * M_PI / 180.0f; 
     1202                //const float rotAngle = 0.6f * M_PI / 180.0f; 
    12031203 
    12041204                Matrix4x4 rotMatrix = RotationZMatrix(rotAngle); 
     
    12061206                dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 
    12071207 
     1208                // hack: second buddha 
    12081209                const float rotAngle2 = 0.0033f * M_PI; 
    1209  
    12101210                Matrix4x4 rotMatrix2 = RotationZMatrix(rotAngle); 
    1211                 // hack: second buddha 
    12121211                //dynamicObjects[3]->GetTransform()->MultMatrix(rotMatrix2); 
    1213  
    12141212 
    12151213                //const float moveSpeed = 5e-3f; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3360 r3361  
    1414//#define NUM_SAMPLES 24 
    1515#define NUM_SAMPLES 32 
    16 //#define NUM_SAMPLES 8 
     16//#define NUM_SAMPLES 48 
    1717 
    1818//#define MIN_SAMPLES 48 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3356 r3361  
    248248        } 
    249249 
     250        //OUT.illum_col.xyz = float3(ao.x * 1e1f, col.yz); 
     251 
    250252        //OUT.illum_col.xyz = float3(ao.w * 5e-1f, 0, 0); 
    251253        //OUT.illum_col.xyz = float3(ao.z * 1e-3f); 
    252         //OUT.illum_col.xyz = float3(ao.y * 1e-3f);x 
     254        //OUT.illum_col.xyz = float3(ao.y * 1e-3f); 
    253255        //OUT.illum_col.xyz = ao.xyz; 
    254256 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3360 r3361  
    4040 
    4141        // hack: prevent to shade the sky 
    42 #if 1 
     42#if 0 
    4343        if (color.w > DEPTH_THRESHOLD) 
    4444        { 
     
    250250 
    251251        // compute position from old frame for dynamic objects + translational portion 
    252         //const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 
     252        const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 
    253253        // don't use difVec here: want to detect if the actual pixel has changed => ssao changed 
    254         const float3 translatedPos = -oldEyePos + worldPos.xyz; 
     254        //const float3 translatedPos = -oldEyePos + worldPos.xyz; 
    255255 
    256256 
     
    293293        // means that we only use slight temporal coherence over some frames 
    294294        // so that there is no noticeable drag 
    295         const float pixelCouldBeValid = 2.0f; 
     295        const float pixelCouldBeValid = 4.0f; 
    296296        // this pixel information has to be discarded in order to not create artifacts 
    297297        const float pixelIsNotValid = 100.0f; 
     
    306306        } 
    307307        else if ( // check if changed from dynamic to not dynamic object 
    308                  ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     308                 ( 
     309                          (oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
    309310                         ( 
    310311                          (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 
    311312                          (oldDynamic || newDynamic) &&  // check if we have a dynamic object  
    312                           (depthDif > MIN_DEPTH_DIFF)))) // and there is a depth discontinuity 
     313                          (depthDif > MIN_DEPTH_DIFF))) 
     314                          ) // and there is a depth discontinuity 
    313315        {        
    314316                isPixelValid = pixelCouldBeValid; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3355 r3361  
    308308} 
    309309 
     310//#define TRYOUT 
     311 
     312#ifdef TRYOUT 
    310313 
    311314/** The ssao shader returning the an intensity value between 0 and 1. 
     
    399402                // check if the samples have been valid in the last frame 
    400403                // only mark sample as invalid if in the last / current frame 
    401                 // they possibly have any influence on the ao 
     404                // they possibly have any influence on the AO 
    402405 
    403406                const float changeFactor = sampleColor.y; 
     
    412415                const float partlyResetThres = 1.0f; 
    413416 
    414                 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
     417                const float tooFarAway = step(.5f, lengthToSample - changeFactor); 
    415418                if (0)//pixelValid <= partlyResetThres) 
    416419                        validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); 
     
    451454} 
    452455 
     456#else 
     457 
     458float3 ssao(fragment IN, 
     459                        sampler2D colors, 
     460                        sampler2D noiseTex, 
     461                        sampler2D samples, 
     462                        float3 normal, 
     463                        float3 centerPosition, 
     464                        float radius, 
     465                        float3 bl, 
     466                        float3 br, 
     467                        float3 tl, 
     468                        float3 tr,  
     469                        float3 viewDir, 
     470                        float convergence, 
     471                        float sampleIntensity, 
     472                        bool isMovingObject, 
     473                        float oldIdx, 
     474                        sampler2D attribsTex 
     475                        ) 
     476{ 
     477        float total_ao = .0f; 
     478        float validSamples = .0f; 
     479        float numSamples = .0f; 
     480 
     481        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
     482 
     483        for (int i = 0; i < NUM_SAMPLES; ++ i)  
     484        { 
     485                float2 offset; 
     486 
     487                const float2 ssaoOffset =  
     488                        tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 
     489 
     490 
     491                //////////////////// 
     492                //-- add random noise: reflect around random normal vector  
     493                //-- (affects performance for some reason!) 
     494 
     495                if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
     496                { 
     497                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     498                        //offset = myreflect(samples[i], mynoise); 
     499                        //offset = myrotate(samples[i], mynoise.x); 
     500                        offset = myrotate(ssaoOffset, mynoise.x); 
     501                } 
     502                else 
     503                { 
     504                        offset = ssaoOffset; 
     505                } 
     506 
     507 
     508                // weight with projected coordinate to reach similar kernel size for near and far 
     509                const float2 texcoord = IN.texCoord.xy + offset * radius; 
     510 
     511                const float4 sampleColor = tex2Dlod(colors, float4(texcoord, .0f, .0f)); 
     512                const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 
     513                 
     514                 
     515 
     516                //////////////// 
     517                //-- compute contribution of sample using the direction and angle 
     518 
     519                float3 dirSample = samplePos - centerPosition; 
     520 
     521                const float minDist = 1e-6f; 
     522                const float eps = 1e-3f; 
     523 
     524                const float lengthToSample = length(dirSample); 
     525                const float sampleWeight = 1.0f / max(lengthToSample, eps); 
     526 
     527                dirSample /= max(length(dirSample), minDist); // normalize 
     528 
     529                // angle between current normal and direction to sample controls AO intensity. 
     530                const float cosAngle = dot(dirSample, normal); 
     531 
     532                //const float aoContrib = sampleIntensity / sqrLen; 
     533                const float aoContrib = sampleIntensity * sampleWeight; 
     534                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
     535 
     536                total_ao += max(cosAngle, .0f) * aoContrib; 
     537 
     538                ++ numSamples; 
     539 
     540 
     541#ifdef PERFORMANCE_TEST 
     542                // check if the samples have been valid in the last frame 
     543                // only mark sample as invalid if in the last / current frame 
     544                // they possibly have any influence on the ao 
     545 
     546                //const float pixelValid = sampleColor.x; 
     547                //const float pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f; 
     548                //float pixelValid = max(sampleColor.x, length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f); 
     549                float pixelValid = sampleColor.x; 
     550 
     551                if (pixelValid < 1) 
     552                { 
     553                        const float3 sampleDiffVec = tex2Dlod(attribsTex, float4(texcoord, .0f, .0f)).xyz; 
     554                        pixelValid = length(sampleDiffVec - diffVec) < 1e-3f ? .0f : 10.0f; 
     555                } 
     556 
     557                // hack: 
     558                // we check if the sample could have been near enough to the current pixel  
     559                // or if the angle is small enough 
     560                // to have any influence in the current or last frame 
     561 
     562#if 1 
     563                const float changeFactor = sampleColor.y; 
     564                const float partlyResetThres = 1.0f; 
     565 
     566                if (0)//pixelValid <= partlyResetThres) 
     567                { 
     568                        const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
     569                        validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); 
     570                } 
     571                else 
     572                { 
     573                        validSamples = max(validSamples, pixelValid); 
     574                } 
     575#endif 
     576 
     577#ifdef USE_GTX 
     578                // we can bail out early and use a minimal #samples) 
     579                // if some conditions are met as long as the hardware supports it 
     580                if (numSamples >= MIN_SAMPLES) 
     581                { 
     582                        //break; 
     583                        // if the pixel belongs to a static object and all the samples stay valid in the current frame 
     584                        if (!isMovingObject && (validSamples < 1.0f) && (convergence > NUM_SAMPLES)) break; 
     585                        // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high  
     586                        // (=> there was no discontinuity recently) 
     587                        //else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break; 
     588                        else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 
     589                } 
     590#endif 
     591 
     592#endif // PERFORMANCE_TEST 
     593        } 
     594 
     595        // "normalize" ao contribution 
     596        total_ao /= numSamples; 
     597 
     598#if 1 
     599        // if surface normal perpenticular to view dir, approx. half of the samples will not count 
     600        // => compensate for this (on the other hand, projected sampling area could be larger!) 
     601        const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 
     602        total_ao *= viewCorrection; 
     603#endif 
     604 
     605        //return float3(total_ao, validSamples, numSamples); 
     606        return float3(min(1.0f, total_ao), validSamples, numSamples); 
     607} 
     608#endif 
    453609 
    454610 
     
    501657         
    502658#ifdef PERFORMANCE_TEST  
    503 //#if 0 
    504659        float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 
    505660 
     
    530685        const float3 diffVec = float3(.0f); 
    531686        const bool isMovingObject = false; 
    532         const float oldSsao = 0; 
    533          
    534         float oldWeight = 0; 
    535         float oldIdx    = 0; 
     687        const float oldSsao = .0f; 
     688         
     689        float oldWeight = .0f; 
     690        float oldIdx    = .0f; 
    536691         
    537692#endif 
     
    544699                if (1) 
    545700                { 
     701#ifdef TRYOUT 
    546702                        ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz,  
    547703                                      radiusMult, bl, br, tl, tr, normalize(viewDir), 
    548704                                          oldWeight, sampleIntensity, isMovingObject, oldIdx); 
     705#else 
     706 
     707                          ao = ssao(IN, colors, noiseTex, samples, 
     708                                      normal, eyeSpacePos.xyz, radiusMult, bl,  
     709                                          br, tl, tr, normalize(viewDir),  
     710                                          oldWeight, sampleIntensity, isMovingObject, oldIdx, 
     711                                          attribsTex); 
     712#endif                             
    549713                } 
    550714                else 
    551715                { 
    552                         ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, radiusMult,  
     716                        /*ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, radiusMult,  
    553717                                   bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity,  
    554718                                           isMovingObject, normals, oldIdx); 
     719                                           */ 
    555720                } 
    556721        } 
     
    575740         
    576741        // don't check for moving objects, otherwise almost no coherence 
    577         if (!isMovingObject) 
     742        if (1)//!isMovingObject) 
    578743        { 
    579744                if (ao.y > completelyResetThres)  
     
    584749                else if (ao.y > partlyResetThres) 
    585750                { 
    586                         oldWeight = min(oldWeight, 4.0f * newWeight); 
     751                        const float factor = 4.0f; 
     752                        oldWeight = min(oldWeight, factor * newWeight); 
    587753                        //oldWeight = .0f;  
    588754                        //oldIdx    = .0f; 
     
    594760        //-- blend ao between old and new samples (and avoid division by zero) 
    595761 
    596         OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight); 
     762        OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 
    597763        OUT.illum_col.x /= (newWeight + oldWeight); 
     764        //OUT.illum_col.x = clamp(OUT.illum_col.x, 0, 1); 
     765        //OUT.illum_col.x = ao.y; 
    598766 
    599767        // the new weight for the next frame 
Note: See TracChangeset for help on using the changeset viewer.