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

原文地址:http://blog.sina.com.cn/s/blog_6ad33d3501015cb7.html

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 (minmax)) = 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 (2DRectCube) 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 ObjectLinearEyeLinearSphereMapCubeReflectCubeNormal; 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 }
        }
    }
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章