Changeset 2975


Ignore:
Timestamp:
09/26/08 10:31:58 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r2972 r2975  
    283283                                > 
    284284                        </File> 
    285                         <File 
    286                                 RelativePath=".\src\ToneMapper.cpp" 
    287                                 > 
    288                         </File> 
    289                         <File 
    290                                 RelativePath=".\src\ToneMapper.h" 
    291                                 > 
    292                         </File> 
    293285                        <Filter 
    294286                                Name="timer" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2974 r2975  
    99#include "ShadowMapping.h" 
    1010#include "Light.h" 
    11 #include "ToneMapper.h" 
    1211 
    1312 
     
    553552                FirstPass(fbo, light); 
    554553 
    555         glEnable(GL_TEXTURE_2D); 
    556         // generate mip map levels for position texture 
    557         glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
    558         glGenerateMipmapEXT(GL_TEXTURE_2D); 
    559  
    560554 
    561555        switch (mShadingMethod) 
     
    576570        float imageKey, whiteLum, middleGrey; 
    577571 
     572        // generate mip map levels of position texture 
     573        glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
     574        glGenerateMipmapEXT(GL_TEXTURE_2D); 
     575 
    578576        ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 
    579577        ToneMap(fbo, light, imageKey, whiteLum, middleGrey); 
     
    603601{ 
    604602#ifdef USE_3D_SSAO 
     603        // bias from [-1, 1] to [0, 1] 
    605604        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
    606605                                                                0.0f, 0.5f, 0.0f, 0.5f, 
    607606                                                                0.0f, 0.0f, 0.5f, 0.5f, 
    608                                                                 0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 
     607                                                                0.0f, 0.0f, 0.0f, 1.0f);  
    609608 
    610609        Matrix4x4 m = projViewMatrix * biasMatrix;  
     
    615614        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
    616615 
    617         GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
     616        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    618617        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    619618        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    620619 
    621         // generate mip map levels for position texture 
     620        // generate mip map levels of position texture 
    622621        glBindTexture(GL_TEXTURE_2D, positionsTex); 
    623622        glGenerateMipmapEXT(GL_TEXTURE_2D); 
     
    628627        glDrawBuffers(1, mrt + mFboIndex); 
    629628 
    630  
    631         //GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture(); 
    632629        GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 
    633630 
     
    677674        glBegin(GL_QUADS); 
    678675 
    679         // note: slightly larger texture hides ambient occlusion error on border but costs resolution 
    680         //const float new_offs = 0.55f; 
    681         const float new_offs = 0.5f; 
    682          
    683         glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-new_offs, -new_offs, -0.5f); 
    684         glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( new_offs, -new_offs, -0.5f); 
    685         glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( new_offs,  new_offs, -0.5f); 
    686         glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-new_offs,  new_offs, -0.5f); 
     676        // note: slightly larger texture could hide ambient occlusion error on border but costs resolution 
     677        const float offs = 0.5f; 
     678         
     679        glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f); 
     680        glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f); 
     681        glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs,  offs, -0.5f); 
     682        glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs,  offs, -0.5f); 
    687683 
    688684        glEnd(); 
     
    11331129                                                                                         float &middleGrey) 
    11341130{ 
    1135         ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    1136  
    1137         // we assume that we have a floating point rgba texture 
    1138         float *pixels = (float *)colorBuffer->ReadTexture(); 
    1139          
    1140         const int w = colorBuffer->GetHeight(); 
    1141         const int h = colorBuffer->GetWidth(); 
    1142  
    1143         imageKey = ToneMapper().CalcImageKey(pixels, w, h); 
    1144         whiteLum = 1.0f * ToneMapper().CalcMaxLuminance(pixels, w, h); 
    1145  
    1146         //const float minKey = 0.18f; 
    1147         //const float maxKey = 0.72f; 
    1148  
    1149         //const float minKey = 0.0045f; 
     1131        // hack: estimate value where sky burns out 
     1132        whiteLum = log(1e4f); 
     1133         
     1134        //////////////////// 
     1135        //-- linear interpolate brightness key depending on the current sun position 
     1136 
    11501137        const float minKey = 0.09f; 
    11511138        const float maxKey = 0.5f; 
     
    11531140        const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 
    11541141        middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey; 
    1155  
    1156         //cout << "middlegrey: " << middleGrey << endl; 
    1157         delete [] pixels; 
    1158  
    1159  
    1160         ///////////// 
    1161  
    1162         /*GLuint colorsTex = colorBuffer->GetTexture(); 
    1163  
    1164         fbo->Bind(); 
    1165  
    1166         colorBufferIdx = 3 - colorBufferIdx; 
    1167         glDrawBuffers(1, mrt + colorBufferIdx); 
    1168  
    1169         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1170  
    1171         cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    1172         cgGLBindProgram(sCgInitialIntensityProgram); 
    1173          
    1174         cgGLSetTextureParameter(sColorsTexInitialParam, colorsTex); 
    1175         cgGLEnableTextureParameter(sColorsTexInitialParam); 
    1176  
    1177         // first pass: create high res intensity texture 
    1178         glColor3f(1.0f, 1.0f, 1.0f); 
    1179  
    1180         float offs2 = 0.5f; 
    1181  
    1182         glBegin(GL_QUADS); 
    1183  
    1184         // the neighbouring texels 
    1185         float x_offs = 0;//1.0f / mWidth; 
    1186         float y_offs = 0;//1.0f / mHeight; 
    1187  
    1188         SetVertex(0, 0, x_offs, y_offs); 
    1189         SetVertex(1, 0, x_offs, y_offs); 
    1190         SetVertex(1, 1, x_offs, y_offs); 
    1191         SetVertex(0, 1, x_offs, y_offs); 
    1192  
    1193         glEnd(); 
    1194  
    1195         cgGLDisableTextureParameter(sColorsTexToneParam); 
    1196  
    1197         FrameBufferObject::Release(); 
    1198  
    1199          
    1200         //////////// 
    1201         //-- second phase: down sample the texture in order to compute the average 
    1202          
    1203         // q: required passes for computing 1x1 texture? 
    1204         int passes = 32; 
    1205  
    1206         for (int i = 0; i < 32; ++ i) 
    1207         { 
    1208                 //DownSample(fbo); 
    1209         } 
    1210 */ 
    1211         PrintGLerror("antialiasing"); 
    12121142} 
    12131143 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2974 r2975  
    2828//#define ILLUM_INTENSITY 9e-1f; 
    2929 
    30 #define SSAO_MIPMAP_LEVEL 1 
    31 #define GI_MIPMAP_LEVEL 2 
     30#define SSAO_MIPMAP_LEVEL 0//1 
     31#define GI_MIPMAP_LEVEL 0//2 
    3232 
    3333 
     
    4141//-- Tone mapping 
    4242 
    43 #define MINLOGLUM 10.0f 
     43#define MINLOGLUM (-10.0f) 
    4444#define MAXLOGLUM 10.0f 
    4545 
     46#define INV_LOGLUM_RANGE 0.05f 
     47#define LOGLUM_RANGE 20.0f 
     48 
    4649#endif // __SHADERENV_H 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2974 r2975  
    8181         
    8282        OUT.color = col; 
    83         OUT.color.w = color.w; 
    84  
    85         // write out logaritmic luminance for tone mapping 
     83         
     84 
     85        //////////// 
     86        //-- write out logaritmic luminance for tone mapping 
     87 
    8688        const float3 w = float3(0.299f, 0.587f, 0.114f); 
    8789 
     
    8991        float logLum = log(1e-5f + lum); 
    9092 
    91         float invLogLumRange =  1 / (MAXLOGLUM + MINLOGLUM); 
    92         float logLumOffset = MINLOGLUM * invLogLumRange; 
    93         float logLumScaled = logLum * invLogLumRange + logLumOffset; 
     93        float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 
     94        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    9495 
    9596        OUT.color.w = logLumScaled; 
     
    194195        OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 
    195196 
    196         // write out logaritmic luminance for tone mapping 
     197        //////////// 
     198        //-- write out logaritmic luminance for tone mapping 
     199 
    197200        const float3 w = float3(0.299f, 0.587f, 0.114f); 
    198201 
     
    200203        float logLum = log(1e-5f + lum); 
    201204 
    202         OUT.color.w = 100;//logLum; 
     205        float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 
     206        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
     207 
     208        OUT.color.w = logLumScaled; 
    203209         
    204210        return OUT; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2974 r2975  
    5252                                 uniform float2 samples[NUM_SAMPLES], 
    5353                                 uniform float3 currentNormal, 
    54                                  uniform float3 currentViewDir, 
    55                                  uniform float4 centerPosition 
     54                                 uniform float4 centerPosition, 
     55                                 float w 
     56                                 //, uniform float3 currentViewDir 
    5657                                 ) 
    5758{ 
    5859        GiStruct gi; 
    59  
    60         // the w coordinate from the persp. projection 
    61         float w = centerPosition.w; 
    6260 
    6361        // Check in a circular area around the current position. 
     
    117115        } 
    118116 
    119         gi.illum = saturate(total_color); 
     117        gi.illum = total_color; 
    120118        gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 
    121119 
     
    143141 
    144142        float4 norm = tex2D(normals, IN.texCoord.xy); 
    145          
    146         // the ambient term 
     143        float3 normal = normalize(norm.xyz);     
     144        // something like a constant ambient term 
    147145        const float amb = norm.w; 
    148  
    149         // expand normal 
    150         float3 normal = normalize(norm.xyz); 
    151  
    152146        /// the current view direction 
    153         float3 viewDir;// = normalize(IN.view); 
    154  
     147        //float3 viewDir = normalize(IN.view); 
     148 
     149        // the w coordinate from the persp. projection 
     150        float w = norm.w; 
    155151        // the current world position 
    156152        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    157          
    158153        // the current color 
    159154        const float4 currentCol = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    160155        // the current depth is stored in the w component 
    161         const float currentDepth = currentCol.w; 
    162  
    163         GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, centerPosition); 
     156        const float currentDepth = centerPosition.w; 
     157 
     158        GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w); //, viewDir); 
    164159         
    165160 
     
    186181 
    187182        const float oldNumSamples = oldSsao.y; 
     183        const float oldAvgDepth = oldSsao.z; 
    188184 
    189185        if ((temporalCoherence > 0.0f) && 
    190186                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    191187                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    192                 (abs(depthDif)  < 1e-3f) 
    193                 && (oldNumSamples > gi.ao.y - 1.5f) // check if something happened in the surrounding area 
     188                (abs(depthDif) < 1e-3f) 
     189                // check if something changed in the surrounding area 
     190                && (oldNumSamples > 0.2 * gi.ao.y) 
     191                && (oldAvgDepth / newAvgDepth > 0.99) 
    194192                ) 
    195193        { 
     
    218216                          uniform sampler2D ssaoTex, 
    219217                          uniform sampler2D illumTex 
    220                    ) 
     218                          ) 
    221219{ 
    222220        pixel OUT; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2974 r2975  
    117117 
    118118        float4 norm = tex2D(normals, IN.texCoord.xy); 
    119          
    120         // expand normal 
    121119        float3 normal = normalize(norm.xyz); 
    122          
     120 
    123121        // a constant ambient term 
    124122        const float amb = norm.w; 
    125123        // the w coordinate from the persp. projection 
    126124        float w = norm.w; 
    127  
    128125        // the current world position 
    129126        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    130          
    131127        // the current color 
    132128        const float currentDepth = centerPosition.w; 
     
    141137        realPos.w = 1.0f; 
    142138 
    143         // reproject 
     139 
     140        /////////// 
     141        //-- reprojection from new frame into old one 
     142 
    144143        float4 oldPos = mul(oldModelViewProj, realPos); 
    145144 
     
    161160                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    162161                (abs(depthDif) < 1e-3f)  
    163                 && (oldNumSamples > ao.y - 1.5f) // check if something happened in the surrounding area 
     162                // check if visibility changed in the surrounding area: 
     163                // then we have to recompute 
     164                && (oldNumSamples > ao.y - 1.5f)  
    164165                ) 
    165166        { 
    166167                // increase the weight for convergence 
    167168                newWeight = oldWeight + 1.0f; 
    168  
    169                 //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor); 
    170169                OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight; 
    171170 
     
    193192 
    194193        float4 col = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
    195         float depth = tex2Dlod(positions, float4(IN.texCoord.xy, 0, 0)).w; 
    196194        float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 
    197195 
    198196        OUT.illum_col = col * ao.x; 
    199         OUT.illum_col.w = ao.w; 
     197        //OUT.illum_col.w = ao.w; 
     198        OUT.illum_col.w = col.w; 
    200199 
    201200        return OUT; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r2974 r2975  
    9090        // obtain new image key from highest mipmap level 
    9191        float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w; 
    92  
    93         float logLumRange = MAXLOGLUM + MINLOGLUM; 
    94         //float logLumOffset = MINLOGLUM * logLumRange; 
    95         float logLum = logLumScaled * logLumRange - MINLOGLUM; 
     92        float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 
    9693 
    9794        float newImageKey = exp(logLum); 
Note: See TracChangeset for help on using the changeset viewer.