Division can be slightly off in materials custom node with parameter input

Summary

division that should result in 1.0 will be ~0.99999995 (the next lower value to 1.0 in a 32bit float) in the custom node (in materials)

factors to reproduce:

  • affects division in custom node (HLSL)
  • the divisor (denominator) must be fed by a material parameter, not a constant
  • affected float values for input: 3, 6, 7, 12, 13, 14, 15, 24, 26, 28, 30, 37, 41, 45, 47, 48, …

note:

  • the bit representation of the values inside the the custom node are identical (I built myself a visualizer)
  • Unreals default divide node is not affected

my guess:
The compiler is usually optimizing something, but can’t do that if the divisor is an unpredictable parameter. That’s my guess because the input values in “va1/var2” can be the same in bit representation, but the result will still be slightly off, if var2 is fed by an independent parameter.

returns true:
“return var1/var1 == 1;”

these variations return false:
“return var1/trunc(var1) == 1;”
“return trunc(var1)/var1 == 1;”
“return var1/floor(var1) == 1;”
“return floor(var1)/var1 == 1;”
“return var1/ceil(var1) == 1;”
“return ceil(var1)/var1 == 1;”
Also using the nodes of trunc, floor, ceil outside the custom node and having “return var1/var1 == 1;” inside the custom node, will return false as well.

What Type of Bug are you experiencing?

Rendering (Graphics / Niagara)

Steps to Reproduce

  1. create a material
    in the material:
  2. add a custom node and copy/paste this line into it: return var1/trunc(var1) == 1;
  3. connect the output of the custom node to emission of the material
  4. add an input to the custom node via details panel and call it var1
  5. feed the var1 input with a scalar parameter (no constant), set to 3.0 as default value

Expected Result

The material should be white 1.0 (true) since 3/3=1.

Observed Result

The material preview is black since the return value is 0.0 (false).

Affects Versions

5.8

Platform(s)

Windows

Upload an image