[英]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.