smkplus / ShaderMan

Convert ShaderToy to Unity HLSL/CG
https://smkplus.github.io/ShaderMan.io
MIT License
1.42k stars 197 forks source link

There is a problem about converting mod to fmod #44

Open jovensun opened 2 years ago

jovensun commented 2 years ago

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 isx - 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