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

[Unity 组件参考手册]着色器参考之着色器语法:Properties

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

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

跳转到指定楼层
楼主
发表于 2013-2-24 09:54:47 |只看该作者 |倒序浏览
Shaders can define a list of parameters to be set by artists in Unity's material inspector. The Properties block in the shader file defines them.
着色器可以定义一个参数列表,可以由开发者在材质检视面板编辑参数。着色器文件中的Properties块定义了这些参数:



[Syntax]
Properties { Property [Property ...] }

    Defines the property block. Inside braces multiple properties are defined as follows.

    定义属性块,其中可包含多个属性,其定义如下

name ("display name", Range (min, max)) = number

    Defines a float property, represented as a slider from min to max in the inspector.

    定义浮点数属性,在检视器中可通过一个标注最大最小值的滑条来修改。

name ("display name", Color) = (number,number,number,number)

    Defines a color property.

    定义颜色属性

name ("display name", 2D) = "name" { options }

    Defines a 2D texture property.

    定义2D纹理属性

name ("display name", Rect) = "name" { options }

    Defines a rectangle (non power of 2) texture property.

    定义长方形(非2次方)纹理属性

name ("display name", Cube) = "name" { options }

    Defines a cubemap texture property.

    定义立方贴图纹理属性

name ("display name", Float) = number

    Defines a float property.

    定义浮点数属性

name ("display name", Vector) = (number,number,number,number)

    Defines a four component vector property.

    定义四个向量组成的属性
[Details 细节]
Each property inside the shader is referenced by name (in Unity, it's common to start shader property names with underscore). The property will show up in material inspector as display name. For each property a default value is given after equals sign:
包含在着色器中的每一个属性通过name索引(在Unity中, 通常使用下划线来开始一个着色器属性的名字)。属性会将display name显示在材质检视器中,还可以通过在等符号后为每个属性提供缺省值。
    For Range and Float properties it's just a single number.

    对于Range和Float类型的属性只能是单精度值

    For Color and Vector properties it's four numbers in parentheses.

    对于Color和Vector类型的属性将包含4个由括号围住的数描述。

    For texture (2D, Rect, Cube) the default value is either an empty string, or one of builtin default textures: "white", "black", "gray" or "bump".

    对于纹理(2D, Rect, Cube) 缺省值既可以是一个空字符串也可以是某个内置的缺省纹理:"white", "black", "gray" or "bump"
Later on in the shader, property values are accessed using property name in square brackets: [name].
随后在着色器中,属性值通过[name]来访问。



[Example 示例]
Properties {

// properties for water shader

// 水着色器的属性

    _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders

    _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5

    _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4

    _RefrColor ("Refraction color", Color)  = (.34, .85, .92, 1) // color

    _ReflectionTex ("Environment Reflection", 2D) = "" {} // textures

    _RefractionTex ("Environment Refraction", 2D) = "" {}

    _Fresnel ("Fresnel (A) ", 2D) = "" {}

    _BumpMap ("Bumpmap (RGB) ", 2D) = "" {}

}
Texture property options 纹理属性选项
The options inside curly braces of the texture property are optional. The available options are:
包含在纹理属性的大括号中的选项是可选的。可能的选项有:
TexGen texgenmode 纹理生成类型

    Automatic texture coordinate generation mode for this texture. Can be one of ObjectLinear, EyeLinear, SphereMap, CubeReflect, CubeNormal; these correspond directly to OpenGL texgen modes. Note that TexGen is ignored if custom vertex programs are used.

    纹理的自动生成纹理坐标时的模式。可以是ObjectLinear, EyeLinear, SphereMap, CubeReflect, CubeNormal的其中之一;这些模式和OpenGL纹理生成模式相对应。注意如果使用自定义顶点程序,那么纹理生成将被忽略。

LightmapMode 光照贴图模式

    If given, this texture will be affected by per-renderer lightmap parameters. That is, the texture to use can be not in the material, but taken from the settings of the Renderer instead, see Renderer scripting documentation.

    如果给出这个选项,纹理将能被 渲染器的光线贴图属性所影响。纹理不能被使用在材质中,而是取自渲染器的设定。请参考渲染器脚本文档。
Example 示例
// EyeLinear texgen mode example

// EyeLinear 纹理生成模式

Shader "Texgen/Eye Linear" {

    Properties {

        _MainTex ("Base", 2D) = "white" { TexGen EyeLinear }

    }

    SubShader {

        Pass {

            SetTexture [_MainTex] { combine texture }

        }

    }

}


【来源:互联网】

更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

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

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

GMT+8, 2024-11-16 03:33 , Processed in 0.351140 second(s), 32 queries .

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

© 2008-2019 Narkii Inc.

回顶部