固定功能Vs.着色器-帮助理解概念上的差异 [英] Fixed-Function Vs. Shaders - help understand the conceptual differences

查看:67
本文介绍了固定功能Vs.着色器-帮助理解概念上的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的背景:几个月前,我首次开始使用OpenGL进行实验,这并不是出于特殊目的,只是出于乐趣.我开始阅读OpenGL红皮书,并深入研究了具有许多不同照明的行星系统.持续了一个月,我对openGL的兴趣消失了.大约一周前,它再次醒来,当我从一些SO帖子中收集到的时候,红皮书已经过时了,OpenGL Superbible是更好的学习资源.因此,我开始阅读它.我喜欢着色器的概念,但是由于我对固定管线的旧记忆和着色器的新概念的过渡,我的大脑中发生了真正的混乱.

My background: I first started experimenting with OpenGL some months ago, for no particular purpose, just fun. I started reading the OpenGL redbook, and got as far as making a planetary system with a lot of different lighting. That lasted for a month, and my interest for openGL went away. It awoke again a week or so ago, and as I gathered from some SO posts, the redbook is outdated and the OpenGL Superbible is a better source for learning. So I started reading it. I like the concept of shaders but there's a real mess going on in my brain because of transition from my old memories of the fixed pipeline and the new concept of shaders.

问题:我想写一些我认为是正确的声明,并请OpenGL专家对其进行验证(即我是否正确理解,不太正确或绝对错误).所以...

Question: I would like to write some statements which I think are true and I am asking OpenGL experts to verify them (i.e. whether I am understanding correctly, not quite correctly or absolutely incorrectly). So...

1)如果我们不 使用 任何着色器程序,则没有任何变化.我们有当前颜色,当前法线,当前变换矩阵,当前所有内容,一旦调用glVertex**(...),就会获取这些当前值并将顶点馈入...我不知道该怎么办.事实是,它已使用当前矩阵进行了变换,并对其应用了当前颜色和法线等.

1) If we don't use any shader program, nothing changes. We have current color, current normal, current transformation matrix, current everything, and as soon as we call glVertex**(...) these current values are taken and the vertex is fed to ... I don't know what. The fact is that it's transformed with the current matrix, the current color and normal are applied to it etc.

2)一旦我们 使用 着色器程序,以上所有内容便停止工作.也就是说,glColorglRotate等没有任何意义(是吗?).我的意思是,glColor仍会设置当前颜色,glRotate仍会将当前矩阵乘以旋转矩阵,但是根本没有使用这些颜色.相反,我们通过glVertexAttrib来输入顶点属性.哪个属性表示什么完全取决于我们的顶点着色器和in变量绑定.我们还发现要设置制服的值,然后调用glVertex并执行着色器(我不知道立即还是调用glEnd()之后).实际的顶点和片段处理完全在着色器程序中手动完成.

2) As soon as we use a shader program, all the above stops working. That is, glColor, glRotate etc. make no sense (Do they?). I mean, glColor still does set the current color, glRotate still multiplies the current matrix by the rotation matrix, but these aren't used at all. Instead, we feed vertex attributes by glVertexAttrib. Which attribute means what is totally dependent on our vertex shader and the in variable binding. We also find ans set the values of the uniforms and then call glVertex and the shader is executed ( I don't know immediately or after glEnd() is called). The actual vertex and fragment processing is done entirely manually in the shader program.

3)着色器不向深度测试添加任何内容.也就是说,我不需要在着色器中进行处理.我只是打电话给glEnable(GL_DEPTH_TEST).脸部剔除也不受影响.

3) Shaders don't add anything to depth testing. That is, I don't need to take care of it in a shader. I just call glEnable(GL_DEPTH_TEST). Neither is face culling affected.

4)在着色器中无需注意Alpha混合和抗锯齿. glEnable通话就足够了.

4) Alpha blending and antialiasing need not be taken care of in shaders. glEnable calls will suffice.

5)使用gluPerspective,glRotate,glPushMatrix和其他矩阵函数,然后检索当前矩阵并将其作为统一供入着色器,是否是一个好主意?因此,不需要使用第三方矩阵库.

5) Is it a good idea to use gluPerspective, glRotate, glPushMatrix and other matrix functions, and then retrieve the current matrix and feed it as a uniform to a shader? Thus there won't be any need in using a 3rd party matrix library.

推荐答案

  1. 这取决于您所讨论的OpenGL版本.直到OpenGL 3.0,所有固定功能仍然存在,因此,是的,如果您决定只使用固定功能,它将继续像往常一样工作.从3.0开始,不推荐使用大量固定管道,而从3.1开始,它已完全消失.使用这些,您实际上不再具有仅使用固定管道的选项.

  1. It depends on what version of OpenGL you're talking about. Up through OpenGL 3.0, all the fixed functionality is still present, so yes, if you decide to just use fixed functionality it continues to work like it always did. Starting from 3.0, quite a bit of the fixed pipeline was deprecated, and as of 3.1 it disappears completely. Using these, you no longer really have the option to just use the fixed pipeline.

还是要视情况而定.例如,直到OpenGL 3.0,即使使用着色器,仍然支持glColor.区别在于,不是自动将其应用于绘制的内容,而是将其提供给着色器,该着色器可以不更改地使用它,按其认为合适的方式对其进行修改,或者完全忽略它.因此,您的片段着色器将接收gl_FrontColor和gl_BackColor,并将实际的片段颜色写入gl_FragColor.但是,如果您使用的是OpenGL 3.1或更高版本,则glColor(例如)将不再存在-颜色将是您提供给着色器的另一个值,就像您可能/将要进行其他任何操作一样.

Again, it depends. For example, up through OpenGL 3.0, glColor is still supported, even when you use a shader. The difference is that instead of automatically being applied to what gets drawn, it's supplied to your shader, which can use it unchanged, modify it as it sees fit, or ignore it completely. So, your fragment shader receives gl_FrontColor and gl_BackColor, and writes the actual fragment color to gl_FragColor. If you're using OpenGL 3.1 or newer, however, glColor (for example) just no longer exists -- a color will be just another value you supply to your shader like you could/would anything else.

是正确的,至少在OpenGL 3.1之前是这样.从4.0开始,有一个新的计算着色器(我相信)可以参与深度测试之类的东西(但是我还没有使用它,所以我对此不太确定).

That's correct, at least up to OpenGL 3.1. As of 4.0, there's a new compute shader that (I believe) can get involved in things like depth testing (but I haven't used it, so I'm a bit uncertain about that).

是的,您仍然可以使用内置的alpha混合.根据您的硬件,您可能还需要考虑使用gl_ARB_draw_buffers_blend扩展名(如果我没记错的话,从OpenGL 4开始是强制性的).

Yes, you can still use built-in alpha blending. Depending on your hardware, you may also want to consider using the gl_ARB_draw_buffers_blend extension (which is mandatory as of OpenGL 4, if I recall correctly).

再次,这取决于您正在谈论的OpenGL版本.当前的OpenGL完全消除了对矩阵的所有支持,因此您别无选择,只能使用其他一些矩阵库.较早的版本以统一的方式向着色器提供了gl_ModelViewMatrix和gl_NormalMatrix之类的东西,因此您可以按照自己的意愿去做.

Yet again, it depends on the version of OpenGL you're talking about. Current OpenGL completely eliminates all support for matrices so you have no choice but to use some other matrix library. Older versions supplied things like gl_ModelViewMatrix and gl_NormalMatrix to your shader as a uniform so you could go that route if you chose.

这篇关于固定功能Vs.着色器-帮助理解概念上的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆