《Unity着色器圣经》3.0.2 | ShaderLab着色器

目录索引

译文

我们编写的大多数着色器都以“Shader”的声明开头,紧随其后的是它在 Unity 检查器中的路径与名字,例如:“shader inspector path/shader name”。

在 ShaderLab 声明式语言中,诸如子着色器(SubShader)、回退(Fallback)等语义块都是写在“Shader”声明的大括号里的。

Shader "InspectorPath/shaderName" 
{ 
    // ShaderLab代码写在这里面
}

我们先前创建的着色器“USB_simple_color”的路径与名字是“Unlit/USB_simple_color”,因此如果我们要将它赋给某个材质,就需要进入 Unity 检查器,查找“Unlit”路径,然后选择“USB_simple_color”。

不小心命名错了?没关系,着色器的路径与名字都可以根据需求进行更改:

// 默认情况
Shader "Unlit / USB_simple_color" 
{ 
    // ShaderLab代码写在这里面
} 

// 自定义路径 USB (Unity Shader Bible) 
Shader "USB / USB_simple_color" 
{ 
    // ShaderLab代码写在这里面
}

原文对照

Most of our shaders written in code will start with the declaration of the Shader, then its path in the Unity Inspector and finally the name that we assign to it (e.g. Shader “shader inspector path/shader name”).

Both the properties such as the SubShader and the Fallback are written inside the “Shader” field in ShaderLab declarative language.

Shader "InspectorPath/shaderName" 
{ 
    // write ShaderLab code here 
}

Since USB_simple_color has been declared as “Unlit/USB_simple_color” by default, if we want to assign it to a material, then we will have to go to the Unity Inspector, look for the Unlit path and then select “USB_simple_color”.

Both the path and the name of the shader can be changed as needed by the project organization.

// default value 
Shader "Unlit / USB_simple_color" 
{ 
    // write ShaderLab code here 
} 

// customized path to USB (Unity Shader Bible) 
Shader "USB / USB_simple_color" 
{ 
    // write ShaderLab code here 
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容