Changeset 3103 for GTP/trunk/App/Demos
- Timestamp:
- 11/06/08 10:41:02 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3102 r3103 244 244 </File> 245 245 <File 246 RelativePath=".\src\SceneQuery.cpp" 247 > 248 </File> 249 <File 250 RelativePath=".\src\SceneQuery.h" 251 > 252 </File> 253 <File 246 254 RelativePath=".\src\SkyPreetham.cpp" 247 255 > … … 495 503 </File> 496 504 <File 497 RelativePath=".\src\SceneQuery.h"498 >499 </File>500 <File501 505 RelativePath=".\src\ShaderManager.h" 502 506 > … … 679 683 </File> 680 684 <File 681 RelativePath=".\src\SceneQuery.cpp"682 >683 </File>684 <File685 685 RelativePath=".\src\ShaderManager.cpp" 686 686 > … … 753 753 <File 754 754 RelativePath=".\src\shaders\antialiasing.cg" 755 > 756 </File> 757 <File 758 RelativePath=".\src\shaders\combineSsao.cg" 755 759 > 756 760 </File> -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3095 r3103 64 64 // ssao random spherical samples 65 65 static Sample2 samples2[NUM_SAMPLES]; 66 // default sequence of samples67 //static Sample2 defaultSamples2[NUM_SAMPLES];68 66 // number of pcf tabs 69 Sample2 pcfSamples[NUM_PCF_TABS]; 67 static Sample2 pcfSamples[NUM_PCF_TABS]; 68 69 70 static float ssaoFilterOffsets[NUM_SSAO_FILTERSAMPLES * 2]; 71 static float ssaoFilterWeights[NUM_SSAO_FILTERSAMPLES]; 70 72 71 73 … … 78 80 { 79 81 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 80 81 82 cam->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 82 83 … … 257 258 //-- the flip-flop fbos 258 259 259 mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 260 const int dsw = w / 2; 261 const int dsh = h / 2; 262 263 mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 260 264 //mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 261 265 … … 268 272 } 269 273 270 mDownSampleFbo = new FrameBufferObject( w / 2, h / 2, FrameBufferObject::DEPTH_NONE);274 mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 271 275 //mDownSampleFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 272 276 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); … … 277 281 278 282 // create noise texture for ssao 279 CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 283 //CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 284 CreateNoiseTex2D(mWidth / 8, mHeight / 8); 280 285 281 286 mProjViewMatrix = IdentityMatrix(); … … 316 321 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag"); 317 322 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 318 sCgCombineSsaoProgram = sm->CreateFragmentProgram(" ssao", "combine", "combineSsao");323 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 319 324 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 320 325 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); … … 391 396 sCgCombineIllumProgram->AddParameter("illumTex", 2); 392 397 393 sCgCombineSsaoProgram->AddParameter("colors", 0); 394 sCgCombineSsaoProgram->AddParameter("ssaoTex", 1); 395 sCgCombineSsaoProgram->AddParameter("filterOffs", 2); 396 sCgCombineSsaoProgram->AddParameter("filterWeights", 3); 398 sCgCombineSsaoProgram->AddParameter("colorsTex", 0); 399 sCgCombineSsaoProgram->AddParameter("normalsTex", 1); 400 sCgCombineSsaoProgram->AddParameter("ssaoTex", 2); 401 sCgCombineSsaoProgram->AddParameter("filterOffs", 3); 402 sCgCombineSsaoProgram->AddParameter("filterWeights", 4); 403 404 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 405 poisson.Generate((float *)ssaoFilterOffsets); 406 407 //const float filterWidth = 10.0f; 408 const float filterWidth = 5.0f; 409 410 //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); 411 //const float yoffs = filterWidth / mDownSampleFbo->GetHeight(); 412 const float xoffs = (float)filterWidth / 1024.0f; 413 const float yoffs = (float)filterWidth / 768.0f; 414 415 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 416 { 417 float x = ssaoFilterOffsets[2 * i + 0]; 418 float y = ssaoFilterOffsets[2 * i + 1]; 419 420 ssaoFilterOffsets[2 * i + 0] *= xoffs; 421 ssaoFilterOffsets[2 * i + 1] *= yoffs; 422 423 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 424 } 397 425 398 426 399 427 float filterWeights[NUM_PCF_TABS]; 400 PoissonDiscSampleGenerator2 poisson (NUM_PCF_TABS, 1.0f);401 poisson .Generate((float *)pcfSamples);428 PoissonDiscSampleGenerator2 poisson2(NUM_PCF_TABS, 1.0f); 429 poisson2.Generate((float *)pcfSamples); 402 430 403 431 for (int i = 0; i < NUM_PCF_TABS; ++ i) … … 427 455 FirstPass(fbo, light); 428 456 457 458 if (mShadingMethod != 0) 459 { 460 // downsample fbo buffers for colors 461 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); 462 // normals 463 DownSample(fbo, 1, mDownSampleFbo, 1); 464 } 465 429 466 switch (mShadingMethod) 430 467 { 431 468 case SSAO: 432 // downsample fbo buffers for colors, normals433 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);434 DownSample(fbo, 1, mDownSampleFbo, 1);435 469 436 470 ComputeSsao(fbo, tempCohFactor); … … 438 472 break; 439 473 case GI: 440 // downsample fbo buffers for colors, normals441 DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);442 DownSample(fbo, 1, mDownSampleFbo, 1);443 444 474 ComputeGlobIllum(fbo, tempCohFactor); 445 475 CombineIllum(fbo); … … 707 737 708 738 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 709 739 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 710 740 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 711 741 … … 714 744 glDrawBuffers(1, mrt + colorBufferIdx); 715 745 716 float filterOffsets[NUM_SSAO_FILTERSAMPLES * 2];717 float filterWeights[NUM_SSAO_FILTERSAMPLES];718 719 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f);720 poisson.Generate((float *)filterOffsets);721 722 //const float filterWidth = 10.0f;723 const float filterWidth = 7.0f;724 const float xoffs = filterWidth / fbo->GetWidth();725 const float yoffs = filterWidth / fbo->GetHeight();726 727 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)728 {729 float x = filterOffsets[2 * i + 0];730 float y = filterOffsets[2 * i + 1];731 732 filterOffsets[2 * i + 0] *= xoffs;733 filterOffsets[2 * i + 1] *= yoffs;734 735 filterWeights[i] = GaussianDistribution(x, y, 1.0f);736 }737 738 739 746 sCgCombineSsaoProgram->SetTexture(0, colorsTex); 740 sCgCombineSsaoProgram->SetTexture(1, ssaoTex); 741 742 sCgCombineSsaoProgram->SetArray2f(2, (float *)filterOffsets, NUM_SSAO_FILTERSAMPLES); 743 sCgCombineSsaoProgram->SetArray1f(3, (float *)filterWeights, NUM_SSAO_FILTERSAMPLES); 747 sCgCombineSsaoProgram->SetTexture(1, normalsTex); 748 sCgCombineSsaoProgram->SetTexture(2, ssaoTex); 749 750 sCgCombineSsaoProgram->SetArray2f(3, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 751 sCgCombineSsaoProgram->SetArray1f(4, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 744 752 745 753 DrawQuad(sCgCombineSsaoProgram); … … 874 882 875 883 876 void DeferredRenderer::DownSample(FrameBufferObject *fbo, int bufferIdx, 884 void DeferredRenderer::DownSample(FrameBufferObject *fbo, 885 int bufferIdx, 877 886 FrameBufferObject *downSampleFbo, 878 887 int downSampleBufferIdx) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r3102 r3103 776 776 m.x[2][3] = .0f; 777 777 778 m.x[3][0] = (right + left) * xDif;779 m.x[3][1] = (top + bottom) * yDif;780 m.x[3][2] = (far + near) * zDif;778 m.x[3][0] = -(right + left) * xDif; 779 m.x[3][1] = -(top + bottom) * yDif; 780 m.x[3][2] = -(far + near) * zDif; 781 781 m.x[3][3] = 1.0f; 782 782 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r2955 r3103 68 68 69 69 // check if in disk, else exit early 70 if (rx * rx + ry * ry > mRadius * mRadius) 70 const float distanceSquared = rx * rx + ry * ry; 71 72 if ((rx * rx + ry * ry > mRadius * mRadius) 73 // also test if sample exactly in center => avoid that 74 || (distanceSquared <= 1e-3f) 75 ) 71 76 continue; 72 77 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
r3102 r3103 162 162 glMatrixMode(GL_MODELVIEW); 163 163 glPushMatrix(); 164 //glLoadIdentity();164 glLoadIdentity(); 165 165 166 166 glMatrixMode(GL_PROJECTION); 167 167 glPushMatrix(); 168 //glLoadIdentity();168 glLoadIdentity(); 169 169 170 170 OrthoCamera *orthoCam = new OrthoCamera(xlen, -xlen, ylen, -ylen, .0f, mSceneBox.Size().z); 171 171 172 orthoCam->Yaw(.5 * M_PI);173 172 orthoCam->SetDirection(Vector3(0, 0, -1)); 174 173 orthoCam->SetPosition(pos); … … 177 176 178 177 //glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 179 //glMatrixMode(GL_MODELVIEW);178 glMatrixMode(GL_MODELVIEW); 180 179 //orthoCam->SetupCameraView(); 181 180 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3102 r3103 458 458 //-- load some dynamic stuff 459 459 460 /*LoadModel("hbuddha.dem", dynamicObjects);460 LoadModel("hbuddha.dem", dynamicObjects); 461 461 //LoadModel("hbuddha2.dem", dynamicObjects); 462 462 buddha = dynamicObjects.back(); … … 484 484 } 485 485 486 */487 486 488 487 /////////// … … 884 883 885 884 Matrix4x4 mat = TranslationMatrix(planepos); 886 //buddha->GetTransform()->SetMatrix(mat);885 buddha->GetTransform()->SetMatrix(mat); 887 886 888 887 Vector3 oldPos = camera->GetPosition(); … … 933 932 /// enable vbo vertex array 934 933 glEnableClientState(GL_VERTEX_ARRAY); 935 936 934 937 935 // render with the specified method (forward rendering, forward + depth, deferred) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3100 r3103 18 18 //#define DISTANCE_SCALE 1e-1f 19 19 #define DISTANCE_SCALE 5e-2f 20 //#define DISTANCE_SCALE 0.2f 20 21 21 22 //#define ILLUM_INTENSITY 8e-2f … … 42 43 #define MAX_LOD_LEVEL 10 43 44 44 #define MIN_DEPTH_DIFF 1e-2f45 //#define MIN_DEPTH_DIFF 5e-1f45 //#define MIN_DEPTH_DIFF 1e-2f 46 #define MIN_DEPTH_DIFF 0.1f 46 47 #define PRECISION_SCALE 1e-1f 47 48 … … 52 53 /////////////////// 53 54 54 #define NUM_DOWNSAMPLES 1655 #define NUM_DOWNSAMPLES 9 55 56 56 #define NUM_SSAO_FILTERSAMPLES 10057 #define NUM_SSAO_FILTERSAMPLES 28 57 58 58 59 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3094 r3103 104 104 //-- reconstruct world space position from sample 105 105 106 //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0));107 const float4 sample = tex2D(colors, texcoord);106 const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 107 //const float4 sample = tex2D(colors, texcoord); 108 108 109 109 const float eyeSpaceDepth = sample.w; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3101 r3103 4 4 // Screen Spaced Ambient Occlusion shader 5 5 // based on shader of Alexander Kusternig 6 7 8 #define USE_EYE_SPACE_DEPTH 19 10 6 11 7 struct fragment … … 82 78 ) 83 79 { 84 const float2 mynoise = tex2D (noiseTex, texcoord0).xy;80 const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy; 85 81 86 82 const float2 offsetTransformed = myreflect(offset, mynoise); … … 151 147 //else trafo = inverseModelTrafo * oldModelViewProj; 152 148 153 float3 dummyPt = worldPos.xyz - oldEyePos;149 float3 translatedPt = worldPos.xyz - oldEyePos; 154 150 155 151 // reproject into old frame and calculate texture position of sample in old frame 156 float4 backProjPos = mul(oldModelViewProj, float4( dummyPt, 1.0f));152 float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 157 153 backProjPos /= backProjPos.w; 158 154 // fit from unit cube into 0 .. 1 … … 169 165 170 166 const float invlen = 1.0f / length(viewVec); 171 const float projectedEyeSpaceDepth = length( dummyPt) * invlen;167 const float projectedEyeSpaceDepth = length(translatedPt) * invlen; 172 168 173 169 const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 170 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 174 171 175 172 float notValid = 0.5f; 176 173 174 /* 177 175 for (int i = 0; i < NUM_SAMPLES; ++ i) 178 176 { … … 191 189 if (sampleDif >= 5e-2f) ++ notValid; 192 190 } 191 */ 193 192 194 193 // the number of valid samples in this frame … … 202 201 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 203 202 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 204 && ( abs(depthDif)<= MIN_DEPTH_DIFF)203 && (depthDif <= MIN_DEPTH_DIFF) 205 204 // if visibility changed in the surrounding area we have to recompute 206 205 //&& (oldNumSamples > 0.8f * newNumSamples) … … 259 258 //-- add random noise: reflect around random normal vector (rather slow!) 260 259 261 float2 mynoise = tex2D (noiseTex, IN.texCoord).xy;260 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 262 261 const float2 offsetTransformed = myreflect(offset, mynoise); 263 262 #else … … 275 274 276 275 float3 dirSample = samplePos - centerPosition; 277 const float lengthToSample = length(dirSample);276 const float lengthToSample = max(length(dirSample), 1e-6f); 278 277 279 278 dirSample /= lengthToSample; // normalize 280 279 281 280 // angle between current normal and direction to sample controls AO intensity. 282 constfloat cosAngle = max(dot(dirSample, normal), .0f);283 281 float cosAngle = max(dot(dirSample, normal), .0f); 282 284 283 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 285 284 // the distance to a sample approaches zero … … 291 290 // => compensate for this (on the other hand, projected sampling area could be larger!) 292 291 293 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, normal);292 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 294 293 total_ao += cosAngle * aoContrib * viewCorrection; 295 294 #else … … 352 351 oldbl, oldbr, oldtl, oldtr); 353 352 353 //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 354 354 return OUT; 355 355 } 356 357 358 float Filter(float2 texCoord,359 uniform sampler2D ssaoTex,360 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],361 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])362 {363 float average = .0f;364 float w = .0f;365 366 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)367 {368 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x;369 w += filterWeights[i];370 }371 372 average *= 1.0f / (float)w;373 374 return average;375 }376 377 378 pixel combine(fragment IN,379 uniform sampler2D colors,380 uniform sampler2D ssaoTex,381 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],382 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]383 )384 {385 pixel OUT;386 387 float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));388 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));389 390 if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);391 392 OUT.illum_col = col * ao.x;393 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);394 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);395 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);396 OUT.illum_col.w = col.w;397 398 return OUT;399 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3017 r3103 91 91 { 92 92 color = tex2D(colors, downSampleOffs[i]); 93 94 93 const float intensity = dot(cols[i].rgb, w); 95 94 … … 146 145 147 146 // obtain new image key from highest mipmap level 148 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w;147 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, MAX_LOD_LEVEL)).w; 149 148 float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 150 149 … … 153 152 // adjust to middle gray 154 153 const float lum = middleGrey * pixLum / newImageKey; 155 156 154 // map to range and calc burnout 157 155 const float scaleLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); … … 170 168 171 169 pixel OUT; 172 170 173 171 const float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 174 175 172 OUT.col = color; 176 173 … … 187 184 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 188 185 189 if (oldLogLum > 1e-5f) // too bright 186 // exponential smoothing of tone mapping over time 187 if (oldLogLum > 1e-5f) // loglum from last frame too bright 190 188 OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 191 189 else
Note: See TracChangeset
for help on using the changeset viewer.