《Unity着色器圣经》3.3.4 | ShaderLab回退

目录索引

译文

我们曾多次提到过,当我们的子着色器报错或无法与目标硬件兼容时,回退(Fallback)允许我们为材质分配一个兜底的着色器。

其语法如下所示:

Fallback "shaderPath"

“着色器路径”对应于在子着色器编译失败时用于兜底的着色器的名称和路径。

我们也可以不在程序中声明回退,可以直接留空或使用“Fallback Off(关闭回退)”,但是依然建议使用已包含在 Unity 中的内置着色器的路径和名称,例如 “Mobile/Diffuse”。这样我们就能确保着色器在编译失败时仍能继续编译。

Shader "InspectorPath/shaderName"
{
    Properties { ... }
    SubShader { ... }
    Fallback "Mobile/Unlit"
}

在上面的示例中,如果子着色器产生错误,回退将返回属于“Mobile”类别的“Unlit”着色器。如果我们开发的项目是一个多平台游戏,建议为回退声明一个特定路径,这样可以确保我们的程序在大多数设备上都能运行。


原文对照

As mentioned above, this property allows us to assign a shader type object to the object in case our SubShader generates an error or is not compatible with the target hardware.

Its syntax is as follows:

Fallback "shaderPath"

“Shader Path” corresponds to the name and path of the shader that we want to use in case the SubShader fails.

The fallback can also be undeclared, leaving the space blank or using “Fallback Off”, all the same, it is recommended to use a path and names of shaders that have been included in Unity such as “Mobile/Diffuse”. This way, we can be sure that our shader will keep compiling in case of failures.

Shader "InspectorPath/shaderName"
{
    Properties { ... }
    SubShader { ... }
    Fallback "Mobile/Unlit"
}

In the previous example, the Fallback will return an “Unlit” type shader belonging to the category “Mobile” in case the SubShader generates an error. If we are developing a multiplatform game, it is advisable to declare a specific path for the Fallback, this way we can ensure that our program works on most devices.

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容