Changeset 3324 for GTP


Ignore:
Timestamp:
02/20/09 19:26:13 (15 years ago)
Author:
mattausch
Message:

indexing working not so bad

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r3322 r3324  
    7171static GLuint noiseTex2D = 0; 
    7272static GLuint noiseTex1D = 0; 
    73  
    74  
     73static GLuint sampleTex2D = 0; 
     74 
     75 
     76static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 
    7577// ssao random spherical samples 
    76 static Sample2 samples2[NUM_SAMPLES]; 
    77 //#define NUM_PRECOMPUTED_SAMPLES 240 
    78 //static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 
     78//static Sample2 samples2[NUM_SAMPLES]; 
     79 
    7980// pcf samples 
    8081static Sample2 pcfSamples[NUM_PCF_TABS]; 
     
    212213        case DeferredRenderer::SAMPLING_QUADRATIC: 
    213214                { 
    214                         //static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
     215                        QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 
    215216                        //static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
    216                         static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 
    217217                        g.Generate((float *)samples2); 
    218218                } 
     
    263263 
    264264        cout << "created noise texture" << endl; 
     265 
     266        PrintGLerror("noisetexture"); 
     267} 
     268 
     269 
     270static void CreateSampleTex(Sample2 *samples, int numSamples) 
     271{ 
     272        glEnable(GL_TEXTURE_2D); 
     273        glGenTextures(1, &sampleTex2D); 
     274        glBindTexture(GL_TEXTURE_2D, sampleTex2D); 
     275                 
     276        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     277        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     278        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
     279        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
     280 
     281        int w = numSamples; 
     282        int h = 1; 
     283 
     284        float *tempBuffer = new float[numSamples * 3]; 
     285 
     286        for (int i = 0; i < numSamples; ++ i) 
     287        { 
     288                tempBuffer[i * 3 + 0] = samples[i].x; 
     289                tempBuffer[i * 3 + 1] = samples[i].y; 
     290                tempBuffer[i * 3 + 2] = 0; 
     291                 
     292        } 
     293 
     294        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer); 
     295 
     296        glBindTexture(GL_TEXTURE_2D, 0); 
     297        glDisable(GL_TEXTURE_2D); 
     298 
     299        cout << "created sample texture" << endl; 
     300 
     301        delete [] tempBuffer; 
    265302 
    266303        PrintGLerror("noisetexture"); 
     
    439476                 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr",  
    440477                 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"}; 
     478         
    441479        sCgSsaoProgram->AddParameters(ssaoParams, 0, 20); 
    442480         
     
    751789        sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    752790         
    753         static int currentPos = 0; 
    754  
    755         if (mUseTemporalCoherence || mRegenerateSamples) 
     791        if (/*mUseTemporalCoherence || */mRegenerateSamples) 
    756792        { 
    757793                mRegenerateSamples = false; 
     
    760796                // in the first case, the sample patterns look nicer, but the kernel 
    761797                // needs longer to converge 
    762                 //if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)      { 
    763                         currentPos = 0; 
    764                         GenerateSamples(mSamplingMethod); 
    765                 //} 
    766  
     798                GenerateSamples(mSamplingMethod); 
     799                CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
    767800                //if (mSortSamples) { SortSamples(); } 
    768                 sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES); 
    769  
    770                 currentPos += NUM_SAMPLES; 
     801                //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
     802                //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 
     803                sCgSsaoProgram->SetTexture(i, sampleTex2D); 
    771804        } 
    772805         
     
    774807 
    775808        for (int j = 0; j < 4; ++ j, ++ i) 
     809        { 
    776810                sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 
     811        } 
    777812 
    778813        sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3323 r3324  
    55//////////// 
    66//-- ssao + gi parameters 
    7  
     7#define NUM_PRECOMPUTED_SAMPLES 4096 
    88//#define NUM_SAMPLES 8 
    99//#define NUM_SAMPLES 16 
    1010//#define NUM_SAMPLES 24 
    11 #define NUM_SAMPLES 24 
     11#define NUM_SAMPLES 48 
    1212 
    1313//#define MIN_SAMPLES 48 
    14 #define MIN_SAMPLES 24 
     14#define MIN_SAMPLES 8 
    1515 
    1616#define DISTANCE_SCALE 1e-2f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3313 r3324  
    263263 
    264264        // check if the pixel belonged to a dyanmic object in the last frame 
    265         const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    266         const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
     265        const bool oldDynamic =  false;(squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
     266        const bool newDynamic = false; (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 
    267267 
    268268        // actually 0 means pixel is valid 
    269269        const float pixelIsValid = 0.0f; 
    270270        // means that we only use slight temporal coherence over some frames 
    271         // so that there si no noticeable drag 
     271        // so that there is no noticeable drag 
    272272        const float pixelCouldBeValid = 2.0f; 
    273273        // this pixel information has to be discarded in order to not create artifacts 
    274274        const float pixelIsNotValid = 100.0f; 
    275275 
    276         const float xOffs = 0;// 0.5f / 1024.0f; 
    277         const float yOffs = 0;// 0.5f / 768.0f; 
    278  
    279         if ((oldTexCoords.x < xOffs) || (oldTexCoords.x > (1.0f - xOffs)) ||  
    280                 (oldTexCoords.y < yOffs) || (oldTexCoords.y > (1.0f - yOffs)) 
     276        // check if the pixel was outside of the frame buffer 
     277        if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) ||  
     278                (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f) 
    281279                ) 
    282280        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3322 r3324  
    7777        weight of the pixel in the new frame. 
    7878*/ 
    79 inline float2 Reproject(float4 worldPos, 
    80                                                                 float eyeSpaceDepth, 
    81                                                                 float2 texcoord0, 
    82                                                                 float3 oldEyePos, 
    83                                                                 sampler2D oldTex, 
    84                                                                 float4x4 oldModelViewProj, 
    85                                                                 sampler2D colors, 
    86                                                                 float3 projPos, 
    87                                                                 float invW, 
    88                                                                 float3 oldbl, 
    89                                                                 float3 oldbr, 
    90                                                                 float3 oldtl, 
    91                                                                 float3 oldtr, 
    92                                                                 float3 diffVec 
    93                                                                 ) 
     79inline float3 Reproject(float4 worldPos, 
     80                                                float eyeSpaceDepth, 
     81                                                float2 texcoord0, 
     82                                                float3 oldEyePos, 
     83                                                sampler2D oldTex, 
     84                                                float4x4 oldModelViewProj, 
     85                                                sampler2D colors, 
     86                                                float3 projPos, 
     87                                                float invW, 
     88                                                float3 oldbl, 
     89                                                float3 oldbr, 
     90                                                float3 oldtl, 
     91                                                float3 oldtr, 
     92                                                float3 diffVec 
     93                                                ) 
    9494{ 
    9595        // compute position from old frame for dynamic objects + translational portion 
     
    125125        // the weight of the accumulated samples from the previous frames 
    126126        float w; 
     127 
     128        float idx = oldPixel.z; 
    127129 
    128130        ////////////// 
     
    151153        } 
    152154 
    153         return float2(ssao, w); 
     155        return float3(ssao, w, idx); 
    154156} 
    155157 
     
    167169                         sampler2D colors, 
    168170                         sampler2D noiseTex, 
    169                          float2 samples[NUM_SAMPLES], 
     171                         sampler2D samples, 
    170172                         float3 normal, 
    171173                         float3 centerPosition, 
     
    179181                         float sampleIntensity, 
    180182                         bool isMovingObject, 
    181                          sampler2D normalTex 
     183                         sampler2D normalTex, 
     184                         int idx 
    182185                         ) 
    183186{ 
     
    190193                float2 offset; 
    191194 
     195                const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 
     196 
     197 
    192198                //////////////////// 
    193199                //-- add random noise: reflect around random normal vector  
    194200                //-- (affects performance for some reason!) 
    195201 
    196                 if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD) 
     202                if (convergence < SSAO_CONVERGENCE_THRESHOLD) 
    197203                { 
    198204                        float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 
    199205                        //offset = myreflect(samples[i], mynoise); 
    200                         offset = myrotate(samples[i], mynoise.x); 
     206                        //offset = myrotate(samples[i], mynoise.x); 
     207                        offset = myrotate(ssaoOffset, mynoise.x); 
    201208                } 
    202209                else 
    203210                { 
    204                         offset = samples[i]; 
     211                        offset = ssaoOffset; 
    205212                } 
    206213                 
     
    441448                   uniform sampler2D normals, 
    442449                   uniform sampler2D noiseTex, 
    443                    uniform float2 samples[NUM_SAMPLES], 
     450                   uniform sampler2D samples, 
    444451                   uniform sampler2D oldTex, 
    445452                   uniform float4x4 modelViewProj, 
     
    488495        //-- compute temporal reprojection 
    489496 
    490         float2 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
     497        float3 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 
    491498                                        oldTex, oldModelViewProj,  
    492499                                                                        colors,  
     
    499506        const float oldSsao = temporalVals.x; 
    500507        float oldWeight = temporalVals.y; 
    501          
     508        float oldIdx = temporalVals.z; 
     509 
    502510        float3 ao; 
    503511 
     
    506514        { 
    507515                //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    508                 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals); 
     516                ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 
    509517                //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 
    510518        } 
     
    552560        OUT.illum_col.y = combinedWeight; 
    553561        // can be used to check if this pixel belongs to a moving object 
    554         OUT.illum_col.z = SqrLen(diffVec); 
     562        //OUT.illum_col.z = SqrLen(diffVec); 
     563        OUT.illum_col.z = oldIdx + newWeight; 
    555564        OUT.illum_col.w = eyeSpaceDepth; 
    556565 
Note: See TracChangeset for help on using the changeset viewer.