B
B
black_list_man2021-01-12 12:22:31
Qt
black_list_man, 2021-01-12 12:22:31

Why does the vertex shader work so differently on different devices?

I have a vertex shader that multiplies a vertex by a normal and then projects it. Its task is to triangulate lines. Normals are calculated on the CPU. Line width is set by u_width

#version 100
attribute vec4 a_position;
attribute vec2 a_normal;
uniform mat4 u_proj;;
uniform float u_width;

void main() {
 vec4 delta = vec4(a_normal * u_width, 0, 0);
 vec4 new_pos = a_position+delta;
 gl_Position = u_proj*new_pos;
}


The result of working on a desktop under windows, on an android tablet with support for opengl es 3.1, as well as in a browser (webGL) is exactly the same. Everything works as it should. This is what the result looks like. Lines of arbitrary width are obtained.
5ffd648c05f82821115165.png

But (!) I have an android phone (based on intel Atom and opengl ES 2.0) and everything works completely differently on it. Namely: the value of u_width does not change the thickness of the line, but simply scales all the points, making the lines longer, but not wider. The picture below shows the same test scene.
5ffd64c200af7322517483.png
I can achieve exactly the same result on the desktop by simply scaling the matrix by a number equal to the line width instead of multiplying the normal.matrix.scale(width,width,0);
It turns out that on this device (phone based on intel Atom) the value of u_width simply scales the matrix. But how? And why? Maybe Qt is doing something with my shader at application compile time?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question