【发布时间】:2014-03-18 20:14:52
【问题描述】:
我的应用程序中有一个顶点着色器,它在 iPad 模拟器上的结果与具有相同输入的 iPad Mini 上的结果截然不同。
上面是模拟器的问题截图(也是我希望的结果),下面是iPad Mini上的结果:
我相信我已经将问题缩小到顶点着色器中的一个函数,如下所示
float dist(vec2 a, vec2 b) {
return sqrt(pow(a.x + b.x, 2.0) + pow(a.y + b.y, 2.0));
//when the line below is used the results are identical
// return 1.0;
}
从我的评论中可以看出,注释掉第一个return语句并返回1.0的结果是两个着色器返回相同的结果。
下面是上下文中的函数。
attribute vec3 position;
uniform vec2 wavePos;
uniform float waveAmplitude;
uniform float wavePeriod;
uniform mat4 modelViewProjectMatrix;
//this is the problem function
float dist(vec2 a, vec2 b) {
return sqrt(pow(a.x + b.x, 2.0) + pow(a.y + b.y, 2.0));
//when the line below is used the results are identical
// return 1.0;
}
void main() {
vec3 newPosition = position;
newPosition.z = 0.1 * ((wavePeriod - dist(position.xy, wavePos))/wavePeriod) * waveAmplitude;
// uncommenting this does not solve the inconsistent output problem
//newPosition.z = dist(position.xy, wavePos);
gl_Position = modelViewProjectMatrix * vec4(newPosition, 1.0);
}
【问题讨论】:
-
您是否尝试过明确指定
precision highp float? -
我已经尝试
highp的返回类型为dist。precision highp是在模拟器上运行时出现语法错误。
标签: ipad opengl-es ios-simulator opengl-es-2.0 glsl