Commit: 06fd4c3617c5398807230d68533928fc06d3328a Author: Omar Emara Date: Wed Nov 17 21:11:45 2021 +0200 Branches: viewport-compositor https://developer.blender.org/rB06fd4c3617c5398807230d68533928fc06d3328a
Viewport Compositor: Port Difference Key node This patch ports the Difference 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_difference_matte.glsl M source/blender/nodes/composite/nodes/node_composite_diffMatte.cc =================================================================== diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 5d99f14dc6b..3dfedf13d8e 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -294,6 +294,7 @@ data_to_c_simple(shaders/composite/gpu_shader_composite_color_matte.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_color_spill.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_color_to_luminance.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_composite.glsl SRC) +data_to_c_simple(shaders/composite/gpu_shader_composite_difference_matte.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_ellipse_mask.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_exposure.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_gamma.glsl SRC) diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c index f44abf4ee60..b553b62b77f 100644 --- a/source/blender/gpu/intern/gpu_material_library.c +++ b/source/blender/gpu/intern/gpu_material_library.c @@ -60,6 +60,7 @@ extern char datatoc_gpu_shader_composite_color_matte_glsl[]; extern char datatoc_gpu_shader_composite_color_spill_glsl[]; extern char datatoc_gpu_shader_composite_color_to_luminance_glsl[]; extern char datatoc_gpu_shader_composite_composite_glsl[]; +extern char datatoc_gpu_shader_composite_difference_matte_glsl[]; extern char datatoc_gpu_shader_composite_ellipse_mask_glsl[]; extern char datatoc_gpu_shader_composite_exposure_glsl[]; extern char datatoc_gpu_shader_composite_gamma_glsl[]; @@ -255,6 +256,11 @@ static GPUMaterialLibrary gpu_shader_composite_composite_library = { .dependencies = {NULL}, }; +static GPUMaterialLibrary gpu_shader_composite_difference_matte_library = { + .code = datatoc_gpu_shader_composite_difference_matte_glsl, + .dependencies = {NULL}, +}; + static GPUMaterialLibrary gpu_shader_composite_ellipse_mask_library = { .code = datatoc_gpu_shader_composite_ellipse_mask_glsl, .dependencies = {NULL}, @@ -831,6 +837,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = { &gpu_shader_composite_color_spill_library, &gpu_shader_composite_color_to_luminance_library, &gpu_shader_composite_composite_library, + &gpu_shader_composite_difference_matte_library, &gpu_shader_composite_ellipse_mask_library, &gpu_shader_composite_exposure_library, &gpu_shader_composite_gamma_library, diff --git a/source/blender/gpu/shaders/composite/gpu_shader_composite_difference_matte.glsl b/source/blender/gpu/shaders/composite/gpu_shader_composite_difference_matte.glsl new file mode 100644 index 00000000000..d769cadce3c --- /dev/null +++ b/source/blender/gpu/shaders/composite/gpu_shader_composite_difference_matte.glsl @@ -0,0 +1,10 @@ +void node_composite_difference_matte( + vec4 color, vec4 key, float tolerance, float falloff, out vec4 result, out float matte) +{ + vec4 difference = abs(color - key); + float average_difference = (difference.r + difference.g + difference.b) / 3.0; + bool is_opaque = average_difference > tolerance + falloff; + float alpha = is_opaque ? color.a : (max(0.0, average_difference - tolerance) / falloff); + matte = min(alpha, color.a); + result = color * matte; +} diff --git a/source/blender/nodes/composite/nodes/node_composite_diffMatte.cc b/source/blender/nodes/composite/nodes/node_composite_diffMatte.cc index 1e1a48381b7..6eb66be466d 100644 --- a/source/blender/nodes/composite/nodes/node_composite_diffMatte.cc +++ b/source/blender/nodes/composite/nodes/node_composite_diffMatte.cc @@ -44,6 +44,23 @@ static void node_composit_init_diff_matte(bNodeTree *UNUSED(ntree), bNode *node) c->t2 = 0.1f; } +static int node_composite_gpu_diff_matte(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + const NodeChroma *data = (NodeChroma *)node->storage; + + return GPU_stack_link(mat, + node, + "node_composite_difference_matte", + in, + out, + GPU_uniform(&data->t1), + GPU_uniform(&data->t2)); +} + void register_node_type_cmp_diff_matte(void) { static bNodeType ntype; @@ -53,6 +70,7 @@ void register_node_type_cmp_diff_matte(void) node_type_socket_templates(&ntype, cmp_node_diff_matte_in, cmp_node_diff_matte_out); node_type_init(&ntype, node_composit_init_diff_matte); node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_composite_gpu_diff_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