Working threshold mask and debug on Bloom

This commit is contained in:
Olivier Prat 2017-10-09 11:09:51 +02:00
parent 98d39ff9e0
commit 50ab73009a
3 changed files with 32 additions and 27 deletions

View file

@ -70,21 +70,20 @@ void ThresholdAndDownsampleJob::run(const render::RenderContextPointer& renderCo
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
batch.enableStereo(false);
/* batch.setViewportTransform(halfViewport);
batch.setViewportTransform(halfViewport);
batch.setProjectionTransform(glm::mat4());
batch.resetViewTransform();
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(inputFrameBuffer->getSize(), args->_viewport));
batch.setPipeline(_pipeline);*/
batch.setPipeline(_pipeline);
batch.setFramebuffer(_downsampledBuffer);
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, gpu::Vec4(1.0f, 0.2f, 0.9f, 1.f));
/*batch.setResourceTexture(COLOR_MAP_SLOT, inputColor);
batch.setResourceTexture(COLOR_MAP_SLOT, inputColor);
batch._glUniform1f(THRESHOLD_SLOT, _threshold);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setViewportTransform(args->_viewport);
batch.setResourceTexture(COLOR_MAP_SLOT, nullptr);
batch.setFramebuffer(nullptr);*/
batch.setFramebuffer(nullptr);
});
outputs = _downsampledBuffer;
@ -102,13 +101,14 @@ void DebugBloom::run(const render::RenderContextPointer& renderContext, const In
RenderArgs* args = renderContext->args;
const auto frameBuffer = inputs.get0();
const auto framebufferSize = frameBuffer->getSize();
const auto level0FB = inputs.get1();
const gpu::TexturePointer levelTextures[1] = {
level0FB->getRenderBuffer(0)
};
if (!_pipeline) {
auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS();
auto ps = gpu::StandardShaderLib::getDrawTextureOpaquePS();
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
@ -123,19 +123,16 @@ void DebugBloom::run(const render::RenderContextPointer& renderContext, const In
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
batch.enableStereo(false);
//batch.setFramebuffer(frameBuffer);
batch.setViewportTransform(args->_viewport);
batch.setFramebuffer(frameBuffer);
batch.setViewportTransform(args->_viewport);
batch.setProjectionTransform(glm::mat4());
batch.resetViewTransform();
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(glm::ivec2(framebufferSize.x, framebufferSize.y), args->_viewport));
glm::mat4 projMat;
Transform viewMat;
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat, false);
batch.setPipeline(_pipeline);
batch.setResourceTexture(0, levelTextures[0]);
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(0, nullptr);
});
}
@ -162,7 +159,9 @@ void Bloom::configure(const Config& config) {
void Bloom::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs) {
const auto halfSizeBuffer = task.addJob<ThresholdAndDownsampleJob>("BloomThreshold", inputs);
const auto& input = inputs.get<Inputs>();
const auto& frameBuffer = input[1];
const auto debugInput = DebugBloom::Inputs(inputs.get<Bloom::Inputs>().get1(), halfSizeBuffer).asVarying();
const auto debugInput = DebugBloom::Inputs(frameBuffer, halfSizeBuffer).asVarying();
task.addJob<DebugBloom>("DebugBloom", debugInput);
}

View file

@ -22,19 +22,25 @@ void main(void) {
vec4 greens = textureGather(colorMap, varTexCoord0, 1);
vec4 blues = textureGather(colorMap, varTexCoord0, 2);
float hardness = 8;
vec4 rMask = clamp((reds-threshold) * hardness, 0, 1);
vec4 gMask = clamp((greens-threshold) * hardness, 0, 1);
vec4 bMask = clamp((blues-threshold) * hardness, 0, 1);
reds = smoothstep(vec4(0,0,0,0), reds, rMask);
greens = smoothstep(vec4(0,0,0,0), greens, gMask);
blues = smoothstep(vec4(0,0,0,0), blues, bMask);
vec3 texel0 = vec3(reds.x, greens.x, blues.x);
vec3 texel1 = vec3(reds.y, greens.y, blues.y);
vec3 texel2 = vec3(reds.z, greens.z, blues.z);
vec3 texel3 = vec3(reds.w, greens.w, blues.w);
outFragColor = vec4((texel0+texel1+texel2+texel3)/4.0, 1.0);
vec4 luminances;
vec3 luminanceWeights = vec3(0.3,0.5,0.2);
luminances.x = dot(texel0, luminanceWeights);
luminances.y = dot(texel1, luminanceWeights);
luminances.z = dot(texel2, luminanceWeights);
luminances.w = dot(texel0, luminanceWeights);
float hardness = 8;
vec4 mask = clamp((luminances-threshold) * hardness, 0, 1);
vec3 color;
color.x = dot(mask, reds);
color.y = dot(mask, greens);
color.z = dot(mask, blues);
outFragColor = vec4(color/4.0, 1.0);
}

View file

@ -161,7 +161,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).asVarying();
task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
// LIght Cluster Grid Debuging job
// Light Cluster Grid Debuging job
{
const auto debugLightClustersInputs = DebugLightClusters::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, linearDepthTarget, lightClusters).asVarying();
task.addJob<DebugLightClusters>("DebugLightClusters", debugLightClustersInputs);