Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jolly <charlie>2021-12-14 00:20:07 +0300
committerCharlie Jolly <mistajolly@gmail.com>2021-12-14 21:27:01 +0300
commit5b61737a8f41688699fd1d711a25b7cea86d1530 (patch)
treefcea899c2663e666a6b2e9f15b31dfe2064c7a42 /intern/cycles/kernel/osl
parent44232a2ce6d8762f10366f6bb660a37ce3e1acbd (diff)
Nodes: Add vector support to Map Range node
This replaces lost functionality from the old GN Attribute Map Range node. This also adds vector support to the shader version of the node. Notes: This breaks forward compatibility as this node now uses data storage. Reviewed By: HooglyBoogly, brecht Differential Revision: https://developer.blender.org/D12760
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r--intern/cycles/kernel/osl/shaders/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/osl/shaders/node_vector_map_range.osl74
2 files changed, 75 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/shaders/CMakeLists.txt b/intern/cycles/kernel/osl/shaders/CMakeLists.txt
index 6b62e7bb52f..4cafdb2a6d7 100644
--- a/intern/cycles/kernel/osl/shaders/CMakeLists.txt
+++ b/intern/cycles/kernel/osl/shaders/CMakeLists.txt
@@ -92,6 +92,7 @@ set(SRC_OSL
node_value.osl
node_vector_curves.osl
node_vector_math.osl
+ node_vector_map_range.osl
node_vector_rotate.osl
node_vector_transform.osl
node_velvet_bsdf.osl
diff --git a/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl b/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl
new file mode 100644
index 00000000000..1a59691fc45
--- /dev/null
+++ b/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011-2021 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdcycles.h"
+
+float safe_divide(float a, float b)
+{
+ return (b != 0.0) ? a / b : 0.0;
+}
+
+point safe_divide(point a, point b)
+{
+ return point(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z));
+}
+
+shader node_vector_map_range(string range_type = "linear",
+ int use_clamp = 0,
+ point VectorIn = point(1.0, 1.0, 1.0),
+ point From_Min_FLOAT3 = point(0.0, 0.0, 0.0),
+ point From_Max_FLOAT3 = point(1.0, 1.0, 1.0),
+ point To_Min_FLOAT3 = point(0.0, 0.0, 0.0),
+ point To_Max_FLOAT3 = point(1.0, 1.0, 1.0),
+ point Steps_FLOAT3 = point(4.0, 4.0, 4.0),
+ output point VectorOut = point(0.0, 0.0, 0.0))
+{
+ point factor = VectorIn;
+ point from_min = From_Min_FLOAT3;
+ point from_max = From_Max_FLOAT3;
+ point to_min = To_Min_FLOAT3;
+ point to_max = To_Max_FLOAT3;
+ point steps = Steps_FLOAT3;
+
+ if (range_type == "stepped") {
+ factor = safe_divide((factor - from_min), (from_max - from_min));
+ factor = point((steps.x > 0.0) ? floor(factor.x * (steps.x + 1.0)) / steps.x : 0.0,
+ (steps.y > 0.0) ? floor(factor.y * (steps.y + 1.0)) / steps.y : 0.0,
+ (steps.z > 0.0) ? floor(factor.z * (steps.z + 1.0)) / steps.z : 0.0);
+ }
+ else if (range_type == "smoothstep") {
+ factor = safe_divide((factor - from_min), (from_max - from_min));
+ factor = clamp(factor, 0.0, 1.0);
+ factor = (3.0 - 2.0 * factor) * (factor * factor);
+ }
+ else if (range_type == "smootherstep") {
+ factor = safe_divide((factor - from_min), (from_max - from_min));
+ factor = clamp(factor, 0.0, 1.0);
+ factor = factor * factor * factor * (factor * (factor * 6.0 - 15.0) + 10.0);
+ }
+ else {
+ factor = safe_divide((factor - from_min), (from_max - from_min));
+ }
+ VectorOut = to_min + factor * (to_max - to_min);
+ if (use_clamp > 0) {
+ VectorOut.x = (to_min.x > to_max.x) ? clamp(VectorOut.x, to_max.x, to_min.x) :
+ clamp(VectorOut.x, to_min.x, to_max.x);
+ VectorOut.y = (to_min.y > to_max.y) ? clamp(VectorOut.y, to_max.y, to_min.y) :
+ clamp(VectorOut.y, to_min.y, to_max.y);
+ VectorOut.z = (to_min.z > to_max.z) ? clamp(VectorOut.z, to_max.z, to_min.z) :
+ clamp(VectorOut.z, to_min.z, to_max.z);
+ }
+}