Changeset 2975 for GTP/trunk/App/Demos
- Timestamp:
- 09/26/08 10:31:58 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2972 r2975 283 283 > 284 284 </File> 285 <File286 RelativePath=".\src\ToneMapper.cpp"287 >288 </File>289 <File290 RelativePath=".\src\ToneMapper.h"291 >292 </File>293 285 <Filter 294 286 Name="timer" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2974 r2975 9 9 #include "ShadowMapping.h" 10 10 #include "Light.h" 11 #include "ToneMapper.h"12 11 13 12 … … 553 552 FirstPass(fbo, light); 554 553 555 glEnable(GL_TEXTURE_2D);556 // generate mip map levels for position texture557 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture());558 glGenerateMipmapEXT(GL_TEXTURE_2D);559 560 554 561 555 switch (mShadingMethod) … … 576 570 float imageKey, whiteLum, middleGrey; 577 571 572 // generate mip map levels of position texture 573 glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 574 glGenerateMipmapEXT(GL_TEXTURE_2D); 575 578 576 ComputeToneParameters(fbo, light, imageKey, whiteLum, middleGrey); 579 577 ToneMap(fbo, light, imageKey, whiteLum, middleGrey); … … 603 601 { 604 602 #ifdef USE_3D_SSAO 603 // bias from [-1, 1] to [0, 1] 605 604 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 606 605 0.0f, 0.5f, 0.0f, 0.5f, 607 606 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); 609 608 610 609 Matrix4x4 m = projViewMatrix * biasMatrix; … … 615 614 cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 616 615 617 GLuint colorsTex = fbo->GetColorBuffer( 3)->GetTexture();616 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 618 617 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 619 618 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 620 619 621 // generate mip map levels forposition texture620 // generate mip map levels of position texture 622 621 glBindTexture(GL_TEXTURE_2D, positionsTex); 623 622 glGenerateMipmapEXT(GL_TEXTURE_2D); … … 628 627 glDrawBuffers(1, mrt + mFboIndex); 629 628 630 631 //GLuint oldTex = mOldFbo->GetColorBuffer(0)->GetTexture();632 629 GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture(); 633 630 … … 677 674 glBegin(GL_QUADS); 678 675 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); 687 683 688 684 glEnd(); … … 1133 1129 float &middleGrey) 1134 1130 { 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 1150 1137 const float minKey = 0.09f; 1151 1138 const float maxKey = 0.5f; … … 1153 1140 const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z()); 1154 1141 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 texture1178 glColor3f(1.0f, 1.0f, 1.0f);1179 1180 float offs2 = 0.5f;1181 1182 glBegin(GL_QUADS);1183 1184 // the neighbouring texels1185 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 average1202 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");1212 1142 } 1213 1143 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2974 r2975 28 28 //#define ILLUM_INTENSITY 9e-1f; 29 29 30 #define SSAO_MIPMAP_LEVEL 131 #define GI_MIPMAP_LEVEL 230 #define SSAO_MIPMAP_LEVEL 0//1 31 #define GI_MIPMAP_LEVEL 0//2 32 32 33 33 … … 41 41 //-- Tone mapping 42 42 43 #define MINLOGLUM 10.0f43 #define MINLOGLUM (-10.0f) 44 44 #define MAXLOGLUM 10.0f 45 45 46 #define INV_LOGLUM_RANGE 0.05f 47 #define LOGLUM_RANGE 20.0f 48 46 49 #endif // __SHADERENV_H -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2974 r2975 81 81 82 82 OUT.color = col; 83 OUT.color.w = color.w; 84 85 // write out logaritmic luminance for tone mapping 83 84 85 //////////// 86 //-- write out logaritmic luminance for tone mapping 87 86 88 const float3 w = float3(0.299f, 0.587f, 0.114f); 87 89 … … 89 91 float logLum = log(1e-5f + lum); 90 92 91 float invLogLumRange = 1 / (MAXLOGLUM + MINLOGLUM); 92 float logLumOffset = MINLOGLUM * invLogLumRange; 93 float logLumScaled = logLum * invLogLumRange + logLumOffset; 93 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 94 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 94 95 95 96 OUT.color.w = logLumScaled; … … 194 195 OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 195 196 196 // write out logaritmic luminance for tone mapping 197 //////////// 198 //-- write out logaritmic luminance for tone mapping 199 197 200 const float3 w = float3(0.299f, 0.587f, 0.114f); 198 201 … … 200 203 float logLum = log(1e-5f + lum); 201 204 202 OUT.color.w = 100;//logLum; 205 float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE; 206 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 207 208 OUT.color.w = logLumScaled; 203 209 204 210 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r2974 r2975 52 52 uniform float2 samples[NUM_SAMPLES], 53 53 uniform float3 currentNormal, 54 uniform float3 currentViewDir, 55 uniform float4 centerPosition 54 uniform float4 centerPosition, 55 float w 56 //, uniform float3 currentViewDir 56 57 ) 57 58 { 58 59 GiStruct gi; 59 60 // the w coordinate from the persp. projection61 float w = centerPosition.w;62 60 63 61 // Check in a circular area around the current position. … … 117 115 } 118 116 119 gi.illum = saturate(total_color);117 gi.illum = total_color; 120 118 gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 121 119 … … 143 141 144 142 float4 norm = tex2D(normals, IN.texCoord.xy); 145 146 // theambient term143 float3 normal = normalize(norm.xyz); 144 // something like a constant ambient term 147 145 const float amb = norm.w; 148 149 // expand normal150 float3 normal = normalize(norm.xyz);151 152 146 /// the current view direction 153 float3 viewDir;// = normalize(IN.view); 154 147 //float3 viewDir = normalize(IN.view); 148 149 // the w coordinate from the persp. projection 150 float w = norm.w; 155 151 // the current world position 156 152 const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 157 158 153 // the current color 159 154 const float4 currentCol = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 160 155 // the current depth is stored in the w component 161 const float currentDepth = c urrentCol.w;162 163 GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, centerPosition);156 const float currentDepth = centerPosition.w; 157 158 GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w); //, viewDir); 164 159 165 160 … … 186 181 187 182 const float oldNumSamples = oldSsao.y; 183 const float oldAvgDepth = oldSsao.z; 188 184 189 185 if ((temporalCoherence > 0.0f) && 190 186 (tex.x >= 0.0f) && (tex.x < 1.0f) && 191 187 (tex.y >= 0.0f) && (tex.y < 1.0f) && 192 (abs(depthDif) < 1e-3f) 193 && (oldNumSamples > gi.ao.y - 1.5f) // check if something happened in the surrounding area 188 (abs(depthDif) < 1e-3f) 189 // check if something changed in the surrounding area 190 && (oldNumSamples > 0.2 * gi.ao.y) 191 && (oldAvgDepth / newAvgDepth > 0.99) 194 192 ) 195 193 { … … 218 216 uniform sampler2D ssaoTex, 219 217 uniform sampler2D illumTex 220 218 ) 221 219 { 222 220 pixel OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2974 r2975 117 117 118 118 float4 norm = tex2D(normals, IN.texCoord.xy); 119 120 // expand normal121 119 float3 normal = normalize(norm.xyz); 122 120 123 121 // a constant ambient term 124 122 const float amb = norm.w; 125 123 // the w coordinate from the persp. projection 126 124 float w = norm.w; 127 128 125 // the current world position 129 126 const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 130 131 127 // the current color 132 128 const float currentDepth = centerPosition.w; … … 141 137 realPos.w = 1.0f; 142 138 143 // reproject 139 140 /////////// 141 //-- reprojection from new frame into old one 142 144 143 float4 oldPos = mul(oldModelViewProj, realPos); 145 144 … … 161 160 (tex.y >= 0.0f) && (tex.y < 1.0f) && 162 161 (abs(depthDif) < 1e-3f) 163 && (oldNumSamples > ao.y - 1.5f) // check if something happened in the surrounding area 162 // check if visibility changed in the surrounding area: 163 // then we have to recompute 164 && (oldNumSamples > ao.y - 1.5f) 164 165 ) 165 166 { 166 167 // increase the weight for convergence 167 168 newWeight = oldWeight + 1.0f; 168 169 //OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor);170 169 OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight; 171 170 … … 193 192 194 193 float4 col = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 195 float depth = tex2Dlod(positions, float4(IN.texCoord.xy, 0, 0)).w;196 194 float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 197 195 198 196 OUT.illum_col = col * ao.x; 199 OUT.illum_col.w = ao.w; 197 //OUT.illum_col.w = ao.w; 198 OUT.illum_col.w = col.w; 200 199 201 200 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r2974 r2975 90 90 // obtain new image key from highest mipmap level 91 91 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w; 92 93 float logLumRange = MAXLOGLUM + MINLOGLUM; 94 //float logLumOffset = MINLOGLUM * logLumRange; 95 float logLum = logLumScaled * logLumRange - MINLOGLUM; 92 float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 96 93 97 94 float newImageKey = exp(logLum);
Note: See TracChangeset
for help on using the changeset viewer.