基于此示例,我正在尝试在 android 上发出单纯形噪声:
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 片段着色器在不同设备上产生非常不同的结果
在设备上,此代码(#ifdef 和 #extension 已删除,并且统一变量设置正确)会产生白屏。(在多个设备上测试,使用 #version 300 es 并使用较旧的着色器版本,结果始终相同。)
这个错误是由 floor() 不准确引起的吗?
或者有没有办法在没有这些 mod289 函数的情况下生成单纯形噪声?(2d 噪音运行得很好)