《Unity着色器圣经》3.1.3 | ShaderLab子着色器

目录索引

译文

着色器的第二个重要组成是子着色器(SubShader),着色器如果想完美的加载运行至少需要包含一个子着色器。当一个着色器中有多个子着色器时,Unity 将逐一处理,并根据硬件特性从子着色器列表中选择最合适的。要想理解这个过程,让我们先假设我们现在有一个要运行在 metal 图形程序接口(适用于iOS)上的着色器,那么 Unity 会先运行第一个支持 metal 的子着色器。如果没有一个子着色器可以在 metal 上运行,Unity 就会运行默认的回退着色器,这样硬件就可以在着色器不报错的情况下继续执行功能。

Shader "InspectorPath/shaderName" 
{
    Properties { … } 
    SubShader 
    { 
        // shader configuration here 
    } 
}

回头看看我们在章节之初创建的 USB_simple_color 着色器,它的子着色器的部分的默认内容是这样的:

Shader "USB/USB_simple_color" 
{ 
    Properties { … } 
    SubShader 
    { 
        Tags { "RenderType"="Opaque" } 
        LOD 100 

        Pass { … } 
    } 
} 

原文对照

The second component of a shader is the SubShader. Each shader is made up of at least one SubShader for the perfect loading of the program. When there is more than one SubShader, Unity will process each of them and take the most suitable according to the hardware characteristics, starting from the first to the last on the list. To understand this, let’s assume that the shader is going to run on hardware that supports metal graph API (iOS). For this, Unity will run the first SubShader that supports metal graphs and run it. When a SubShader is not supported, Unity will try to use the Fallback component that corresponds to a default shader, so the hardware can continue with its task without graphical errors.

Shader "InspectorPath/shaderName" 
{
    Properties { … } 
    SubShader 
    { 
        // shader configuration here 
    } 
}

If we pay attention to our USB_simple_color shader, the SubShader will appear as follows in its default values:

Shader "USB/USB_simple_color" 
{ 
    Properties { … } 
    SubShader 
    { 
        Tags { "RenderType"="Opaque" } 
        LOD 100 

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

请登录后发表评论

    暂无评论内容