mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 11:02:24 +02:00
Introducing msaa to forward renderer
This commit is contained in:
parent
1330b108d6
commit
bd3a732cdc
4 changed files with 128 additions and 7 deletions
|
@ -197,7 +197,73 @@ void Blit::run(const RenderContextPointer& renderContext, const gpu::Framebuffer
|
|||
});
|
||||
}
|
||||
|
||||
void ExtractFrustums::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& output) {
|
||||
|
||||
void ResolveFramebuffer::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
|
||||
RenderArgs* args = renderContext->args;
|
||||
auto srcFbo = inputs.get0();
|
||||
auto destFbo = inputs.get1();
|
||||
|
||||
if (!destFbo) {
|
||||
destFbo = args->_blitFramebuffer;
|
||||
}
|
||||
outputs = destFbo;
|
||||
|
||||
// Check valid src and dest
|
||||
if (!srcFbo || !destFbo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check valid size for sr and dest
|
||||
auto frameSize(srcFbo->getSize());
|
||||
if (destFbo->getSize() != frameSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpu::Vec4i rectSrc;
|
||||
rectSrc.z = frameSize.x;
|
||||
rectSrc.w = frameSize.y;
|
||||
gpu::doInBatch("Resolve", args->_context, [&](gpu::Batch& batch) {
|
||||
batch.blit(srcFbo, rectSrc, destFbo, rectSrc);
|
||||
});
|
||||
}
|
||||
|
||||
void ResolveNewFramebuffer::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
|
||||
RenderArgs* args = renderContext->args;
|
||||
auto srcFbo = inputs;
|
||||
outputs.reset();
|
||||
|
||||
// Check valid src
|
||||
if (!srcFbo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check valid size for sr and dest
|
||||
auto frameSize(srcFbo->getSize());
|
||||
|
||||
// Resizing framebuffers instead of re-building them seems to cause issues with threaded rendering
|
||||
if (_outputFramebuffer && _outputFramebuffer->getSize() != frameSize) {
|
||||
_outputFramebuffer.reset();
|
||||
}
|
||||
|
||||
if (!_outputFramebuffer) {
|
||||
_outputFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("resolvedNew.out"));
|
||||
auto colorFormat = gpu::Element::COLOR_SRGBA_32;
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR);
|
||||
auto colorTexture = gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
_outputFramebuffer->setRenderBuffer(0, colorTexture);
|
||||
}
|
||||
|
||||
gpu::Vec4i rectSrc;
|
||||
rectSrc.z = frameSize.x;
|
||||
rectSrc.w = frameSize.y;
|
||||
gpu::doInBatch("ResolveNew", args->_context, [&](gpu::Batch& batch) { batch.blit(srcFbo, rectSrc, _outputFramebuffer, rectSrc); });
|
||||
|
||||
outputs = _outputFramebuffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExtractFrustums::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& output) {
|
||||
assert(renderContext->args);
|
||||
assert(renderContext->args->_context);
|
||||
|
||||
|
|
|
@ -90,6 +90,28 @@ public:
|
|||
void run(const render::RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer);
|
||||
};
|
||||
|
||||
|
||||
class ResolveFramebuffer {
|
||||
public:
|
||||
using Inputs = render::VaryingSet2<gpu::FramebufferPointer, gpu::FramebufferPointer>;
|
||||
using Outputs = gpu::FramebufferPointer;
|
||||
using JobModel = render::Job::ModelIO<ResolveFramebuffer, Inputs, Outputs>;
|
||||
|
||||
void run(const render::RenderContextPointer& renderContext, const Inputs& source, Outputs& dest);
|
||||
};
|
||||
|
||||
class ResolveNewFramebuffer {
|
||||
public:
|
||||
using Inputs = gpu::FramebufferPointer;
|
||||
using Outputs = gpu::FramebufferPointer;
|
||||
using JobModel = render::Job::ModelIO<ResolveNewFramebuffer, Inputs, Outputs>;
|
||||
|
||||
void run(const render::RenderContextPointer& renderContext, const Inputs& source, Outputs& dest);
|
||||
private:
|
||||
gpu::FramebufferPointer _outputFramebuffer;
|
||||
};
|
||||
|
||||
|
||||
class ExtractFrustums {
|
||||
public:
|
||||
|
||||
|
|
|
@ -129,10 +129,16 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
|
|||
task.addJob<DebugZoneLighting>("DrawZoneStack", debugZoneInputs);
|
||||
}
|
||||
|
||||
// Just resolve the msaa
|
||||
/* const auto resolveInputs =
|
||||
ResolveFramebuffer::Inputs(framebuffer, static_cast<gpu::FramebufferPointer>(nullptr)).asVarying();
|
||||
auto resolvedFramebuffer = task.addJob<ResolveFramebuffer>("Resolve", resolveInputs); */
|
||||
auto resolvedFramebuffer = task.addJob<ResolveNewFramebuffer>("Resolve", framebuffer);
|
||||
|
||||
// Lighting Buffer ready for tone mapping
|
||||
// Forward rendering on GLES doesn't support tonemapping to and from the same FBO, so we specify
|
||||
// the output FBO as null, which causes the tonemapping to target the blit framebuffer
|
||||
const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast<gpu::FramebufferPointer>(nullptr) ).asVarying();
|
||||
const auto toneMappingInputs = ToneMappingDeferred::Inputs(resolvedFramebuffer, static_cast<gpu::FramebufferPointer>(nullptr)).asVarying();
|
||||
task.addJob<ToneMappingDeferred>("ToneMapping", toneMappingInputs);
|
||||
|
||||
// Layered Overlays
|
||||
|
@ -144,26 +150,32 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
|
|||
// task.addJob<Blit>("Blit", framebuffer);
|
||||
}
|
||||
|
||||
void PrepareFramebuffer::configure(const Config& config) {
|
||||
_numSamples = config.getNumSamples();
|
||||
}
|
||||
|
||||
void PrepareFramebuffer::run(const RenderContextPointer& renderContext, gpu::FramebufferPointer& framebuffer) {
|
||||
glm::uvec2 frameSize(renderContext->args->_viewport.z, renderContext->args->_viewport.w);
|
||||
|
||||
// Resizing framebuffers instead of re-building them seems to cause issues with threaded rendering
|
||||
if (_framebuffer && _framebuffer->getSize() != frameSize) {
|
||||
if (_framebuffer && (_framebuffer->getSize() != frameSize || _framebuffer->getNumSamples() != _numSamples)) {
|
||||
_framebuffer.reset();
|
||||
}
|
||||
|
||||
if (!_framebuffer) {
|
||||
_framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("forward"));
|
||||
|
||||
int numSamples = _numSamples;
|
||||
|
||||
auto colorFormat = gpu::Element::COLOR_SRGBA_32;
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT);
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR);
|
||||
auto colorTexture =
|
||||
gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
gpu::Texture::createRenderBufferMultisample(colorFormat, frameSize.x, frameSize.y, numSamples, defaultSampler);
|
||||
_framebuffer->setRenderBuffer(0, colorTexture);
|
||||
|
||||
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format
|
||||
auto depthTexture =
|
||||
gpu::Texture::createRenderBuffer(depthFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
gpu::Texture::createRenderBufferMultisample(depthFormat, frameSize.x, frameSize.y, numSamples, defaultSampler);
|
||||
_framebuffer->setDepthStencilBuffer(depthTexture, depthFormat);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,37 @@ public:
|
|||
void build(JobModel& task, const render::Varying& input, render::Varying& output);
|
||||
};
|
||||
|
||||
|
||||
class PrepareFramebufferConfig : public render::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty)
|
||||
public:
|
||||
int getNumSamples() const { return numSamples; }
|
||||
void setNumSamples(int num) {
|
||||
numSamples = std::max(1, std::min(32, num));
|
||||
emit dirty();
|
||||
}
|
||||
|
||||
signals:
|
||||
void dirty();
|
||||
|
||||
protected:
|
||||
int numSamples{ 4 };
|
||||
};
|
||||
|
||||
class PrepareFramebuffer {
|
||||
public:
|
||||
using Inputs = gpu::FramebufferPointer;
|
||||
using JobModel = render::Job::ModelO<PrepareFramebuffer, Inputs>;
|
||||
using Config = PrepareFramebufferConfig;
|
||||
using JobModel = render::Job::ModelO<PrepareFramebuffer, Inputs, Config>;
|
||||
|
||||
void configure(const Config& config);
|
||||
void run(const render::RenderContextPointer& renderContext,
|
||||
gpu::FramebufferPointer& framebuffer);
|
||||
|
||||
private:
|
||||
gpu::FramebufferPointer _framebuffer;
|
||||
int _numSamples;
|
||||
};
|
||||
|
||||
class PrepareForward {
|
||||
|
|
Loading…
Reference in a new issue