Skip to content

There is a problem about converting mod to fmod #44

@jovensun

Description

@jovensun

Converting mod directly to fmod can cause problems, such as the toy below.
https://www.shadertoy.com/view/XsXXDn

GLSL mod is x - y * floor(x/y)
HLSL fmod is x - y * trunc(x/y)
CG fmod is

float2 fmod(float2 a, float2 b)
{
  float2 c = frac(abs(a/b))*abs(b);
  return (a < 0) ? -c : c;   /* if ( a < 0 ) c = 0-c */
}

https://forum.unity.com/threads/translating-a-glsl-shader-noise-algorithm-to-hlsl-cg.485750/#post-3164874
https://developer.download.nvidia.cn/cg/fmod.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions