Cycles Render Engine - inconsistent Math Node values

Hello

Yesterday, I put together a small ‘lookup value’ solution (Node Group) for a material in Cycles which was not behaving as intended. After double-checking, I realised that there was a problem with the ‘internal’ calculations of the Math Nodes.

Here is an example to illustrate the problem:



Notice that the white colour output is wrong since the input values are identical. However, when I change the input values the output is correct.

Here is another example using the ‘Divide’ and ‘Multiply’ Math Nodes:



When the ‘Divide’ Node is plugged in the top slot the output is wrong. When the ‘Multiply’ Node is plugged in the top slot the output is correct. But these are the same input values…?

I would like to know if anyone could explain this behaviour of the Math Nodes. I think it may be a bug but I want to make certain it is before reporting.

This is a serious problem because such inconsistencies in the calculations of the Math Nodes will affect any ‘Node Group System’ that uses them and essentially make it unreliable.

Any answers/thoughts will be greatly appreciated.

PS: I should mention that I am using Blender 2.77a (not installed the latest, yet :eek: ) on Windows 7 64bit.

That’s very strange and hard to predict. For example in the first image, first case, first math node, if you remove .001 from the first value and add .001 the the 2nd, the color changes, but if you do the opposite (add .001 to the first and remove .001 from the 2nd), then it doesn’t.

To me this is worth reporting.

I haven’t looked into it, but immediately it looks like float->binary issue.
http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/
How does it behave if you scale it up by 1000 and round it? It’s not often I have to counter this effect in cycles nodes. But it helps to be aware of the limitations of floating point maths in binary and struct things differently when it hits you. I have encountered such “weird” (at the time, because I wasn’t aware of the float issues) things happening even in Excel when I tried to debug some code and even that would give the wrong results.

I think blender works with 7 digits only and at 0.001 and with scene scale of 1
you are at the limit of what blender can do I guess

so scale it up X 10 and divide but even that might give some errors !

happy cl

Hello again,

Thank you for your thoughts and suggestions. It is, indeed, a float precision issue and a nice guy from the Blender Foundation Developer forum offered this workaround which works fine albeit using two extra calculations… see screenshot below:


In the hope that this answer will help other people having similar issues, I consider this thread solved…

regards,

P.T.