Reputation: 448
I have this fragment shader code that displays differently between iOS simulator (non-retina) and iPad2 (non-retina) :
highp vec2 textCoord;
textCoord.x = gl_FragCoord.x / uViewPortWidth;
textCoord.y = gl_FragCoord.y / uViewPortHeight;
highp vec4 resultColor = texture2D(uTexture, textCoord);
gl_FragColor = resultColor;
Somehow in real device, the result is jagged. But in simulator, it's smooth as hell.
Real device :
Is it because of precision problem of the gl_FragCoord? Weird how it only works on simulator...
Any tips how to deal with gl_FragCoord? Thanks!
Upvotes: 1
Views: 922
Reputation: 100602
gl_FragCoord
is defined as mediump
. So compliant implementations of ES 2 can give it as little as 10 bits of storage. However ES doesn't place an upper limit, so another equally compliant implementation may discard the precision modifiers and treat everything as a 16-bit (or greater) type.
It also stipulates that:
The precision used to internally evaluate an operation, and the precision qualification subsequently associated with any resulting intermediate values, must be at least as high as the highest precision qualification of the operands consumed by the operation.
So the precision used to perform your calculations will be at least mediump
— or highp
if that's how uViewPortWidth/Height
are declared.
However exactly what precision that gives you is still implementation dependant. Anecdotally, the simulator does generally use a higher precision.
So, as a first attempt, make sure that divide is highp
by any means. If that doesn't get the precision you want then the GPU likely doesn't provide it in a single unit so you'll have to consider a more complicated solution.
Upvotes: 2