Changeset 3372 for GTP


Ignore:
Timestamp:
05/19/09 19:17:41 (15 years ago)
Author:
mattausch
Message:

reverted but now a good version

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

Legend:

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

    r3371 r3372  
    168168        geom->mMaterial = mat; 
    169169 
    170         static int count = 0; 
    171         if (count ++ < 10) 
    172170        cout << "creating new geometry with " << numElements << " vertices" << endl; 
    173171 
     
    206204 
    207205 
    208 bool ObjConverter::Convert(const string &filename,  
    209                                                    const std::string &outputFilename) 
     206bool ObjConverter::Convert(const string &filename, const std::string &outputFilename) 
    210207{ 
    211208        mNumShapes = 0; 
     
    361358                str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2); 
    362359         
     360 
     361        /////// 
     362        //-- texture 
     363/* 
     364#ifdef USE_TEXTURE 
     365        int texId = 0; 
     366#else 
     367        int texId = -1; 
     368#endif 
     369 
     370        str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
     371 
     372        bool alphaTestEnabled = false; 
     373        //bool cullFaceEnabled = false; 
     374        bool cullFaceEnabled = true; 
     375 
     376        str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
     377        str.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool)); 
     378 
     379        // material 
     380        bool hasMaterial = true; 
     381        //bool hasMaterial = false; 
     382        str.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 
     383         
     384        if (hasMaterial) 
     385        { 
     386                SimpleVec ambient, diffuse, spec, emm; 
     387 
     388                ambient.x = ambient.y = ambient.z = 0.2f; 
     389                //diffuse.x = diffuse.y = diffuse.z = 1.0f; 
     390                diffuse.x = 0.7f; diffuse.y = 0.5f; diffuse.z = 0.2f; 
     391                spec.x    = spec.y    = spec.z    =  .0f; 
     392                emm = spec; 
     393 
     394                // only write rgb part of the material 
     395                str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
     396                str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
     397                str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 
     398                str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 
     399        } 
     400*/ 
    363401} 
    364402 
     
    369407        ogzstream ofile(filename.c_str()); 
    370408 
    371         if (!ofile.is_open()) return false; 
     409        if (!ofile.is_open()) 
     410                return false; 
    372411         
    373412 
     
    409448        { 
    410449                WriteGeometry(ofile, *it); 
    411  
    412                 int texId = 0; 
    413                 ofile.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
    414  
    415                 bool alphaTestEnabled = false; 
    416                 //bool cullFaceEnabled = false; 
    417                 bool cullFaceEnabled = true; 
    418  
    419                 ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
    420                 ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool)); 
    421  
    422                 // material 
    423                 bool hasMaterial = true; 
    424                 ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 
    425  
    426                 if (hasMaterial) 
    427                 { 
    428                         SimpleVec ambient, diffuse, spec, emm; 
    429  
    430                         ambient.x = ambient.y = ambient.z =  .2f; 
    431                         diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    432                         spec.x    = spec.y    = spec.z    =  .0f; 
    433                         emm = spec; 
    434  
    435                         // only write rgb part of the material 
    436                         ofile.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
    437                         ofile.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
    438                         ofile.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 
    439                         ofile.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 
    440                 } 
    441         } 
     450        } 
     451 
     452        int texId = 0; 
     453        ofile.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
     454 
     455        bool alphaTestEnabled = false; 
     456        //bool cullFaceEnabled = false; 
     457        bool cullFaceEnabled = true; 
     458                 
     459        ofile.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool)); 
     460        ofile.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool)); 
     461 
     462        // material 
     463        bool hasMaterial = true; 
     464        ofile.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool)); 
     465         
     466        SimpleVec ambient, diffuse, spec, emm; 
     467 
     468        ambient.x = ambient.y = ambient.z = 0.2f; 
     469        diffuse.x = diffuse.y = diffuse.z = 1.0f; 
     470        spec.x = spec.y = spec.z = .0f; 
     471        emm = spec; 
     472 
     473        // only write rgb part of the material 
     474        ofile.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
     475        ofile.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
     476        ofile.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 
     477        ofile.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 
     478 
    442479 
    443480        int entityCount = 1; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter2.cpp

    r3371 r3372  
    129129                                for (int j = 0; j < 3; ++ j) 
    130130                                { 
     131                                        //if (tIndices[idx[j]] >= (int)texcoords.size()) 
     132                                                //cerr << "error: texcoord indices exceed array size " << texcoords.size() << " " << tIndices[idx[j]] << endl; 
    131133                                        const int tidx = min((int)texcoords.size() - 1, tIndices[idx[j]]); 
     134 
    132135                                        faceTexcoords.push_back(texcoords[tidx]); 
    133136                                } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r3371 r3372  
    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; 
     
    6060 
    6161        cout << "conversion successful" << endl; 
    62         //cout << "press any key" << std::cin.get(); 
     62        cout << "press any key" << std::cin.get(); 
    6363 
    6464        return 0; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env

    r3362 r3372  
    3030visibilitySolutionInitialState=500000000 
    3131# renderMode: Frustum Culling, Stop And Wait, CHC, CHC ++ 
    32 renderMode=3 
     32renderMode=0 
    3333 
    3434############ 
     
    7171 
    7272# the used render method (forward, forward + depth pass, deferred, deferred + depth pass 
    73 #renderMethod=2 
    74 renderMethod=0 
     73renderMethod=2 
     74#renderMethod=0 
    7575 
    7676#modelPath=data/city/model/ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3371 r3372  
    226226        case DeferredRenderer::SAMPLING_QUADRATIC: 
    227227                { 
    228                         //PoissonDiscSampleGenerator2D poisson(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
    229                         //poisson.Generate((float *)samples2); 
    230228                        QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
    231229                        g.Generate((float *)samples2); 
     
    845843 
    846844        //if (mRegenerateSamples) 
    847         if (//mUseTemporalCoherence ||  
    848                 mRegenerateSamples) 
     845        if (1)//mUseTemporalCoherence || mRegenerateSamples) 
    849846        { 
    850847                mRegenerateSamples = false; 
     
    861858                else 
    862859                { 
    863                         UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
     860                        //UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
    864861                } 
    865862 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.cpp

    r3322 r3372  
    7979        } 
    8080 
    81         // only even prime number 
     81        // only even prime numbers 
    8282        if (idx == 1) return 2; 
    8383 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3371 r3372  
    356356    str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount); 
    357357         
    358         //cout << "vertexCount: " << vertexCount << endl; 
    359  
    360358        normals = new Vector3[vertexCount]; 
    361359        str.read(reinterpret_cast<char *>(normals), sizeof(Vector3) * vertexCount); 
    362360 
    363  
    364361        Vector3 *tangents; 
    365362 
     
    377374        str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 
    378375 
    379         //cout << "texCoordCount: " << texCoordCount << endl; 
    380376 
    381377        if (texCoordCount) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r3371 r3372  
    248248        for (int i = 0; i < mNumSamples; ++ i) 
    249249        { 
    250                 x[0] = RandomValue(0, 1); x[1] = RandomValue(0, 1); 
    251                 //mHalton->GetNext(x); 
     250                //x[0] = RandomValue(0, 1); x[1] = RandomValue(0, 1); 
     251                mHalton->GetNext(x); 
    252252                 
    253253                const float a = 2.0f * M_PI * x[0]; 
    254254                const float r = sqrt(x[1]); 
    255                 //const float rad = mRadius * r * r * r * r; 
    256                 const float rad = mRadius * r;// * r; 
     255                 
     256                const float rad = mRadius * r; 
    257257 
    258258                s[i].x = rad * cos(a); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3371 r3372  
    645645        VertexArray positions; 
    646646        //const float factor2 = 1.6f; 
    647         const float factor2 = 1.5f; 
     647        const float factor2 = .0f; 
     648        //const float factor2 = 1.5f; 
    648649 
    649650        // for buddha (lowres) 
     
    835836        // another color buffer 
    836837        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 
    837  
    838838 
    839839        for (int i = 0; i < 4; ++ i) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3371 r3372  
    88//#define NUM_PRECOMPUTED_SAMPLES 8124 
    99#define NUM_PRECOMPUTED_SAMPLES 4096 
    10 //#define NUM_PRECOMPUTED_SAMPLES 1024 
     10//#define NUM_PRECOMPUTED_SAMPLES 16 
    1111 
    12 //#define NUM_SAMPLES 16 
    13 #define NUM_SAMPLES 16 
     12#define NUM_SAMPLES 32 
     13//#define NUM_SAMPLES 24 
    1414//#define NUM_SAMPLES 32 
    1515//#define NUM_SAMPLES 64 
    1616 
    17 #define MIN_SAMPLES 16 
     17#define MIN_SAMPLES 8 
    1818//#define MIN_SAMPLES 48 
    1919 
     
    2626 
    2727//#define SSAO_CONVERGENCE_THRESHOLD 300.0f 
    28 #define SSAO_CONVERGENCE_THRESHOLD 700.0f 
    29 //#define SSAO_CONVERGENCE_THRESHOLD 1300.0f 
     28//#define SSAO_CONVERGENCE_THRESHOLD 700.0f 
     29#define SSAO_CONVERGENCE_THRESHOLD 1300.0f 
    3030//#define SSAO_CONVERGENCE_THRESHOLD 1500.0f 
    3131 
     
    6666#define NUM_DOF_TABS 16 
    6767 
    68 //#define USE_GTX 
     68#define USE_GTX 
    6969 
    7070#define SSAO_FILTER_RADIUS 5 
     
    7474#define PERFORMANCE_TEST 1 
    7575 
    76 #define USE_OPTIMIZATION 0 
     76#define USE_OPTIMIZATION 1 
    7777 
    7878 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3369 r3372  
    33 
    44 
    5 /*************************************************/ 
    6 /*     Filter for combining ssao with image      */ 
    7 /*************************************************/ 
     5/********************************************************/ 
     6/*         Filter for combining ssao with image         */ 
     7/********************************************************/ 
    88 
    99 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3369 r3372  
    315315        float3 translatedPos = -oldEyePos + worldPos.xyz + difVec; 
    316316         
     317 
    317318        ///////////////// 
    318319        //-- reproject into old frame and calculate texture position of sample in old frame 
     
    381382        pix.color.z = color.w; 
    382383*/ 
    383         const float3 translatedPos = ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos, oldModelViewProj); 
     384        const float3 translatedPos =  
     385                ComputeTranslatedPos(color, difVec.xyz, IN.view, oldEyePos, oldModelViewProj); 
    384386 
    385387        pix.color.xyz = translatedPos; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3371 r3372  
    5353 
    5454        // get position exactly between texel centers 
    55         float2 center = (floor(texCoord * res) + float2(.5f)) * texCoord; 
    56         //center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x; 
    57         //center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y; 
    58         //center.y = (floor(texCoord.y * res.y) + .5f) * yOffs; 
    59  
    60         /*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs,  yoffs), 0, 0)).y; 
    61         texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 
    62         texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 
    63         texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y; 
    64  
    65         const float m1 = min(texelCenterConv.x, texelCenterConv.y); 
    66         const float m2 = min(texelCenterConv.z, texelCenterConv.w); 
    67  
    68         const float convergence = min(m1, m2);*/ 
    69  
     55        float2 center = (floor(texCoord * res) + float2(.5f)) * invRes; 
     56         
    7057        //const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y; 
    7158        const float convergence = tex2Dlod(tex, float4(texCoord, 0, 0)).y; 
     
    133120 
    134121        if (1 
    135                 && (oldTexCoords.x > 0) && (oldTexCoords.x < 1.0f) 
    136                 && (oldTexCoords.y > 0) && (oldTexCoords.y < 1.0f) 
     122                && (oldTexCoords.x > .0f) && (oldTexCoords.x < 1.0f) 
     123                && (oldTexCoords.y > .0f) && (oldTexCoords.y < 1.0f) 
    137124                && (depthDif <= MIN_DEPTH_DIFF)  
    138125                ) 
    139126        { 
    140                 // pixel valid => retrieve the convergence weight 
    141                 /*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    142                 float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 
    143                 float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    144                 float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y; 
    145  
    146                 w = min(min(w1, w2), min(w3, w4));*/ 
     127#if 0 
     128                idx = floor(oldPixel.z); 
     129#else 
     130 
     131                // nearest neighbour 
     132                float2 center; 
     133                center.x = (floor(oldTexCoords.x * 1024) + .5f) / 1024; 
     134                center.y = (floor(oldTexCoords.y * 768) + .5f) / 768; 
    147135                 
    148                 //w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 
    149                 w   = oldPixel.y; 
    150                 idx = floor(oldPixel.z); 
    151                 //idx = oldPixel.z; 
     136                const float4 oldPixelExact = tex2Dlod(oldTex, float4(center, .0f, .0f));  
     137                idx = oldPixelExact.z; 
     138#endif 
     139 
     140                w = oldPixel.y; 
    152141        } 
    153142        else 
     
    487476                float2 offset; 
    488477 
    489                 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 
     478                const float2 ssaoOffset = tex2Dlod(samples, float4((.5f + i + floor(oldIdx)) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 
    490479                //const float2 ssaoOffset = dummySamples[i]; 
    491480 
     
    494483                //-- (affects performance for some reason!) 
    495484 
    496                 if (1)//!USE_OPTIMIZATION || 
    497                         //(convergence < SSAO_CONVERGENCE_THRESHOLD)) 
     485                if (!USE_OPTIMIZATION || 
     486                        (convergence < SSAO_CONVERGENCE_THRESHOLD)) 
    498487                { 
    499488                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
     
    521510                float3 dirSample = samplePos - centerPosition; 
    522511 
    523                 const float minDist = 1e-6f; 
    524512                const float eps = 1e-3f; 
    525513 
     
    527515                const float sampleWeight = 1.0f / max(lengthToSample, eps); 
    528516 
    529                 dirSample /= max(length(dirSample), minDist); // normalize 
     517                dirSample /= max(length(dirSample), eps); // normalize 
    530518 
    531519                // angle between current normal and direction to sample controls AO intensity. 
     
    540528 
    541529 
    542 //#ifdef PERFORMANCE_TEST 
    543 #if 1 
     530#ifdef PERFORMANCE_TEST 
    544531                // check if the samples have been valid in the last frame 
    545532                // only mark sample as invalid if in the last / current frame 
     
    552539                const float distanceDiff = abs(oldDistance - lengthToSample); 
    553540 
    554                 float pixelValid = (oldSamplePos.x > 1e14f) ? 100.0f : .0f; 
    555  
    556                 if ((cosAngle >= 0) && (pixelValid < 90.0f))// || (cosAngle2 >= 0)) 
    557                 { 
    558                         pixelValid = (distanceDiff > 1e-3f) ? 100.0f : .0f; 
    559                         //pixelValid = (distanceDiff > 1e-3f) ? 5.0f : .0f; 
     541                float pixelValid = .0f; 
     542 
     543                if ((texcoord.x > .0f) && (texcoord.x < 1.0f) && (texcoord.y > .0f) && (texcoord.y < 1.0f)) 
     544                { 
     545                        if ((oldSamplePos.x > 1e14f))// || ((cosAngle >= 0) && (distanceDiff > 1e-3f))) 
     546                        { 
     547                                pixelValid = 100.0f; 
     548                        } 
     549                        else if ((cosAngle >= 0) && (distanceDiff > 1e-3f)) 
     550                        { 
     551                                pixelValid = 5.0f; 
     552                        } 
    560553                } 
    561554 
     
    742735 
    743736                oldWeight = min(oldWeight, factor * NUM_SAMPLES); 
     737 
    744738                if (newIdx >= factor * NUM_SAMPLES)  
    745739                { 
Note: See TracChangeset for help on using the changeset viewer.