查看: 2437|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]着色器参考之着色器语法:Color, Material, Lighting

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-25 17:05:34 |只看该作者 |倒序浏览
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标准的按每顶点计算的光照模型。光照打开时,光照受材质块,颜色材质和平行高光命令的影响。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 and fragment programs 。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.顶点颜色和灯光是对任何已渲染过后的几何体所添加的第一步效果。这个操作处在顶点级别,用于计算在纹理被应用之前被使用的基础颜色。
【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.
    这个命令会添加高光光照到着色器通道的末尾,因此贴图对高光没有影响。只在光照开启时有效。
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 替代 材质中的光发射值。  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的时候你会获得一个细微的亮斑。
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) + EmissionThe 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).方程式的灯光部分(带括号)对所有打在对象上的光线重复使用。典型情况是你希望将漫反射和阴影光保持一致(所有内置Unity着色器都是如此)。
【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 "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:使材质颜色作为材质检视面板可视的属性的着色器扩展版本: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):最后,一个完全齐备的顶点光照着色器(参考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
            }
        }
    }
}  【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

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

GMT+8, 2024-9-20 14:36 , Processed in 0.092114 second(s), 33 queries .

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

© 2008-2019 Narkii Inc.

回顶部