Commit: a3c16b6279cc247747e9b17e226d988565cb1f6b Author: Omar Emara Date: Sun Nov 14 20:06:57 2021 +0200 Branches: viewport-compositor https://developer.blender.org/rBa3c16b6279cc247747e9b17e226d988565cb1f6b
Viewport Compositor: Port Box Mask node This patch ports the Box Mask node to the viewport compositor. =================================================================== M source/blender/gpu/CMakeLists.txt M source/blender/gpu/intern/gpu_material_library.c A source/blender/gpu/shaders/composite/gpu_shader_composite_box_mask.glsl M source/blender/nodes/composite/nodes/node_composite_boxmask.cc =================================================================== diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 976f8c78dd0..1d2b5b1c8dc 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -284,6 +284,7 @@ data_to_c_simple(shaders/common/gpu_shader_common_mix_rgb.glsl SRC) data_to_c_simple(shaders/common/gpu_shader_common_hash.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_alpha_over.glsl SRC) +data_to_c_simple(shaders/composite/gpu_shader_composite_box_mask.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_bright_contrast.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_color_balance.glsl SRC) data_to_c_simple(shaders/composite/gpu_shader_composite_color_correction.glsl SRC) diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c index ec51c003741..3cb9e586d12 100644 --- a/source/blender/gpu/intern/gpu_material_library.c +++ b/source/blender/gpu/intern/gpu_material_library.c @@ -50,6 +50,7 @@ extern char datatoc_gpu_shader_common_mix_rgb_glsl[]; extern char datatoc_gpu_shader_common_hash_glsl[]; extern char datatoc_gpu_shader_composite_alpha_over_glsl[]; +extern char datatoc_gpu_shader_composite_box_mask_glsl[]; extern char datatoc_gpu_shader_composite_bright_contrast_glsl[]; extern char datatoc_gpu_shader_composite_color_balance_glsl[]; extern char datatoc_gpu_shader_composite_color_correction_glsl[]; @@ -191,6 +192,11 @@ static GPUMaterialLibrary gpu_shader_composite_alpha_over_library = { .dependencies = {NULL}, }; +static GPUMaterialLibrary gpu_shader_composite_box_mask_library = { + .code = datatoc_gpu_shader_composite_box_mask_glsl, + .dependencies = {NULL}, +}; + static GPUMaterialLibrary gpu_shader_composite_bright_contrast_library = { .code = datatoc_gpu_shader_composite_bright_contrast_glsl, .dependencies = {&gpu_shader_common_math_util_library, @@ -783,6 +789,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = { &gpu_shader_material_wireframe_library, &gpu_shader_material_world_normals_library, &gpu_shader_composite_alpha_over_library, + &gpu_shader_composite_box_mask_library, &gpu_shader_composite_bright_contrast_library, &gpu_shader_composite_color_balance_library, &gpu_shader_composite_color_correction_library, diff --git a/source/blender/gpu/shaders/composite/gpu_shader_composite_box_mask.glsl b/source/blender/gpu/shaders/composite/gpu_shader_composite_box_mask.glsl new file mode 100644 index 00000000000..c9263969f94 --- /dev/null +++ b/source/blender/gpu/shaders/composite/gpu_shader_composite_box_mask.glsl @@ -0,0 +1,41 @@ +#define CMP_NODE_MASKTYPE_ADD 0.0 +#define CMP_NODE_MASKTYPE_SUBTRACT 1.0 +#define CMP_NODE_MASKTYPE_MULTIPLY 2.0 +#define CMP_NODE_MASKTYPE_NOT 3.0 + +void node_composite_box_mask(float in_mask, + float value, + const float mask_type, + float x_location, + float y_location, + float half_width, + float half_height, + float cos_angle, + float sin_angle, + out float out_mask) +{ + vec2 uv = g_data.uv_render_layer.xy; + uv -= vec2(x_location, y_location); + uv.y *= ViewportSize.y / ViewportSize.x; + uv = mat2(cos_angle, -sin_angle, sin_angle, cos_angle) * uv; + uv = abs(uv); + bool is_inside = uv.x < half_width && uv.y < half_height; + + if (mask_type == CMP_NODE_MASKTYPE_ADD) { + out_mask = is_inside ? max(in_mask, value) : in_mask; + } + else if (mask_type == CMP_NODE_MASKTYPE_SUBTRACT) { + out_mask = is_inside ? clamp(in_mask - value, 0.0, 1.0) : in_mask; + } + else if (mask_type == CMP_NODE_MASKTYPE_MULTIPLY) { + out_mask = is_inside ? in_mask * value : 0.0; + } + else if (mask_type == CMP_NODE_MASKTYPE_NOT) { + out_mask = is_inside ? (in_mask > 0.0 ? 0.0 : value) : in_mask; + } +} + +#undef CMP_NODE_MASKTYPE_ADD +#undef CMP_NODE_MASKTYPE_SUBTRACT +#undef CMP_NODE_MASKTYPE_MULTIPLY +#undef CMP_NODE_MASKTYPE_NOT diff --git a/source/blender/nodes/composite/nodes/node_composite_boxmask.cc b/source/blender/nodes/composite/nodes/node_composite_boxmask.cc index cdf96065f97..26d76eed908 100644 --- a/source/blender/nodes/composite/nodes/node_composite_boxmask.cc +++ b/source/blender/nodes/composite/nodes/node_composite_boxmask.cc @@ -21,6 +21,8 @@ * \ingroup cmpnodes */ +#include <cmath> + #include "../node_composite_util.hh" /* **************** SCALAR MATH ******************** */ @@ -43,6 +45,34 @@ static void node_composit_init_boxmask(bNodeTree *UNUSED(ntree), bNode *node) node->storage = data; } +static int node_composite_gpu_boxmask(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + const NodeBoxMask *data = (NodeBoxMask *)node->storage; + + const float mask_type = (float)node->custom1; + const float cos_angle = std::cos(data->rotation); + const float sin_angle = std::sin(data->rotation); + const float half_width = data->width / 2.0; + const float half_height = data->height / 2.0; + + return GPU_stack_link(mat, + node, + "node_composite_box_mask", + in, + out, + GPU_constant(&mask_type), + GPU_uniform(&data->x), + GPU_uniform(&data->y), + GPU_uniform(&half_width), + GPU_uniform(&half_height), + GPU_uniform(&cos_angle), + GPU_uniform(&sin_angle)); +} + void register_node_type_cmp_boxmask(void) { static bNodeType ntype; @@ -51,6 +81,7 @@ void register_node_type_cmp_boxmask(void) node_type_socket_templates(&ntype, cmp_node_boxmask_in, cmp_node_boxmask_out); node_type_init(&ntype, node_composit_init_boxmask); node_type_storage(&ntype, "NodeBoxMask", node_free_standard_storage, node_copy_standard_storage); + node_type_gpu(&ntype, node_composite_gpu_boxmask); 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