Changeset 3216 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 12/09/08 01:11:40 (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
r3215 r3216 318 318 319 319 320 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam): 320 DeferredRenderer::DeferredRenderer(int w, int h, 321 PerspectiveCamera *cam, 322 bool ssaoUseFullResolution): 321 323 mWidth(w), mHeight(h), 322 324 mCamera(cam), … … 328 330 mSortSamples(true), 329 331 mKernelRadius(1e-8f), 332 mSsaoFilterRadius(12.0f), 330 333 mSampleIntensity(0.2f), 331 334 mSunVisiblePixels(0) … … 334 337 //-- the flip-flop fbos 335 338 336 //const int dsw = w / 2; const int dsh = h / 2; 339 int downSampledWidth, downSampledHeight; 340 341 if (ssaoUseFullResolution) 342 { 343 downSampledWidth = w; downSampledHeight = h; 344 cout << "using full resolution ssao" << endl; 345 } 346 else 347 { 348 downSampledWidth = w / 2; downSampledHeight = h / 2; 349 cout << "using half resolution ssao" << endl; 350 } 351 337 352 const int dsw = w; const int dsh = h; 338 353 339 mIllumFbo = new FrameBufferObject(d sw, dsh, FrameBufferObject::DEPTH_NONE);354 mIllumFbo = new FrameBufferObject(downSampledWidth, downSampledHeight, FrameBufferObject::DEPTH_NONE); 340 355 //mIllumFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 341 356 … … 400 415 ShaderManager *sm = ShaderManager::GetSingleton(); 401 416 402 sCgDeferredProgram = sm->CreateFragmentProgram("deferred", "main", " deferredFrag");403 sCgDeferredShadowProgram = sm->CreateFragmentProgram("deferred", "main_shadow", " deferredFragShader");404 sCgSsaoProgram = sm->CreateFragmentProgram("ssao", "main", " ssaoFrag");405 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", " giFrag");406 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", " combineGi");407 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", " combine", "combineSsao");408 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", " antiAliasing");409 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", " toneMap");417 sCgDeferredProgram = sm->CreateFragmentProgram("deferred", "main", "DeferredFrag"); 418 sCgDeferredShadowProgram = sm->CreateFragmentProgram("deferred", "main_shadow", "DeferredFragShadow"); 419 sCgSsaoProgram = sm->CreateFragmentProgram("ssao", "main", "SsaoFrag"); 420 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "GiFrag"); 421 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "CombineGi"); 422 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao"); 423 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "AntiAliasing"); 424 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "ToneMap"); 410 425 sCgDownSampleProgram = sm->CreateFragmentProgram("deferred", "Output", "Output"); 411 426 sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth"); 412 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", " avgLogLum");427 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "AvgLogLum"); 413 428 sCgPrepareSsaoProgram = sm->CreateFragmentProgram("deferred", "PrepareSsao", "PrepareSsao"); 414 429 sCgLenseFlareProgram = sm->CreateFragmentProgram("lenseFlare", "LenseFlare", "LenseFlare"); … … 451 466 452 467 string combineSsaoParams[] = 453 {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", 454 "filterWeights", "modelViewProj", "bl", "br", "tl", "tr", "w", "h"}; 455 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 12); 468 {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights", 469 "ssaoFilterRadius", "modelViewProj", "bl", "br", "tl", 470 "tr", "w", "h"}; 471 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13); 456 472 457 473 ////////////// … … 503 519 //-- prepare filters for ssao 504 520 505 506 const float filterWidth = 1.0f; 507 508 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 509 poisson.Generate((float *)ssaoFilterOffsets); 510 511 const float xoffs = (float)filterWidth / mWidth; 512 const float yoffs = (float)filterWidth / mHeight; 513 514 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 515 { 516 float x = ssaoFilterOffsets[2 * i + 0]; 517 float y = ssaoFilterOffsets[2 * i + 1]; 518 519 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 520 //ssaoFilterWeights[i] = 1.0f; 521 522 ssaoFilterOffsets[2 * i + 0] *= xoffs; 523 ssaoFilterOffsets[2 * i + 1] *= yoffs; 524 } 521 PrepareSsaoFilter(); 525 522 526 523 … … 615 612 616 613 614 void DeferredRenderer::PrepareSsaoFilter() 615 { 616 const float filterWidth = 1.0f; 617 618 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 619 poisson.Generate((float *)ssaoFilterOffsets); 620 621 const float xoffs = (float)filterWidth / mWidth; 622 const float yoffs = (float)filterWidth / mHeight; 623 624 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 625 { 626 float x = ssaoFilterOffsets[2 * i + 0]; 627 float y = ssaoFilterOffsets[2 * i + 1]; 628 629 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 630 //ssaoFilterWeights[i] = 1.0f; 631 632 ssaoFilterOffsets[2 * i + 0] *= xoffs; 633 ssaoFilterOffsets[2 * i + 1] *= yoffs; 634 } 635 } 636 617 637 618 638 static inline float SqrMag(const Sample2 &s) … … 934 954 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 935 955 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 936 956 sCgCombineSsaoProgram->SetValue1f(i ++, mSsaoFilterRadius); 957 937 958 sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); 938 959 … … 1320 1341 1321 1342 1343 void DeferredRenderer::SetSsaoFilterRadius(float ssaoFilterRadius) 1344 { 1345 mSsaoFilterRadius = ssaoFilterRadius; 1346 } 1347 1348 1322 1349 void DeferredRenderer::SetSortSamples(bool sortSamples) 1323 1350 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3215 r3216 26 26 public: 27 27 /** Constructor for a deferred shader taking the requested output image size, 28 the current camera ;28 the current camera, and if the ssao should be full or half resolution 29 29 */ 30 DeferredRenderer(int w, int h, PerspectiveCamera *cam); 31 /** The algorithm renders the scene given an fbo consists of 1 color buffer, 32 1 position buffer, and 1 normal buffer. 33 We also need the projection view matrix of the last frame for reprojection, and 34 a smoothing factor for temporal coherence 30 DeferredRenderer(int w, int h, PerspectiveCamera *cam, bool ssaoUsefulResolution); 31 /** Destructor 35 32 */ 33 ~DeferredRenderer(); 34 /** The main render function 35 Currently our fbo consists of one combined color + depth buffer, a normal buffer, 36 and a buffer holding the difference of the pixel positions from the last frame. 36 37 37 ~DeferredRenderer(); 38 Set useToneMapping to true if tone mapping should be applied 39 Set useAntiAliasing true if some basic edge antialiasing should be performed 40 If a shadowMap is specified that is not NULL, the shadow mapped shading algorithm is applied. 38 41 42 The temporal coherence factor is the maximal number of ssao samples that are accumulated 43 without losing any prior sample information. 44 Set this number too low and flickering can be seen, too 45 high and the adaption to some changes in the ssao might be too slow. Usually from about 46 1000 samples a flickering cannot be seen. 47 */ 39 48 void Render(FrameBufferObject *fbo, 40 49 float tempCohFactor, … … 46 55 47 56 48 void SetUseTemporalCoherence(bool temporal);49 50 57 enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT}; 51 58 /** Use ssao or ssao + color bleeding 59 */ 52 60 enum SHADING_METHOD {DEFAULT, SSAO, GI}; 53 54 61 /** Set the samplig method for the indirect illumination 55 62 */ … … 58 65 */ 59 66 void SetShadingMethod(SHADING_METHOD s); 60 67 /** Sort the samples so texture access is faster 68 */ 61 69 void SetSortSamples(bool sortSamples); 62 70 /** Sets ssao sample intensity. 71 */ 63 72 void SetSampleIntensity(float sampleIntensity); 64 73 /** Sets ssao kernel radius. 74 */ 65 75 void SetKernelRadius(float kernelRadius); 76 /** Sets ssao filter radius. 77 */ 78 void SetSsaoFilterRadius(float radius); 66 79 /** Sets the number of visible pixels of the sun 67 80 */ 68 81 void SetSunVisiblePixels(int visiblePixels); 82 /** If true tem poral coherence is used for ssao 83 */ 84 void SetUseTemporalCoherence(bool temporal); 69 85 70 86 … … 126 142 void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light); 127 143 144 void PrepareSsaoFilter(); 145 128 146 129 147 //////////// … … 133 151 /// deferred shading output image height 134 152 int mHeight; 153 154 ////////////////// 155 135 156 136 157 PerspectiveCamera *mCamera; … … 152 173 FBOContainer mFBOs; 153 174 154 static ShaderContainer sShaders;155 156 175 Matrix4x4 mProjViewMatrix; 157 176 Matrix4x4 mOldProjViewMatrix; … … 166 185 167 186 float mKernelRadius; 187 float mSsaoFilterRadius; 168 188 float mSampleIntensity; 169 189 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r3215 r3216 63 63 bool mUseNormalMapping; 64 64 65 65 66 protected: 66 67 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.h
r2953 r3216 23 23 */ 24 24 SceneEntityConverter() {}; 25 26 //~SceneEntityConverter();27 28 25 /** Converts this box to a scene entity 29 26 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3215 r3216 110 110 int maxDepthForTestingChildren = 3; 111 111 112 bool ssaoUseFullResolution = false; 113 112 114 113 115 /// the technique used for rendering … … 151 153 float ssaoKernelRadius = 1e-8f; 152 154 float ssaoSampleIntensity = 0.2f; 155 float ssaoFilterRadius = 12.0f; 153 156 float ssaoTempCohFactor = 255.0; 154 157 bool sortSamples = true; … … 400 403 env.GetFloatParam(string("ssaoSampleIntensity"), ssaoSampleIntensity); 401 404 405 env.GetBoolParam(string("ssaoUseFullResolution"), ssaoUseFullResolution); 406 402 407 //env.GetStringParam(string("modelPath"), model_path); 403 408 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); … … 426 431 cout << "sample intensity: " << ssaoSampleIntensity << endl; 427 432 cout << "kernel radius: " << ssaoKernelRadius << endl; 433 cout << "ssao full resolution: " << ssaoUseFullResolution << endl; 428 434 429 435 //cout << "model path: " << model_path << endl; … … 1186 1192 1187 1193 if (!deferredShader) deferredShader = 1188 new DeferredRenderer(texWidth, texHeight, camera );1194 new DeferredRenderer(texWidth, texHeight, camera, ssaoUseFullResolution); 1189 1195 1190 1196 DeferredRenderer::SHADING_METHOD shadingMethod; … … 1198 1204 } 1199 1205 else 1206 { 1200 1207 shadingMethod = DeferredRenderer::DEFAULT; 1208 } 1201 1209 1202 1210 deferredShader->SetSunVisiblePixels(sunVisiblePixels); … … 1205 1213 deferredShader->SetKernelRadius(ssaoKernelRadius); 1206 1214 deferredShader->SetSampleIntensity(ssaoSampleIntensity); 1215 deferredShader->SetSsaoFilterRadius(ssaoFilterRadius); 1207 1216 deferredShader->SetUseTemporalCoherence(useTemporalCoherence); 1208 1217 deferredShader->SetSortSamples(sortSamples); … … 1320 1329 case '7': 1321 1330 ssaoTempCohFactor *= 0.5f; 1331 cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 1322 1332 break; 1323 1333 case '8': 1324 1334 ssaoTempCohFactor *= 2.0f; 1335 cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl; 1325 1336 break; 1326 1337 case '9': 1327 1338 ssaoKernelRadius *= 0.8f; 1339 cout << "new ssao kernel radius: " << ssaoKernelRadius << endl; 1328 1340 break; 1329 1341 case '0': 1330 1342 ssaoKernelRadius *= 1.2f; 1343 cout << "new ssao kernel radius: " << ssaoKernelRadius << endl; 1331 1344 break; 1332 1345 case 'n': 1333 1346 ssaoSampleIntensity *= 0.9f; 1347 cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 1334 1348 break; 1335 1349 case 'N': 1336 1350 ssaoSampleIntensity *= 1.1f; 1351 cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl; 1352 break; 1353 case 'o': 1354 ssaoFilterRadius *= 0.9f; 1355 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1356 break; 1357 case 'O': 1358 ssaoFilterRadius *= 1.1f; 1359 cout << "new ssao filter radius: " << ssaoFilterRadius << endl; 1337 1360 break; 1338 1361 case 'l': … … 1340 1363 useLODs = !useLODs; 1341 1364 SceneEntity::SetUseLODs(useLODs); 1365 cout << "using LODs: " << useLODs << endl; 1342 1366 break; 1343 1367 case 'P': … … 1358 1382 useTemporalCoherence = !useTemporalCoherence; 1359 1383 break; 1360 case 'o':1384 /* case 'o': 1361 1385 case 'O': 1362 1386 useOptimization = !useOptimization; 1387 // chc optimization of using the objects instead of 1388 // the bounding boxes for querying previously visible nodes 1363 1389 traverser->SetUseOptimization(useOptimization); 1364 break; 1390 break;*/ 1365 1391 case 'a': 1366 1392 case 'A': … … 1413 1439 useLenseFlare = !useLenseFlare; 1414 1440 break; 1441 1415 1442 default: 1416 1443 return; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp
r3213 r3216 1135 1135 1136 1136 if (!deferredShader) deferredShader = 1137 new DeferredRenderer(texWidth, texHeight, camera );1137 new DeferredRenderer(texWidth, texHeight, camera, 0); 1138 1138 1139 1139 DeferredRenderer::SHADING_METHOD shadingMethod; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3214 r3216 19 19 20 20 #define NUM_SSAO_FILTER_SAMPLES 16 21 22 #define SSAO_FILTER_WIDTH 12.0f23 //#define SSAO_FILTER_WIDTH 6.0f24 21 25 22 #define SSAO_CONVERGENCE_THRESHOLD 700.0f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3212 r3216 21 21 22 22 23 /** Filter taking into account depth and normal differences, 24 and convergence of a sample 23 /** Filter taking into account depth, normal discontinuities 24 and ssao convergence of a sample (the higher the more reliably 25 has the sample a correct ssao value) 25 26 */ 26 27 float DiscontinuityFilter(float2 texCoord, … … 31 32 uniform sampler2D colorsTex, 32 33 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 33 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 34 float scale 35 ) 36 { 37 float average = .0f; 38 float total_w = .0f; 39 40 const float eyeSpaceDepth = color.w; 41 42 const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 43 44 float4 aoSample; 45 float3 sampleNorm; 46 float3 samplePos; 47 float w; 48 float4 sampleTexCoord; 49 float depthFactor; 50 float normalFactor; 51 float convergenceFactor; 52 float sampleDepth; 53 54 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 55 { 56 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 57 58 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 59 sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 60 61 // check depth discontinuity 62 sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w; 63 //sampleDepth = aoSample.w; 64 65 //depthFactor = 1.0f / max(abs(eyeSpaceDepth - sampleDepth), 1e-2f); 66 depthFactor = 1.0f - step(1e-2f, abs(1.0f - eyeSpaceDepth / sampleDepth)); 67 //normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f); 68 normalFactor = max(dot(sampleNorm, centerNormal), 1e-3f); 69 //convergenceFactor = min(100.0f, aoSample.y); 70 convergenceFactor = aoSample.y + 1.0f; 71 72 // combine the weights 73 w = filterWeights[i] * convergenceFactor * depthFactor * normalFactor; 74 //w = normalFactor * convergenceFactor; 75 76 average += aoSample.x * w; 77 total_w += w; 78 } 79 80 average /= max(total_w, 1e-6f); 81 82 return saturate(average); 83 } 84 85 86 87 /** Filter taking into account depth and normal differences, 88 and convergence of a sample 89 */ 90 float DiscontinuityFilter2(float2 texCoord, 91 float4 ao, 92 float4 color, 93 uniform sampler2D ssaoTex, 94 uniform sampler2D normalsTex, 95 uniform sampler2D colorsTex, 96 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 97 float scale, 98 float3 bl, 99 float3 br, 100 float3 tl, 101 float3 tr) 34 float scale, 35 float3 bl, 36 float3 br, 37 float3 tl, 38 float3 tr) 102 39 { 103 40 float average = .0f; … … 154 91 155 92 /** Function combining image and indirect illumination buffer using a 156 depth and normal aware discontinuity filter. 93 depth and normal aware discontinuity filter. We assume that 94 we are using half resolution ssao for this version of the combineSsao 157 95 */ 158 pixel combine(fragment IN, 159 uniform sampler2D colorsTex, 160 uniform sampler2D ssaoTex, 161 uniform sampler2D normalsTex, 162 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 163 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 164 uniform float4x4 modelViewProj, 165 uniform float3 bl, 166 uniform float3 br, 167 uniform float3 tl, 168 uniform float3 tr, 169 uniform float w, 170 uniform float h 171 ) 96 pixel CombineSsaoHalfRes(fragment IN, 97 uniform sampler2D colorsTex, 98 uniform sampler2D ssaoTex, 99 uniform sampler2D normalsTex, 100 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 101 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 102 uniform float ssaoFilterRadius, 103 uniform float4x4 modelViewProj, 104 uniform float3 bl, 105 uniform float3 br, 106 uniform float3 tl, 107 uniform float3 tr, 108 uniform float w, 109 uniform float h 110 ) 172 111 { 173 112 pixel OUT; … … 176 115 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 177 116 117 // the following has to be done for half resolution ssao: 178 118 // get the minimum convergence by exactly sampling the 4 surrounding 179 119 // texels in the old texture, otherwise flickering because convergence 180 120 // will be interpolated when upsampling and filter size does not match! 121 181 122 float4 texelCenterConv; 182 123 const float xoffs = .5f / w; const float yoffs = .5f / h; … … 210 151 211 152 // descend to zero filter size after reaching thres pixels 212 const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / ( SSAO_FILTER_WIDTH- 1.0f);153 const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / (ssaoFilterRadius - 1.0f); 213 154 const float convergenceScale = convergenceWeight / (convergence + convergenceWeight); 214 const float scale = SSAO_FILTER_WIDTH* convergenceScale * distanceScale;155 const float scale = ssaoFilterRadius * convergenceScale * distanceScale; 215 156 216 157 // the filtered ssao value 217 ao.x = DiscontinuityFilter 2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr);158 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 218 159 } 219 160
Note: See TracChangeset
for help on using the changeset viewer.