如何将视图/模型/投影矩阵传递到 OpenGL ES 2.0 中的顶点着色器?
在 OpenGL ES 2.0 中,您显然无法再进行
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
设置模型矩阵,但我认为这些矩阵仍然以某种方式内置,因为 GLSL 规范 告诉您如何在顶点着色器中访问它们。
//
// Matrix state. p. 31, 32, 37, 39, 40.
//
uniform mat4 gl_ModelViewMatrix;
uniform mat4 gl_ProjectionMatrix;
uniform mat4 gl_ModelViewProjectionMatrix;
那么如何将这些值传递给我的着色器呢? 我是否以某种方式使用glUniformMatrix4fv?
OpenGL ES 2.0 编程指南 中的源代码对着色器部分很有帮助,但所有示例似乎只是保留矩阵变换并确保它们的顶点在 -1.0 和 1.0 之间。
更新:显然 OpenGL ES 着色器语言不支持像 gl_ModelViewMatrix
这样的预定义条目,因此唯一的答案是定义您自己的自定义模型/视图/投影矩阵,如下面链接的代码中所示,使用 glGetUniformLocation
和 <代码>glUniformMatrix4fv。 我很困惑,因为 OpenGL Shader Builder 确实支持它们,但那是普通的 OpenGL,而不是 OpenGL ES。
In OpenGL ES 2.0, you apparently can't do
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
any more to set the model matrix, but I think these matrices are still built in somehow, since the GLSL spec tells you how to access them in a vertex shader.
//
// Matrix state. p. 31, 32, 37, 39, 40.
//
uniform mat4 gl_ModelViewMatrix;
uniform mat4 gl_ProjectionMatrix;
uniform mat4 gl_ModelViewProjectionMatrix;
so how do I pass these values to my shader? do I use glUniformMatrix4fv
somehow?
The source code from the OpenGL ES 2.0 Programming Guide has been helpful for the shader part but all the examples appear to just leave the matrix transforms alone and just make sure their vertices are between -1.0 and 1.0.
UPDATE: apparently the OpenGL ES Shader Language does not support the pre-defined entries like gl_ModelViewMatrix
, so the only answer is to define your own custom model/view/projection matrices as done in the code linked below, using glGetUniformLocation
and glUniformMatrix4fv
. I was confused because the OpenGL Shader Builder does support them, but that's plain OpenGL, not OpenGL ES.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gl_ModelViewProjectionMatrix 似乎不在“OpenGL ES 着色语言版本 1.00”规范中。 着色语言规范似乎有很多,因此这可能是造成混乱的原因。 据我了解,您可以为矩阵存储定义自己的制服。
gl_ModelViewProjectionMatrix does not appear to be in the "OpenGL ES Shading Language version 1.00" specification. There seems to be many Shading Language specifications, so that likely was the cause of confusion. As I understand it, you define your own uniforms for matrix storage.