Sin (x) returns only 4 different values โ€‹โ€‹for a moderately large input in the shader of the GLSL fragment, Intel HD4000

I have a simple OpenGL 3.3 shader written in GLSL. Essentially, I evaluate sin(x) for a moderately large x (10,000 to 2,000,000), something like this:

 #version 330 out vec4 fColor; void main() { fColor = vec4(sin(gl_FragCoord.x * gl_FragCoord.y)); } 

It works fine on my NVidia graphics card, but on my Intel HD4000, the sine returns only four different values โ€‹โ€‹(+/- 1.0 and around +/- 0.3 ). over the entrance about 10,000.

System: Windows 64bit, (Intel) driver version 15.28.20.64.3347.

My questions: is this a mistake? or is it part of the freedom of suppliers to implement sine in this way?

+9
source share
1 answer

This is a fairly common โ€œmistakeโ€ in fast trigonometric implementations - they usually use an approximation that works well for values โ€‹โ€‹in the range (- & pi;, & pi;), but not good for large values.

Since the GLSL specification does not require any particular level of accuracy or precision for these functions, it can be argued that as long as the error in sin (x) is much less than | x | this is normal, but this level of error seems excessive.

+9
source

All Articles