Changeset 2991


Ignore:
Timestamp:
10/02/08 16:34:58 (16 years ago)
Author:
mattausch
Message:

what todo with tone mapping: manually donwsample??
or manually downsample ssao?? or use smaller rendertarget for ssao solution??

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

Legend:

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

    r2990 r2991  
    2828 
    2929static CGparameter sColorsTexDeferredParam; 
    30 static CGparameter sOldColorsTexDeferredParam; 
    31 static CGparameter sOldColorsTexShadowParam; 
    32  
    3330static CGparameter sPositionsTexDeferredParam; 
    3431static CGparameter sNormalsTexDeferredParam; 
     
    326323                sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions");   
    327324                sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors");   
    328                 sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors"); 
     325                //sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors"); 
    329326                sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 
    330327                 
     
    495492                sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 
    496493                sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 
    497                 sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors"); 
     494                //sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors"); 
    498495 
    499496 
     
    556553                                                          float tempCohFactor, 
    557554                                                          DirectionalLight *light, 
    558                                                           ShadowMap *shadowMap) 
     555                                                          bool useToneMapping, 
     556                                                          ShadowMap *shadowMap 
     557                                                          ) 
    559558{ 
    560559        // switch roles of old and new fbo 
     
    591590        else 
    592591                FirstPass(fbo, light); 
    593  
    594         glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
    595         glGenerateMipmapEXT(GL_TEXTURE_2D); 
    596592 
    597593        switch (mShadingMethod) 
     
    610606        } 
    611607 
    612         float imageKey, whiteLum, middleGrey; 
    613 /* 
    614         glPixelStorei(GL_PACK_ALIGNMENT, 1); 
    615         // generate mip map levels for average loglum and tone mapping  
    616         glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
    617         glGenerateMipmapEXT(GL_TEXTURE_2D); 
    618          
    619         ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 
    620         ToneMap(fbo, light, imageKey, whiteLum, middleGrey); 
    621 */ 
     608        if (useToneMapping) 
     609        { 
     610                float imageKey, whiteLum, middleGrey; 
     611 
     612                ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 
     613                ToneMap(fbo, light, imageKey, whiteLum, middleGrey); 
     614        } 
     615 
    622616        AntiAliasing(fbo, light); 
    623617 
     
    836830        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    837831 
    838         GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 
     832        //GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 
    839833 
    840834        fbo->Bind(); 
     
    852846        cgGLEnableTextureParameter(sColorsTexDeferredParam); 
    853847 
    854         cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex); 
    855         cgGLEnableTextureParameter(sOldColorsTexDeferredParam); 
     848        //cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex); 
     849        //cgGLEnableTextureParameter(sOldColorsTexDeferredParam); 
    856850 
    857851        cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex); 
     
    879873 
    880874        cgGLDisableTextureParameter(sColorsTexDeferredParam); 
    881         cgGLDisableTextureParameter(sOldColorsTexDeferredParam); 
     875        //cgGLDisableTextureParameter(sOldColorsTexDeferredParam); 
    882876        cgGLDisableTextureParameter(sPositionsTexDeferredParam); 
    883877        cgGLDisableTextureParameter(sNormalsTexDeferredParam); 
     
    903897 
    904898        // generate mip map levels for position texture 
    905         //glBindTexture(GL_TEXTURE_2D, positionsTex); 
    906         //glGenerateMipmapEXT(GL_TEXTURE_2D); 
     899        //glBindTexture(GL_TEXTURE_2D, positionsTex); glGenerateMipmapEXT(GL_TEXTURE_2D); 
    907900 
    908901        // read the second buffer, write to the first buffer 
     
    11181111        GLuint shadowTex = shadowMap->GetDepthTexture(); 
    11191112 
    1120         GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 
     1113        //GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 
    11211114 
    11221115        Matrix4x4 shadowMatrix; 
     
    11431136        cgGLEnableTextureParameter(sShadowMapParam); 
    11441137 
    1145         cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex); 
    1146         cgGLEnableTextureParameter(sOldColorsTexShadowParam); 
     1138        //cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex); 
     1139        //cgGLEnableTextureParameter(sOldColorsTexShadowParam); 
    11471140 
    11481141        cgGLSetParameter1f(sMaxDepthShadowParam, mScaleFactor); 
     
    11781171        cgGLDisableTextureParameter(sNormalsTexShadowParam); 
    11791172        cgGLDisableTextureParameter(sShadowMapParam); 
    1180  
    1181         cgGLDisableTextureParameter(sOldColorsTexShadowParam); 
    1182  
    11831173        cgGLDisableTextureParameter(sNoiseTexShadowParam); 
     1174        //cgGLDisableTextureParameter(sOldColorsTexShadowParam); 
    11841175 
    11851176        FrameBufferObject::Release(); 
     
    12261217        const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 
    12271218        middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey; 
     1219 
     1220 
     1221        ////////// 
     1222        //-- compute avg loglum 
     1223 
     1224        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
     1225 
     1226        fbo->Bind(); 
     1227 
     1228        colorBufferIdx = 3 - colorBufferIdx; 
     1229        glDrawBuffers(1, mrt + colorBufferIdx); 
     1230 
     1231        GLuint colorsTex = colorBuffer->GetTexture(); 
     1232         
     1233        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1234 
     1235        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1236        cgGLBindProgram(sCgToneProgram); 
     1237         
     1238        cgGLSetTextureParameter(sColorsTexLogLumParam, colorsTex); 
     1239         
     1240        glColor3f(1.0f, 1.0f, 1.0f); 
     1241 
     1242        glBegin(GL_QUADS); 
     1243 
     1244        glColor3f(1.0f, 1.0f, 1.0f); 
     1245 
     1246        const float offs = 0.5f; 
     1247 
     1248        glBegin(GL_QUADS); 
     1249 
     1250        glTexCoord2f(0, 0); glVertex3f(-offs, -offs, -0.5f); 
     1251        glTexCoord2f(1, 0); glVertex3f( offs, -offs, -0.5f); 
     1252        glTexCoord2f(1, 1); glVertex3f( offs,  offs, -0.5f); 
     1253        glTexCoord2f(0, 1); glVertex3f(-offs,  offs, -0.5f); 
     1254 
     1255        glEnd(); 
     1256 
     1257        cgGLDisableTextureParameter(sColorsTexLogLumParam); 
     1258 
     1259        FrameBufferObject::Release(); 
     1260 
     1261        PrintGLerror("ToneMapParams"); 
     1262 
     1263 
     1264        /////////////////// 
     1265        //-- compute avg loglum in scene using mipmapping 
     1266 
     1267        glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
     1268        glGenerateMipmapEXT(GL_TEXTURE_2D); 
    12281269} 
    12291270 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2976 r2991  
    4444                                float tempCohFactor,  
    4545                                DirectionalLight *light, 
    46                                 ShadowMap *shadowMap = NULL); 
     46                                bool useToneMapping, 
     47                                ShadowMap *shadowMap = NULL 
     48                                ); 
    4749 
    4850        /** Initialises the deferred shader and loads the required shaders: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp

    r2979 r2991  
    193193         
    194194        GLint width, height; 
    195  
    196195        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 
    197196        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 
    198197 
    199         cout << "w: " << width << "h: " << height << endl; 
     198        //cout << "w: " << width << "h: " << height << endl; 
    200199 
    201200        unsigned char *data = new unsigned char[bytes * 4 * width * height]; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2990 r2991  
    215215bool altKeyPressed = false; 
    216216 
     217#define USE_TONE_MAPPING 1 
     218 
     219 
    217220// function forward declarations 
    218221void InitExtensions(); 
     
    842845         
    843846 
    844         //const bool useToneMapping = (renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED); 
    845         const bool useToneMapping = false; 
     847        const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && USE_TONE_MAPPING; 
    846848 
    847849        Vector3 sunAmbient; 
     
    854856        ambient[2] = sunAmbient.z; 
    855857 
    856  
    857858        // no tone mapping => scale 
    858859        if (!useToneMapping) 
    859860        { 
    860861                const float maxComponent = sunDiffuse.MaxComponent(); 
    861                 //cout<< "sunambient: " << sunAmbient << " mag " << Magnitude(sunDiffuse) << " max: " << maxComponent << endl; 
    862862                sunDiffuse /= maxComponent; 
    863863        } 
     
    11601160        RenderSky(); 
    11611161 
    1162         //state.Reset(); glEnable(GL_TEXTURE_2D); 
    1163         //aeroplane->Render(&state); 
    1164  
    11651162 
    11661163        if ((renderMethod == RENDER_DEFERRED) || 
     
    11931190 
    11941191                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1195                 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, sm); 
     1192                ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, USE_TONE_MAPPING, sm); 
    11961193        } 
    11971194 
     
    20302027                state.SetRenderPassType(RenderState::DEFERRED); 
    20312028 
    2032         //const bool useToneMapping = (renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED); 
    2033         const bool useToneMapping = false; 
     2029        const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && USE_TONE_MAPPING; 
    20342030 
    20352031        preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2985 r2991  
    4949#define MAX_LOD_LEVEL 99 
    5050 
     51 
     52 
    5153#endif // __SHADERENV_H 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2990 r2991  
    6464                   uniform sampler2D positions, 
    6565                   uniform sampler2D normals, 
    66                    uniform float3 lightDir, 
    67                   uniform sampler2D oldColors 
     66                   uniform float3 lightDir 
     67                  //, uniform sampler2D oldColors 
    6868                   ) 
    6969{ 
     
    8383        OUT.color = col; 
    8484         
    85 #if 1 
     85#if 0 
    8686 
    8787        OUT.color.w = color.w; 
     
    9292        //-- write out logaritmic luminance for tone mapping 
    9393 
    94         float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)); 
     94        // the old loglum is stored in the hightest mipmap-level 
     95        float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w; 
    9596 
    9697        const float3 w = float3(0.299f, 0.587f, 0.114f); 
     
    102103        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    103104 
    104         if (oldColor.w > 0) 
    105                 OUT.color.w = lerp(oldColor.w, logLumScaled, 0.1f); 
     105        if (oldLogLum > 0) 
     106                OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    106107        else 
    107108                OUT.color.w = logLumScaled; 
     
    164165                                  uniform sampler2D noiseTexture, 
    165166                                  uniform float2 samples[NUM_PCF_TABS], 
    166                                   uniform float3 lightDir, 
    167                                   uniform sampler2D oldColors 
     167                                  uniform float3 lightDir 
     168                                  //, uniform sampler2D oldColors 
    168169                                  ) 
    169170{ 
     
    190191        //if ((emmisive < 1.5f) // hack: prevent shadowing the sky       
    191192        if ( 
    192                 (position.w > 1e19f) 
     193                (position.w < 1e19f) 
    193194                && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 
    194195                ) 
     
    216217        //-- write out logaritmic luminance for tone mapping 
    217218 
    218         float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)); 
     219#if 0 
     220 
     221        OUT.color.w = color.w; 
     222 
     223#else 
     224 
     225        float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w; 
    219226 
    220227        const float3 w = float3(0.299f, 0.587f, 0.114f); 
     
    226233        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    227234 
    228         if (oldColor.w > 0) 
    229                 OUT.color.w = lerp(oldColor.w, logLumScaled, 0.1f); 
     235        if (oldLogLum > 0) 
     236                OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    230237        else 
    231238                OUT.color.w = logLumScaled; 
    232          
     239#endif   
    233240        return OUT; 
    234241} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2990 r2991  
    4444 
    4545 
    46 float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
    47 { 
    48         //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 
    49         float3 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 
    50         float3 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 
    51  
    52         float3 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 
     46 
     47inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     48{ 
     49        float3 x1 = lerp(bl, tl, w.y); 
     50        float3 x2 = lerp(br, tr, w.y);  
     51        float3 v = lerp(x1, x2, w.x);  
    5352 
    5453        return v; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2990 r2991  
    3434inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
    3535{ 
    36         //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 
    37         float3 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 
    38         float3 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 
    39  
    40         float3 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 
     36        float3 x1 = lerp(bl, tl, w.y); 
     37        float3 x2 = lerp(br, tr, w.y);  
     38        float3 v = lerp(x1, x2, w.x);  
    4139 
    4240        return v; 
     
    4442 
    4543 
    46 inline float3 ReconstructSamplePosition(uniform sampler2D colors, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr) 
     44inline float3 ReconstructSamplePosition(float3 eyePos,  
     45                                                                                uniform sampler2D colors, 
     46                                                                                float2 texcoord,  
     47                                                                                float3 bl, float3 br, float3 tl, float3 tr) 
    4748{ 
    4849        /*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
     
    5051        // reconstruct world space position 
    5152        float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
    52         float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
    53         */ 
     53        float3 sample_position = eyePos - rotView * eyeSpaceDepth;*/ 
    5454        float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
    5555 
     
    102102                        ++ numSamples; 
    103103 
    104                 float3 sample_position = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr); 
     104                float3 sample_position = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 
    105105 
    106106                float3 vector_to_sample = sample_position - centerPosition.xyz; 
     
    174174 
    175175        //const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos); 
    176         const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, /*viewDir, */eyePos, bl, br, tl, tr); 
     176        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    177177                 
    178178 
     
    208208                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
    209209                (abs(depthDif) < 1e-4f)  
    210                 // check if visibility changed in the surrounding area: 
    211                 // then we have to recompute 
    212                 && ((newWeight < 10) || (oldNumSamples > 0.9f * newNumSamples)) 
     210                // if visibility changed in the surrounding area we have to recompute 
     211                && (oldNumSamples > 0.8f * newNumSamples) 
    213212                //&& (oldAvgDepth / newAvgDepth > 0.99) 
    214213                ) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r2975 r2991  
    105105        return OUT; 
    106106} 
     107 
     108 
     109pixel CalcAvgLogLum(frag IN, uniform sampler2D colors) 
     110{ 
     111        //////////// 
     112        //-- write out logaritmic luminance for tone mapping 
     113 
     114        pixel OUT; 
     115 
     116        // the old loglum is stored in the hightest mipmap-level 
     117        float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
     118        float oldLogLum = tex2Dlod(colors, float4(IN.texCoord.xy, 0, MAX_LOD_LEVEL)).w; 
     119 
     120        // the intensity weights 
     121        const float3 w = float3(0.299f, 0.587f, 0.114f); 
     122 
     123        float lum = dot(color.rgb, w); 
     124        float logLum = log(1e-5f + lum); 
     125 
     126        float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 
     127        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
     128 
     129        OUT.color = color; 
     130 
     131        if (oldLogLum > 0) 
     132                OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 
     133        else 
     134                OUT.color.w = logLumScaled; 
     135} 
Note: See TracChangeset for help on using the changeset viewer.