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

编写顶点和片段着色器:在Cg中访问着色器属性

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

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

跳转到指定楼层
楼主
发表于 2013-2-24 09:56:46 |只看该作者 |倒序浏览
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/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

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

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

GMT+8, 2024-9-23 05:26 , Processed in 0.191853 second(s), 33 queries .

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

© 2008-2019 Narkii Inc.

回顶部