Be aware that the GLSL mod function is not an exact equivalent to fmod function in HLSL, the result will be different when dealing with negative values. HLSL fmod is equivalent to x - y * trunc(x/y) GLSL mod is equivalent to x - y * floor(x/y)) If you are converting a shader, you may want to implement your own mod function using that code instead.