查看: 2720|回复: 3
打印 上一主题 下一主题

[Shaders] Shader语法:Pass的Color, Material, Lighting

[复制链接]

2722

主题

42

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
38268
精华
111

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2014-7-29 21:51:53 |只看该作者 |倒序浏览
ShaderLab syntax: Color, Material, Lighting

ShaderLab 语法:颜色,材质,光照

The material and lighting parameters are used to control the built-in vertex lighting. Vertex lighting is the standard Direct3D/OpenGL lighting model that is computed for each vertex. Lighting on turns it on. Lighting is affected by Material block, ColorMaterial and SeparateSpecular commands.

材质和照明参数是用来控制内置的顶点光照。顶点光照是Direct3D/OpenGL的标准照明模型,它计算每一个顶点。Lighting on命令打开它。光照受Material block,ColorMaterial和SeparateSpecular命令影响

Per-pixel lights are usually implemented with custom vertex/fragment programs and don't use vertex lighting. For these you don't use any of the commands described here, instead you define your own vertex and fragment programs where you do all lighting, texturing and anything else yourself.

逐像素光照 通常是实现自定义的顶点/片断程序,它不使用顶点照明。这篇文章中描述的任何命令都不会用来操作逐像素光照,你可以通过自己定义的顶点和片段编程来实现这个效果。


Vertex Coloring & Lighting is the first effect to gets calculated for any rendered geometry. It operates on the vertex level, and calculates the base color that is used before textures are applied.

当渲染任何几何图形时候,顶点颜色和光照是第1个被计算的效果。在纹理应用之前,它首先操作顶点层级,然后计算基础颜色。
Syntax 句法

The top level commands control whether to use fixed function lighting or not, and some configuration options. The main setup is in the Material Block, detailed further below.

顶层命令控制是否使用固定功能照明,以及一些配置选项。主要在Material Block中设置,详见下文。

Color Color 颜色
Sets the object to a solid color. A color is either four RGBA values in parenthesis, or a color property name in square brackets.
设置对象纯色。可以是一种RGBA颜色值(在括号中的),或颜色属性的名称(在方括号中的)。

Material { Material Block } 材质
The Material block is used to define the material properties of the object.
材质块是用来定义对象的材质性能

Lighting On | Off 灯光开关
For the settings defined in the Material block to have any effect, you must enable Lighting with the Lighting On command. If lighting is off instead, the color is taken straight from the Color command.
为了使在材质块中定义的设置有效,您必须启用 Lighting On命令开启光照。如果灯光关闭,则直接通过Color命令获得颜色。

SeparateSpecular On | Off
This command makes specular lighting be added to the end of the shader pass, so specular lighting is unaffected by texturing. Only has effect whenLighting On is used.
这个命令将镜面光照添加到Shader 通道的末尾,这样能使镜面反射光不被纹理影响。这个效果仅仅当照明开启时有效。

ColorMaterial AmbientAndDiffuse | Emission 颜色材质 环境漫反射光照 及放射光
makes per-vertex color be used instead of the colors set in the material. AmbientAndDiffuse replaces Ambient and Diffuse values of the material;Emission replaces Emission value of the material.
使用每一个顶点颜色去替换在材质中设置的颜色。AmbientAndDiffuse 替换环境漫反射光照的值。Emission 替换掉放射光的值。
Emission 可以理解为物体自发光。

Material Block 材质块

This contains settings for how the material reacts to the light. Any of these properties can be left out, in which case they default to black (i.e. have no effect).

这些是为了设置材质如何影响光照。任何这些属性都能被排除,在这种情况下它们被认为默认为黑色(没起到效果)。

Diffuse Color 漫反射颜色
The diffuse color component. This is an object's base color.
这个是物体最基础的颜色。

Ambient Color 环境色
The ambient color component. This is the color the object has when it's hit by the ambient light set in the RenderSettings.
当物体被环境光影响时候给物体设置颜色,这个取决于在RenderSettings中设置的环境颜色。

Specular Color 反射光
The color of the object's specular highlight.
设置物体的高光反射颜色

Shininess Number 清晰度
The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.
突出清晰度,值在0和1之间。为0时候,你得到1个巨大的高光看起来像很多漫射光照;为1时候,你得到一个小的斑点。

Emission Color 自发光颜色
The color of the object when it is not hit by any light.
当没被其他光线影响时候,物体本身的自发光颜色。

The full color of lights hitting the object is:

当物体被所有光线照射时候他的颜色的计算公式如下:
Ambient * RenderSettings ambient setting +
(Light Color * Diffuse + Light Color * Specular) + Emission

The light parts of the equation (within parenthesis) is repeated for all lights that hit the object.

在括号中的那部分光线计算,是计算所有照射到物体上的光线。

Typically you want to keep the Diffuse and Ambient colors the same (all builtin Unity shaders do this).

通常情况下,你要保持漫反射和环境的颜色相同(所有内建的unity3d shader 都是这么做的)。


Examples 例子:

Always render object in pure red:

总是用纯红色渲染物体
Shader "Solid Red" {
SubShader {
Pass { Color (1,0,0,0) }
}
}

Basic Shader that colors the object white and applies vertex lighting:

基本的Shader设置物体的材质漫反射和环境色为白色,同时开启顶点光照。
Shader "VertexLit White" {
SubShader {
Pass {
Material {
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
}
Lighting On
}
}
}

An extended version that adds material color as a property visible in Material Inspector:

一个扩展版本的Shder.将材质的主颜色设置为可以在材质检索器中看到的属性。
Shader "VertexLit Simple" {
Properties {
_Color ("Main Color", COLOR) = (1,1,1,1)
}
SubShader {
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
}
}
}

And finally, a full fledged vertex-lit shader (see also SetTexture reference page):

最后是1个完整的成熟的照明顶点着色器(参照 SetTexture引用)
Shader "VertexLit" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

hyui    

1

主题

2

听众

6671

积分

高级设计师

Rank: 6Rank: 6

纳金币
2715
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2014-7-29 22:01:14 |只看该作者
Good to know !
回复

使用道具 举报

无效楼层,该帖已经被删除
您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-16 07:21 , Processed in 0.158121 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部