不准确的渲染精度比WebGL的

问题描述:

我试图让Android上单纯的噪音,在此基础上例如:不准确的渲染精度比WebGL的

https://github.com/ashima/webgl-noise/blob/master/src/noise2D.glsl

转换代码和编译它在设备上后,我意识到,模式远不是随机的。我已经将代码分解到最基本的部分,我仍然看到桌面(我测试这些在http://glslsandbox.com/e)和移动之间的巨大差异,我已经得到了这个。

#ifdef GL_ES 
precision mediump float; 
#endif 

#extension GL_OES_standard_derivatives : enable 

uniform float time; 
uniform vec2 mouse; 
uniform vec2 resolution; 

float u_time = time; 
vec2 u_resolution = resolution; 

vec3 mod289(vec3 x) { 
    vec3 t = x * 0.00346020761; 
    t = floor(t); 
    t = t * 289.0; 

    return x - t; 

    //return x - floor(x * (1.0/289.0)) * 289.0; 
} 

vec3 permute(vec3 x) { 
    vec3 t = x * 34.0; 
    t = t + 1.0; 
    t = t * x; 
    return mod289(t); 

    //return mod289(((x*34.0)+1.0)*x); 
} 


void main(void) { 

    vec2 p = vec2((gl_FragCoord.xy/u_resolution.xx - 0.5) * 2.0); 

    vec3 value = permute(p.xyx * 10000.0 + u_time * 0.1); 

    gl_FragColor = vec4(value, 1.0); 
    //gl_FragColor = vec4(p + 1.0, 0.0, 1.0); 
} 

将它们分成行的目的是我也早些遇到过这种错误。 GLSL ES fragment shader produces very different results on different devices

在设备上,此代码(#ifdef和#extension删除,并且统一变量设置正确)会产生一个白色屏幕。 (在多个设备上测试,使用#version 300 es并且使用旧着色器版本,结果始终相同。)

这是由floor()的不准确性引起的错误吗?

或者有没有办法在没有这些mod289函数的情况下生成单工噪声? (2D噪音跑就好了)

这极有可能是您的桌面GPU使用的计算(即使你在shader,只要求FP16指定mediump)FP32精度。

如果你设置precision highp float它工作得更好吗?这将强制执行fp32浮点计算。

但是,请注意,并非所有移动设备都支持highp-它只在OpenGL ES 3.x之后才成为强制性的,因此某些OpenGL ES 2.x GPU仅支持fp16计算。

(什么设备都在运行吗?)

+0

我只测试了较低的设备上的highp,它是ARM的Mali-400 MP2(双核)。支持es 3.0的Adreno 305更好的支持highp,解决了我的问题。 注意其他人有这个问题,你可以检查精度的支持: http://*.com/questions/4414041/what-is-the-precision-of-highp-floats-in-glsl-es -2-0-for-iphone-ipod-touch-ipad 如果不支持highp,则glGetShaderPrecisionFormat返回零。 – andras

+0

Mali-400系列仅适用于OpenGL ES 2.x,不支持fp32,因此在这种情况下,您只需获得fp16 – solidpixel