History

Gathering the diffusion passes in the SUrfaceGEometryPAss job

samcake committed 10 years ago

Commit ff132fa1 parent 3638a3b7 files · +145 −65Browse files

Showing the changes to libraries/render-utils/src/SurfaceGeometryPass.cpp (1 of 7 files). Show all

Unified · Split

libraries/render-utils/src/SurfaceGeometryPass.cpp+110−33
@@ -282,6 +282,10 @@ void SurfaceGeometryFramebuffer::updateLinearDepth(const gpu::TexturePointer& li · 281 unmodified lines
282282 void SurfaceGeometryFramebuffer::clear() {
283283 _curvatureFramebuffer.reset();
284284 _curvatureTexture.reset();
285+ _lowCurvatureFramebuffer.reset();
286+ _lowCurvatureTexture.reset();
287+ _blurringFramebuffer.reset();
288+ _blurringTexture.reset();
285289 }
286290
287291 gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() {
@@ -293,9 +297,17 @@ void SurfaceGeometryFramebuffer::allocate() { · 5 unmodified lines
293297 auto width = _frameSize.x;
294298 auto height = _frameSize.y;
295299
296− _curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width >> getResolutionLevel(), height >> getResolutionLevel(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
300+ _curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
297301 _curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
298302 _curvatureFramebuffer->setRenderBuffer(0, _curvatureTexture);
303+
304+ _lowCurvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
305+ _lowCurvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
306+ _lowCurvatureFramebuffer->setRenderBuffer(0, _lowCurvatureTexture);
307+
308+ _blurringTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
309+ _blurringFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
310+ _blurringFramebuffer->setRenderBuffer(0, _blurringTexture);
299311 }
300312
301313 gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() {
@@ -312,6 +324,34 @@ gpu::TexturePointer SurfaceGeometryFramebuffer::getCurvatureTexture() { · 10 unmodified lines
312324 return _curvatureTexture;
313325 }
314326
327+gpu::FramebufferPointer SurfaceGeometryFramebuffer::getLowCurvatureFramebuffer() {
328+ if (!_lowCurvatureFramebuffer) {
329+ allocate();
330+ }
331+ return _lowCurvatureFramebuffer;
332+}
333+
334+gpu::TexturePointer SurfaceGeometryFramebuffer::getLowCurvatureTexture() {
335+ if (!_lowCurvatureTexture) {
336+ allocate();
337+ }
338+ return _lowCurvatureTexture;
339+}
340+
341+gpu::FramebufferPointer SurfaceGeometryFramebuffer::getBlurringFramebuffer() {
342+ if (!_blurringFramebuffer) {
343+ allocate();
344+ }
345+ return _blurringFramebuffer;
346+}
347+
348+gpu::TexturePointer SurfaceGeometryFramebuffer::getBlurringTexture() {
349+ if (!_blurringTexture) {
350+ allocate();
351+ }
352+ return _blurringTexture;
353+}
354+
315355 void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) {
316356 if (resolutionLevel != getResolutionLevel()) {
317357 clear();
@@ -320,8 +360,7 @@ void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { · 2 unmodified lines
320360 }
321361
322362 SurfaceGeometryPass::SurfaceGeometryPass() :
323− _firstBlurPass(false),
324− _secondBlurPass(true, _firstBlurPass.getParameters())
363+ _diffusePass(false)
325364 {
326365 Parameters parameters;
327366 _parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) &parameters));
@@ -345,6 +384,10 @@ void SurfaceGeometryPass::configure(const Config& config) { · 17 unmodified lines
345384 _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
346385 }
347386 _surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel);
387+
388+ _diffusePass.getParameters()->setFilterRadiusScale(config.diffuseFilterScale);
389+ _diffusePass.getParameters()->setDepthThreshold(config.diffuseDepthThreshold);
390+
348391 }
349392
350393
@@ -358,33 +401,52 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 7 unmodified lines
358401 const auto deferredFramebuffer = inputs.get1();
359402 const auto linearDepthFramebuffer = inputs.get2();
360403
361− auto linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
404+
405+ auto linearDepthTexture = linearDepthFramebuffer->getLinearDepthTexture();
406+ auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
407+ auto sourceViewport = args->_viewport;
408+ auto curvatureViewport = sourceViewport;
409+
410+ if (_surfaceGeometryFramebuffer->getResolutionLevel() > 0) {
411+ linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture();
412+ normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
413+ curvatureViewport = curvatureViewport >> _surfaceGeometryFramebuffer->getResolutionLevel();
414+ }
362415
363416 if (!_surfaceGeometryFramebuffer) {
364417 _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
365418 }
366419 _surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture);
367420
368− // auto normalTexture = deferredFramebuffer->getDeferredNormalTexture();
369− auto normalTexture = linearDepthFramebuffer->getHalfNormalTexture();
370−
371421 auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer();
422+ auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
372423 #ifdef USE_STENCIL_TEST
373− if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
374− curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
424+ if (curvatureFramebuffer->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
425+ curvatureFramebuffer->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
375426 }
376427 #endif
377− auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
428+
429+ auto lowCurvatureFramebuffer = _surfaceGeometryFramebuffer->getLowCurvatureFramebuffer();
430+ auto lowCurvatureTexture = _surfaceGeometryFramebuffer->getLowCurvatureTexture();
431+
432+ auto blurringFramebuffer = _surfaceGeometryFramebuffer->getBlurringFramebuffer();
433+ auto blurringTexture = _surfaceGeometryFramebuffer->getBlurringTexture();
378434
379435 outputs.edit0() = _surfaceGeometryFramebuffer;
380436 outputs.edit1() = curvatureFramebuffer;
437+ outputs.edit2() = curvatureFramebuffer;
438+ outputs.edit3() = lowCurvatureFramebuffer;
381439
382440 auto curvaturePipeline = getCurvaturePipeline();
441+ auto diffuseVPipeline = _diffusePass.getBlurVPipeline();
442+ auto diffuseHPipeline = _diffusePass.getBlurHPipeline();
383443
384− auto depthViewport = args->_viewport;
385− auto curvatureViewport = depthViewport >> 1;
386− // >> _surfaceGeometryFramebuffer->getResolutionLevel();
444+ glm::ivec2 textureSize(curvatureTexture->getDimensions());
445+ _diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport));
446+ _diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
447+ _diffusePass.getParameters()->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
387448
449+
388450 gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
389451 _gpuTimer.begin(batch);
390452 batch.enableStereo(false);
@@ -393,43 +455,58 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 2 unmodified lines
393455 batch.setViewTransform(Transform());
394456
395457 batch.setViewportTransform(curvatureViewport);
396− batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getCurvatureFrameSize(), curvatureViewport));
458+ batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getSourceFrameSize(), curvatureViewport));
397459
460+ // Curvature pass
398461 batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
399462 batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer);
400−
401− // Curvature pass
402463 batch.setFramebuffer(curvatureFramebuffer);
403−
404− // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
405−
464+ // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse
406465 #ifdef USE_STENCIL_TEST
407466 // Except if stenciling out
408467 batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
409468 #endif
410−
411469 batch.setPipeline(curvaturePipeline);
412470 batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture);
413471 batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture);
414472 batch.draw(gpu::TRIANGLE_STRIP, 4);
415473
416− batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, nullptr);
417− batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, nullptr);
474+ // Diffusion pass
475+ const int BlurTask_ParamsSlot = 0;
476+ const int BlurTask_SourceSlot = 0;
477+ const int BlurTask_DepthSlot = 1;
478+ batch.setUniformBuffer(BlurTask_ParamsSlot, _diffusePass.getParameters()->_parametersBuffer);
418479
419− _gpuTimer.end(batch);
420− });
480+ batch.setResourceTexture(BlurTask_DepthSlot, linearDepthTexture);
481+
482+ batch.setFramebuffer(blurringFramebuffer);
483+ batch.setPipeline(diffuseVPipeline);
484+ batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
485+ batch.draw(gpu::TRIANGLE_STRIP, 4);
421486
422− const auto diffuseCurvaturePassInputs = render::BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture);
423− gpu::FramebufferPointer midBlurredFramebuffer;
424− _firstBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, midBlurredFramebuffer);
487+ batch.setFramebuffer(curvatureFramebuffer);
488+ batch.setPipeline(diffuseHPipeline);
489+ batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
490+ batch.draw(gpu::TRIANGLE_STRIP, 4);
425491
426− gpu::FramebufferPointer lowBlurredFramebuffer;
427− _secondBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, lowBlurredFramebuffer);
428−
429−
430− outputs.edit2() = midBlurredFramebuffer;
431− outputs.edit3() = lowBlurredFramebuffer;
492+ batch.setFramebuffer(blurringFramebuffer);
493+ batch.setPipeline(diffuseVPipeline);
494+ batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture);
495+ batch.draw(gpu::TRIANGLE_STRIP, 4);
432496
497+ batch.setFramebuffer(lowCurvatureFramebuffer);
498+ batch.setPipeline(diffuseHPipeline);
499+ batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture);
500+ batch.draw(gpu::TRIANGLE_STRIP, 4);
501+
502+ batch.setResourceTexture(BlurTask_SourceSlot, nullptr);
503+ batch.setResourceTexture(BlurTask_DepthSlot, nullptr);
504+ batch.setUniformBuffer(BlurTask_ParamsSlot, nullptr);
505+
506+ _gpuTimer.end(batch);
507+ });
508+
509+
433510 auto config = std::static_pointer_cast<Config>(renderContext->jobConfig);
434511 config->gpuTime = _gpuTimer.getAverage();
435512 }