Skip to content

Porting GLSL shader mod() function to Metal Compute Shader

novocodev edited this page Jun 17, 2016 · 3 revisions

When porting shaders from GLSL shader language to Metal shader language the GLSL mod() function is not the same a the Metal fmod() function.

GLSL mod() can be expanded to:

return x - y * floor(x/y)

Metal fmod() can be expanded to:

x – y * trunc(x/y)

fmod() returns the same value as mod() while x and y are positive, but returns different values if either x or y are negative.

Clone this wiki locally