如何执行 OpenGL ES 2.0 着色器矩阵乘法?
我正在尝试使用着色器程序转换顶点,但我无法理解结果。 我准备了一个投影、一个视图(trans)和模型(trans)矩阵:
首先我有一个顶点着色器函数:viewproj * 位置。在 Objective-C 程序中,我首先将恒等式乘以平移和投影矩阵,然后统一为 viewproj。我可以从角度上看到几何学对全局平移的响应。
我想单独统一矩阵并在着色器中全部操作。我统一了一个 proj、view(trans)、model(trans),并在着色器中尝试:projviewmodel位置。但是 sem 没有很好地转换(表示形式?)然后我尝试简单地模拟我的第一个转换。我在着色器中统一了项目和视图,我尝试使用 (viewproj)position 来执行相同的操作,但视图项目不是在 C 中完成的。
我使用第 0-4 列中描述的矩阵是第一列。并使用 http://www.songho.ca/opengl/gl_transform 中定义的结构。 html#modelview
现在我不知道我错过了什么,希望有一个简单的答案。如果有人有线索,谢谢。
pd:我可以调试这个着色器吗? (XCode + iphoneos模拟器)
I'm trying to transform vertices with a shader program, but i can't understand the results.
I prepared a projection, a view(trans), and model(trans) matrices:
First i have a vertex shader function of: viewproj * position. In a Objective-C program i start with identity multiplicated by a translation and projection matrices and then uniformed to viewproj. I can see geometry responding to a global translation, in perspective.
I would like to uniform matrices separately and operate all in shader. I uniform a proj, view(trans), model(trans), and try in shader: projviewmodelposition. But sems not well transformed (out representation?) Then i try to simply simulate my first transform. I uniform proj, and view, in shader i try with (viewproj)position in order to do the same operation, but is'nt the viewproj done in C.
I'm using matrices described in columns 0-4 is first column. And with the structure defined in http://www.songho.ca/opengl/gl_transform.html#modelview
Now i don't know what i'm missing, wish that have a simple answer. If any one have a clue, thank you.
pd: Can i debug this shaders? ( XCode + iphoneos simulator )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OpenGL 着色器中的矩阵乘法如下所示:
inPos 是 vec3 顶点位置。
如果你想要更多的矩阵(DirectX 风格),那么你必须使用
理想的矩阵应该从 OpenGL 中提取,并且投影不应该是恒等变换。如果您需要 2d 图形,请使用 gluOrtho2D。
此外,您可能会在将矩阵加载到制服中时意外转置或忘记转置矩阵。
无论如何,如果您在使用着色器时遇到问题,请首先编写无需着色器即可渲染内容的应用程序,然后编写着色器并从 OpenGL 加载变换矩阵,然后将其(如果需要)转换为自定义矩阵计算例程。
根据 OpenGL 版本,您可能可以使用 ftransform() GLSL 函数,这将进一步简化事情。
Matrix multiplication in OpenGL shader goes like this:
inPos is vec3 vertex position.
If you want more matrices (DirectX style), then you'll have to use
Ideally matrices should be extracted from OpenGL, and projection shouldn't be identity transform. Use gluOrtho2D if you need 2d graphics.
Also you could accidentally transpose or forget to transpose matrices while loading them into uniform.
Anyway, if you have trouble with shaders, first write app that will render things without shader, then write shader and load transformation matrices from OpenGL, then convert it (if you need that) to custom matrix computation routines.
Depending on OpenGL version, you may have ftransform() GLSL function available which will simplify things even further.
它的恒等->翻译->viewproj->投影,就像你说的那样:
你很难读懂。您可以发布一些代码吗?
It's identity->translation->viewproj->projection, just like you said :
You're hard to read. Could you post some code instead please ?