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>2019-12-07 15:35:07 +0300
committerCharlie Jolly <mistajolly@gmail.com>2019-12-07 15:52:42 +0300
commit958d0d4236b1cfa600a7f36f6bdc51fdd0d98a97 (patch)
tree567a1e3209e6302dd784c054b858a8b5fb92bc9f /source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
parent0406eb110332a863811d7fb6228f9a7ca514e022 (diff)
Shader Nodes: Add Interpolation modes to Map Range node
Modes: Linear interpolation (default), stepped linear, smoothstep and smootherstep. This also includes an additional option for the **Clamp node** to switch between **Min Max** (default) and **Range** mode. This was needed to allow clamping when **To Max** is less than **To Min**. Reviewed By: JacquesLucke, brecht Differential Revision: https://developer.blender.org/D5827
Diffstat (limited to 'source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl69
1 files changed, 67 insertions, 2 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
index a185774f4b3..7853aae31a1 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
@@ -1,5 +1,16 @@
-void map_range(
- float value, float fromMin, float fromMax, float toMin, float toMax, out float result)
+float smootherstep(float edge0, float edge1, float x)
+{
+ x = clamp(safe_divide((x - edge0), (edge1 - edge0)), 0.0, 1.0);
+ return x * x * x * (x * (x * 6.0 - 15.0) + 10.0);
+}
+
+void map_range_linear(float value,
+ float fromMin,
+ float fromMax,
+ float toMin,
+ float toMax,
+ float steps,
+ out float result)
{
if (fromMax != fromMin) {
result = toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin);
@@ -8,3 +19,57 @@ void map_range(
result = 0.0;
}
}
+
+void map_range_stepped(float value,
+ float fromMin,
+ float fromMax,
+ float toMin,
+ float toMax,
+ float steps,
+ out float result)
+{
+ if (fromMax != fromMin) {
+ float factor = (value - fromMin) / (fromMax - fromMin);
+ factor = (steps > 0.0) ? floor(factor * (steps + 1.0)) / steps : 0.0;
+ result = toMin + factor * (toMax - toMin);
+ }
+ else {
+ result = 0.0;
+ }
+}
+
+void map_range_smoothstep(float value,
+ float fromMin,
+ float fromMax,
+ float toMin,
+ float toMax,
+ float steps,
+ out float result)
+{
+ if (fromMax != fromMin) {
+ float factor = (fromMin > fromMax) ? 1.0 - smoothstep(fromMax, fromMin, value) :
+ smoothstep(fromMin, fromMax, value);
+ result = toMin + factor * (toMax - toMin);
+ }
+ else {
+ result = 0.0;
+ }
+}
+
+void map_range_smootherstep(float value,
+ float fromMin,
+ float fromMax,
+ float toMin,
+ float toMax,
+ float steps,
+ out float result)
+{
+ if (fromMax != fromMin) {
+ float factor = (fromMin > fromMax) ? 1.0 - smootherstep(fromMax, fromMin, value) :
+ smootherstep(fromMin, fromMax, value);
+ result = toMin + factor * (toMax - toMin);
+ }
+ else {
+ result = 0.0;
+ }
+}