[Bf-blender-cvs] [289852dfb51] viewport-compositor: Viewport Compositor: Port Map Value node
Omar Emara
noreply at git.blender.org
Tue Dec 28 20:02:44 CET 2021
Commit: 289852dfb51041176c3fdde2ac752ea0a7b681ec
Author: Omar Emara
Date: Sat Nov 13 20:30:35 2021 +0200
Branches: viewport-compositor
https://developer.blender.org/rB289852dfb51041176c3fdde2ac752ea0a7b681ec
Viewport Compositor: Port Map Value node
This patch ports the Map Value node to the viewport compositor. The
shader is a straightforward port of the compositor code.
===================================================================
M source/blender/gpu/shaders/composite/gpu_shader_composite_map_value.glsl
M source/blender/nodes/composite/nodes/node_composite_mapValue.cc
===================================================================
diff --git a/source/blender/gpu/shaders/composite/gpu_shader_composite_map_value.glsl b/source/blender/gpu/shaders/composite/gpu_shader_composite_map_value.glsl
index 3f8d269339d..9694c92b27e 100644
--- a/source/blender/gpu/shaders/composite/gpu_shader_composite_map_value.glsl
+++ b/source/blender/gpu/shaders/composite/gpu_shader_composite_map_value.glsl
@@ -33,3 +33,23 @@ void node_composite_map_range(float value,
}
}
}
+
+void node_composite_map_value(float value,
+ float offset,
+ float size,
+ const float use_min,
+ float min,
+ const float use_max,
+ float max,
+ out float result)
+{
+ result = (value + offset) * size;
+
+ if (use_min != 0.0 && result < min) {
+ result = min;
+ }
+
+ if (use_max != 0.0 && result > max) {
+ result = max;
+ }
+}
diff --git a/source/blender/nodes/composite/nodes/node_composite_mapValue.cc b/source/blender/nodes/composite/nodes/node_composite_mapValue.cc
index 25c00c2ba13..21a2f6397f8 100644
--- a/source/blender/nodes/composite/nodes/node_composite_mapValue.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_mapValue.cc
@@ -38,6 +38,30 @@ static void node_composit_init_map_value(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = BKE_texture_mapping_add(TEXMAP_TYPE_POINT);
}
+static int node_composite_gpu_map_value(GPUMaterial *mat,
+ bNode *node,
+ bNodeExecData *UNUSED(execdata),
+ GPUNodeStack *in,
+ GPUNodeStack *out)
+{
+ const TexMapping *texture_mapping = (TexMapping *)node->storage;
+
+ const float use_min = texture_mapping->flag & TEXMAP_CLIP_MIN ? 1.0f : 0.0f;
+ const float use_max = texture_mapping->flag & TEXMAP_CLIP_MAX ? 1.0f : 0.0f;
+
+ return GPU_stack_link(mat,
+ node,
+ "node_composite_map_value",
+ in,
+ out,
+ GPU_uniform(texture_mapping->loc),
+ GPU_uniform(texture_mapping->size),
+ GPU_constant(&use_min),
+ GPU_uniform(texture_mapping->min),
+ GPU_constant(&use_max),
+ GPU_uniform(texture_mapping->max));
+}
+
void register_node_type_cmp_map_value(void)
{
static bNodeType ntype;
@@ -46,6 +70,7 @@ void register_node_type_cmp_map_value(void)
node_type_socket_templates(&ntype, cmp_node_map_value_in, cmp_node_map_value_out);
node_type_init(&ntype, node_composit_init_map_value);
node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage);
+ node_type_gpu(&ntype, node_composite_gpu_map_value);
nodeRegisterType(&ntype);
}
More information about the Bf-blender-cvs
mailing list