diff options
author | Charlie Jolly <charlie> | 2020-02-17 18:15:46 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2020-02-17 18:43:18 +0300 |
commit | 20a4cdfd700d3722fdcaa3b3952ccea1b0e6ee47 (patch) | |
tree | 16eee69e8e1d3bdfb902e05df15b055f7141fd4d /source/blender/nodes | |
parent | ab3a6e050c856345d10f8e36155913288559e4dc (diff) |
Cycles: Vector Rotate Node using Axis and Angle method
This node provides the ability to rotate a vector around a `center` point using either `Axis Angle` , `Single Axis` or `Euler` methods.
Reviewed By: #cycles, brecht
Differential Revision: https://developer.blender.org/D3789
Diffstat (limited to 'source/blender/nodes')
-rw-r--r-- | source/blender/nodes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/nodes/NOD_shader.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/NOD_static_types.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_vector_rotate.c | 96 |
4 files changed, 99 insertions, 0 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index e15eb5af2c4..41227a14fb3 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -206,6 +206,7 @@ set(SRC shader/nodes/node_shader_uvmap.c shader/nodes/node_shader_valToRgb.c shader/nodes/node_shader_value.c + shader/nodes/node_shader_vector_rotate.c shader/nodes/node_shader_vectTransform.c shader/nodes/node_shader_vector_displacement.c shader/nodes/node_shader_vector_math.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 69d779c9b7f..a89a9e927b9 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -85,6 +85,7 @@ void register_node_type_sh_volume_info(void); void register_node_type_sh_script(void); void register_node_type_sh_normal_map(void); void register_node_type_sh_tangent(void); +void register_node_type_sh_vector_rotate(void); void register_node_type_sh_vect_transform(void); void register_node_type_sh_vertex_color(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 2b141e1a639..7fec3324aab 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -117,6 +117,7 @@ DefNode(ShaderNode, SH_NODE_TEX_CHECKER, def_sh_tex_checker, "TEX DefNode(ShaderNode, SH_NODE_TEX_BRICK, def_sh_tex_brick, "TEX_BRICK", TexBrick, "Brick Texture", "" ) DefNode(ShaderNode, SH_NODE_TEX_POINTDENSITY, def_sh_tex_pointdensity,"TEX_POINTDENSITY", TexPointDensity, "Point Density", "" ) DefNode(ShaderNode, SH_NODE_TEX_COORD, def_sh_tex_coord, "TEX_COORD", TexCoord, "Texture Coordinate","" ) +DefNode(ShaderNode, SH_NODE_VECTOR_ROTATE, def_sh_vector_rotate, "VECTOR_ROTATE", VectorRotate, "Vector Rotate", "" ) DefNode(ShaderNode, SH_NODE_VECT_TRANSFORM, def_sh_vect_transform, "VECT_TRANSFORM", VectorTransform, "Vector Transform", "" ) DefNode(ShaderNode, SH_NODE_SEPHSV, 0, "SEPHSV", SeparateHSV, "Separate HSV", "" ) DefNode(ShaderNode, SH_NODE_COMBHSV, 0, "COMBHSV", CombineHSV, "Combine HSV", "" ) diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_rotate.c b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.c new file mode 100644 index 00000000000..3fd627cd886 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_vector_rotate.c @@ -0,0 +1,96 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup shdnodes + */ + +#include "../node_shader_util.h" + +/* **************** Vector Rotate ******************** */ +static bNodeSocketTemplate sh_node_vector_rotate_in[] = { + {SOCK_VECTOR, 1, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + {SOCK_VECTOR, 1, N_("Center"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_NONE, PROP_NONE}, + {SOCK_FLOAT, 1, N_("Angle"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_ANGLE, PROP_NONE}, + {SOCK_VECTOR, 1, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER}, + {-1, 0, ""}}; + +static bNodeSocketTemplate sh_node_vector_rotate_out[] = {{SOCK_VECTOR, 0, N_("Vector")}, + {-1, 0, ""}}; + +static int gpu_shader_vector_rotate(GPUMaterial *mat, + bNode *node, + bNodeExecData *UNUSED(execdata), + GPUNodeStack *in, + GPUNodeStack *out) +{ + + static const char *names[] = { + [NODE_VECTOR_ROTATE_TYPE_AXIS] = "node_vector_rotate_axis_angle", + [NODE_VECTOR_ROTATE_TYPE_AXIS_X] = "node_vector_rotate_axis_x", + [NODE_VECTOR_ROTATE_TYPE_AXIS_Y] = "node_vector_rotate_axis_y", + [NODE_VECTOR_ROTATE_TYPE_AXIS_Z] = "node_vector_rotate_axis_z", + [NODE_VECTOR_ROTATE_TYPE_EULER_XYZ] = "node_vector_rotate_euler_xyz", + [NODE_VECTOR_ROTATE_TYPE_EULER_XZY] = "node_vector_rotate_euler_xzy", + [NODE_VECTOR_ROTATE_TYPE_EULER_YXZ] = "node_vector_rotate_euler_yxz", + [NODE_VECTOR_ROTATE_TYPE_EULER_YZX] = "node_vector_rotate_euler_yzx", + [NODE_VECTOR_ROTATE_TYPE_EULER_ZXY] = "node_vector_rotate_euler_zxy", + [NODE_VECTOR_ROTATE_TYPE_EULER_ZYX] = "node_vector_rotate_euler_zyx", + }; + + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + return GPU_stack_link(mat, node, names[node->custom1], in, out); + } + else { + return 0; + } +} + +static void node_shader_update_vector_rotate(bNodeTree *UNUSED(ntree), bNode *node) +{ + bNodeSocket *sock_rotation = nodeFindSocket(node, SOCK_IN, "Rotation"); + nodeSetSocketAvailability(sock_rotation, + !ELEM(node->custom1, + NODE_VECTOR_ROTATE_TYPE_AXIS, + NODE_VECTOR_ROTATE_TYPE_AXIS_X, + NODE_VECTOR_ROTATE_TYPE_AXIS_Y, + NODE_VECTOR_ROTATE_TYPE_AXIS_Z)); + bNodeSocket *sock_axis = nodeFindSocket(node, SOCK_IN, "Axis"); + nodeSetSocketAvailability(sock_axis, ELEM(node->custom1, NODE_VECTOR_ROTATE_TYPE_AXIS)); + bNodeSocket *sock_angle = nodeFindSocket(node, SOCK_IN, "Angle"); + nodeSetSocketAvailability(sock_angle, + ELEM(node->custom1, + NODE_VECTOR_ROTATE_TYPE_AXIS, + NODE_VECTOR_ROTATE_TYPE_AXIS_X, + NODE_VECTOR_ROTATE_TYPE_AXIS_Y, + NODE_VECTOR_ROTATE_TYPE_AXIS_Z)); +} + +void register_node_type_sh_vector_rotate(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_VECTOR_ROTATE, "Vector Rotate", NODE_CLASS_OP_VECTOR, 0); + node_type_socket_templates(&ntype, sh_node_vector_rotate_in, sh_node_vector_rotate_out); + node_type_gpu(&ntype, gpu_shader_vector_rotate); + node_type_update(&ntype, node_shader_update_vector_rotate); + + nodeRegisterType(&ntype); +} |