ShaderLab语法:Shader
Shader is the root command of a shader file. Each file must define one (and only one) Shader. It specifies how any objects whose material uses this shader are rendered.
Shader是一个shader的文件的根命令。每个文件必须定义一个(只有一个) Shader。它指定有哪些物体的材质使用这个shader进行渲染。
Shader "name" { [Properties] Subshaders [Fallback] } Defines a shader. It will appear in the material inspector listed under name. Shaders optionally can define a list of properties that show up as material settings. After this comes a list of SubShaders, and optionally a fallback.
Shader "name" { [Properties] Subshaders [Fallback] } 定义了一个着色器。它的名字将会出现在Unity3d材质检索器中并以定义的name显示。Shader可以为设定材质的列表有选择地定义属性显示。在此之后可以定义一个SubShaders列表,及一个可选的返回值(Fallback指当该Shader无法工作时候,返回一个可以正常工作的备用渲染处理)。
细节
Shaders can have a list of properties. Any properties declared in a shader are shown in the material inspector inside Unity. Typical properties are the object color, textures, or just arbitrary values to be used by the shader.
着色器可以有一个属性列表。在着色器中声明的任何属性都将在Unity3D材质检索器中显示。典型的属性是对象的颜色,纹理,或一个将要在渲染中使用的任意值。
Each shader is comprised of a list of sub-shaders. You must have at least one. When loading a shader, Unity will go through the list of subshaders, and pick the first one that is supported by the end user's machine. If no subshaders are supported, Unity will try to use fallback shader.
每个着色器由一系列的子着色器组成。你必须至少指定一个子着色器。当加载一个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可以实现不同的效果在不同的显卡上。
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 _Color (that shows up in material inspector as Main Color) with a default value of (1, 0.5, 0.5, 1). Then a single subshader is defined. The subshader consists of one Pass that turns on vertex lighting and sets up basic material for it.
这个shader定义颜色属性的默认值(1,0.5,0.5,1)_Color(将在Unity3D的材质检索器中作为主要颜色属性显示)。然后一个单一的subshader定义。该subshader组成一个渲染通道,打开顶点照明,并设置了它的基本材质属性。
由www.J2meGame.com精心原创,转载请说明。