Changeset 3326 for GTP


Ignore:
Timestamp:
02/23/09 18:33:26 (15 years ago)
Author:
mattausch
Message:

strange texture error!!

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

Legend:

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

    r3325 r3326  
    268268 
    269269 
     270static void UpdateSampleTex(Sample2 *samples, int numSamples) 
     271{ 
     272        glEnable(GL_TEXTURE_2D); 
     273        glBindTexture(GL_TEXTURE_2D, sampleTex2D); 
     274                 
     275        const int w = numSamples; const int h = 1; 
     276 
     277        float *tempBuffer = new float[numSamples * 3]; 
     278 
     279        for (int i = 0; i < numSamples; ++ i) 
     280        { 
     281                tempBuffer[i * 3 + 0] = samples[i].x; 
     282                tempBuffer[i * 3 + 1] = samples[i].y; 
     283                tempBuffer[i * 3 + 2] = 0; 
     284                 
     285        } 
     286 
     287        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_FLOAT, (float *)tempBuffer); 
     288 
     289        glBindTexture(GL_TEXTURE_2D, 0); 
     290        glDisable(GL_TEXTURE_2D); 
     291 
     292        cout << "updated sample texture" << endl; 
     293 
     294        delete [] tempBuffer; 
     295 
     296        PrintGLerror("noisetexture"); 
     297} 
     298 
     299 
    270300static void CreateSampleTex(Sample2 *samples, int numSamples) 
    271301{ 
     
    279309        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    280310 
    281         int w = numSamples; 
    282         int h = 1; 
     311        const int w = numSamples; const int h = 1; 
    283312 
    284313        float *tempBuffer = new float[numSamples * 3]; 
     
    506535 
    507536        string combineSsaoParams[] =  
    508                 //{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"}; 
    509537                {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"}; 
    510538 
    511         //sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13); 
    512539        sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9); 
    513540 
     
    517544        string filterSsaoParams[] =  
    518545                {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"}; 
    519  
    520546        sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 9); 
    521547 
     
    549575         
    550576        string prepareSsaoParams[] =  
    551                 {"colorsTex", "normalsTex", "diffVals", "oldTex", "oldTex2",  
     577                {"colorsTex", "normalsTex", "diffVals", "oldTex",  
    552578                 "oldEyePos", "modelViewProj", "oldModelViewProj", 
    553                  "oldbl", "oldbr", "oldtl", "oldtr"}; 
    554  
     579                 "oldbl", "oldbr", "oldtl", "oldtr", "myTex"}; 
    555580        sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 12); 
    556581 
     
    673698        // if it hasn't been done yet => just output the latest buffer 
    674699        if (!mUseAntiAliasing || !displayAfterAA) 
     700        { 
    675701                Output(fbo);  
     702        } 
    676703 
    677704        glEnable(GL_LIGHTING); 
     
    801828                // needs longer to converge 
    802829                GenerateSamples(mSamplingMethod); 
    803                 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
     830 
     831                if (!sampleTex2D) 
     832                { 
     833                        CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
     834                } 
     835                else 
     836                { 
     837                        UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 
     838                } 
     839 
    804840                //if (mSortSamples) { SortSamples(); } 
    805841                //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 
     
    936972        // read the second buffer, write to the first buffer 
    937973        mIllumFbo->Bind(); 
    938  
    939974        glDrawBuffers(2, mrt + mIllumFboIndex); 
    940975 
     976        // bind the old buffers for temporal coherence 
    941977        GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    942978        GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 
     
    10121048        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
    10131049         
    1014         //mIllumFbo->Bind(); 
    1015         //glDrawBuffers(1, mrt + mIllumFboIndex + 1); 
    10161050        mTempFbo->Bind(); 
    10171051        glDrawBuffers(1, mrt); 
     
    10401074        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    10411075        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    1042         //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 
    10431076        GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 
    10441077         
     
    11731206        // flip flop between illumination buffers 
    11741207        GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    1175         GLuint oldTex2 = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 
     1208        GLuint myTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 
    11761209 
    11771210        int i = 0; 
     
    11811214        sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 
    11821215        sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 
    1183         sCgPrepareSsaoProgram->SetTexture(i ++, oldTex2); 
    11841216 
    11851217        Vector3 de; 
     
    11931225        sCgPrepareSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix); 
    11941226 
     1227 
    11951228        for (int j = 0; j < 4; ++ j, ++ i) 
    11961229        { 
    11971230                sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 
    11981231        } 
     1232 
     1233        sCgPrepareSsaoProgram->SetTexture(i ++, myTex); 
    11991234 
    12001235        glPushAttrib(GL_VIEWPORT_BIT); 
     
    12441279        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    12451280        GLuint colorsTex = colorBuffer->GetTexture(); 
    1246         //FrameBufferObject::Release(); 
     1281         
    12471282 
    12481283        FlipFbos(fbo); 
     
    12721307        DrawQuad(sCgDownSampleProgram); 
    12731308 
    1274         PrintGLerror("output"); 
     1309        PrintGLerror("Output"); 
    12751310} 
    12761311 
     
    12791314{ 
    12801315        for (int i = 0; i < 4; ++ i) 
     1316        { 
    12811317                mOldCornersView[i] = mCornersView[i]; 
     1318        } 
    12821319 
    12831320        mOldProjViewMatrix = mProjViewMatrix; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r3114 r3326  
    153153        */ 
    154154        void Render(RenderState *state, SceneEntity *parent); 
    155  
     155        /** Adds a new technique to the material 
     156        */ 
    156157        void AddTechnique(Technique *t); 
    157  
     158        /** Returns the default technique (usually the first) 
     159        */ 
    158160        Technique *GetDefaultTechnique() const; 
    159161 
    160162        Technique *GetTechnique(int i) const; 
    161  
     163        /** Returns the number of techniques associated with this material 
     164        */ 
    162165        int GetNumTechniques() const; 
    163  
    164166 
    165167 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3325 r3326  
    6161#define NUM_DOF_TABS 16 
    6262 
    63 #define USE_GTX 
     63//#define USE_GTX 
    6464 
    6565#define SSAO_FILTER_RADIUS 5 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg

    r3323 r3326  
    192192        { 
    193193                // the filtered ssao value 
    194                 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 
     194                //OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 
    195195        } 
    196196 
     
    223223        const float convergence = ao.y; 
    224224 
    225         const float2 xyStep = float2(0, 1.0f / res.y); 
     225        const float2 xyStep = float2(.0f, 1.0f / res.y); 
    226226         
    227227        // filter reaches size 1 pixel when sample size reaches threshold  
     
    232232        { 
    233233                // the filtered ssao value 
    234                 ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 
     234                //ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 
    235235        } 
    236236 
     
    249249        } 
    250250 
     251        //OUT.illum_col.xyz = float3(col.w * 5e-3f, 0, 0); 
     252        OUT.illum_col.xyz = ao.xyz; 
     253 
    251254        OUT.illum_col.w = col.w; 
    252255 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3325 r3326  
    1515        float4 color: COLOR0; 
    1616        float3 normal: COLOR1; 
    17         float3 diffVal: COLOR2; 
     17        //float3 diffVal: COLOR2; 
    1818}; 
    1919 
     
    3737        float4 outColor; 
    3838 
    39         // hack: prevent shading the sky 
     39        // hack: prevent to shade the sky 
    4040        if (color.w > DEPTH_THRESHOLD) 
    4141        { 
     
    171171                lightSpacePos /= lightSpacePos.w; 
    172172 
    173                 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex); 
     173                float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth,  
     174                                                      lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex); 
    174175                diffuse *= shadowTerm; 
    175176        } 
     
    209210        */ 
    210211inline float2 PixelValid(sampler2D oldTex, 
    211                                                  sampler2D oldTex2, 
    212212                                                 float4 color, 
    213213                                                 float3 difVec, 
     
    220220                                                 float3 oldbr, 
    221221                                                 float3 oldtl, 
    222                                                  float3 oldtr 
     222                                                 float3 oldtr, 
     223                                                 sampler2D myTex 
    223224                                                 ) 
    224225{ 
     
    249250         
    250251        // fit from unit cube into 0 .. 1 
    251         const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f; 
    252         //const float2 oldTexCoords = texCoord; 
     252        const float2 oldTexCoords = backProjPos.xy * .5f + .5f; 
     253         
    253254        // retrieve the sample from the last frame 
    254         const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 
    255         const float4 oldPixel2 = tex2Dlod(oldTex2, float4(oldTexCoords, .0f, .0f)); 
     255        const float4 oldPixel = tex2Dlod(myTex, float4(oldTexCoords, .0f, .0f)); 
     256        const float oldDiff = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)).x; 
    256257 
    257258        // calculate eye space position of sample in old frame 
     
    266267        const float squaredLen = SqrLen(difVec); 
    267268         
     269 
    268270        // test if this pixel was valid in the old frame 
    269271        float isPixelValid; 
    270272 
    271273        // check if the pixel belonged to a dynamic object in the last frame 
    272         const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 
    273         const bool oldDynamic = (oldPixel2.x > DYNAMIC_OBJECTS_THRESHOLD); 
     274        const bool newDynamic = (squaredLen > 100000);//DYNAMIC_OBJECTS_THRESHOLD); 
     275        const bool oldDynamic = (oldDiff > 1000000);//DYNAMIC_OBJECTS_THRESHOLD); 
     276 
    274277 
    275278        // actually 0 means pixel is valid 
    276         const float pixelIsValid = 0.0f; 
     279        const float pixelIsValid = .0f; 
    277280        // means that we only use slight temporal coherence over some frames 
    278281        // so that there is no noticeable drag 
     
    281284        const float pixelIsNotValid = 100.0f; 
    282285 
     286 
    283287        // check if the pixel was outside of the frame buffer 
    284         if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) ||  
    285                 (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f) 
     288        if ((oldTexCoords.x <= .0f) || (oldTexCoords.x >= 1.0f) ||  
     289                (oldTexCoords.y <= .0f) || (oldTexCoords.y >= 1.0f) 
    286290                ) 
    287291        { 
    288292                isPixelValid = pixelIsNotValid; 
    289293        } 
    290         else if (// check if changed from dynamic to not dynamic object 
    291                 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
    292                 ( 
    293                 (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 
    294                 // check if we have a dynamic object  
    295                 (oldDynamic || newDynamic) &&  
    296                 // and there is a depth discontinuity 
    297                 (depthDif > MIN_DEPTH_DIFF)))) 
     294        else if ( // check if changed from dynamic to not dynamic object 
     295                 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 
     296                         ( 
     297                          (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 
     298                          (oldDynamic || newDynamic) &&  // check if we have a dynamic object  
     299                          (depthDif > MIN_DEPTH_DIFF)))) // and there is a depth discontinuity 
    298300        {        
    299                 isPixelValid = pixelCouldBeValid;  
     301                isPixelValid = pixelCouldBeValid; 
    300302        } 
    301303        else  
     
    303305                isPixelValid = pixelIsValid; 
    304306        } 
    305  
     307         
     308        //isPixelValid = 2e20f; 
    306309        return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 
    307310} 
     
    312315*/ 
    313316pixel PrepareSsao(fragment IN, 
    314                                    uniform sampler2D colorsTex, 
    315                                    uniform sampler2D normalsTex, 
    316                                    uniform sampler2D diffVals, 
    317                                    uniform sampler2D oldTex, 
    318                                    uniform sampler2D oldTex2, 
    319                                    uniform float4x4 modelViewProj, 
    320                                    uniform float4x4 oldModelViewProj, 
    321                                    uniform float3 oldbl, 
    322                                    uniform float3 oldbr, 
    323                                    uniform float3 oldtl, 
    324                                    uniform float3 oldtr, 
    325                                    uniform float3 oldEyePos 
    326                                    ) 
     317                                  uniform sampler2D colorsTex, 
     318                                  uniform sampler2D normalsTex, 
     319                                  uniform sampler2D diffVals, 
     320                                  uniform sampler2D oldTex, 
     321                                  uniform float4x4 modelViewProj, 
     322                                  uniform float4x4 oldModelViewProj, 
     323                                  uniform float3 oldbl, 
     324                                  uniform float3 oldbr, 
     325                                  uniform float3 oldtl, 
     326                                  uniform float3 oldtr, 
     327                                  uniform float3 oldEyePos, 
     328                                  uniform sampler2D myTex 
     329                                  ) 
    327330{    
    328331        pixel pix; 
    329332 
    330         float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 
     333        float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, .0f, .0f)); 
    331334        // store scaled view vector so wie don't have to normalize for e.g., ssao 
    332335        color.w /= length(IN.view); 
     
    337340 
    338341        // do reprojection and filter out the pixels that are not save 
    339         float2 pValid = PixelValid(oldTex, 
    340                                        oldTex2, 
    341                                        color,  
    342                                                            difVec.xyz, 
    343                                                            IN.texCoord, 
    344                                                            IN.view, 
    345                                                            oldEyePos, 
    346                                                            modelViewProj, 
    347                                                            oldModelViewProj, 
    348                                                            oldbl, oldbr, oldtl, oldtr 
    349                                                           ); 
     342        const float2 pValid = PixelValid(oldTex, 
     343                                             color,  
     344                                                                         difVec.xyz, 
     345                                                                         IN.texCoord, 
     346                                                                         IN.view, 
     347                                                                         oldEyePos, 
     348                                                                         modelViewProj,                                                    
     349                                                                         oldModelViewProj, 
     350                                                                         oldbl, oldbr, oldtl, oldtr, 
     351                                                                         myTex 
     352                                                                        ); 
    350353 
    351354        pix.color = color; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3325 r3326  
    273273                // to the current pixel or if the angle is small enough 
    274274                // to have any influence in the current or last frame 
    275 #if 1 
     275#if 0 
    276276                const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 
    277277 
     
    281281                else 
    282282                        validSamples = max(validSamples, pixelValid); 
    283 #else 
    284                 validSamples = max(validSamples, pixelValid); 
    285283#endif 
    286284 
     
    408406                // or if the angle is small enough 
    409407                // to have any influence in the current or last frame 
    410 #if 1 
     408#if 0 
    411409                const float partlyResetThres = 1.0f; 
    412410 
     
    416414                else 
    417415                        validSamples = max(validSamples, pixelValid); 
    418 #else 
    419                 validSamples = max(validSamples, pixelValid); 
    420416#endif 
    421417 
     
    523519        if (eyeSpaceDepth < DEPTH_THRESHOLD) 
    524520        { 
    525                 //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
    526                 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 
     521                if (0) 
     522                        ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 
     523                else 
     524                        ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor,  
     525                                   bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity,  
     526                                           isMovingObject, normals, oldIdx); 
    527527        } 
    528528        else 
     
    545545         
    546546        // don't check for moving objects, otherwise almost no coherence 
    547         if (!isMovingObject) 
     547        /*if (!isMovingObject) 
    548548        { 
    549549                if (ao.y > completelyResetThres)  
     
    558558                        oldIdx = .0f; 
    559559                } 
    560         } 
     560        }*/ 
     561 
    561562 
    562563        ////////// 
     
    573574        OUT.illum_col.w = eyeSpaceDepth; 
    574575 
    575         // can be used to check if this pixel belongs to a moving object 
     576        // this value can be used to check if this pixel belongs to a moving object 
    576577        OUT.col.x = SqrLen(diffVec); 
    577578        //OUT.illum_col.z = SqrLen(diffVec); 
    578          
     579 
     580        OUT.illum_col.xyz = normal.xyz; 
    579581        return OUT; 
    580582} 
Note: See TracChangeset for help on using the changeset viewer.