Realtime Compositor: Use luminance coefficients in SMAA

This patch utilizes luminance coefficients in the SMAA edge detection
phase to match the existing implementation in the CPU compositor.
This commit is contained in:
Omar Emara
2023-03-27 09:10:51 +02:00
parent c42370d577
commit 3d06905ac4
2 changed files with 8 additions and 1 deletions
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "IMB_colormanagement.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
@@ -20,6 +22,10 @@ static Result detect_edges(Context &context,
GPUShader *shader = context.shader_manager().get("compositor_smaa_edge_detection");
GPU_shader_bind(shader);
float luminance_coefficients[3];
IMB_colormanagement_get_luminance_coefficients(luminance_coefficients);
GPU_shader_uniform_3fv(shader, "luminance_coefficients", luminance_coefficients);
GPU_shader_uniform_1f(shader, "smaa_threshold", threshold);
GPU_shader_uniform_1f(
shader, "smaa_local_contrast_adaptation_factor", local_contrast_adaptation_factor);
@@ -5,11 +5,12 @@
GPU_SHADER_CREATE_INFO(compositor_smaa_edge_detection)
.local_group_size(16, 16)
.define("SMAA_GLSL_3")
.define("SMAA_LUMA_WEIGHT", "float4(1.0, 1.0, 1.0, 1.0)")
.define("SMAA_RT_METRICS",
"vec4(1.0 / vec2(textureSize(input_tx, 0)), vec2(textureSize(input_tx, 0)))")
.define("SMAA_LUMA_WEIGHT", "vec4(luminance_coefficients, 0.0)")
.define("SMAA_THRESHOLD", "smaa_threshold")
.define("SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR", "smaa_local_contrast_adaptation_factor")
.push_constant(Type::VEC3, "luminance_coefficients")
.push_constant(Type::FLOAT, "smaa_threshold")
.push_constant(Type::FLOAT, "smaa_local_contrast_adaptation_factor")
.sampler(0, ImageType::FLOAT_2D, "input_tx")