Houdini 学习文档 -VEX language reference

Details of VEX syntax, data types, and so on.

VEX语法、数据类型等的详细信息

 

Contexts 环境


VEX programs are written for a specific context. For example, a shader that controls the surface color of an object is written for the surface context. A shader that determines the illuminance from a light is written for the light context. A VEX program that creates or filters channel data is written for the chop context.

VEX程序是针对特定上下文编写的。例如,控制对象表面颜色的着色器是为表面上下文编写的。一个着色器,确定了从一个光的照度是为光的上下文编写的。创建或筛选通道数据的VEX程序是为chop上下文编写的。

The context affects which functions, statements, and global variables are available.

上下文影响哪些函数、语句和全局变量可用。

See VEX contexts for an overview of the ways in which you can use VEX.

If you are writing for a shading context (surface, displacement, light, etc.), you should also read the shading context specific information.

Statements 状态


VEX supports the usual statements familiar from C. It also supports shading-specific statements such as the illuminance and gatherloops that are only available in certain contexts.

VEX支持c语言中常见的语句,它还支持特定于着色的语句,比如光照和采集量循环,这些语句只在特定上下文中可用。

 

Built-in function 内置函数 

VEX contains a large library of built-in functions. Some functions are only available in certain contexts.

VEX包含一个内置函数的大型库。有些函数只在某些上下文中可用。

See VEX functions.

 

User-defined functions 自定义函数

Functions are defined similarly to C: specify the return type, the function name, and parenthesized list of arguments, followed by the code block.

函数的定义类似于C:指定返回类型、函数名和参数的圆括号列表,后面跟着代码块。

Arguments of the same type can be declared in a comma separated list without re-declaring the type. Other arguments must be separated by a semi-colon.

相同类型的参数可以在逗号分隔的列表中声明,而无需重新声明类型。其他参数必须用分号分隔。

int test(int a, b; string c) {
    if (a > b) {
        printf(c);
    }
}

You can overload functions with the same name but different argument signatures and/or return type.

您可以重载具有相同名称但不同参数签名和/或返回类型的函数。

You can introduce a function definition with the optional function keyword to avoid type ambiguity.

可以使用可选函数关键字引入函数定义,以避免类型模糊。

  • Notes 节点
    • User functions must be declared before they are referenced.

    • 在引用用户函数之前,必须声明它们。

    • The functions are in-lined automatically by the compiler, so recursion will not work. To write a recursive algorithm, you should useshader calls instead.

    • 函数由编译器自动内联,因此递归不能工作。要编写递归算法,应该使用eshader调用。

    • As in RenderMan Shading Language, parameters to user functions are always passed by reference, so modifications in a user function affect the variable the function was called with. You can force a shader parameter to be read-only by prefixing it with the constkeyword. To ensure that the user function writes to an output parameter, prefix it with the export keyword.

    • 在RenderMan着色语言中,用户函数的参数总是通过引用传递的,所以用户函数中的修改会影响函数调用的变量。您可以使用const关键字前缀强制着色器参数为只读。要确保用户函数写入输出参数,请在其前面加上export关键字。

    • There is no limit on the number of user functions.

    • 用户函数的数量没有限制。

    • You can have more than one return statement in a function.

    • 一个函数中可以有多个return语句。

    • You can access global variables directly (unlike RenderMan Shading Language, you do not need to declare them with extern). However, we recommend you avoid accessing global variables, since this limits your function to only work in one context (where those globals exist). Instead, pass the global(s) to the function as parameters.

    • 您可以直接访问全局变量(与RenderMan着色语言不同,您不需要使用extern声明它们)。但是,我们建议您避免访问全局变量,因为这将您的函数限制为只能在一个上下文中工作(在全局变量存在的地方)。相反,将全局作为参数传递给函数。

    • Functions can be defined inside of a function (nested functions).

    • 函数可以在函数(嵌套函数)中定义。

Main(context) function 主函数

A VEX program must contain one function whose return type is the name of the context. This is the main function of the program that is called by mantra. The compiler expects one context function per file.

VEX程序必须包含一个函数,该函数的返回类型是上下文的名称。这是mantra程序的主函数。编译器期望每个文件有一个主函数

This function should do the work (by calling out to built-in and/or user-defined functions) of calculating any required information and modifying global variables. You do not use the return statement to return a value from the context function. See the specific context pages for the global variables available in each context.

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值