Commit: f18c18ae5285e8c7663af910b191e4b4908de07b
Author: Omar Emara
Date:   Wed Nov 17 20:37:54 2021 +0200
Branches: viewport-compositor
https://developer.blender.org/rBf18c18ae5285e8c7663af910b191e4b4908de07b

Viewport Compositor: Port Color Spill node

This patch ports the Color Spill 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_color_spill.glsl
M       source/blender/nodes/composite/nodes/node_composite_colorSpill.cc

===================================================================

diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 4bb1a508afc..5d99f14dc6b 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -291,6 +291,7 @@ 
data_to_c_simple(shaders/composite/gpu_shader_composite_chroma_matte.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)
 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_ellipse_mask.glsl SRC)
diff --git a/source/blender/gpu/intern/gpu_material_library.c 
b/source/blender/gpu/intern/gpu_material_library.c
index 9b7588c9912..f44abf4ee60 100644
--- a/source/blender/gpu/intern/gpu_material_library.c
+++ b/source/blender/gpu/intern/gpu_material_library.c
@@ -57,6 +57,7 @@ extern char datatoc_gpu_shader_composite_chroma_matte_glsl[];
 extern char datatoc_gpu_shader_composite_color_balance_glsl[];
 extern char datatoc_gpu_shader_composite_color_correction_glsl[];
 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_ellipse_mask_glsl[];
@@ -239,6 +240,11 @@ static GPUMaterialLibrary 
gpu_shader_composite_color_matte_library = {
     .dependencies = {&gpu_shader_common_color_util_library, NULL},
 };
 
+static GPUMaterialLibrary gpu_shader_composite_color_spill_library = {
+    .code = datatoc_gpu_shader_composite_color_spill_glsl,
+    .dependencies = {NULL},
+};
+
 static GPUMaterialLibrary gpu_shader_composite_color_to_luminance_library = {
     .code = datatoc_gpu_shader_composite_color_to_luminance_glsl,
     .dependencies = {&gpu_shader_common_color_util_library, NULL},
@@ -822,6 +828,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = {
     &gpu_shader_composite_color_balance_library,
     &gpu_shader_composite_color_correction_library,
     &gpu_shader_composite_color_matte_library,
+    &gpu_shader_composite_color_spill_library,
     &gpu_shader_composite_color_to_luminance_library,
     &gpu_shader_composite_composite_library,
     &gpu_shader_composite_ellipse_mask_library,
diff --git 
a/source/blender/gpu/shaders/composite/gpu_shader_composite_color_spill.glsl 
b/source/blender/gpu/shaders/composite/gpu_shader_composite_color_spill.glsl
new file mode 100644
index 00000000000..3a747b6972d
--- /dev/null
+++ b/source/blender/gpu/shaders/composite/gpu_shader_composite_color_spill.glsl
@@ -0,0 +1,13 @@
+void node_composite_color_spill(vec4 color,
+                                float factor,
+                                float spill_channel,
+                                vec3 spill_scale,
+                                vec2 limit_channels,
+                                float limit_scale,
+                                out vec4 result)
+{
+  float average_limit = (color[int(limit_channels.x)] + 
color[int(limit_channels.y)]) / 2.0;
+  float map = factor * color[int(spill_channel)] - limit_scale * average_limit;
+  result.rgb = map > 0.0 ? color.rgb + spill_scale * map : color.rgb;
+  result.a = color.a;
+}
diff --git a/source/blender/nodes/composite/nodes/node_composite_colorSpill.cc 
b/source/blender/nodes/composite/nodes/node_composite_colorSpill.cc
index 7bdc2e8289e..c918090201c 100644
--- a/source/blender/nodes/composite/nodes/node_composite_colorSpill.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_colorSpill.cc
@@ -46,6 +46,48 @@ static void node_composit_init_color_spill(bNodeTree 
*UNUSED(ntree), bNode *node
   ncs->unspill = 0;     /* do not use unspill */
 }
 
+static int node_composite_gpu_color_spill(GPUMaterial *mat,
+                                          bNode *node,
+                                          bNodeExecData *UNUSED(execdata),
+                                          GPUNodeStack *in,
+                                          GPUNodeStack *out)
+{
+  const NodeColorspill *data = (NodeColorspill *)node->storage;
+
+  const float spill_channel = (float)(node->custom1 - 1);
+  float spill_scale[3] = {data->uspillr, data->uspillg, data->uspillb};
+  spill_scale[node->custom1 - 1] *= -1.0f;
+  if (data->unspill == 0) {
+    spill_scale[0] = 0.0f;
+    spill_scale[1] = 0.0f;
+    spill_scale[2] = 0.0f;
+    spill_scale[node->custom1 - 1] = -1.0f;
+  }
+
+  /* Always assume the limit method to be average, and for the single method, 
assign the same
+   * channel to both limit channels. */
+  float limit_channels[2];
+  if (node->custom2 == 0) {
+    limit_channels[0] = (float)data->limchan;
+    limit_channels[1] = (float)data->limchan;
+  }
+  else {
+    limit_channels[0] = (float)(node->custom1 % 3);
+    limit_channels[1] = (float)((node->custom1 + 1) % 3);
+  }
+  const float limit_scale = data->limscale;
+
+  return GPU_stack_link(mat,
+                        node,
+                        "node_composite_color_spill",
+                        in,
+                        out,
+                        GPU_uniform(&spill_channel),
+                        GPU_uniform(spill_scale),
+                        GPU_uniform(limit_channels),
+                        GPU_uniform(&limit_scale));
+}
+
 void register_node_type_cmp_color_spill(void)
 {
   static bNodeType ntype;
@@ -55,6 +97,7 @@ void register_node_type_cmp_color_spill(void)
   node_type_init(&ntype, node_composit_init_color_spill);
   node_type_storage(
       &ntype, "NodeColorspill", node_free_standard_storage, 
node_copy_standard_storage);
+  node_type_gpu(&ntype, node_composite_gpu_color_spill);
 
   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

Reply via email to