Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_invert.cc
| Show All 27 Lines | |||||
| /* **************** INVERT ******************** */ | /* **************** INVERT ******************** */ | ||||
| static bNodeSocketTemplate sh_node_invert_in[] = { | static bNodeSocketTemplate sh_node_invert_in[] = { | ||||
| {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, | {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, | ||||
| {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, | {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, | ||||
| {-1, ""}}; | {-1, ""}}; | ||||
| static bNodeSocketTemplate sh_node_invert_out[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}}; | static bNodeSocketTemplate sh_node_invert_out[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}}; | ||||
| static void node_shader_exec_invert(void *UNUSED(data), | |||||
| int UNUSED(thread), | |||||
| bNode *UNUSED(node), | |||||
| bNodeExecData *UNUSED(execdata), | |||||
| bNodeStack **in, | |||||
| bNodeStack **out) | |||||
| { | |||||
| float col[3], icol[3], fac; | |||||
| nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); | |||||
| nodestack_get_vec(col, SOCK_VECTOR, in[1]); | |||||
| icol[0] = 1.0f - col[0]; | |||||
| icol[1] = 1.0f - col[1]; | |||||
| icol[2] = 1.0f - col[2]; | |||||
| /* if fac, blend result against original input */ | |||||
| if (fac < 1.0f) { | |||||
| interp_v3_v3v3(out[0]->vec, col, icol, fac); | |||||
| } | |||||
| else { | |||||
| copy_v3_v3(out[0]->vec, icol); | |||||
| } | |||||
| } | |||||
| static int gpu_shader_invert(GPUMaterial *mat, | static int gpu_shader_invert(GPUMaterial *mat, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| GPUNodeStack *in, | GPUNodeStack *in, | ||||
| GPUNodeStack *out) | GPUNodeStack *out) | ||||
| { | { | ||||
| return GPU_stack_link(mat, node, "invert", in, out); | return GPU_stack_link(mat, node, "invert", in, out); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_invert_cc | } // namespace blender::nodes::node_shader_invert_cc | ||||
| void register_node_type_sh_invert() | void register_node_type_sh_invert() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_invert_cc; | namespace file_ns = blender::nodes::node_shader_invert_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR); | sh_node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR); | ||||
| node_type_socket_templates(&ntype, file_ns::sh_node_invert_in, file_ns::sh_node_invert_out); | node_type_socket_templates(&ntype, file_ns::sh_node_invert_in, file_ns::sh_node_invert_out); | ||||
| node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_invert); | |||||
| node_type_gpu(&ntype, file_ns::gpu_shader_invert); | node_type_gpu(&ntype, file_ns::gpu_shader_invert); | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||