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个被计算的效果。在纹理应用之前,它首先操作顶点层级,然后计算基础颜色。
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 颜色
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 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 都是这么做的)。
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 } } } }