Page MenuHome

Fix T43273: vector math cross product inconsistent
ClosedPublic

Authored by Kévin Dietrich (kevindietrich) on Jan 16 2015, 7:15 PM.

Diff Detail

Repository
rB Blender

Event Timeline

Kévin Dietrich (kevindietrich) retitled this revision from to Fix T43273: vector math cross product inconsistent.
Kévin Dietrich (kevindietrich) updated this object.

Generally sounds fine, but i wouldn't mix this two changes into a single commit. Or maybe i'm missing something and they're related to each other?

No, you're right, we shouldn't mix those, I just forgot about about the typo fix and it got in. Will make a separate patch.

Bastien Montagne (mont29) added inline comments.
source/blender/nodes/shader/nodes/node_shader_vectMath.c
79–89 ↗(On Diff #3174)

Why is this change needed? To me (noob) eyes it only adds verbose code with no benefits at all?

90 ↗(On Diff #3174)

Tsst, empty line ;)

source/blender/nodes/shader/nodes/node_shader_vectMath.c
79–89 ↗(On Diff #3174)

Well, the node has two outputs : a vector and a value. Previously the code would do the following:

vector = cross(input1, input2);
value = normalize(vector);

and now (fixed):

vector = cross(input1, input2);
value = length(vector);
vector = normalize(vector);

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.

90 ↗(On Diff #3174)

Okay so who am I now to act as the code style police from time to time in this code review system... :P

source/blender/nodes/shader/nodes/node_shader_vectMath.c
79–89 ↗(On Diff #3174)

I 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…

source/blender/nodes/shader/nodes/node_shader_vectMath.c
79–89 ↗(On Diff #3174)

hmm, 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.

  • revert changes to node_shader_vecMath.c, turns out it was good from the get-go...

Think you have commit rights? If so, please go on and commit, such one-liners do not really need a strict review now ;)

This revision is now accepted and ready to land.Jan 17 2015, 2:24 PM
source/blender/gpu/shaders/gpu_shader_material.glsl
341

Why not to divide by outval? Would save calculating vector length second time.

@Bastien Montagne (mont29), I don't have commits rights at the moment.

source/blender/gpu/shaders/gpu_shader_material.glsl
341

Sounds fair, will do.

Then, can we have a (public) mail, so that we can commit on your behalf (this way, you'll appear as author of the commit in git history)?

Kévin Dietrich (kevindietrich) edited edge metadata.
  • Avoid recalculating vector length

Shouldn't arc be doing this automatically? Anyway, I'm already in the git logs (even for Cycles) with this mail: kevin.dietrich _at_ mailoo.org

This revision was automatically updated to reflect the committed changes.