GLSL 多着色器程序 VS 制服切换 [英] GLSL multiple shaderprogram VS uniforms switches

查看:34
本文介绍了GLSL 多着色器程序 VS 制服切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究着色器管理器架构,我有几个问题要问更高级的人.我目前的选择反对以下两种设计:

I'm working on a shader manager architecture and I have several questions for more advanced people. My current choice oppose two designs which are:


1.每个材质着色器程序

=> 为程序中使用的每种材质创建一个着色器程序.


1. Per material shader program

=> Create one shader program per material used in the program.

  • 考虑到每个对象可能都有自己的材质,它涉及到大量的 glUseProgram 调用.
  • 暗示创建了许多着色器程序对象.
  • 比 #2 更复杂的架构.
  • 可以为材质中使用的每个选项"专门生成着色器代码.
  • 如果我没记错的话,uniform 只需要设置一次(在创建着色器程序时).


2.全局着色器程序

=> 为每个着色器功能(闪电、反射、视差贴图...)创建一个着色器程序,并使用配置变量根据要渲染的材质启用或放弃选项.


2. Global shader programs

=> Create one shader program per shader functionality (lightning, reflection, parallax mapping...) and use configuration variables to enable or discard options depending on the material to render.

  • 每帧必须多次更改制服.
  • 较低的着色器程序数.
  • 减少 SP 切换 (glUseProgram).


您可能会注意到我目前的倾向是#1,但我想知道您对此的看法.


You might notice that my current tendency is #1, but I wanted to know your opinion about it.

  • 初始制服设置是否抵消了 glUseProgram 调用开销(我不是特别讨厌速度)?
  • 在第 1 种情况下,出于任何内存或性能方面的考虑,我应该在创建 SP 时只调用一次 glLinkProgram,还是每次调用 glUseProgram 时都必须取消链接/链接?
  • 是否有更好的解决方案?

谢谢!

推荐答案

让我们看看#1:

考虑到每个对象可能都有自己的材质,它涉及到大量的 glUseProgram 调用.

Considering every object might have its own material, it involves a lot of glUseProgram calls.

这没什么大不了的,真的.交换程序很难,但你也会交换纹理,所以并不是说你还没有改变重要的状态.

This isn't that big of a deal, really. Swapping programs is hard, but you'd be swapping textures too, so it's not like you're not already changing important state.

暗示创建了很多shaderprogram对象.

Implies the creation of a lot of shaderprogram objects.

这会很痛.实际上,#1 的主要问题是着色器的爆炸性组合.尽管 ARB_separate_program_objects 会有所帮助,但这仍然意味着您必须编写大量着色器,或者想出一种不编写大量着色器的方法.

This is going to hurt. Indeed, the main problem with #1 is the explosive combination of shaders. While ARB_separate_program_objects will help, it still means you have to write a lot of shaders, or come up with a way to not write a lot of shaders.

或者您可以使用延迟渲染,这有助于缓解这种情况.它的众多优点之一是它将材料数据的生成与将材料数据转换为光反射率(颜色)的计算分开.因此,您可以使用的着色器要少得多.您有一组生成材质数据的着色器,还有一组使用材质数据进行光照计算.

Or you can use deferred rendering, which helps to mitigate this. Among its many advantages is that it separates the generation of the material data from the computations that transform this material data into light reflectance (colors). Because of that, you have far fewer shaders to work with. You have a set of shaders that produces material data, and a set that uses the material data to do lighting computations.

所以我会说使用 #1 和延迟渲染.

So I would say to use #1 with deferred rendering.

这篇关于GLSL 多着色器程序 VS 制服切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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