- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
Shader declares it's properties in a Properties block. If you want to access some of those properties in a Cg shader program, you need to declare a Cg variable with the same name and a matching type. An example is provided in Shader Tutorial: Vertex and Fragment Programs.
着色器是在属性块声明它的属性。如果你想在Cg 着色器程序中访问这些属性的话,你需要在Cg中声明一个与之相同名字对应类型的变量。在着色器教程:顶点和片段程序中提供了一个例子。
For example these shader properties:
下面是一些着色器属性:
_MyColor ("Some Color", Color) = (1,1,1,1)
_MyVector ("Some Vector", Vector) = (0,0,0,0)
_MyFloat ("My float", Float) = 0.5
_MyTexture ("Texture", 2D) = "white" {}
_MyCubemap ("Cubemap", CUBE) = "" {}
would be declared for access in Cg code as:
在Cg代码中的声明:
float4 _MyColor;
float4 _MyVector;
float _MyFloat;
sampler2D _MyTexture;
samplerCUBE _MyCubemap;
Cg can also accept uniform keyword, but it is not necessary:
Cg也可以接受uniform关键字,但这是不必要的:
uniform float4 _MyColor;
Property types in ShaderLab map to Cg variable types this way:
在着色器语言中的属性类型与Cg变量类型的对应:
Color and Vector properties map to float4 variables.
Color和Vector属性对应 float4 类型。
Range and Float properties map to float variables.
Range和Float属性对应 float 类型。
Texture properties map to sampler2D variables for regular (2D) textures.
Texture属性对应 普通2D纹理的sampler2D 类型。
CUBE and RECT textures map to samplerCUBE and samplerRECT variables respectively.
CUBE和RECT纹理对应 samplerCUBE 和 samplerRECT类型。
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/ |
|