Unity3D Shader官方教程翻译(六)----Shader语法:Pass的Color, Material, Lighting

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 when Lighting 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原创,转载请说明。


你可能感兴趣的:(Unity3D Shader官方教程翻译(六)----Shader语法:Pass的Color, Material, Lighting)