Changeset 2999


Ignore:
Timestamp:
10/03/08 14:35:07 (16 years ago)
Author:
mattausch
Message:

trying to use smaller fbo

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

Legend:

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

    r2991 r2999  
    8686        mHeight = h; 
    8787 
     88        int myformat = GL_RGBA; 
     89 
    8890        switch (format) 
    8991        { 
     
    9496        case BUFFER_FLOAT_32:  
    9597                mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break; 
     98        case BUFFER_LUMINANCE_ALPHA:  
     99                mGlFormat = GL_FLOAT; mInternalFormat = GL_LUMINANCE_ALPHA ; 
     100                myformat = GL_LUMINANCE_ALPHA; 
     101                break; 
    96102        default: 
    97103                mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; 
     
    109115        glGenTextures(1, &mTexId); 
    110116        glBindTexture(GL_TEXTURE_2D, mTexId); 
    111         glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, GL_RGBA, mGlFormat, NULL); 
     117        glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, myformat, mGlFormat, NULL); 
    112118 
    113119        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h

    r2966 r2999  
    1515public: 
    1616 
    17         enum FORMAT { BUFFER_UBYTE, BUFFER_FLOAT_16, BUFFER_FLOAT_32 }; 
     17        enum FORMAT { BUFFER_UBYTE, BUFFER_FLOAT_16, BUFFER_FLOAT_32, BUFFER_LUMINANCE_ALPHA }; 
    1818        enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE }; 
    1919        enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR }; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2997 r2999  
    274274static CGparameter sMaxDepthParam; 
    275275static CGparameter sMaxDepthParamTex; 
    276 static CGparameter sCurrentPosParamTex; 
    277 static CGparameter sCurrentPosParam; 
     276static CGparameter sEyePosParamTex; 
     277static CGparameter sEyePosParam; 
     278 
     279static CGparameter sTLParam; 
     280static CGparameter sTRParam; 
     281static CGparameter sBRParam; 
     282static CGparameter sBLParam; 
     283 
     284static CGparameter sTLParamTex; 
     285static CGparameter sTRParamTex; 
     286static CGparameter sBRParamTex; 
     287static CGparameter sBLParamTex; 
    278288 
    279289static Matrix4x4 oldViewProjMatrix; 
     
    457467                exit(0); 
    458468        } 
    459  
     469         
     470#if 0 
     471 
     472        int merged = 0; 
     473 
     474        SceneEntity *oldEnt = NULL; 
     475 
     476        cout << "merging entities .. " << endl; 
    460477        SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 
    461  
    462         int merged = 0; 
    463          
    464         SceneEntity *oldEnt = NULL; 
    465 #if 0 
    466         cout << "merging entities .. " << endl; 
    467478 
    468479        for (sit = sceneEntities.begin(); sit < sit_end; ++ sit) 
     
    498509        cout << "merged " << merged << " of " << (int)sceneEntities.size() << " entities " << endl; 
    499510#endif 
     511 
    500512        // set far plane based on scene extent 
    501513        farDist = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 
     
    599611 
    600612                sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 
    601                 sCurrentPosParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "currentPos"); 
     613                sEyePosParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos"); 
    602614                RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex"); 
    603615         
    604616                cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); 
     617 
     618                sTLParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tl");  
     619                sTRParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tr");  
     620                sBRParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "br");  
     621                sBLParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "bl");  
    605622        } 
    606623        else 
     
    620637 
    621638                sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 
    622                 sCurrentPosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "currentPos"); 
     639                sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos"); 
    623640                 
    624641                cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist); 
     642 
     643                sTLParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "tl");  
     644                sTRParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "tr");  
     645                sBRParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "br");  
     646                sBLParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "bl");  
    625647        } 
    626648        else 
     
    646668        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
    647669        // the positions buffer 
    648         fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
     670        //fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
     671        fbo->AddColorBuffer(ColorBufferObject::BUFFER_LUMINANCE_ALPHA, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
    649672        // the normals buffer 
    650673        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
     
    935958 
    936959 
     960static void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) 
     961{ 
     962        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     963 
     964        camera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
     965 
     966        bl = Normalize(nbl - fbl); 
     967        br = Normalize(nbr - fbr); 
     968        tl = Normalize(ntl - ftl); 
     969        tr = Normalize(ntr - ftr); 
     970} 
     971 
     972 
    937973void InitDeferredRendering() 
    938974{ 
     
    952988 
    953989        const Vector3 pos = camera->GetPosition(); 
    954         cgGLSetParameter3f(sCurrentPosParam, pos.x, pos.y, pos.z); 
    955         cgGLSetParameter3f(sCurrentPosParamTex, pos.x, pos.y, pos.z); 
     990 
     991        cgGLSetParameter3f(sEyePosParam, pos.x, pos.y, pos.z); 
     992        cgGLSetParameter3f(sEyePosParamTex, pos.x, pos.y, pos.z); 
     993 
     994        Vector3 tl, tr, bl, br; 
     995        ComputeViewVectors(tl, tr, bl, br); 
     996 
     997        cgGLSetParameter3f(sBLParam, bl.x, bl.y, bl.z); 
     998        cgGLSetParameter3f(sBRParam, br.x, br.y, br.z); 
     999        cgGLSetParameter3f(sTLParam, tl.x, tl.y, tl.z); 
     1000        cgGLSetParameter3f(sTRParam, tr.x, tr.y, tr.z); 
     1001 
     1002        cgGLSetParameter3f(sBLParamTex, bl.x, bl.y, bl.z); 
     1003        cgGLSetParameter3f(sBRParamTex, br.x, br.y, br.z); 
     1004        cgGLSetParameter3f(sTLParamTex, tl.x, tl.y, tl.z); 
     1005        cgGLSetParameter3f(sTRParamTex, tr.x, tr.y, tr.z); 
    9561006 
    9571007        // draw to 3 color buffers 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2991 r2999  
    6565                                   uniform float4 centerPosition, 
    6666                                   float w, 
    67                                    // uniform float3 viewDir, 
    6867                                   uniform float3 eyePos, 
    6968                                   uniform float3 bl, 
     
    7170                                   uniform float3 tl, 
    7271                                   uniform float3 tr 
     72                                   //, uniform float3 viewDir 
    7373                                   ) 
    7474{ 
     
    102102                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    103103 
    104                 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 
    105                         ++ numSamples; 
     104                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 
    106105 
    107106                // reconstruct world space position from sample 
    108107                float4 sample = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)); 
    109108                const float eyeSpaceDepth = sample.w; 
    110                 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     109                //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     110                float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
    111111                 
    112112                const float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
     
    213213        const float oldAvgDepth = oldSsao.z; 
    214214 
    215         if ((temporalCoherence > 0.0f) && 
     215        if (//(temporalCoherence > 0.0f) && 
    216216                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    217217                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    218218                (abs(depthDif) < 1e-3f) 
    219219                // check if something changed in the surrounding area 
    220                 && (oldNumSamples > 0.2 * gi.ao.y) 
    221                 //&& (oldAvgDepth / newAvgDepth > 0.99) 
     220                //&& (oldNumSamples > 0.2 * gi.ao.y) 
    222221                ) 
    223222        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2989 r2999  
    3838{ 
    3939  float4 col: COLOR0; 
    40   float4 pos: COLOR1; 
     40  //float4 pos: COLOR1; 
     41  float2 pos: COLOR1; 
    4142  float4 norm: COLOR2; 
    4243}; 
     
    6566 
    6667 
     68// bilinear interpolation 
     69inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     70{ 
     71        float3 x1 = lerp(bl, tl, w.y); 
     72        float3 x2 = lerp(br, tr, w.y);  
     73        float3 v = lerp(x1, x2, w.x);  
     74 
     75        return v; 
     76} 
     77 
     78 
    6779pixel fragtex(fragin IN,  
    6880                          uniform sampler2D dirtTex, 
    6981                          uniform float maxDepth, 
    7082                          uniform sampler2D tex, 
    71                           uniform float3 currentPos) 
     83                          uniform float3 eyePos, 
     84                          uniform float3 bl, 
     85                          uniform float3 br, 
     86                          uniform float3 tl, 
     87                          uniform float3 tr) 
    7288{ 
     89        float4 texColor = tex2D(tex, IN.texCoord.xy); 
     90 
     91        // account for alpha blending 
     92        if (texColor.w < 0.5f) discard; 
     93 
    7394        pixel pix; 
    74  
    75         float4 texColor = tex2D(tex, IN.texCoord.xy); 
    7695 
    7796        // save color in first render target 
    7897        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 
    7998        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;  
    80          
     99 
    81100        // save world position in second render target 
    82         pix.pos = IN.worldPos * maxDepth; 
     101        //pix.pos = IN.worldPos * maxDepth; 
    83102        // save world space normal in third rt 
    84103        pix.norm.xyz = IN.normal; 
     
    86105        // store projection coordinates with positions (used for ssao) 
    87106        pix.norm.w = IN.projPos.w; 
    88         // write the depth 
    89         pix.pos.w = IN.mypos.z / IN.mypos.w; 
    90107 
    91         // account for alpha blending 
    92         if (pix.col.w < 0.5f) 
    93                 discard; 
     108        const float4 projPos = IN.mypos / IN.mypos.w; 
     109        // store the projected depth 
     110        pix.pos.y = projPos.z; 
     111 
     112        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
     113        const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
    94114 
    95115        // hack: squeeze some information about ambient into the texture 
    96116        //pix.col.w = glstate.material.emission.x; 
    97         pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 
     117 
     118        // eye linear depth 
     119        pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 
     120        pix.pos.x = pix.col.x; 
    98121 
    99122        return pix; 
     
    101124 
    102125 
    103 pixel frag(fragin IN, uniform float maxDepth, uniform float3 currentPos) 
     126pixel frag(fragin IN,  
     127                   uniform float maxDepth,  
     128                   uniform float3 eyePos, 
     129                   uniform float3 bl, 
     130                   uniform float3 br, 
     131                   uniform float3 tl, 
     132                   uniform float3 tr) 
    104133{ 
    105134        pixel pix; 
     
    107136        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    108137        pix.col = glstate.material.diffuse + glstate.material.emission; 
    109         pix.pos = IN.worldPos * maxDepth; 
     138        //pix.pos = IN.worldPos * maxDepth; 
    110139 
    111140        pix.norm.xyz = IN.normal; 
     
    113142        // store projection coordinates with positions (used for ssao) 
    114143        pix.norm.w = IN.mypos.w; 
    115         // the projected depth 
    116         pix.pos.w = IN.mypos.z / IN.mypos.w; 
    117          
     144 
     145        const float4 projPos = IN.mypos / IN.mypos.w; 
     146        // store the projected depth 
     147        pix.pos.y = projPos.z; 
     148 
     149        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
     150        const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
     151 
    118152        // hack: squeeze some information about the ambient term into the target 
    119153        //pix.col.w = glstate.material.emission.x; 
    120         pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 
     154        pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 
     155        pix.pos.x = pix.col.x; 
    121156 
    122157        return pix; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2997 r2999  
    4848                                                                                float3 bl, float3 br, float3 tl, float3 tr) 
    4949{ 
    50 #if 0 
     50#if 1 
    5151        float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
    52         float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
    53          
    54         float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
     52        //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     53        float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
     54         
     55        float3 samplePos = eyePos - rotView * eyeSpaceDepth; 
    5556#else 
    56         float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
    57 #endif 
    58         return sample_position; 
     57        float3 samplePos = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
     58#endif 
     59        return samplePos; 
    5960} 
    6061 
     
    101102                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * scaleFactor; 
    102103 
    103                 if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) 
    104                         ++ numSamples; 
    105  
    106                 float3 sample_position = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 
    107  
    108                 float3 vector_to_sample = sample_position - centerPosition.xyz; 
    109                 const float length_to_sample = length(vector_to_sample); 
    110  
    111                 float3 direction_to_sample = vector_to_sample / length_to_sample; 
     104                //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f))++ numSamples; 
     105 
     106                // get sample world space position 
     107                float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
     108                //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     109                float3 rotView = Interpol(texcoord, bl, br, tl, tr); 
     110         
     111                float3 samplePos = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 
     112 
     113 
     114                /////// 
     115                //-- compute contribution of current sample taking into account direction and angle 
     116 
     117                float3 dirSample = samplePos - centerPosition.xyz; 
     118                const float lengthSample = length(dirSample); 
     119 
     120                float3 nDirSample = dirSample / lengthSample; 
    112121 
    113122                // angle between current normal and direction to sample controls AO intensity. 
    114                 const float cos_angle = max(dot(direction_to_sample, currentNormal), 0.0f); 
     123                const float cos_angle = max(dot(nDirSample, currentNormal), 0.0f); 
    115124 
    116125                // the distance_scale offset is used to avoid singularity that occurs at global illumination when  
    117126                // the distance to a sample approaches zero 
    118                 const float distance_intensity =  
    119                         (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample); 
     127                const float intensity =  
     128                        (SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + lengthSample * lengthSample); 
    120129 
    121130#if 0 
    122131                // if surface normal perpenticular to view dir, approx. half of the samples will not count 
    123132                // => compensate for this (on the other hand, projected sampling area could be larger!) 
    124                 const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
    125                 total_ao += cos_angle * distance_intensity * view_correction; 
    126 #endif 
    127                 total_ao += cos_angle * distance_intensity; 
     133                const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
     134                total_ao += cos_angle * intensity * viewCorrection; 
     135#endif 
     136                total_ao += cos_angle * intensity; 
    128137        } 
    129138 
    130139        return float2(max(0.0f, 1.0f - total_ao), numSamples); 
    131         //return saturate(dot(currentViewDir, currentNormal)); 
    132140} 
    133141 
     
    165173        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    166174 
    167 #if 1    
     175#if 0    
    168176        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    169177 
     
    197205        float4 oldPos = mul(oldModelViewProj, realPos); 
    198206 
     207        const float4 projPos = oldPos / oldPos.w; 
     208 
    199209        // the current depth projected into the old frame 
    200         const float projDepth = oldPos.z / oldPos.w; 
     210        const float projDepth = projPos.z; 
    201211 
    202212        // fit from unit cube into 0 .. 1 
    203         float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     213        float2 tex = (projPos.xy) * 0.5f + 0.5f; 
    204214 
    205215        // optain the sample from the last frame 
     
    212222        const float depthDif = 1.0f - projDepth / oldDepth; 
    213223 
    214  
    215224        float newWeight; 
    216225 
    217226        // the number of valid samples in this frame 
    218         const float newNumSamples = ao.y; 
     227        //const float newNumSamples = ao.y; 
    219228 
    220229 
     
    224233                (abs(depthDif) < 1e-4f)  
    225234                // if visibility changed in the surrounding area we have to recompute 
    226                 && (oldNumSamples > 0.8f * newNumSamples) 
     235                //&& (oldNumSamples > 0.8f * newNumSamples) 
    227236                ) 
    228237        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r2992 r2999  
    130130        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    131131 
    132         if (oldLogLum > 0) 
     132        if (oldLogLum > 1e-5f) // too hight log lum 
    133133                OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    134134        else 
Note: See TracChangeset for help on using the changeset viewer.