Changeset 2976
- Timestamp:
- 09/26/08 18:31:24 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2975 r2976 28 28 29 29 static CGparameter sColorsTexDeferredParam; 30 static CGparameter sOldColorsTexDeferredParam; 31 30 32 static CGparameter sPositionsTexDeferredParam; 31 33 static CGparameter sNormalsTexDeferredParam; … … 111 113 static CGparameter sIntensityTexDownSampleParam; 112 114 113 114 115 static unsigned int pbo[] = {0, 0}; 116 117 static unsigned int sCurrentPBOIdx = 0; 115 118 //#define USE_3D_SSAO 116 119 … … 128 131 Sample2 pcfSamples[NUM_PCF_TABS]; 129 132 130 static intcolorBufferIdx = 0;133 int DeferredRenderer::colorBufferIdx = 0; 131 134 132 135 static void PrintGLerror(char *msg) … … 141 144 } 142 145 } 146 147 static int computeSize(int level) 148 { 149 // Compute total image size. 150 float w = 1024; 151 float h = 768; 152 153 int mipmapSize = max(1, w / (1 << level) ) * 154 max(1, h / (1 << level) ) * sizeof(float) * 4; 155 156 return mipmapSize; 157 } 158 143 159 144 160 … … 257 273 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 258 274 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 275 276 glGenBuffersARB(2, pbo); 277 278 int dataSize = 1024 * 1768 * 4 * sizeof(float); 279 280 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo[0]); 281 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, dataSize, 0, GL_STREAM_READ_ARB); 282 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo[1]); 283 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, dataSize, 0, GL_STREAM_READ_ARB); 284 285 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); 259 286 } 260 287 … … 297 324 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions"); 298 325 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 326 sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors"); 299 327 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 300 328 … … 521 549 522 550 mFboIndex = 2 - mFboIndex; 523 //swap(mNewFbo, mOldFbo); 524 551 525 552 FrameBufferObject::Release(); 526 553 … … 537 564 glPushMatrix(); 538 565 glLoadIdentity(); 539 540 colorBufferIdx = 0;541 566 542 567 const float offs = 0.5f; … … 551 576 else 552 577 FirstPass(fbo, light); 553 554 578 555 579 switch (mShadingMethod) … … 570 594 float imageKey, whiteLum, middleGrey; 571 595 572 // generate mip map levels of position texture 596 glPixelStorei(GL_PACK_ALIGNMENT, 1); 597 // generate mip map levels for average loglum and tone mapping 573 598 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 574 599 glGenerateMipmapEXT(GL_TEXTURE_2D); 575 600 576 601 ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 577 602 ToneMap(fbo, light, imageKey, whiteLum, middleGrey); … … 770 795 { 771 796 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 797 GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 772 798 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 773 799 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); … … 786 812 cgGLSetTextureParameter(sColorsTexDeferredParam, colorsTex); 787 813 cgGLEnableTextureParameter(sColorsTexDeferredParam); 814 815 cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex); 816 cgGLEnableTextureParameter(sOldColorsTexDeferredParam); 788 817 789 818 cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex); … … 811 840 812 841 cgGLDisableTextureParameter(sColorsTexDeferredParam); 842 cgGLDisableTextureParameter(sOldColorsTexDeferredParam); 813 843 cgGLDisableTextureParameter(sPositionsTexDeferredParam); 814 844 cgGLDisableTextureParameter(sNormalsTexDeferredParam); … … 1129 1159 float &middleGrey) 1130 1160 { 1161 // read pixels from framebuffer to PBO 1162 /* glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo[sCurrentPBOIdx]); 1163 1164 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 1165 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, NULL); 1166 1167 ///////////// 1168 //-- map the PBO to process its data by CPU 1169 1170 sCurrentPBOIdx = 1 - sCurrentPBOIdx; 1171 1172 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo[sCurrentPBOIdx]); 1173 GLfloat *ptr = (GLfloat *)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); 1174 1175 if (ptr) 1176 { 1177 float lumScaled = ptr[4 * 2 - 1]; 1178 float logLum = lumScaled * LOGLUM_RANGE + MINLOGLUM; 1179 imageKey = exp(logLum); 1180 1181 cout << "key: " << imageKey << " " << lumScaled << endl; 1182 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); 1183 } 1184 */ 1185 float *pixels = (float *)fbo->GetColorBuffer(colorBufferIdx)->ReadTexture(); 1186 1187 float lumScaled = pixels[3];//4 * 2 - 1]; 1188 1189 float logLum = lumScaled * LOGLUM_RANGE + MINLOGLUM; 1190 imageKey = exp(logLum); 1191 1192 delete [] pixels; 1193 cout << "key: " << imageKey << " " << lumScaled << endl; 1194 1195 // back to conventional pixel operation 1196 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); 1197 1198 1131 1199 // hack: estimate value where sky burns out 1132 1200 whiteLum = log(1e4f); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2973 r2976 61 61 62 62 void SetShadingMethod(SHADING_METHOD s); 63 static int colorBufferIdx; 63 64 64 65 protected: … … 112 113 113 114 bool mRegenerateSamples; 115 114 116 }; 115 117 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2965 r2976 162 162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapParam); 163 163 164 if (useMipMap) glGenerateMipmapEXT(GL_TEXTURE_2D); 164 if (useMipMap) 165 { 166 //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); 167 glGenerateMipmapEXT(GL_TEXTURE_2D); 168 } 165 169 166 170 // print status … … 186 190 } 187 191 188 unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight]; 189 192 glBindTexture(GL_TEXTURE_2D, 0); 193 glFlush(); 194 glFinish(); 190 195 glEnable(GL_TEXTURE_2D); 191 196 glBindTexture(GL_TEXTURE_2D, mTexId); 192 193 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, mGlFormat, data); 197 //glBindTexture(GL_TEXTURE_2D, mTexId); 198 GLint width, height; 199 200 glGetTexLevelParameteriv(GL_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &width); 201 glGetTexLevelParameteriv(GL_TEXTURE_2D, 1, GL_TEXTURE_HEIGHT, &height); 202 203 cout << "w: " << width << "h: " << height << endl; 204 205 /*glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 206 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 207 208 cout << "w: " << width << "h: " << height << endl; 209 */ 210 unsigned char *data = new unsigned char[bytes * 4 * width * height]; 211 212 213 glGetTexImage(GL_TEXTURE_2D, 1, GL_RGBA, GL_FLOAT, data); 214 //glGetTexImage(GL_TEXTURE_RECTANGLE_EXT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, (void *)data); 194 215 195 216 glBindTexture(GL_TEXTURE_2D, 0); 196 217 glDisable(GL_TEXTURE_2D); 197 218 219 float *d = (float *)data; 220 221 /*for (int i = 0; i < 10000; ++ i) 222 { 223 if (i % 100 == 0) 224 cout << "x: " << d[i]; 225 }*/ 226 //cout << endl << endl; 198 227 return data; 199 228 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2974 r2976 168 168 PerfTimer frameTimer, algTimer; 169 169 170 170 static int sCurrentMrtSet = 0; 171 171 172 172 /// the used render type for this render pass … … 617 617 618 618 // the diffuse color buffer 619 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_ NEAREST, ColorBufferObject::FILTER_NEAREST);619 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_LINEAR); 620 620 621 621 // the positions buffer … … 626 626 627 627 // another color buffer 628 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_ NEAREST, ColorBufferObject::FILTER_NEAREST);628 fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_LINEAR); 629 629 630 630 PrintGLerror("fbo"); … … 1053 1053 // draw to 3 color buffers 1054 1054 // a color, normal, and positions buffer 1055 glDrawBuffers(4, mrt); 1055 if (sCurrentMrtSet == 0) 1056 { 1057 DeferredRenderer::colorBufferIdx = 0; 1058 glDrawBuffers(3, mrt); 1059 } 1060 else 1061 { 1062 DeferredRenderer::colorBufferIdx = 3; 1063 glDrawBuffers(3, mrt2); 1064 } 1065 sCurrentMrtSet = 1 - sCurrentMrtSet; 1056 1066 1057 1067 glEnableClientState(GL_NORMAL_ARRAY); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glInterface.h
r2899 r2976 23 23 #endif 24 24 25 static GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 25 static GLenum mrt[] = 26 {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 27 28 static GLenum mrt2[] = 29 {GL_COLOR_ATTACHMENT3_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT0_EXT}; 26 30 27 31 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2974 r2976 87 87 float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0)); 88 88 89 float4 sc= tex2Dlod(colors, float4(IN.c.xy, 0, 0));89 float4 centerColor = tex2Dlod(colors, float4(IN.c.xy, 0, 0)); 90 90 91 float4 col = (s0 + s1 + s2 + s3 + sc) * 0.2f;91 float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 92 92 //return (s0 + s1 + s2 + s3) * 0.25f; 93 94 col.w = centerColor.w; 93 95 94 96 return col; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2975 r2976 64 64 uniform sampler2D positions, 65 65 uniform sampler2D normals, 66 uniform float3 lightDir 66 uniform float3 lightDir, 67 uniform sampler2D oldColors 67 68 ) 68 69 { … … 86 87 //-- write out logaritmic luminance for tone mapping 87 88 89 float4 oldColor = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 99)); 90 88 91 const float3 w = float3(0.299f, 0.587f, 0.114f); 89 92 … … 94 97 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 95 98 96 OUT.color.w = logLumScaled; 99 const static float factor = 0.2f; 100 101 OUT.color.w = lerp(oldColor.w, logLumScaled, factor); 97 102 98 103 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2975 r2976 189 189 // check if something changed in the surrounding area 190 190 && (oldNumSamples > 0.2 * gi.ao.y) 191 && (oldAvgDepth / newAvgDepth > 0.99)191 //&& (oldAvgDepth / newAvgDepth > 0.99) 192 192 ) 193 193 {
Note: See TracChangeset
for help on using the changeset viewer.