Changeset View
Standalone View
source/blender/nodes/shader/nodes/node_shader_vectMath.c
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | static void node_shader_exec_vect_math(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) | ||||
| nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); | nodestack_get_vec(vec1, SOCK_VECTOR, in[0]); | ||||
| nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); | nodestack_get_vec(vec2, SOCK_VECTOR, in[1]); | ||||
| if (node->custom1 == 0) { /* Add */ | if (node->custom1 == 0) { /* Add */ | ||||
| out[0]->vec[0] = vec1[0] + vec2[0]; | out[0]->vec[0] = vec1[0] + vec2[0]; | ||||
| out[0]->vec[1] = vec1[1] + vec2[1]; | out[0]->vec[1] = vec1[1] + vec2[1]; | ||||
| out[0]->vec[2] = vec1[2] + vec2[2]; | out[0]->vec[2] = vec1[2] + vec2[2]; | ||||
| out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[0])) / 3; | out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; | ||||
| } | } | ||||
| else if (node->custom1 == 1) { /* Subtract */ | else if (node->custom1 == 1) { /* Subtract */ | ||||
| out[0]->vec[0] = vec1[0] - vec2[0]; | out[0]->vec[0] = vec1[0] - vec2[0]; | ||||
| out[0]->vec[1] = vec1[1] - vec2[1]; | out[0]->vec[1] = vec1[1] - vec2[1]; | ||||
| out[0]->vec[2] = vec1[2] - vec2[2]; | out[0]->vec[2] = vec1[2] - vec2[2]; | ||||
| out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[0])) / 3; | out[1]->vec[0] = (fabsf(out[0]->vec[0]) + fabsf(out[0]->vec[1]) + fabsf(out[0]->vec[2])) / 3.0f; | ||||
| } | } | ||||
| else if (node->custom1 == 2) { /* Average */ | else if (node->custom1 == 2) { /* Average */ | ||||
| out[0]->vec[0] = vec1[0] + vec2[0]; | out[0]->vec[0] = vec1[0] + vec2[0]; | ||||
| out[0]->vec[1] = vec1[1] + vec2[1]; | out[0]->vec[1] = vec1[1] + vec2[1]; | ||||
| out[0]->vec[2] = vec1[2] + vec2[2]; | out[0]->vec[2] = vec1[2] + vec2[2]; | ||||
| out[1]->vec[0] = normalize_v3(out[0]->vec); | out[1]->vec[0] = normalize_v3(out[0]->vec); | ||||
| } | } | ||||
| else if (node->custom1 == 3) { /* Dot product */ | else if (node->custom1 == 3) { /* Dot product */ | ||||
| out[1]->vec[0] = (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); | out[1]->vec[0] = (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); | ||||
| } | } | ||||
| else if (node->custom1 == 4) { /* Cross product */ | else if (node->custom1 == 4) { /* Cross product */ | ||||
| out[0]->vec[0] = (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); | float vec[3]; | ||||
| out[0]->vec[1] = (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); | |||||
| out[0]->vec[2] = (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); | vec[0] = (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]); | ||||
| vec[1] = (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); | |||||
| vec[2] = (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); | |||||
| out[1]->vec[0] = len_v3(vec); | |||||
| out[0]->vec[0] = vec[0] / len_v3(vec); | |||||
| out[0]->vec[1] = vec[1] / len_v3(vec); | |||||
| out[0]->vec[2] = vec[2] / len_v3(vec); | |||||
mont29: Tsst, empty line ;) | |||||
Not Done Inline ActionsOkay so who am I now to act as the code style police from time to time in this code review system... :P kevindietrich: Okay so who am I now to act as the code style police from time to time in this code review… | |||||
| out[1]->vec[0] = normalize_v3(out[0]->vec); | |||||
| } | } | ||||
Not Done Inline ActionsWhy is this change needed? To me (noob) eyes it only adds verbose code with no benefits at all? mont29: Why is this change needed? To me (noob) eyes it only adds verbose code with no benefits at all? | |||||
Not Done Inline ActionsWell, the node has two outputs : a vector and a value. Previously the code would do the following: vector = cross(input1, input2); and now (fixed): vector = cross(input1, input2); That's how Cycles goes, and also GLSL except the normalization of the vector was missing at the end. Also I admit it's a tad verbose but apparently there are no cross and normalize function to return a vector in BLI. As far as I could see, they only return a single float. kevindietrich: Well, the node has two outputs : a vector and a value. Previously the code would do the… | |||||
Not Done Inline ActionsI do not see the issue with value = normalize_v3(vector);, normalize_v3() does return the length of the vector (before normalization), and normalizes the vector in-place… mont29: I do not see the issue with `value = normalize_v3(vector);`, `normalize_v3()` does return the… | |||||
Not Done Inline Actionshmm, I did not see that... guess I just got stuck on the name... also, quite a funny one: while debugging, I kept changing the code but couldn't see any difference, until I realized I was compiling a release build while launching a debug one to test! :/ Anyhows, will update. kevindietrich: hmm, I did not see that... guess I just got stuck on the name... also, quite a funny one: while… | |||||
| else if (node->custom1 == 5) { /* Normalize */ | else if (node->custom1 == 5) { /* Normalize */ | ||||
| if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ | if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ | ||||
| out[0]->vec[0] = vec1[0]; | out[0]->vec[0] = vec1[0]; | ||||
| out[0]->vec[1] = vec1[1]; | out[0]->vec[1] = vec1[1]; | ||||
| out[0]->vec[2] = vec1[2]; | out[0]->vec[2] = vec1[2]; | ||||
| } | } | ||||
| else { | else { | ||||
| out[0]->vec[0] = vec2[0]; | out[0]->vec[0] = vec2[0]; | ||||
| ▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines | |||||
Tsst, empty line ;)