在OpenGL ES 2.0 GLSL中转置mat4 [英] Transpose a mat4 in OpenGL ES 2.0 GLSL
问题描述
我想在OpenGL ES 2.0顶点着色器中转置矩阵,但是显然我的iPad 3不支持GLSL #version 120
,这是内置函数transpose(mat4)
所必需的.
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)
.
我知道有一些方法可以解决此问题,例如在将矩阵传递到图形芯片之前将其在CPU上转置,但是如果我可以将其转置到那里,它将使我的着色器更加简单.
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.
因此,在iOS 6设备上的着色器中是否可以选择transpose
mat4?
So, is there an option to transpose
a mat4 in a shader on an iOS 6 device?
另一件事:问题
表示OpenGL ES 2.0使用GLSL 1.20.那么#version 120
为什么不能在iPad 3上运行?
says that OpenGL ES 2.0 uses GLSL 1.20. So why doesn't #version 120
work on the iPad 3?
推荐答案
您是否尝试过自行移调?这是性能问题吗?如果没有,我会尝试一下,因为这是优化程序应该处理的事情,它将花费两分钟.像这样:
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;
}
这篇关于在OpenGL ES 2.0 GLSL中转置mat4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!