Ignore:
Timestamp:
09/26/08 10:31:58 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.