Math node beginner question

someone please help me out here, im a beginner and im really frustated

from what i understand, the modulo operation (outside blender) returns the remainder of a division operation?
for example 5 mod 2 = 1 or 3 mod 3 = 0, have i got this right?

but inside blender shading nodes, when i connect the same value node (3) to both inputs of a math truncated modulo node (so 3 mod 3), the output i get is 3
i expected the output to be 0 since the remainder of 3/3 is 0

what am i missing?

the remainder is 0, just set the epsilon to 0 too

thanks for the reply, im afraid i cant understand your suggestion though

the compare node compares the modulo output against the value of 3 with an epsilon set to 0.010 and outputs 1 / white which means that the modulo output value falls within the range of 2.990 to 3.010
so how could it be 0 as you say? am i missing something?

here is epsilon set to 0 as you suggested, unsurprisingly same result, the compare node still outputs 1 / white showing that the modulo output is 3

That’s not what I am getting. Share the file maybe?

also here is the compare node muted, the cube is still white showing that the modulo output value is not 0

yeah, share the file. Can’t think of any reason this should happen other than wrong shading mode / active gn viewer node or smt like that

1 Like

could you please try something if its not much trouble
set the same nodes as shown in the picture with the exact same values (exact though)
then toggle between eevee and cycles and tell me if you see any differences

ogonek is right the result is 0 not sure what you are looking at with the cube,…maybe a different material slot? (eevee and cycles the same)

Setting the Epsilon to 0.000 does not change anything, you have to set it to 3 or more for the result to be positive (1)

2 Likes

yes, i know, thats what i was expecting to get obviously, thnx for the reply

no, there are no other material slots

i found two clues

  • the problem happens only with eevee, not with cycles
  • the behavior occurs only with certain values
    if the value is 1, 2, 4, 5, 10, 11 etc then the result is black in eevee and in cycles
    if the value is 3, 6, 12, 13, 14, 15, 24, 30 etc then the result is white in eevee and black in cycles

here are some screenshots plus the file itself although i dont expect it to be of any help


modulo.blend (917.9 KB)

This is probably a floating point arithmetric problem.
You should report it as a bug.

thnx for the reply, so you think it might be a bug then?
then at least i can finally stop trying to make it work and just do it with division and subtraction nodes
im building a large and complex shader and this was frustrating me

still, im a bit hesitant to report it as a bug because everyone else says its working fine on their system but also i dont see how such an obvious bug in such a popular (i assume) basic node could have gone unnoticed by other users

3 mod 3 == 0 but Blender (Eevee) says 3 mod 3 == 3, then it has to be a bug. (something designed and supposed to work, but it doesn’t)

I can also confirm that it’s happening in my machine (AMD, all versions since 3.6 up to 4.3.1).didn’t test even older versions… but it might still be there

It’s funny that until now nobody really stepped into this!!!
(I rarelly use Eevee, but still…)

3 Likes

Yeah I’d report it aswell. To give you some feedback I dont get with integer values here as you get, just with some float values like eg 3.2, but then also just in Eevee and not Cycles. I am not sure if the modulo node here is defined to work fully on float values though.

1 Like

Hello,

Sorry, but no problems on my side, :blender_logo_64_png: 4.3.0 - 4.2 LTS & 3.6 LTS

Cycles :

EEVEE :

EEVEE “float” :


(CPU Intel i7 - GPU NVidia GTX 1080 Ti)

1 Like

It may be that NVidia cards don’t have this problem… (and would explain that I’ve never encountered this before)

If it’s a floating point error, then it’s completly dependent on the video card/driver, and some alternative procedure must be created for the ‘faulty’ chipsets.
Still, it’s a bug and should be reported.

3 Likes

wow, so its not just me
and it could be related to hardware (i really wouldnt see that coming)
but that would explain why some users get it and some dont
also its safe to assume that the majority of users would be using nvidia for the benefit of gpu acceleration so that also partially answers why not many people have encountered this issue if the source of the problem is indeed hardware/driver related
i will mark Secrop s answer as a solution

also thanks a lot for your replies and tests everyone

2 Likes

either hardware or drivers, I have a Nvidia 3060, it is a shame that AMD can not break the Nvidia monopoly.

At least you are not going mad :grinning:

Out of curiosity, does it happen with cycles set to CPU too? And are both floored and truncated modulo buggy? (Cannot replicate it here either btw, gtx 1060)

How does this look for you under Eevee?
32

1 Like

Oooh, now I get it. Not with your value but with some values it definitely puts out the input number instead of 0. Both with trunc and floored modulo.

comparing mod output with input value and 0 and then multiply the inverse would be my idea for a workaround but this is definitely a bug.
modulo_bug.blend (453.4 KB)

2 Likes