Page 1 of 1

Multiply vs. Power node

PostPosted: Wed Nov 15, 2017 3:36 pm
by Desoxi
Hey again,
i was just writing/noding (however its called in node systems :D ) a shader which rounds corners on images.
So i wanted to control the "roundness" of the corners and have written the following code to test with 2 multiply nodes:
Image

https://ibb.co/c5w58R

That works fine, but i dont have any control over the roundness. So i decided to change that to a power node to control the exponent via the inspector:

Image

https://ibb.co/iChdTR

However the power nodes did not work. While the multiply nodes work just fine and round all 4 corners:

Image

https://ibb.co/n2i2oR

the power nodes just round the top right corner and ignores all other corners:

Image

https://ibb.co/kaRmhm

That is weird because mathematically it should be the same!
So i tried a few things and played around and randomly changed the scalar value which is the input to the both "exp" inputs of the power nodes from "property" to "constant" and voila! It works!
This really is really weird and i think that it is a bug.
Do you know if there is a workaround for me to still be able to expose that scalar to the inspector? Or do i have to wait for a patch? :)

EDIT: even on constant scalar nodes it doesnt work on real numbers like x.y with y!= 0
And values like 7, 9, 10 or 11 doesnt work either. Cant see a pattern there atm. Maybe im missing something obvious.

Re: Multiply vs. Power node

PostPosted: Thu Nov 16, 2017 2:06 pm
by Amplify_RnD_Rick
Hey Desoxi,

That's quite the interesting issue and it's not completely obvious why this happen.

The Power node is using the Cg/HLSL pow function to calculate the result. This function internally is not implemented as you would think, it used an optimized expression exp(x * log(y)) which has its flaws.

This function does not take into account possible signal changes. In your case there's a simple solution to make sure it gives you correct results, which is passing the remapped values through an Abs node before connecting them into the Base port of the Power node.

Something like this:
PowFix.PNG
PowFix.PNG (235.51 KiB) Viewed 1152 times


Please let us know if this solution works for you and don't hesitate on reaching us if you have further questions or stumble into any other issues.