Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_normal.cc
| Show All 31 Lines | |||||
| }; | }; | ||||
| static bNodeSocketTemplate sh_node_normal_out[] = { | static bNodeSocketTemplate sh_node_normal_out[] = { | ||||
| {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, | {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION}, | ||||
| {SOCK_FLOAT, N_("Dot")}, | {SOCK_FLOAT, N_("Dot")}, | ||||
| {-1, ""}, | {-1, ""}, | ||||
| }; | }; | ||||
| /* generates normal, does dot product */ | |||||
| static void node_shader_exec_normal(void *UNUSED(data), | |||||
| int UNUSED(thread), | |||||
| bNode *UNUSED(node), | |||||
| bNodeExecData *UNUSED(execdata), | |||||
| bNodeStack **in, | |||||
| bNodeStack **out) | |||||
| { | |||||
| float vec[3]; | |||||
| /* stack order input: normal */ | |||||
| /* stack order output: normal, value */ | |||||
| nodestack_get_vec(vec, SOCK_VECTOR, in[0]); | |||||
| /* render normals point inside... the widget points outside */ | |||||
| out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec); | |||||
| } | |||||
| static int gpu_shader_normal(GPUMaterial *mat, | static int gpu_shader_normal(GPUMaterial *mat, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| GPUNodeStack *in, | GPUNodeStack *in, | ||||
| GPUNodeStack *out) | GPUNodeStack *out) | ||||
| { | { | ||||
| GPUNodeLink *vec = GPU_uniform(out[0].vec); | GPUNodeLink *vec = GPU_uniform(out[0].vec); | ||||
| return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec); | return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_normal_cc | } // namespace blender::nodes::node_shader_normal_cc | ||||
| void register_node_type_sh_normal() | void register_node_type_sh_normal() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_normal_cc; | namespace file_ns = blender::nodes::node_shader_normal_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR); | sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR); | ||||
| node_type_socket_templates(&ntype, file_ns::sh_node_normal_in, file_ns::sh_node_normal_out); | node_type_socket_templates(&ntype, file_ns::sh_node_normal_in, file_ns::sh_node_normal_out); | ||||
| node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_normal); | |||||
| node_type_gpu(&ntype, file_ns::gpu_shader_normal); | node_type_gpu(&ntype, file_ns::gpu_shader_normal); | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||