diff options
Diffstat (limited to 'source')
8 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp index eb6bb2caf56..0fb6933afe7 100644 --- a/source/blender/compositor/nodes/COM_MathNode.cpp +++ b/source/blender/compositor/nodes/COM_MathNode.cpp @@ -86,6 +86,9 @@ void MathNode::convertToOperations(NodeConverter &converter, const CompositorCon case NODE_MATH_ABS: operation = new MathAbsoluteOperation(); break; + case NODE_MATH_ATAN2: + operation = new MathArcTan2Operation(); + break; } if (operation) { diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index 32a1e77b9a7..dbc91980acd 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -343,3 +343,16 @@ void MathAbsoluteOperation::executePixelSampled(float output[4], float x, float clampIfNeeded(output); } + +void MathArcTan2Operation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler) +{ + float inputValue1[4]; + float inputValue2[4]; + + this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler); + this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler); + + output[0] = atan2(inputValue1[0], inputValue2[0]); + + clampIfNeeded(output); +}
\ No newline at end of file diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h index 32cd19f1fb9..04019372711 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.h +++ b/source/blender/compositor/operations/COM_MathBaseOperation.h @@ -169,4 +169,10 @@ public: void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); }; +class MathArcTan2Operation : public MathBaseOperation { +public: + MathArcTan2Operation() : MathBaseOperation() {} + void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); +}; + #endif diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index a0ca719e207..aace5e95169 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -413,6 +413,11 @@ void math_abs(float val1, out float outval) outval = abs(val1); } +void math_atan2(float val1, float val2, out float outval) +{ + outval = atan(val1, val2); +} + void squeeze(float val, float width, float center, out float outval) { outval = 1.0 / (1.0 + pow(2.71828183, -((val - center) * width))); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 8ae1a79f8f7..8d3ab29a2fb 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1060,6 +1060,7 @@ enum { NODE_MATH_GREATER = 16, NODE_MATH_MOD = 17, NODE_MATH_ABS = 18, + NODE_MATH_ATAN2 = 19, }; /* mix rgb node flags */ diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 773ca307a8c..f5c464c0758 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -140,6 +140,7 @@ const EnumPropertyItem rna_enum_node_math_items[] = { {NODE_MATH_GREATER, "GREATER_THAN", 0, "Greater Than", ""}, {NODE_MATH_MOD, "MODULO", 0, "Modulo", ""}, {NODE_MATH_ABS, "ABSOLUTE", 0, "Absolute", ""}, + {NODE_MATH_ATAN2, "ARCTAN2", 0, "Arctan2", ""}, {0, NULL, 0, NULL, NULL} }; diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index 2a1e936570d..9fa906729dc 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -221,6 +221,11 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = fabsf(a); break; } + case NODE_MATH_ATAN2: + { + r = atan2(a, b); + break; + } } if (node->custom2 & SHD_MATH_CLAMP) { CLAMP(r, 0.0f, 1.0f); @@ -235,6 +240,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_abs", + "math_atan2" }; switch (node->custom1) { @@ -249,6 +255,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( case NODE_MATH_LESS: case NODE_MATH_GREATER: case NODE_MATH_MOD: + case NODE_MATH_ATAN2: GPU_stack_link(mat, names[node->custom1], in, out); break; case NODE_MATH_SIN: diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c index 19bc16fb82d..d8dc2a62625 100644 --- a/source/blender/nodes/texture/nodes/node_texture_math.c +++ b/source/blender/nodes/texture/nodes/node_texture_math.c @@ -189,6 +189,12 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor break; } + case NODE_MATH_ATAN2: + { + *out = atan2(in0, in1); + break; + } + default: { BLI_assert(0); |