在OpenGL引擎中组织GLSL着色器 [英] Organizing GLSL shaders in OpenGL engine

查看:120
本文介绍了在OpenGL引擎中组织GLSL着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个更好?


  1. 有一个具有大量制服的着色器程序
    使用,或者映射来做(例如,我需要一个网格进行视差映射,另一个网格进行视差/镜像映射)。

  1. To have one shader program with a lot of uniforms specifying lights to use, or mappings to do (e.g. I need one mesh to be parallax mapped, and another one parallax/specular mapped). I'd make a cached list of uniforms for lazy transfers, and just change a couple of uniforms for every next mesh if it needs to do so.

如果需要,可以为每个下一个网格更改一些制服。 对于每个需要的情况都有很多着色程序,每个都有少量制服,并且如果需要,可以使用 glUseProgram 执行惰性绑定。这里我假设网格正确分批,以避免重复切换。

To have a lot of shader programs for every needed case, each one with small amount of uniforms, and do the lazy bind with glUseProgram for every mesh if it needs to do so. Here I assume that meshes are properly batched, to avoid redundant switches.


推荐答案

我知道的大多数现代引擎有一个着色器缓存并使用第二个选项,因为显然它的速度更快。

Most modern engines I know have a "shader cache" and use the second option, because apparently it's faster.

也可以看看ARB_shader_subroutine,连锁。但我认为它只有DX11类硬件。

Also you can take a look at the ARB_shader_subroutine which allows dynamic linkage. But I think it's only available on DX11 class hardware.

这篇关于在OpenGL引擎中组织GLSL着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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