[英]Fragment shader seems to floor() imprecisely
我正在尝试在片段着色器中插入坐标。 不幸的是,如果接近上边缘,则fVertexInteger
的插值似乎是四舍五入的,而不是fVertexInteger
。 这发生在大约fVertexInteger >= x.97
。
例:
floor(64.7)
返回64.0
>正确
floor(64.98)
返回65.0
>错误
在x.0
以上的天花板收盘处x.0
发生同样的情况,其中ceil(65.02)
返回65.0
而不是66.0
。
问:有什么想法如何解决?
注意:
片段着色器:
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 );
}
我不完全知道什么是精度mediump float
实际上是在OpenGL ES在Android,但最有可能的解释是,该文本(或实际代码的变化值) 64.98
已四舍五入为65
(使用圆最接近的位置),甚至还没有放到floor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.