Fragment shader seems to floor() imprecisely
Posted
by
Peter K.
on Game Development
See other posts from Game Development
or by Peter K.
Published on 2013-11-13T10:16:07Z
Indexed on
2013/11/13
16:19 UTC
Read the original article
Hit count: 826
I'm trying to interpolate coordinates in my fragment shader. Unfortunately if close to the upper edge the interpolated value of fVertexInteger
seems to be rounded up instead of beeing floored. This happens above approximately fVertexInteger >= x.97
.
Example:
floor(64.7)
returns64.0
--> correctfloor(64.98)
returns65.0
--> incorrect
The same happens on ceiling close above x.0
, where ceil(65.02)
returns 65.0
instead of 66.0
.
Q: Any ideas how to solve this?
Note:
- GL ES 2.0 with GLSL 1.0
- highp floats are not supported in fragment shaders on my hardware
- flat varying hasn't been a solution, because I'm drawing TRIANGLE_STRIP and can't redeclare the provoking vertex (only OpenGL 3.2+)
Fragment Shader:
varying float fVertexInteger;
varying float fVertexFraction;
void main() {
// Fix vertex integer
fixedVertexInteger = floor(fVertexInteger);
// Fragment color
gl_FragColor = vec4(
fixedVertexInteger / 65025.0,
fract(fixedVertexInteger / 255.0),
fVertexFraction,
1.0 );
}
© Game Development or respective owner