Changeset 2972


Ignore:
Timestamp:
09/24/08 18:06:30 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
1 added
2 deleted
3 edited

Legend:

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

    r2965 r2972  
    799799                                > 
    800800                        </File> 
     801                        <File 
     802                                RelativePath=".\src\shaders\tonemap.cg" 
     803                                > 
     804                        </File> 
    801805                </Filter> 
    802806                <Filter 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2971 r2972  
    3636 
    3737 
     38static CGprogram sCgInitialIntensityProgram; 
     39static CGprogram sCgDownSampleProgram; 
     40static CGprogram sCgToneProgram; 
     41 
     42 
    3843/////////////////////////////////////// 
    3944 
     
    100105static CGparameter sMiddleGreyParam; 
    101106static CGparameter sWhiteLumParam; 
     107 
     108 
     109static CGparameter sColorsTexInitialParam; 
     110static CGparameter sColorsTexToneParam; 
     111static CGparameter sIntensityTexDownSampleParam; 
     112 
    102113 
    103114//#define USE_3D_SSAO 
     
    10971108 
    10981109 
     1110void DeferredRenderer::ComputeToneParameters(FrameBufferObject *fbo) 
     1111{ 
     1112        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
     1113 
     1114        GLuint colorsTex = colorBuffer->GetTexture(); 
     1115         
     1116        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1117 
     1118        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1119        cgGLBindProgram(sCgInitialIntensityProgram); 
     1120         
     1121        cgGLSetTextureParameter(sColorsTexInitialParam, colorsTex); 
     1122        cgGLEnableTextureParameter(sColorsTexInitialParam); 
     1123 
     1124        // first pass: create high res intensity texture 
     1125        glColor3f(1.0f, 1.0f, 1.0f); 
     1126 
     1127        float offs2 = 0.5f; 
     1128 
     1129        glBegin(GL_QUADS); 
     1130 
     1131        // the neighbouring texels 
     1132        float x_offs = 1.0f / mWidth; 
     1133        float y_offs = 1.0f / mHeight; 
     1134 
     1135        SetVertex(0, 0, x_offs, y_offs); 
     1136        SetVertex(1, 0, x_offs, y_offs); 
     1137        SetVertex(1, 1, x_offs, y_offs); 
     1138        SetVertex(0, 1, x_offs, y_offs); 
     1139 
     1140        glEnd(); 
     1141 
     1142        cgGLDisableTextureParameter(sColorsTexToneParam); 
     1143 
     1144         
     1145        //////////// 
     1146        //-- second phase: down sample the texture in order to compute the average 
     1147         
     1148        // q: required passes for computing 1x1 texture? 
     1149        int passes = 32; 
     1150 
     1151        for (int i = 0; i < 32; ++ i) 
     1152        { 
     1153                DownSample(fbo); 
     1154        } 
     1155 
     1156        PrintGLerror("antialiasing"); 
     1157} 
     1158 
     1159 
     1160void DeferredRenderer::DownSample(FrameBufferObject *fbo) 
     1161{ 
     1162        GLuint intensityTex; 
     1163         
     1164        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1165        cgGLBindProgram(sCgDownSampleProgram); 
     1166         
     1167        cgGLSetTextureParameter(sIntensityTexDownSampleParam, intensityTex); 
     1168        cgGLEnableTextureParameter(sIntensityTexDownSampleParam); 
     1169} 
     1170 
     1171 
     1172void DeferredRenderer::ToneMap(FrameBufferObject *fbo, DirectionalLight *light) 
     1173{ 
     1174        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
     1175 
     1176        // we assume that we have a floating point rgba texture 
     1177        float *pixels = (float *)colorBuffer->ReadTexture(); 
     1178 
     1179        const int w = colorBuffer->GetHeight(); 
     1180        const int h = colorBuffer->GetWidth(); 
     1181 
     1182        const float imageKey = ToneMapper().CalcImageKey(pixels, w, h); 
     1183        const float whiteLum = 1.0f * ToneMapper().CalcMaxLuminance(pixels, w, h); 
     1184 
     1185        //const float minKey = 0.18f; 
     1186        //const float maxKey = 0.72f; 
     1187 
     1188        //const float minKey = 0.0045f; 
     1189        const float minKey = 0.09f; 
     1190        const float maxKey = 0.5f; 
     1191 
     1192        const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 
     1193        const float middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey; 
     1194 
     1195        //cout << "middlegrey: " << middleGrey << endl; 
     1196        delete [] pixels; 
     1197 
     1198        GLuint colorsTex = colorBuffer->GetTexture(); 
     1199         
     1200        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1201 
     1202        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1203        cgGLBindProgram(sCgToneProgram); 
     1204         
     1205        cgGLSetTextureParameter(sColorsTexToneParam, colorsTex); 
     1206        cgGLEnableTextureParameter(sColorsTexToneParam); 
     1207 
     1208        cgGLSetParameter1f(sImageKeyParam, imageKey); 
     1209        cgGLSetParameter1f(sWhiteLumParam, whiteLum); 
     1210        cgGLSetParameter1f(sMiddleGreyParam, middleGrey); 
     1211 
     1212        glColor3f(1.0f, 1.0f, 1.0f); 
     1213 
     1214        float offs2 = 0.5f; 
     1215 
     1216        glBegin(GL_QUADS); 
     1217 
     1218        // the neighbouring texels 
     1219        float x_offs = 1.0f / mWidth; 
     1220        float y_offs = 1.0f / mHeight; 
     1221 
     1222        SetVertex(0, 0, x_offs, y_offs); 
     1223        SetVertex(1, 0, x_offs, y_offs); 
     1224        SetVertex(1, 1, x_offs, y_offs); 
     1225        SetVertex(0, 1, x_offs, y_offs); 
     1226 
     1227        glEnd(); 
     1228 
     1229        cgGLDisableTextureParameter(sColorsTexToneParam); 
     1230 
     1231        PrintGLerror("antialiasing"); 
     1232} 
     1233 
    10991234 
    11001235 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2970 r2972  
    7575        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap); 
    7676 
     77        void ComputeToneParameters(FrameBufferObject *fbo); 
     78        void ToneMap(FrameBufferObject *fbo, DirectionalLight *light); 
     79 
     80 
    7781        void CombineSsao(FrameBufferObject *fbo); 
    7882        void CombineIllum(FrameBufferObject *fbo); 
     
    8387        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 
    8488         
     89        void DownSample(FrameBufferObject *fbo); 
     90 
     91 
    8592 
    8693        //////////// 
Note: See TracChangeset for help on using the changeset viewer.