【问题标题】:Why does this Vertex Shader have different output on the device vs. the simulator为什么这个顶点着色器在设备和模拟器上有不同的输出
【发布时间】: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 的返回类型为distprecision highp 是在模拟器上运行时出现语法错误。

标签: ipad opengl-es ios-simulator opengl-es-2.0 glsl


【解决方案1】:

把函数改成

highp float dist(vec2 a, vec2 b) {

    float xsum = a.x + b.x;
    float ysum = a.y + b.y;
    return sqrt(xsum*xsum + ysum*ysum);
}

修复它。

【讨论】:

    猜你喜欢
    • 2013-12-10
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多