Transpose a mat4 in OpenGL ES 2.0 GLSL

后端 未结 2 1919
清酒与你
清酒与你 2021-02-09 05:52

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 fun

2条回答
  •  死守一世寂寞
    2021-02-09 06:09

    Have you tried just transposing it yourself? Is it a performance problem? If not, I would try it because it's something the optimizer should handle and it will take two minutes. Something like:

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

提交回复
热议问题