- Timestamp:
- 10/02/08 16:34:58 (16 years ago)
- 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 28 28 29 29 static CGparameter sColorsTexDeferredParam; 30 static CGparameter sOldColorsTexDeferredParam;31 static CGparameter sOldColorsTexShadowParam;32 33 30 static CGparameter sPositionsTexDeferredParam; 34 31 static CGparameter sNormalsTexDeferredParam; … … 326 323 sPositionsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "positions"); 327 324 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 328 sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors");325 //sOldColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "oldColors"); 329 326 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 330 327 … … 495 492 sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 496 493 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 497 sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors");494 //sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors"); 498 495 499 496 … … 556 553 float tempCohFactor, 557 554 DirectionalLight *light, 558 ShadowMap *shadowMap) 555 bool useToneMapping, 556 ShadowMap *shadowMap 557 ) 559 558 { 560 559 // switch roles of old and new fbo … … 591 590 else 592 591 FirstPass(fbo, light); 593 594 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture());595 glGenerateMipmapEXT(GL_TEXTURE_2D);596 592 597 593 switch (mShadingMethod) … … 610 606 } 611 607 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 622 616 AntiAliasing(fbo, light); 623 617 … … 836 830 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 837 831 838 GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture();832 //GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 839 833 840 834 fbo->Bind(); … … 852 846 cgGLEnableTextureParameter(sColorsTexDeferredParam); 853 847 854 cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex);855 cgGLEnableTextureParameter(sOldColorsTexDeferredParam);848 //cgGLSetTextureParameter(sOldColorsTexDeferredParam, oldColorsTex); 849 //cgGLEnableTextureParameter(sOldColorsTexDeferredParam); 856 850 857 851 cgGLSetTextureParameter(sPositionsTexDeferredParam, positionsTex); … … 879 873 880 874 cgGLDisableTextureParameter(sColorsTexDeferredParam); 881 cgGLDisableTextureParameter(sOldColorsTexDeferredParam);875 //cgGLDisableTextureParameter(sOldColorsTexDeferredParam); 882 876 cgGLDisableTextureParameter(sPositionsTexDeferredParam); 883 877 cgGLDisableTextureParameter(sNormalsTexDeferredParam); … … 903 897 904 898 // 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); 907 900 908 901 // read the second buffer, write to the first buffer … … 1118 1111 GLuint shadowTex = shadowMap->GetDepthTexture(); 1119 1112 1120 GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture();1113 //GLuint oldColorsTex = fbo->GetColorBuffer(3 - colorBufferIdx)->GetTexture(); 1121 1114 1122 1115 Matrix4x4 shadowMatrix; … … 1143 1136 cgGLEnableTextureParameter(sShadowMapParam); 1144 1137 1145 cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex);1146 cgGLEnableTextureParameter(sOldColorsTexShadowParam);1138 //cgGLSetTextureParameter(sOldColorsTexShadowParam, oldColorsTex); 1139 //cgGLEnableTextureParameter(sOldColorsTexShadowParam); 1147 1140 1148 1141 cgGLSetParameter1f(sMaxDepthShadowParam, mScaleFactor); … … 1178 1171 cgGLDisableTextureParameter(sNormalsTexShadowParam); 1179 1172 cgGLDisableTextureParameter(sShadowMapParam); 1180 1181 cgGLDisableTextureParameter(sOldColorsTexShadowParam);1182 1183 1173 cgGLDisableTextureParameter(sNoiseTexShadowParam); 1174 //cgGLDisableTextureParameter(sOldColorsTexShadowParam); 1184 1175 1185 1176 FrameBufferObject::Release(); … … 1226 1217 const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 1227 1218 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); 1228 1269 } 1229 1270 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2976 r2991 44 44 float tempCohFactor, 45 45 DirectionalLight *light, 46 ShadowMap *shadowMap = NULL); 46 bool useToneMapping, 47 ShadowMap *shadowMap = NULL 48 ); 47 49 48 50 /** Initialises the deferred shader and loads the required shaders: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2979 r2991 193 193 194 194 GLint width, height; 195 196 195 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 197 196 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 198 197 199 cout << "w: " << width << "h: " << height << endl;198 //cout << "w: " << width << "h: " << height << endl; 200 199 201 200 unsigned char *data = new unsigned char[bytes * 4 * width * height]; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2990 r2991 215 215 bool altKeyPressed = false; 216 216 217 #define USE_TONE_MAPPING 1 218 219 217 220 // function forward declarations 218 221 void InitExtensions(); … … 842 845 843 846 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; 846 848 847 849 Vector3 sunAmbient; … … 854 856 ambient[2] = sunAmbient.z; 855 857 856 857 858 // no tone mapping => scale 858 859 if (!useToneMapping) 859 860 { 860 861 const float maxComponent = sunDiffuse.MaxComponent(); 861 //cout<< "sunambient: " << sunAmbient << " mag " << Magnitude(sunDiffuse) << " max: " << maxComponent << endl;862 862 sunDiffuse /= maxComponent; 863 863 } … … 1160 1160 RenderSky(); 1161 1161 1162 //state.Reset(); glEnable(GL_TEXTURE_2D);1163 //aeroplane->Render(&state);1164 1165 1162 1166 1163 if ((renderMethod == RENDER_DEFERRED) || … … 1193 1190 1194 1191 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); 1196 1193 } 1197 1194 … … 2030 2027 state.SetRenderPassType(RenderState::DEFERRED); 2031 2028 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; 2034 2030 2035 2031 preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2985 r2991 49 49 #define MAX_LOD_LEVEL 99 50 50 51 52 51 53 #endif // __SHADERENV_H -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2990 r2991 64 64 uniform sampler2D positions, 65 65 uniform sampler2D normals, 66 uniform float3 lightDir ,67 uniform sampler2D oldColors66 uniform float3 lightDir 67 //, uniform sampler2D oldColors 68 68 ) 69 69 { … … 83 83 OUT.color = col; 84 84 85 #if 185 #if 0 86 86 87 87 OUT.color.w = color.w; … … 92 92 //-- write out logaritmic luminance for tone mapping 93 93 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; 95 96 96 97 const float3 w = float3(0.299f, 0.587f, 0.114f); … … 102 103 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 103 104 104 if (old Color.w> 0)105 OUT.color.w = lerp(old Color.w, logLumScaled, 0.1f);105 if (oldLogLum > 0) 106 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 106 107 else 107 108 OUT.color.w = logLumScaled; … … 164 165 uniform sampler2D noiseTexture, 165 166 uniform float2 samples[NUM_PCF_TABS], 166 uniform float3 lightDir ,167 uniform sampler2D oldColors167 uniform float3 lightDir 168 //, uniform sampler2D oldColors 168 169 ) 169 170 { … … 190 191 //if ((emmisive < 1.5f) // hack: prevent shadowing the sky 191 192 if ( 192 (position.w >1e19f)193 (position.w < 1e19f) 193 194 && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 194 195 ) … … 216 217 //-- write out logaritmic luminance for tone mapping 217 218 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; 219 226 220 227 const float3 w = float3(0.299f, 0.587f, 0.114f); … … 226 233 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 227 234 228 if (old Color.w> 0)229 OUT.color.w = lerp(old Color.w, logLumScaled, 0.1f);235 if (oldLogLum > 0) 236 OUT.color.w = lerp(oldLogLum, logLumScaled, 0.1f); 230 237 else 231 238 OUT.color.w = logLumScaled; 232 239 #endif 233 240 return OUT; 234 241 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2990 r2991 44 44 45 45 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 47 inline 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); 53 52 54 53 return v; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2990 r2991 34 34 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 35 35 { 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); 41 39 42 40 return v; … … 44 42 45 43 46 inline float3 ReconstructSamplePosition(uniform sampler2D colors, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr) 44 inline float3 ReconstructSamplePosition(float3 eyePos, 45 uniform sampler2D colors, 46 float2 texcoord, 47 float3 bl, float3 br, float3 tl, float3 tr) 47 48 { 48 49 /*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; … … 50 51 // reconstruct world space position 51 52 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 52 float3 sample_position = eyePos - rotView * eyeSpaceDepth; 53 */ 53 float3 sample_position = eyePos - rotView * eyeSpaceDepth;*/ 54 54 float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 55 55 … … 102 102 ++ numSamples; 103 103 104 float3 sample_position = ReconstructSamplePosition( colors, texcoord, bl, br, tl, tr);104 float3 sample_position = ReconstructSamplePosition(eyePos, colors, texcoord, bl, br, tl, tr); 105 105 106 106 float3 vector_to_sample = sample_position - centerPosition.xyz; … … 174 174 175 175 //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); 177 177 178 178 … … 208 208 (tex.y >= 0.0f) && (tex.y < 1.0f) && 209 209 (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) 213 212 //&& (oldAvgDepth / newAvgDepth > 0.99) 214 213 ) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r2975 r2991 105 105 return OUT; 106 106 } 107 108 109 pixel 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.