Page MenuHome

7 mod 7 in Eevee Math Node return an incorrect value
Closed, ResolvedPublicBUG

Description

While in Cycles the 7 mod 7 correctly returns 0, in Eevee it returns 7.

Exact steps for others to reproduce the error

  • Open 7_mod_7__bug.blend
  • Compare the result of Eevee and cycles


Original Report:

System Information
Operating system: Linux-5.19.0-76051900-generic-x86_64-with-glibc2.35 64 Bits
Graphics card: NVIDIA GeForce RTX 3070 Laptop GPU

Blender Version
Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: rB0759f671ce1f
Worked: Unknown. I stopped checking older versions after the error was still occurring in 2.91.0; bug also present in 3.4 alpha and the nightly build of 3.3.1 release candidate.

Short description of error
In this Blender Studio course, when performing the Round-to-Modulo operation at about the 11-minute mark, I was experimenting with different values and found that the looping pattern breaks when a value that rounds to 7 is used for the "Repitition" input value node. Further experimenting revealed that, with a "Width" input node value small enough for dozens of rows to be present, the looping pattern breaks down with EVERY value I've tried (except zero, which does return a completely black surface). The broken pattern differs between Viewport Shading and Rendered modes.

Exact steps for others to reproduce the error

  1. Open a new blend file and select the default cube.
  2. Switch to the Shading workspace and create a new material.
  3. Add a UV Map input node and connect it to the Base Color input of the Principled BSDF (or directly into the Surface input of the Material Output node).
  4. Place a Separate XYZ node after the UV Map node.
  5. Place a Math node after the Separate XYZ node and set it to Snap.
  6. Place a Math node after the Snap node and set it to Divide.
  7. Place a Math node after the Divide node and set it to Modulo.
  8. Add a Value input node, name it "Width" (or something else descriptive), and connect it to both the Increment input in the Snap node and the second Value input in the Divide node; set the value to around .01 or smaller.
  9. Add a second Value input node, name it "Repetition" (or, again, whatever you choose), and connect it to the second Value input of the Modulo node; set the value to .5 or higher (7 is effective at demonstrating the issue and is what I reference below).
  10. Place a Math node after the Repetition node and set it to Round.
  11. The pattern displayed on the cube will not be a regular pattern of values stepping up by a value of 1. If Repetition is set to 7, for example, instead of a pattern of values looping from 0-6 before restarting at 0, most iterations instead start at 1 and step up to 6, but a few others start at 1 and step up to 7, and here and there one loop will appear as it should.
  12. Using Cycles, switch from the Viewport Shader to Rendered mode and the patterns will be different but still wrong.

The issue is readily apparent upon opening the attached .blend file.

Event Timeline

Thank you for the report.
I can confirm the problem, but the description and file can be greatly simplified.
The real problem is that 7 modulus of 7 in Eevee is being calculated as 7 instead of 0. This must be a precision issue.

Germano Cavalcante (mano-wii) renamed this task from Snap and Modulo nodes not working as expected with rounded values. to 7 mod 7 in Eevee Math Node return an incorrect value.Oct 4 2022, 12:53 AM
Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Confirmed.
Germano Cavalcante (mano-wii) updated the task description. (Show Details)
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".

As an additional data point, 7 Modulo 7 is 0 for me in EEVEE and Cycles.

Perhaps my older GPU has to use a fallback function that ends up doing the correct math?


version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: 0759f671ce1f, type: release
build date: 2022-09-07, 00:44:18
platform: 'Windows-10-10.0.19043-SP0'

version: 3.4.0 Alpha, branch: master, commit date: 2022-10-04 02:54, hash: bf4926b30c6f, type: Release
build date: 2022-10-04, 05:46:09
platform: 'Windows-10-10.0.19043-SP0'

renderer: 'GeForce GTX 470/PCIe/SSE2'
vendor: 'NVIDIA Corporation'
version: '4.5.0 NVIDIA 391.35'

I just want to mention that the issue is occurring regardless of the value, not just 7 mod 7. Here are some demonstrative screenshots using the setup I described and the values 1-4. Note that the error occurs in both EEVEE and Cycles and that for the value of 3 the snap increment needed to be significantly smaller (suggesting it is a precision issue) and the patterns in EEVEE and Cycles are different but both erroneous.