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 } } }} 由www.J2meGame.com原創,轉載請說明。