表达式
The expressions are used to specify UnigineScript code to be called on some event or on user demand. They can be used to generate various elements used in the material (e.g., textures, texture arrays, unstructured buffers, etc.) or contain other logic.表达式用于指定UnigineScript在某些事件或用户需求时调用的代码。它们可用于生成材质中使用的各种元素(例如,纹理、纹理数组、非结构化缓冲区等)或包含其他逻辑。
As a node value you must specify a UnigineScript-based code enclosed in "#{" and "#}". You can also specify a path to an external script file (in usc or h format) or the name of a Script node inside this material.作为节点值,您必须指定包含在 "#{" 和 "#}" 中的基于 UnigineScript 的代码。您还可以指定外部脚本文件的路径(以 usc 或 h 格式)或此材质内的 Script 节点的名称。
The syntax is the following:语法如下:
Expression name =
#{
// UnigineScript code
#}
Or要么
Script script_name =
#{
// UnigineScript code
#}
Expression name = script_name
Or要么
Expression name = "some/path/to/your/script.h" // script.h consists of some UnigineScript code
When the name of an expression specified as RENDER_* (where * is a name of a render callback) and the current material is set globally or assigned to the main camera, the expression code will be executed automatically at the corresponding stage of the rendering sequence. Materials containing such expressions are called scriptable.当表达式的名称指定为 RENDER_*(其中 * 是渲染回调) 且当前素材是全局设置或分配给主摄像机,表情代码会在对应阶段自动执行渲染顺序.包含此类表达式的材料称为可编写脚本.
It is possible to call an expression via the runExpression() function of the Material class. The expression’s name must be unique.可以通过 Material 类的 runExpression() 函数调用表达式。表达式的名称必须是唯一的。
Usage Examples使用示例#
Expression RENDER_CALLBACK_BEGIN_SSAO =
#{
// typical most frequently used parameters passed to the expression when it is called.
int in_width;
int in_height;
int in_depth;
Material in_material;
// get a temporary texture
Texture texture = engine.render.getTemporaryTexture(in_width, in_height);
// set the modified texture as albedo texture of the material
in_material->setTexture("albedo", texture);
#}