7

I'd like to transpose a matrix in my OpenGL ES 2.0 vertex shader, but apparently my iPad 3 doesn't support GLSL #version 120, which is needed for the built-in function transpose(mat4).

I know there are options to work around that, like transposing the matrix on the CPU before passing it to the graphics chip, but it would make my shader a lot simpler if I could transpose it there.

So, is there an option to transpose a mat4 in a shader on an iOS 6 device?

Another thing: The question

What version of GLSL is used in the iPhone(s)?

says that OpenGL ES 2.0 uses GLSL 1.20. So why doesn't #version 120 work on the iPad 3?

4

2 回答 2

14

您是否尝试过自己转置它?是性能问题吗?如果没有,我会尝试它,因为这是优化器应该处理的事情,并且需要两分钟。就像是:

highp mat4 transpose(in highp mat4 inMatrix) {
    highp vec4 i0 = inMatrix[0];
    highp vec4 i1 = inMatrix[1];
    highp vec4 i2 = inMatrix[2];
    highp vec4 i3 = inMatrix[3];

    highp mat4 outMatrix = mat4(
                 vec4(i0.x, i1.x, i2.x, i3.x),
                 vec4(i0.y, i1.y, i2.y, i3.y),
                 vec4(i0.z, i1.z, i2.z, i3.z),
                 vec4(i0.w, i1.w, i2.w, i3.w)
                 );

    return outMatrix;
}
于 2013-08-04T00:03:26.287 回答
4

作为对 iPhone 中使用的是什么版本的 GLSL 的答案正确地说,iOS 支持 OpenGL ES 2.0 及其配套的着色语言:ESSL 1.0。ESSL 1.0 基于但不等同于 GLSL 1.20。

ESSL 1.0 中没有内置转置功能,因此您需要自己实现。

于 2013-08-04T19:39:17.353 回答