Unity3D Shader官方教程翻譯(三)----Shader語法:屬性

xy849288321發表於2013-02-21
ShaderLab syntax: Properties

ShaderLab語法:屬性




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.

著色器可以由藝術家定義一個引數列表,這個引數值可以在Unity3D的材質檢索器中檢視。著色器中屬性塊定義了這些引數。
Syntax
Properties { Property [Property ...] }

Defines the property block. Inside braces multiple properties are defined as follows.
定義了1個屬性塊。括號內的屬性定義如下:
name ("display name", Range (min, max)) = number
Defines a float property, represented as a slider from min to max in the inspector.
定義了1個float屬性,範圍是在min到max之間的值,可以利用檢索器中對應的滑塊調節他們。
name ("display name", Color) = (number,number,number,number)
Defines a color property.
定義了一個顏色
name ("display name", 2D) = "name" { options }
Defines a 2D texture property.
定義了1個2D紋理
name ("display name", Rect) = "name" { options }
Defines a rectangle (non power of 2) texture property.
定義了1個矩形紋理屬性
name ("display name", Cube) = "name" { options }
Defines a cubemap texture property.
定義了1個cubemap紋理屬性
name ("display name", Float) = number
Defines a float property.
定義了1個float
name ("display name", Vector) = (number,number,number,number)
Defines a four component vector property.
定義了1個向量,該向量由4個分量組成。

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:

每個在Shader中的屬性是依據屬性的名字來引用的(在Unity3d中,通常屬性名是以下劃線開頭)。屬性的名字將在材質檢索器中顯示。每一個屬性的預設值為等號後的值。
For Range and Float properties it's just a single number.
Range和Float屬性僅僅是1個數字

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)的預設值是1個字串,或者是預設的內建紋理:"白色","黑色","灰色","凸點"

Later on in the shader, property values are accessed using property name in square brackets: [name].

要在Shader程式設計中訪問屬性可以用屬性名加方括號來訪問如:[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 texgen模式的。注意:如果使用自定義的頂點程式,TexGen被忽略。


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
Shader "Texgen/Eye Linear" {
Properties {
_MainTex ("Base", 2D) = "white" { TexGen EyeLinear }
}
SubShader {
Pass {
SetTexture [_MainTex] { combine texture }
}
}
}

由www.J2meGame.com原創,轉載請說明。

相關文章