Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_math.c
| Context not available. | |||||
| } | } | ||||
| case NODE_MATH_SIN: | case NODE_MATH_SIN: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ | r = sinf(a); | ||||
| r = sinf(a); | |||||
| else | |||||
| r = sinf(b); | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_COS: | case NODE_MATH_COS: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ | r = cosf(a); | ||||
| r = cosf(a); | |||||
| else | |||||
| r = cosf(b); | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_TAN: | case NODE_MATH_TAN: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ | r = tanf(a); | ||||
| r = tanf(a); | |||||
| else | |||||
| r = tanf(b); | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_ASIN: | case NODE_MATH_ASIN: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ | /* Can't do the impossible... */ | ||||
| /* Can't do the impossible... */ | if (a <= 1 && a >= -1) | ||||
| if (a <= 1 && a >= -1) | r = asinf(a); | ||||
| r = asinf(a); | else | ||||
| else | r = 0.0; | ||||
| r = 0.0; | |||||
| } | |||||
| else { | |||||
| /* Can't do the impossible... */ | |||||
| if (b <= 1 && b >= -1) | |||||
| r = asinf(b); | |||||
| else | |||||
| r = 0.0; | |||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_ACOS: | case NODE_MATH_ACOS: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ | /* Can't do the impossible... */ | ||||
| /* Can't do the impossible... */ | if (a <= 1 && a >= -1) | ||||
| if (a <= 1 && a >= -1) | r = acosf(a); | ||||
| r = acosf(a); | else | ||||
| else | r = 0.0; | ||||
| r = 0.0; | |||||
| } | |||||
| else { | |||||
| /* Can't do the impossible... */ | |||||
| if (b <= 1 && b >= -1) | |||||
| r = acosf(b); | |||||
| else | |||||
| r = 0.0; | |||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_ATAN: | case NODE_MATH_ATAN: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ | r = atan(a); | ||||
| r = atan(a); | |||||
| else | |||||
| r = atan(b); | |||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MATH_POW: | case NODE_MATH_POW: | ||||
| Context not available. | |||||
| } | } | ||||
| case NODE_MATH_ROUND: | case NODE_MATH_ROUND: | ||||
| { | { | ||||
| if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ | r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); | ||||
| r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); | } | ||||
| else | |||||
| r = (b < 0) ? (int)(b - 0.5f) : (int)(b + 0.5f); | |||||
| break; | |||||
| } | |||||
| case NODE_MATH_LESS: | case NODE_MATH_LESS: | ||||
| { | { | ||||
| if (a < b) | if (a < b) | ||||
| Context not available. | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| static void node_shader_update_math(bNodeTree *UNUSED(ntree), bNode *node) | |||||
| { | |||||
| bNodeSocket *sock; | |||||
| int operation = node->custom1; | |||||
| // There are only two sockets, you want to always toggle the second one on/off | |||||
| sock = node->inputs.last; | |||||
| // All of the following are one socket operations | |||||
| if (operation == NODE_MATH_SIN || | |||||
| operation == NODE_MATH_COS || | |||||
| operation == NODE_MATH_TAN || | |||||
| operation == NODE_MATH_ASIN || | |||||
| operation == NODE_MATH_ACOS || | |||||
| operation == NODE_MATH_ATAN || | |||||
| operation == NODE_MATH_ROUND || | |||||
| operation == NODE_MATH_ABS | |||||
| ) | |||||
| sock->flag |= SOCK_UNAVAIL; | |||||
| else | |||||
| sock->flag &= ~SOCK_UNAVAIL; | |||||
| } | |||||
| void register_node_type_sh_math(void) | void register_node_type_sh_math(void) | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| Context not available. | |||||
| node_type_storage(&ntype, "", NULL, NULL); | node_type_storage(&ntype, "", NULL, NULL); | ||||
| node_type_exec(&ntype, NULL, NULL, node_shader_exec_math); | node_type_exec(&ntype, NULL, NULL, node_shader_exec_math); | ||||
| node_type_gpu(&ntype, gpu_shader_math); | node_type_gpu(&ntype, gpu_shader_math); | ||||
| node_type_update(&ntype, node_shader_update_math, NULL); | |||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||
| Context not available. | |||||