Summary
The function mod(x, y) calculates the modulo of x over y, i.e., mod(x, y) = x - y * floor(x / y). It is widely used to create animations that repeat over time. For instance, a shader could use mod(iTime, 30.0) to let frames repeat every 30 seconds. The official definition of mod can be found at https://registry.khronos.org/OpenGL-Refpages/es3.0/html/mod.xhtml. However, the AMD Radeon RX 6400 gives inconsistent result for the modulo function in OpenGL ES 3.0. mod(0.0, 4.0) outputs 0.0 as expected, but mod(0.0, 3.0) incorrectly outputs 3.0.
This bug doesn't exist in other AMD GPUs such as AMD Ryzen 5800H. GPUs from other vendors, including NVIDIA RTX 3060 and Intel UHD 730, also don't have such an issue.
A quick way to reproduce the bug in the browser
If you have a Radeon RX 6400 GPU on your computer, you can quickly try to reproduce the bug in your browser by the following steps:
2. Pausing the rendering by clicking the Pause Button under the rendering output box. Then click the Reset Time Button to reset the time to zero. By doing so, the shader input `iTime` denoting the playtime will be set to 0 and will not elapse.
3. Copy & paste the following code into the code box.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
fragColor = vec4(vec3(mod(iTime, 3.0)), 1.0);
}
Click the Compile button under the code box. Do not click the Resume Button since it will cause the iTime to be greater than 0. Now you would see a white screen output, indicating that mod(0.0, 3.0) incorrectly outputs 3.0.
4. Copy & paste the following into the code box:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
fragColor = vec4(vec3(mod(iTime, 4.0)), 1.0); // change the modulo constant from 3.0 to 4.0
}
Click the Compile button under the code box. The output would be a black screen. This is the correct behavior since mod(0.0, 4.0) should be 0.0.
Detailed description and how to reproduce on desktop