着色器在哪里适合OpenGL中的较早渲染方法? [英] Where do shaders fit in with the older methods of rendering in OpenGL?

查看:130
本文介绍了着色器在哪里适合OpenGL中的较早渲染方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多在线教程之后,我已经在OpenGL中编写了一个关卡渲染器.我实际上使用顶点数组和范围绘制命令进行渲染.现在,因为我想用每个像素的光照来照明水平,所以我意识到,着色器在当前不是OpenGL的主要部分,还是很大的一部分.

因此,在这里,我使用了不使用着色器的传统"渲染方法,并且我想知道着色器如何适应事物的整体场景.如果我重新利用OpenGL的最新功能,我的主要渲染功能是否真的可以通过着色器完成?我可以将渲染保留在代码中,而仅使用着色器进行照明吗?

我想正确地做到这一点,而不是很快,所以我将继续阅读OpenGL Superbible并继续学习.

任何人都可以教育我如何适应所有内容,以及这些旧的在线教程(如Nehe和Gametutorials)是否仍然适用.

解决方案

使用固定功能OpenGL大致遵循以下步骤:

  • 设置投影矩阵
  • 设置模型视图矩阵
  • 设置照明参数
  • 将纹理绑定到纹理单位
  • 定义纹理环境操作
  • 设置几何(顶点阵列/顶点缓冲对象)
  • 问题绘图命令

使用着色器时,前5个步骤有所不同.着色器替换了固定功能管线,该管线由在那里完成的设置控制.首先,也是最重要的是,您必须提供实现顶点转换和片段生成的着色器.这些着色器将其参数称为 Uniforms .

您仍在使用矩阵,只是这一次是通过制服而不是矩阵堆栈将它们传递到OpenGL(在OpengGL-2和OpenGL-3兼容性配置文件中,矩阵堆栈仍然存在,并且矩阵已放入内置的制服中.) /p>

纹理仍然绑定到纹理单元.使用采样器制服纹理单元被传递到片段生成中.整个纹理环境已被片段着色器取代.坦率地说:设置片段着色器比摆弄glTexEnvi的调用要容易得多.

照明是通过着色器进行的,因此您可以将照明参数作为制服传递,并在着色器中进行计算.

尽管绘制命令保持不变.

我的主要渲染功能实际上是否将通过着色器完成

如果这是您的意思,是否着色器将执行绘图调用:不!实际上,将不使用显示列表,选择模式和即时模式的旧OpenGL-1.1渲染器提升到OpenGL-3内核并不难. (但是,如果涉及显示列表,选择模式和立即模式...)

I have written a level renderer in OpenGL following many online tutorials. I actually render with vertex arrays and the range draw command. Now because I want to have the level lit with per pixel lighting, I realize shaders are a huge part if not the main part of OpenGL at this point.

So here I am with my "traditional" method of rendering without shaders and I want to know how shaders fit into the grand sceme of things. Will my main rendering function actually be done with shaders if I rework it to utilize the latest capabilities of OpenGL? Can I leave the rendering in code and just use shaders for lighting?

I want to do this correctly, not fast so I am going to continue reading through OpenGL Superbible and learning as I go.

Can anyone educate me as to how everything fits in and if these old tutorials online like Nehe and gametutorials are actually still applicable.

解决方案

Using fixed function OpenGL coarsely follows those steps:

  • Setting projection matrix
  • Setting modelview matrix
  • Set lighting parameters
  • Bind textures to texture units
  • Define texture environment operations
  • Setting up geometry (Vertex Arrays / Vertex Buffer Objects)
  • Issue draw commands

It are the first 5 steps that differ, when using shaders. Shaders replace the fixed function pipeline, which is controlled by the settings done there. First and formost you must supply shaders that implement the vertex transformation and fragment generation. Those shaders take their parameters as so called Uniforms.

You still work with matrices, only this time you deliver them to OpenGL through uniforms instead the matrix stack (in OpengGL-2 and OpenGL-3 compatibility profile the matrix stack is still there and the matrices put into builtin uniforms).

Textures still bound to texture units. Using sampler uniforms texture units are passed into fragment generation. The whole texture environment has been replaced by fragment shaders. And frankly: Setting up a fragment shader is much easier than fiddling with a dozen of calls to glTexEnvi.

Lighting happens through shaders, so you pass lighting parameters as uniforms and do the calculations in the shaders.

The drawing commands though remain the same.

Will my main rendering function actually be done with shaders

If by that you mean, if the shader will do the drawing calls: No! Actually it is not so hard to lift an old OpenGL-1.1 renderer that doesn't make use of Display Lists, Selection Mode and Immediate Mode, to OpenGL-3 core. (If Display Lists, Selection Mode and Immediate Mode are involved though…)

这篇关于着色器在哪里适合OpenGL中的较早渲染方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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