Changeset 3089 for GTP


Ignore:
Timestamp:
11/03/08 01:57:25 (16 years ago)
Author:
mattausch
Message:

working better but stil not fully there

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

Legend:

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

    r3076 r3089  
    169169 
    170170#endif 
     171                geom->mVertices[i].x += 470.398f; 
     172                geom->mVertices[i].y += 240.364f; 
     173                geom->mVertices[i].z += 182.5f; 
     174 
    171175                if (i < geom->mTexcoordCount) 
    172176                { 
     
    238242        while (fgets(str, len, file) != NULL) 
    239243        { 
    240                 if (1)//(line % 100) == 0) 
    241                         cout << "read line " << line << " " << str; 
     244//              if (1)//(line % 100) == 0) 
     245//                      cout << "read line " << line << " " << str; 
    242246                switch (str[0])  
    243247                { 
     
    342346        //-- texture 
    343347 
    344         int texId = -1; 
    345         //int texId = 0; 
     348        //int texId = -1; 
     349        int texId = 0; 
    346350        str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
    347351 
     
    386390        //-- write textures 
    387391 
    388         //int textureCount = 1; 
    389         int textureCount = 0; 
     392        int textureCount = 1; 
     393        //int textureCount = 0; 
    390394 
    391395        ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 
     
    401405                ofile.write(texName.c_str(), sizeof(char) * texnameSize); 
    402406 
    403                 int boundS = 1; 
    404                 int boundT = 1; 
     407                int boundS = 1, boundT = 1; 
    405408 
    406409                ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int)); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3088 r3089  
    143143        p->Bind(); 
    144144 
     145        // interpolate the view vector 
    145146        Vector3 bl = mCornersView[0]; 
    146147        Vector3 br = mCornersView[1]; 
     
    153154        glBegin(GL_QUADS); 
    154155 
    155         glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 
     156        /*glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 
    156157        glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 
    157158        glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs,  offs, -0.5f); 
    158159        glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs,  offs, -0.5f); 
     160 
     161        glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(-offs, -offs); 
     162        glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(offs, -offs); 
     163        glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(offs, offs); 
     164        glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(-offs, offs); 
     165*/       
     166        glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(0, 0); 
     167        glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(1, 0); 
     168        glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(1, 1); 
     169        glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(0, 1); 
    159170 
    160171        glEnd(); 
     
    427438        mIllumFboIndex = 2 - mIllumFboIndex; 
    428439         
    429  
     440        // enable fragment shading 
    430441        ShaderManager::GetSingleton()->EnableFragmentProfile(); 
    431442 
     
    436447        glDisable(GL_DEPTH_TEST); 
    437448 
    438         glPushAttrib(GL_VIEWPORT_BIT); 
    439         glViewport(0, 0, mWidth, mHeight); 
     449        glPolygonMode(GL_FRONT, GL_FILL); 
    440450 
    441451        glMatrixMode(GL_PROJECTION); 
     
    444454 
    445455        const float offs = 0.5f; 
    446         glOrtho(-offs, offs, -offs, offs, 0, 1); 
     456        //glOrtho(-offs, offs, -offs, offs, 0, 1); 
     457        //glOrtho(0, 1, 0, 1, 0, 1); 
     458        gluOrtho2D(0, 1, 0, 1); 
     459 
    447460 
    448461        glMatrixMode(GL_MODELVIEW); 
    449462        glPushMatrix(); 
    450463        glLoadIdentity(); 
     464 
     465         
     466        glPushAttrib(GL_VIEWPORT_BIT); 
     467        glViewport(0, 0, mWidth, mHeight); 
    451468 
    452469        if (shadowMap) 
     
    497514        glPopMatrix(); 
    498515 
     516        // viewport 
    499517        glPopAttrib(); 
    500518 
     
    591609        glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom 
    592610 
    593         glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 
     611        //glVertex3f(x - 0.5f, y - 0.5f, -0.5f); 
     612        glVertex2f(x, y); 
    594613} 
    595614 
     
    608627 
    609628        sCgAntiAliasingProgram->Bind(); 
    610  
    611         glColor3f(1.0f, 1.0f, 1.0f); 
    612629 
    613630        glBegin(GL_QUADS); 
     
    762779        poisson.Generate((float *)filterOffsets); 
    763780 
    764         const float filterWidth = 10.0f; 
     781        //const float filterWidth = 10.0f; 
     782        const float filterWidth = 7.0f; 
    765783        const float xoffs = filterWidth / fbo->GetWidth(); 
    766784        const float yoffs = filterWidth / fbo->GetHeight(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3085 r3089  
    3737 
    3838        const Vector3 pos = GetWorldCenter(); 
    39  
    4039        const float dist = SqrDistance(pos, viewPoint); 
    4140 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r3062 r3089  
    176176        glLoadIdentity(); 
    177177 
    178         glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);  
     178        glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);  
    179179 
    180180        glMatrixMode(GL_MODELVIEW); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r3074 r3089  
    2222void Transform3::Load(RenderState *state) 
    2323{ 
    24         if (mIsIdentity) return; 
    25  
    26         glPushMatrix(); 
    27         glMultMatrixf((float *)mMatrix.x); 
     24        if (!mIsIdentity)  
     25        { 
     26                glPushMatrix(); 
     27                glMultMatrixf((float *)mMatrix.x); 
     28        } 
    2829} 
    2930 
     
    3132void Transform3::Unload(RenderState *state) 
    3233{ 
    33         if (mIsIdentity) return; 
    34         glPopMatrix(); 
     34        if (!mIsIdentity) 
     35        { 
     36                glPopMatrix(); 
     37        } 
    3538} 
    3639 
     
    4043        mIsIdentity = false; 
    4144        mMatrix = mMatrix * trafo; 
    42         //mMatrix = trafo * mMatrix; 
    4345} 
    4446 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3085 r3089  
    459459 
    460460        LoadModel("hbuddha.dem", dynamicObjects); 
     461        //LoadModel("hbuddha2.dem", dynamicObjects); 
    461462        buddha = dynamicObjects.back(); 
    462463         
    463464        const Vector3 sceneCenter(470.398f, 240.364f, 182.5f); 
     465         
    464466        Matrix4x4 transl = TranslationMatrix(sceneCenter); 
    465467        buddha->GetTransform()->SetMatrix(transl); 
     
    938940         
    939941                glEnable(GL_MULTISAMPLE_ARB); 
    940                  
    941942                state.SetRenderTechnique(FORWARD); 
    942                 glEnable(GL_LIGHTING); 
     943                //glEnable(GL_LIGHTING); 
    943944 
    944945                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    950951                glDisable(GL_MULTISAMPLE_ARB); 
    951952                state.SetUseAlphaToCoverage(false); 
    952  
    953953                state.SetRenderTechnique(DEPTH_PASS); 
    954954 
     
    967967 
    968968                glEnable(GL_MULTISAMPLE_ARB); 
    969                  
    970969                state.SetRenderTechnique(DEPTH_PASS); 
    971970 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3088 r3089  
    66//-- ssao + gi parameters 
    77 
    8 //#define NUM_SAMPLES 8 
    9 #define NUM_SAMPLES 16 
     8#define NUM_SAMPLES 8 
     9//#define NUM_SAMPLES 16 
    1010 
    1111// for quadratic falloff 
     
    4343 
    4444#define MIN_DEPTH_DIFF 1e-2f 
    45 #define PRECISION_SCALE 1e-1f 
     45#define PRECISION_SCALE 1e-2f 
    4646 
    4747// burnout 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3087 r3089  
    3333                         uniform float4 color, 
    3434                         uniform float3 normal, 
    35                          uniform float emmisive, 
    3635                         float3 lightDir) 
    3736{ 
     
    4948        // hack: prevent shading the sky 
    5049        if (color.w > 1e19f) outColor = color; 
    51         //if (emmisive > 1.5f) outColor = color; 
    5250        else outColor = (ambient + diffuse) * color; 
    5351 
     
    7068        float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 
    7169         
    72  
    73         // an ambient color term 
    74         float amb = color.w; 
    7570        float3 normal = normalize(norm.xyz); 
    76         float4 col = shade(IN, color, normal, amb, lightDir); 
     71        float4 col = shade(IN, color, normal, lightDir); 
    7772         
    7873        OUT.color = col; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3084 r3089  
    4242 
    4343 
    44 #pragma position_invariant vtx 
     44//#pragma position_invariant vtx 
    4545 
    4646vtxout vtx(vtxin IN) 
     
    6161} 
    6262 
    63 #pragma position_invariant fragtex 
    6463 
    6564pixel fragtex(fragin IN,  
     
    9190 
    9291 
    93 #pragma position_invariant frag 
    94  
    9592pixel frag(fragin IN, uniform float4x4 viewMatrix) 
    9693{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3088 r3089  
    5454                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
    5555{ 
    56         const float eyeSpaceDepth = tex2D(tex, texcoord).w; 
     56        const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 
    5757        float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 
    5858        float3 samplePos = -viewVec * eyeSpaceDepth; 
     
    8080                                                           uniform float3 oldbr, 
    8181                                                           uniform float3 oldtl, 
    82                                                            uniform float3 oldtr 
    83                                                           // float dummy3 
     82                                                           uniform float3 oldtr, 
     83                                                           float3 worldPos 
    8484                                                           ) 
    8585{ 
     
    8787 
    8888        const float2 offsetTransformed = myreflect(offset, mynoise); 
    89         const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 
     89        float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 
     90        //texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f; 
    9091        const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 
    9192 
     
    9596 
    9697        // fit from unit cube into 0 .. 1 
    97         const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 
    98  
     98        float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; 
    9999        // retrieve the sample from the last frame 
    100         float4 oldCol = tex2D(oldTex, oldTexCoords); 
    101  
    102         float oldEyeSpaceDepth = oldCol.w;// dummy3; 
     100        float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 
     101 
     102        float oldEyeSpaceDepth = oldCol.w; 
    103103        float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 
    104104        float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 
    105105 
    106106        float dDiff = length(oldSamplePos - samplePos.xyz); 
     107 
     108        if (length(worldPos.xyz - samplePos.xyz) > 5.0f) 
     109                dDiff = .0f; 
    107110 
    108111        return dDiff; 
     
    150153 
    151154        // retrieve the sample from the last frame 
    152         //float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 
    153         float4 oldCol = tex2D(oldTex, oldTexCoords); 
    154  
    155         //eyeSpaceDepth = 1e6f; 
    156          
    157         //const float dummy3 = 1e-4f; 
    158         //const float oldEyeSpaceDepth = 1e5f * dummy3; 
    159         //const float oldEyeSpaceDepth = oldCol.z / dummy3; 
     155        float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0)); 
     156        //float4 oldCol = tex2D(oldTex, oldTexCoords); 
     157 
    160158        const float oldEyeSpaceDepth = oldCol.w; 
    161  
    162159        //oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f; 
    163160 
     
    166163        float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth; 
    167164 
    168         //const float oldDepth = oldCol.z; 
    169165        const float depthDif = length(oldSamplePos - worldPos.xyz); 
    170         //eyeSpaceDepth *= dummy3; 
    171          
    172         //const float depthDif = abs(oldEyeSpaceDepth - eyeSpaceDepth);// * 1e4f; 
    173         //const float depthDif = abs(oldEyeSpaceDepth - dummy2) * 1e3f; 
    174  
    175         //const float oldNumSamples = oldCol.y; 
    176         const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 
    177         float newWeight; 
    178  
    179         bool isValid = true; 
     166         
     167        float notValid = 0.5f; 
    180168 
    181169        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    182170        { 
    183                 float sampleDif  = ComputeDifference(samples[i], 
     171                float sampleDif = ComputeDifference(samples[i], 
    184172                                          oldTex, 
    185173                                                          oldModelViewProj, 
     
    191179                                                          eyePos, 
    192180                                                          oldEyePos, 
    193                                                           oldbl, oldbr, oldtl, oldtr 
    194                                                           //,dummy3 
    195                                                           ); 
    196  
    197                 //if (sampleDif > 1e-1f) isValid = false; 
    198         } 
    199  
     181                                                          oldbl, oldbr, oldtl, oldtr, 
     182                                                          worldPos.xyz); 
     183 
     184                if (sampleDif >= 1e-1f) ++ notValid; 
     185        } 
     186 
     187        //if (notValid < 1.0f) temporalCoherence = 4.0f; 
    200188        // the number of valid samples in this frame 
    201189        //const float newNumSamples = ao.y; 
     190 
     191        //const float oldNumSamples = oldCol.y; 
     192        const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 
     193        float newWeight; 
    202194 
    203195        if ((temporalCoherence > 1e-6f) 
     
    207199                // if visibility changed in the surrounding area we have to recompute 
    208200                //&& (oldNumSamples > 0.8f * newNumSamples) 
    209                 && isValid 
     201                //&& (notValid < 1.0f) 
    210202                ) 
    211203        { 
     
    213205                newWeight = oldWeight + 1.0f; 
    214206                illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 
    215                 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 
     207                if (notValid > 1.0f) newWeight = 2; 
    216208        } 
    217209        else 
     
    221213        } 
    222214 
    223         //illum_col.x = depthDif; 
    224          
    225         //isValid = 0.0f; 
    226         //illum_col.y = isValid / 16.0f; 
    227215        illum_col.y = newWeight; 
    228216        illum_col.w = eyeSpaceDepth; 
    229         //illum_col.z = dummy2; 
    230  
     217         
    231218        return illum_col; 
    232219} 
     
    291278                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    292279                // the distance to a sample approaches zero 
     280                const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 
    293281                //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 
    294                 const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample); 
    295282 
    296283#if 1 
     
    338325        // reconstruct position from the eye space depth 
    339326        const float3 viewDir = IN.view; 
    340         const float eyeSpaceDepth = tex2D(colors, IN.texCoord).w; 
     327        const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 
    341328        const float3 eyeSpacePos = -viewDir * eyeSpaceDepth; 
    342329        const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f); 
     
    399386        float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
    400387 
    401         //if (ao.y < 10.0f)  
    402         //      ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    403  
    404         //OUT.illum_col = col * ao.x; 
    405         OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
     388        if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
     389 
     390        OUT.illum_col = col * ao.x; 
     391        //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    406392        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
    407393        //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
Note: See TracChangeset for help on using the changeset viewer.