在阅读 URP 的 shader 发现基本都有这么一些编译指令:
// Required to compile gles 2.0 with standard SRP library
// All shaders must be compiled with HLSLcc and currently only gles is not using HLSLcc by default
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
从上面的注释中,翻译可得知:
需要使用 Standard SRP 库来编译 gles 2.0
所以 shaders 必须使用 HLSLcc 来编译,并且当前仅有 gles 默认不是使用 HLSLcc 编译器的
所以他的意思就是:如果你发布的游戏有可能再 gles 跑的,那么要设置 pragma perfer_hlslcc gles
来将 shader 编译器设置为 HLSLcc
来编译,搜索了一下,发现 unity 论坛也有人发问过类似的问题:Shader compile pipe in Lightweight Rendepipeline
上面截图是回复的内容,说的是,CG 代码提供给 DX 编译器的话,输出结果前会使用:HLSLcc 编译器来编译 和 优化的。
在 2018.3 版本开始 HLSLcc 编译器就已经作为 ES2 的默认编译器了,尽可能的让每个 shader 都使用 hlsl2glsl 来编译
也就是说,2018.3 的 unity版本之后,都可以不设置?
如果是都不用设置的话,那我已经是在 2019.4.30f1 版本环境了,都超过了 2018.3 版本的,为何 URP shader 还有这样的注释 和 编译指令