开发者

Optimising the model-view transformation in GLSL for 2D

So, the standard way to transform vertices and then pass to the fragment shader in GLSL is something like this:

uniform mat4 u_modelview;
attribute vec4 a_position;

void main() {
    gl_Position = u_modelview * a_position;
}

However, I am working 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 an extra operation is required at output. However the matrix multiplication is for 9 elements instead of 16. Can 开发者_开发技巧I do any better?


I think that graphics hardware transforms with 3x3 and 4x4 matrices for the same amount of time. Do you have a proven bottleneck at the process of transforming vertices? Usually slowdown appears at the fragment shader, not the vertex


It depends. If you have complex information per-vertex and it's a bottleneck for you, then if you decrease the per-vertex data you should see some speed increase.

The best thing is to set up a test and measure it both ways.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜