|
|
@@ -23,94 +23,85 @@ Bloom::~Bloom()
|
|
|
}
|
|
|
|
|
|
//==============================================================================
|
|
|
-Error Bloom::initFb(FramebufferPtr& fb, TexturePtr& rt)
|
|
|
+Error Bloom::initInternal(const ConfigSet& config)
|
|
|
{
|
|
|
- // Set to bilinear because the blurring techniques take advantage of that
|
|
|
- m_r->createRenderTarget(
|
|
|
- m_width, m_height, RT_PIXEL_FORMAT, 1, SamplingFilter::LINEAR, 1, rt);
|
|
|
+ GrManager& gr = getGrManager();
|
|
|
|
|
|
- // Create FB
|
|
|
- FramebufferInitInfo fbInit;
|
|
|
- fbInit.m_colorAttachmentCount = 1;
|
|
|
- fbInit.m_colorAttachments[0].m_texture = rt;
|
|
|
- fbInit.m_colorAttachments[0].m_loadOperation =
|
|
|
- AttachmentLoadOperation::DONT_CARE;
|
|
|
- fb = getGrManager().newInstance<Framebuffer>(fbInit);
|
|
|
+ m_upscale.m_width = m_r->getWidth() / BLOOM_FRACTION;
|
|
|
+ m_upscale.m_height = m_r->getHeight() / BLOOM_FRACTION;
|
|
|
|
|
|
- return ErrorCode::NONE;
|
|
|
-}
|
|
|
-
|
|
|
-//==============================================================================
|
|
|
-Error Bloom::initInternal(const ConfigSet& config)
|
|
|
-{
|
|
|
- m_width = m_r->getWidth() / BLOOM_FRACTION;
|
|
|
- m_height = m_r->getHeight() / BLOOM_FRACTION;
|
|
|
+ m_extractExposure.m_width =
|
|
|
+ m_r->getWidth() >> (m_r->getIs().getRtMipmapCount() - 2);
|
|
|
+ m_extractExposure.m_height =
|
|
|
+ m_r->getHeight() >> (m_r->getIs().getRtMipmapCount() - 2);
|
|
|
|
|
|
m_threshold = config.getNumber("bloom.threshold");
|
|
|
m_scale = config.getNumber("bloom.scale");
|
|
|
- m_blurringDist = config.getNumber("bloom.blurringDist");
|
|
|
-
|
|
|
- ANKI_CHECK(initFb(m_hblurFb, m_hblurRt));
|
|
|
- ANKI_CHECK(initFb(m_vblurFb, m_vblurRt));
|
|
|
|
|
|
- // init shaders & pplines
|
|
|
- GrManager& gr = getGrManager();
|
|
|
+ // Create RTs
|
|
|
+ m_r->createRenderTarget(m_extractExposure.m_width,
|
|
|
+ m_extractExposure.m_height,
|
|
|
+ RT_PIXEL_FORMAT,
|
|
|
+ 1,
|
|
|
+ SamplingFilter::LINEAR,
|
|
|
+ 1,
|
|
|
+ m_extractExposure.m_rt);
|
|
|
+
|
|
|
+ m_r->createRenderTarget(m_upscale.m_width,
|
|
|
+ m_upscale.m_height,
|
|
|
+ RT_PIXEL_FORMAT,
|
|
|
+ 1,
|
|
|
+ SamplingFilter::LINEAR,
|
|
|
+ 1,
|
|
|
+ m_upscale.m_rt);
|
|
|
+
|
|
|
+ // Create FBs
|
|
|
+ FramebufferInitInfo fbInit;
|
|
|
+ fbInit.m_colorAttachmentCount = 1;
|
|
|
+ fbInit.m_colorAttachments[0].m_texture = m_extractExposure.m_rt;
|
|
|
+ fbInit.m_colorAttachments[0].m_loadOperation =
|
|
|
+ AttachmentLoadOperation::DONT_CARE;
|
|
|
+ m_extractExposure.m_fb = gr.newInstance<Framebuffer>(fbInit);
|
|
|
|
|
|
- PipelineInitInfo ppinit;
|
|
|
- ppinit.m_color.m_attachmentCount = 1;
|
|
|
- ppinit.m_color.m_attachments[0].m_format = RT_PIXEL_FORMAT;
|
|
|
- ppinit.m_depthStencil.m_depthWriteEnabled = false;
|
|
|
- ppinit.m_depthStencil.m_depthCompareFunction = CompareOperation::ALWAYS;
|
|
|
+ fbInit.m_colorAttachments[0].m_texture = m_upscale.m_rt;
|
|
|
+ m_upscale.m_fb = gr.newInstance<Framebuffer>(fbInit);
|
|
|
|
|
|
+ // init shaders
|
|
|
StringAuto pps(getAllocator());
|
|
|
- pps.sprintf("#define ANKI_RENDERER_WIDTH %u\n"
|
|
|
- "#define ANKI_RENDERER_HEIGHT %u\n"
|
|
|
- "#define MIPMAP %u\n",
|
|
|
- m_r->getWidth(),
|
|
|
- m_r->getHeight(),
|
|
|
- IS_MIPMAP_COUNT - 1);
|
|
|
-
|
|
|
- ANKI_CHECK(getResourceManager().loadResourceToCache(
|
|
|
- m_quadVert, "shaders/Quad.vert.glsl", pps.toCString(), "r_"));
|
|
|
-
|
|
|
- ppinit.m_shaders[ShaderType::VERTEX] = m_quadVert->getGrShader();
|
|
|
-
|
|
|
- ANKI_CHECK(getResourceManager().loadResourceToCache(
|
|
|
- m_toneFrag, "shaders/Bloom.frag.glsl", pps.toCString(), "r_"));
|
|
|
-
|
|
|
- ppinit.m_shaders[ShaderType::FRAGMENT] = m_toneFrag->getGrShader();
|
|
|
-
|
|
|
- m_tonePpline = gr.newInstance<Pipeline>(ppinit);
|
|
|
-
|
|
|
- const char* SHADER_FILENAME = "shaders/GaussianBlurGeneric.frag.glsl";
|
|
|
+ pps.sprintf("#define WIDTH %u\n"
|
|
|
+ "#define HEIGHT %u\n"
|
|
|
+ "#define MIPMAP %u.0\n",
|
|
|
+ m_r->getWidth() >> (m_r->getIs().getRtMipmapCount() - 1),
|
|
|
+ m_r->getHeight() >> (m_r->getIs().getRtMipmapCount() - 1),
|
|
|
+ m_r->getIs().getRtMipmapCount() - 1);
|
|
|
+
|
|
|
+ ANKI_CHECK(
|
|
|
+ getResourceManager().loadResourceToCache(m_extractExposure.m_frag,
|
|
|
+ "shaders/Bloom.frag.glsl",
|
|
|
+ pps.toCString(),
|
|
|
+ "r_"));
|
|
|
|
|
|
pps.destroy();
|
|
|
- pps.sprintf("#define HPASS\n"
|
|
|
- "#define COL_RGB\n"
|
|
|
- "#define TEXTURE_SIZE vec2(%f, %f)\n"
|
|
|
- "#define KERNEL_SIZE 19\n",
|
|
|
- F32(m_width),
|
|
|
- F32(m_height));
|
|
|
-
|
|
|
- ANKI_CHECK(getResourceManager().loadResourceToCache(
|
|
|
- m_hblurFrag, SHADER_FILENAME, pps.toCString(), "r_"));
|
|
|
-
|
|
|
- ppinit.m_shaders[ShaderType::FRAGMENT] = m_hblurFrag->getGrShader();
|
|
|
- m_hblurPpline = gr.newInstance<Pipeline>(ppinit);
|
|
|
-
|
|
|
- pps.destroy();
|
|
|
- pps.sprintf("#define VPASS\n"
|
|
|
- "#define COL_RGB\n"
|
|
|
- "#define TEXTURE_SIZE vec2(%f, %f)\n"
|
|
|
- "#define KERNEL_SIZE 15\n",
|
|
|
- F32(m_width),
|
|
|
- F32(m_height));
|
|
|
-
|
|
|
- ANKI_CHECK(getResourceManager().loadResourceToCache(
|
|
|
- m_vblurFrag, SHADER_FILENAME, pps.toCString(), "r_"));
|
|
|
-
|
|
|
- ppinit.m_shaders[ShaderType::FRAGMENT] = m_vblurFrag->getGrShader();
|
|
|
- m_vblurPpline = gr.newInstance<Pipeline>(ppinit);
|
|
|
+ pps.sprintf("#define WIDTH %u\n"
|
|
|
+ "#define HEIGHT %u\n",
|
|
|
+ m_extractExposure.m_width,
|
|
|
+ m_extractExposure.m_height);
|
|
|
+
|
|
|
+ ANKI_CHECK(getResourceManager().loadResourceToCache(m_upscale.m_frag,
|
|
|
+ "shaders/BloomUpscale.frag.glsl",
|
|
|
+ pps.toCString(),
|
|
|
+ "r_"));
|
|
|
+
|
|
|
+ // Init pplines
|
|
|
+ ColorStateInfo colorInf;
|
|
|
+ colorInf.m_attachmentCount = 1;
|
|
|
+ colorInf.m_attachments[0].m_format = RT_PIXEL_FORMAT;
|
|
|
+
|
|
|
+ m_r->createDrawQuadPipeline(m_extractExposure.m_frag->getGrShader(),
|
|
|
+ colorInf,
|
|
|
+ m_extractExposure.m_ppline);
|
|
|
+ m_r->createDrawQuadPipeline(
|
|
|
+ m_upscale.m_frag->getGrShader(), colorInf, m_upscale.m_ppline);
|
|
|
|
|
|
// Set descriptors
|
|
|
{
|
|
|
@@ -121,22 +112,15 @@ Error Bloom::initInternal(const ConfigSet& config)
|
|
|
descInit.m_storageBuffers[0].m_buffer =
|
|
|
m_r->getTm().getAverageLuminanceBuffer();
|
|
|
|
|
|
- m_firstDescrGroup = gr.newInstance<ResourceGroup>(descInit);
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- ResourceGroupInitInfo descInit;
|
|
|
- descInit.m_textures[0].m_texture = m_vblurRt;
|
|
|
- m_hDescrGroup = gr.newInstance<ResourceGroup>(descInit);
|
|
|
+ m_extractExposure.m_rsrc = gr.newInstance<ResourceGroup>(descInit);
|
|
|
}
|
|
|
|
|
|
{
|
|
|
ResourceGroupInitInfo descInit;
|
|
|
- descInit.m_textures[0].m_texture = m_hblurRt;
|
|
|
- m_vDescrGroup = gr.newInstance<ResourceGroup>(descInit);
|
|
|
+ descInit.m_textures[0].m_texture = m_extractExposure.m_rt;
|
|
|
+ m_upscale.m_rsrc = gr.newInstance<ResourceGroup>(descInit);
|
|
|
}
|
|
|
|
|
|
- getGrManager().finish();
|
|
|
return ErrorCode::NONE;
|
|
|
}
|
|
|
|
|
|
@@ -158,9 +142,10 @@ void Bloom::run(RenderingContext& ctx)
|
|
|
CommandBufferPtr& cmdb = ctx.m_commandBuffer;
|
|
|
|
|
|
// pass 0
|
|
|
- cmdb->beginRenderPass(m_vblurFb);
|
|
|
- cmdb->setViewport(0, 0, m_width, m_height);
|
|
|
- cmdb->bindPipeline(m_tonePpline);
|
|
|
+ cmdb->beginRenderPass(m_extractExposure.m_fb);
|
|
|
+ cmdb->setViewport(
|
|
|
+ 0, 0, m_extractExposure.m_width, m_extractExposure.m_height);
|
|
|
+ cmdb->bindPipeline(m_extractExposure.m_ppline);
|
|
|
|
|
|
TransientMemoryInfo dyn;
|
|
|
Vec4* uniforms = static_cast<Vec4*>(
|
|
|
@@ -169,30 +154,21 @@ void Bloom::run(RenderingContext& ctx)
|
|
|
dyn.m_uniformBuffers[0]));
|
|
|
*uniforms = Vec4(m_threshold, m_scale, 0.0, 0.0);
|
|
|
|
|
|
- cmdb->bindResourceGroup(m_firstDescrGroup, 0, &dyn);
|
|
|
+ cmdb->bindResourceGroup(m_extractExposure.m_rsrc, 0, &dyn);
|
|
|
|
|
|
m_r->drawQuad(cmdb);
|
|
|
cmdb->endRenderPass();
|
|
|
|
|
|
- // Blurring passes
|
|
|
+ // pass 1
|
|
|
+ cmdb->setViewport(0, 0, m_upscale.m_width, m_upscale.m_height);
|
|
|
+ cmdb->beginRenderPass(m_upscale.m_fb);
|
|
|
+ cmdb->bindPipeline(m_upscale.m_ppline);
|
|
|
+ cmdb->bindResourceGroup(m_upscale.m_rsrc, 0, nullptr);
|
|
|
+ m_r->drawQuad(cmdb);
|
|
|
+
|
|
|
+ if(!m_r->getSslfEnabled())
|
|
|
{
|
|
|
- // hpass
|
|
|
- cmdb->beginRenderPass(m_hblurFb);
|
|
|
- cmdb->bindResourceGroup(m_hDescrGroup, 0, nullptr);
|
|
|
- cmdb->bindPipeline(m_hblurPpline);
|
|
|
- m_r->drawQuad(cmdb);
|
|
|
cmdb->endRenderPass();
|
|
|
-
|
|
|
- // vpass
|
|
|
- cmdb->beginRenderPass(m_vblurFb);
|
|
|
- cmdb->bindResourceGroup(m_vDescrGroup, 0, nullptr);
|
|
|
- cmdb->bindPipeline(m_vblurPpline);
|
|
|
- m_r->drawQuad(cmdb);
|
|
|
-
|
|
|
- if(!m_r->getSslfEnabled())
|
|
|
- {
|
|
|
- cmdb->endRenderPass();
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|