Commit: 422a556eacc65a2928bda4cf9a84dba09a09bf78 Author: Omar Emara Date: Wed Nov 17 22:07:03 2021 +0200 Branches: viewport-compositor https://developer.blender.org/rB422a556eacc65a2928bda4cf9a84dba09a09bf78
Viewport Compositor: Port Luminance Key node This patch ports the Luminance Key node to the viewport compositor. The shader is a straightforward port of the compositor code. =================================================================== M source/blender/gpu/CMakeLists.txt M source/blender/gpu/intern/gpu_material_library.c A source/blender/gpu/shaders/composite/gpu_shader_composite_luminance_matte.glsl M source/blender/nodes/composite/nodes/node_composite_lummaMatte.cc =================================================================== diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 8a66dddda53..a8a746d62f1 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -303,6 +303,7 @@ data_to_c_simple(shaders/composite/gpu_shader_composite_hue_correct.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_hue_saturation_value.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_image.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_invert.glsl SRC) +data_to_c_simple(shaders/composite/gpu_shader_composite_luminance_matte.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_map_value.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_normal.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_posterize.glsl SRC) diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c index c0d16b3f480..debe6921818 100644 --- a/source/blender/gpu/intern/gpu_material_library.c +++ b/source/blender/gpu/intern/gpu_material_library.c @@ -69,6 +69,7 @@ extern char datatoc_gpu_shader_composite_hue_correct_glsl[]; extern char datatoc_gpu_shader_composite_hue_saturation_value_glsl[]; extern char datatoc_gpu_shader_composite_image_glsl[]; extern char datatoc_gpu_shader_composite_invert_glsl[]; +extern char datatoc_gpu_shader_composite_luminance_matte_glsl[]; extern char datatoc_gpu_shader_composite_map_value_glsl[]; extern char datatoc_gpu_shader_composite_normal_glsl[]; extern char datatoc_gpu_shader_composite_posterize_glsl[]; @@ -302,6 +303,11 @@ static GPUMaterialLibrary gpu_shader_composite_invert_library = { .dependencies = {NULL}, }; +static GPUMaterialLibrary gpu_shader_composite_luminance_matte_library = { + .code = datatoc_gpu_shader_composite_luminance_matte_glsl, + .dependencies = {&gpu_shader_common_color_util_library, NULL}, +}; + static GPUMaterialLibrary gpu_shader_composite_map_value_library = { .code = datatoc_gpu_shader_composite_map_value_glsl, .dependencies = {NULL}, @@ -852,6 +858,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = { &gpu_shader_composite_hue_saturation_value_library, &gpu_shader_composite_image_library, &gpu_shader_composite_invert_library, + &gpu_shader_composite_luminance_matte_library, &gpu_shader_composite_map_value_library, &gpu_shader_composite_normal_library, &gpu_shader_composite_posterize_library, diff --git a/source/blender/gpu/shaders/composite/gpu_shader_composite_luminance_matte.glsl b/source/blender/gpu/shaders/composite/gpu_shader_composite_luminance_matte.glsl new file mode 100644 index 00000000000..1e5ed0f064d --- /dev/null +++ b/source/blender/gpu/shaders/composite/gpu_shader_composite_luminance_matte.glsl @@ -0,0 +1,12 @@ +void node_composite_luminance_matte(vec4 color, + const vec3 luminance_coefficients, + float high, + float low, + out vec4 result, + out float matte) +{ + float luminance = get_luminance(color.rgb, luminance_coefficients); + float alpha = clamp(0.0, 1.0, (luminance - low) / (high - low)); + matte = min(alpha, color.a); + result = color * matte; +} diff --git a/source/blender/nodes/composite/nodes/node_composite_lummaMatte.cc b/source/blender/nodes/composite/nodes/node_composite_lummaMatte.cc index 600406d22b9..0749104408e 100644 --- a/source/blender/nodes/composite/nodes/node_composite_lummaMatte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_lummaMatte.cc @@ -21,6 +21,7 @@ * \ingroup cmpnodes */ +#include "IMB_colormanagement.h" #include "node_composite_util.hh" /* ******************* Luma Matte Node ********************************* */ @@ -43,6 +44,27 @@ static void node_composit_init_luma_matte(bNodeTree *UNUSED(ntree), bNode *node) c->t2 = 0.0f; } +static int node_composite_gpu_luma_matte(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + const NodeChroma *data = (NodeChroma *)node->storage; + + float luminance_coefficients[3]; + IMB_colormanagement_get_luminance_coefficients(luminance_coefficients); + + return GPU_stack_link(mat, + node, + "node_composite_luminance_matte", + in, + out, + GPU_constant(luminance_coefficients), + GPU_uniform(&data->t1), + GPU_uniform(&data->t2)); +} + void register_node_type_cmp_luma_matte(void) { static bNodeType ntype; @@ -51,6 +73,7 @@ void register_node_type_cmp_luma_matte(void) node_type_socket_templates(&ntype, cmp_node_luma_matte_in, cmp_node_luma_matte_out); node_type_init(&ntype, node_composit_init_luma_matte); node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_composite_gpu_luma_matte); nodeRegisterType(&ntype); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs