- Timestamp:
- 09/24/08 18:06:30 (16 years ago)
- 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 799 799 > 800 800 </File> 801 <File 802 RelativePath=".\src\shaders\tonemap.cg" 803 > 804 </File> 801 805 </Filter> 802 806 <Filter -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2971 r2972 36 36 37 37 38 static CGprogram sCgInitialIntensityProgram; 39 static CGprogram sCgDownSampleProgram; 40 static CGprogram sCgToneProgram; 41 42 38 43 /////////////////////////////////////// 39 44 … … 100 105 static CGparameter sMiddleGreyParam; 101 106 static CGparameter sWhiteLumParam; 107 108 109 static CGparameter sColorsTexInitialParam; 110 static CGparameter sColorsTexToneParam; 111 static CGparameter sIntensityTexDownSampleParam; 112 102 113 103 114 //#define USE_3D_SSAO … … 1097 1108 1098 1109 1110 void 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 1160 void 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 1172 void 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 1099 1234 1100 1235 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2970 r2972 75 75 void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap); 76 76 77 void ComputeToneParameters(FrameBufferObject *fbo); 78 void ToneMap(FrameBufferObject *fbo, DirectionalLight *light); 79 80 77 81 void CombineSsao(FrameBufferObject *fbo); 78 82 void CombineIllum(FrameBufferObject *fbo); … … 83 87 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 84 88 89 void DownSample(FrameBufferObject *fbo); 90 91 85 92 86 93 ////////////
Note: See TracChangeset
for help on using the changeset viewer.