Commit: ab25e2f6c6b526ad0083c97a70b285dbde93a8fd
Author: Lukas Tönne
Date:   Mon Dec 21 12:09:28 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBab25e2f6c6b526ad0083c97a70b285dbde93a8fd

Sqrt math node mode, patch by lichtwerk.

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

M       release/scripts/nodes/common_nodes.py
M       source/blender/blenvm/bvm/bvm_eval.cc
M       source/blender/blenvm/bvm/bvm_eval_math.h
M       source/blender/blenvm/bvm/bvm_opcode.h
M       source/blender/blenvm/compile/bvm_nodegraph.cc
M       source/blender/blenvm/intern/bvm_api.cc
M       source/blender/blenvm/util/bvm_util_math.h

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

diff --git a/release/scripts/nodes/common_nodes.py 
b/release/scripts/nodes/common_nodes.py
index dc411f2..cec8cd7 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -221,6 +221,7 @@ class MathNode(CommonNodeBase, ObjectNode):
         ('MODULO', 'Modulo', '', 'NONE', 17),
         ('ABSOLUTE', 'Absolute', '', 'NONE', 18),
         ('CLAMP', 'Clamp', '', 'NONE', 19),
+        ('SQRT', 'Square Root', '', 'NONE', 20),
     ]
     mode = EnumProperty(name="Mode",
                         items=_mode_items)
diff --git a/source/blender/blenvm/bvm/bvm_eval.cc 
b/source/blender/blenvm/bvm/bvm_eval.cc
index 25d1f88..e9d0c14 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -525,6 +525,12 @@ void EvalContext::eval_instructions(const EvalGlobals 
*globals, const Function *
                                eval_op_clamp(stack, offset, offset_r);
                                break;
                        }
+                       case OP_SQRT: {
+                               StackIndex offset_a = 
fn->read_stack_index(&instr);
+                               StackIndex offset_r = 
fn->read_stack_index(&instr);
+                               eval_op_sqrt_float(stack, offset_a, offset_r);
+                               break;
+                       }
                        case OP_ADD_FLOAT3: {
                                StackIndex offset_a = 
fn->read_stack_index(&instr);
                                StackIndex offset_b = 
fn->read_stack_index(&instr);
diff --git a/source/blender/blenvm/bvm/bvm_eval_math.h 
b/source/blender/blenvm/bvm/bvm_eval_math.h
index fa1e640..5454fdc 100644
--- a/source/blender/blenvm/bvm/bvm_eval_math.h
+++ b/source/blender/blenvm/bvm/bvm_eval_math.h
@@ -242,6 +242,12 @@ static void eval_op_clamp(float *stack, StackIndex offset, 
StackIndex offset_r)
        stack_store_float(stack, offset_r, CLAMPIS(f, 0.0f, 1.0f));
 }
 
+static void eval_op_sqrt_float(float *stack, StackIndex offset_a, StackIndex 
offset_r)
+{
+       float a = stack_load_float(stack, offset_a);
+       stack_store_float(stack, offset_r, sqrt_safe(a));
+}
+
 static void eval_op_add_float3(float *stack, StackIndex offset_a, StackIndex 
offset_b, StackIndex offset_r)
 {
        float3 a = stack_load_float3(stack, offset_a);
diff --git a/source/blender/blenvm/bvm/bvm_opcode.h 
b/source/blender/blenvm/bvm/bvm_opcode.h
index 64fc89f..9f7e682 100644
--- a/source/blender/blenvm/bvm/bvm_opcode.h
+++ b/source/blender/blenvm/bvm/bvm_opcode.h
@@ -83,6 +83,7 @@ enum OpCode {
        OP_MODULO,
        OP_ABSOLUTE,
        OP_CLAMP,
+       OP_SQRT,
        
        OP_ADD_FLOAT3,
        OP_SUB_FLOAT3,
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc 
b/source/blender/blenvm/compile/bvm_nodegraph.cc
index a5d5c92..578d3b1 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -816,6 +816,7 @@ OpCode get_opcode_from_node_type(const string &node)
        NODETYPE(MODULO);
        NODETYPE(ABSOLUTE);
        NODETYPE(CLAMP);
+       NODETYPE(SQRT);
        
        NODETYPE(ADD_FLOAT3);
        NODETYPE(SUB_FLOAT3);
@@ -1025,6 +1026,7 @@ static void register_opcode_node_types()
        BINARY_MATH_NODE(MODULO);
        UNARY_MATH_NODE(ABSOLUTE);
        UNARY_MATH_NODE(CLAMP);
+       UNARY_MATH_NODE(SQRT);
        
        #undef BINARY_MATH_NODE
        #undef UNARY_MATH_NODE
diff --git a/source/blender/blenvm/intern/bvm_api.cc 
b/source/blender/blenvm/intern/bvm_api.cc
index 3c98af2..71ebb13 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -871,6 +871,7 @@ static void convert_tex_node(bNodeCompiler *comp, 
PointerRNA *bnode_ptr)
                        case 16: binary_math_node(comp, "GREATER_THAN"); break;
                        case 17: binary_math_node(comp, "MODULO"); break;
                        case 18: unary_math_node(comp, "ABSOLUTE"); break;
+                       case 20: unary_math_node(comp, "SQRT"); break;
                }
        }
        else if (type == "TextureNodeTexVoronoi") {
diff --git a/source/blender/blenvm/util/bvm_util_math.h 
b/source/blender/blenvm/util/bvm_util_math.h
index 586c949..a8ec6eb 100644
--- a/source/blender/blenvm/util/bvm_util_math.h
+++ b/source/blender/blenvm/util/bvm_util_math.h
@@ -57,6 +57,14 @@ inline static float div_safe(float a, float b)
                return 0.0f;
 }
 
+inline static float sqrt_safe(float a)
+{
+       if (a > 0.0f)
+               return sqrtf(a);
+       else
+               return 0.0f;
+}
+
 } /* namespace bvm */
 
 #endif /* __BVM_UTIL_MATH_H__ */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to