Unity3D Shader官方教程翻译(三)----Shader语法:属性





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 }
        }
    }
} 
 
www.J2meGame.com原创,转载请说明。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值