From 3d06905ac45dc6ebce681b6d33e1dc3994a54569 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Mon, 27 Mar 2023 09:10:51 +0200 Subject: [PATCH] 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. --- .../realtime_compositor/algorithms/intern/smaa.cc | 6 ++++++ .../shaders/infos/compositor_smaa_info.hh | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/blender/compositor/realtime_compositor/algorithms/intern/smaa.cc b/source/blender/compositor/realtime_compositor/algorithms/intern/smaa.cc index 7e11b7de3a7..734aef760bb 100644 --- a/source/blender/compositor/realtime_compositor/algorithms/intern/smaa.cc +++ b/source/blender/compositor/realtime_compositor/algorithms/intern/smaa.cc @@ -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); diff --git a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_smaa_info.hh b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_smaa_info.hh index 05ded7f125f..1db6169b296 100644 --- a/source/blender/compositor/realtime_compositor/shaders/infos/compositor_smaa_info.hh +++ b/source/blender/compositor/realtime_compositor/shaders/infos/compositor_smaa_info.hh @@ -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")