原文地址:点击打开链接
ShaderLab syntax: Shader
ShaderLab语法:Shader
Shader
Shader是一个shader的文件的根命令。每个文件必须定义一个(只有一个) Shader。它指定有哪些物体的材质使用这个shader进行渲染。
Syntax
Shader
Shader
Details
细节
Properties 属性
Shaders can have a list of
着色器可以有一个属性列表。在着色器中声明的任何属性都将在Unity3D材质检索器中显示。典型的属性是对象的颜色,纹理,或一个将要在渲染中使用的任意值。
SubShaders & Fallback 子着色器及备用渲染处理
Each shader is comprised of a list of
每个着色器由一系列的子着色器组成。你必须至少指定一个子着色器。当加载一个shader时候,Unity3D将通过subshaders列表,并在列表中选择第一个可以被最终用户机器所支持的子着色器。如果没有一个子着色器被支持,Unity3D将尝试使用备用的着色器进行渲染处理[Fallback]。
Different graphic cards have different capabilities. This raises an eternal issue for game developers; you want your game to look great on the latest hardware, but don't want it to be available only to those 3% of the population. This is where subshaders come in. Create one subshader that has all the fancy graphic effects you can dream of, then add more subshaders for older cards. These subshaders may implement the effect you want in a slower way, or they may choose not to implement some details.
不同的显卡具有不同的功能。这就给游戏开发商提出了一个永恒的问题,你想你的游戏,在最新的硬件上表现得十分出色,但不希望它仅仅提供给那些仅占人口3%的人使用。这就是subshaders的意义。创建一个Subshader给那些牛B的显卡使用,同时创建更多的Subshader给老式显卡使用,让你的游戏兼容最多的显卡。这些subshaders可以实现不同的效果在不同的显卡上。
Examples
Here is one of the simplest shaders possible:
这是1个最简单的Shader例子
// colored vertex lighting Shader "Simple colored lighting" { // a single color property 只有1个颜色属性 Properties { _Color ("Main Color", Color) = (1,.5,.5,1) } // define one subshader 定义1个子着色器 SubShader { Pass { Material { Diffuse [_Color] } Lighting On } } }
This shader defines a color property
这个shader定义颜色属性的默认值(1,0.5,0.5,1)_Color(将在Unity3D的材质检索器中作为主要颜色属性显示)。然后一个单一的subshader定义。该subshader组成一个渲染通道,打开顶点照明,并设置了它的基本材质属性。