Question

I have a vertex shader in my app that has wildly different results on the iPad Simulator as opposed to an iPad Mini with the same input. enter image description here

Above is a screenshot of the problem from the simulator (also the result I am hoping for), and below is the result on the iPad Mini:enter image description here

I believe that I have narrowed down the problem to one function in the vertex shader, reproduced below

    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;
}

As you can see from my comment, the result of commenting out the first return statement and returning 1.0 is that the two shaders return identical results.

Below is the function in context.

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);
}
Was it helpful?

Solution

changing the function to

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);
}

fixes it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top