Optimize model conversion to GLSL for 2D

So, the standard way to convert vertices, and then go to the fragment shader in GLSL, looks something like this:

uniform mat4 u_modelview; attribute vec4 a_position; void main() { gl_Position = u_modelview * a_position; } 

However, I work in 2D, so there is redundancy in the 4x4 matrix. Would it be more efficient for me to do this?

 uniform mat3 u_modelview; attribute vec3 a_position; void main() { gl_Position = vec4(u_modelview * a_position, 1.0); } 

gl_Position requires a 4-component vector, so the output requires an additional operation. However, matrix multiplication is for 9 elements instead of 16. Can I do better?

+4
source share
2 answers

I think that graphic equipment is converted with 3x3 and 4x4 matrices in the same amount of time. Do you have a proven bottleneck in the vertex conversion process? Usually the slowdown appears in the fragment shader, and not at the top

+4
source

It depends. If you have complex information for each vertex and this is a bottleneck for you, then if you reduce the data on the top, you should see some increase in speed.

It’s best to set up a test and measure it in both directions.

+1
source

Source: https://habr.com/ru/post/1345424/


All Articles