Unity3D Shader官方教程翻译(二)

来源:互联网 发布:美图美妆软件 编辑:程序博客网 时间:2024/05/17 05:52
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进行渲染。

Syntax
语法


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无法工作时候,返回一个可以正常工作的备用渲染处理)。


Details

细节
Properties 属性

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材质检索器中显示。典型的属性是对象的颜色,纹理,或一个将要在渲染中使用的任意值。


SubShaders & Fallback 子着色器及备用渲染处理

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可以实现不同的效果在不同的显卡上。
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 _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精心原创,转载请说明。http://www.j2megame.com/html/xwzx/ty/3303.html

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 饥荒精神值为0怎么办 抓不住温暖我能怎么办 父亲打母亲我该怎么办 父亲对母亲家暴怎么办 摊上家暴的父亲怎么办 家暴警察不处理怎么办 父亲把母亲打了怎么办 u盘的文件打不开怎么办 头撞墙起包了怎么办 儿童头撞墙起包怎么办 头撞墙了鼓包了怎么办 北京65岁老年证怎么办 怎么办65岁免费乘车卡 5个月小孩晚上哭怎么办 婴儿要含奶头睡怎么办 我把输入法删了怎么办 头发干枯毛躁怎么办用什么洗发水 落枕后脖子歪了怎么办 睡觉睡得脖子疼怎么办? 婴儿脖子睡歪了怎么办 怀孕8个月肚皮痒怎么办 怀孕大阴唇肿了怎么办 孕妇肚皮撑的疼怎么办 我大阴唇特别长怎么办 切完洋葱辣眼睛怎么办 下昆山车没刷卡怎么办 高德地图用不了怎么办 玩游戏老是闪退怎么办 苹果平板电脑闪退怎么办 钉钉忘记打卡了怎么办 钉钉手机号换了怎么办 玖富叮当贷逾期怎么办 玖富超能怎么办现金贷 包包的油边开裂怎么办 lv包包油边开裂怎么办 lv钱包油边开裂怎么办 德运奶粉没勺子怎么办 音响坏了没声音怎么办 6s蓝牙无法配对怎么办 魅族耳机进水了怎么办 苹果6耳机进水了怎么办