状况
For each ULON node a logical condition can be specified using a state value. If the condition fails the node with all its children is ignored. Thus you can dynamically build the flexible hierarchy of ULON nodes. This can be useful when the contents of the node depends on certain parameters, e.g. a shader to be used is defined by the rendering pass.对于每个 ULON 节点,可以使用状态价值。如果条件失败,则忽略该节点及其所有子节点。因此,您可以动态构建 ULON 节点的灵活层次结构。当节点的内容取决于某些参数时,这可能很有用,例如,要使用的着色器由渲染通道定义。
Conditions are specified after the node's name, starting with the if keyword, the condition itself is enclosed in brackets [ ... ].条件在节点名称之后指定,以 if 关键字开头,条件本身包含在括号 [ ... ] 中。
The syntax is the following:语法如下:
Node name if [condition]
The Group nodes support the nested conditions:这团体节点支持嵌套条件:
Group parent if [condition]
{
Group child if [condition]
}
Condition of the parent node is added to the condition of the child like so: (parent_conditon) && (child_conditon).父节点的条件被添加到子节点的条件中,如下所示: (parent_conditon) && (child_conditon) 。
You can write complex conditions using logical operations:您可以使用逻辑运算编写复杂的条件:
Node name if [(state1 == 1 || state2 == 1) && !state3]
Preprocessor Auto Generation for Shaders着色器的预处理器自动生成#
In the UUSL code all conditions are enclosed in #if and #endif preprocessor on shader compilation, for instance:在 UUSL 代码中,所有条件都包含在着色器编译时的 #if 和 #endif 预处理器中,例如:
StateInt do_a_thing = 1
Slider do_a_thing = 0.5 if [do_a_thing == 2]
Texture do_a_thing = black if [do_a_thing == 3]
Shader example =
#{
// the following UUSL preprocessors are inlined on shader compilations
#if GET_STATE_DO_A_THING == 2
UNIFORM float var_do_a_thing;
#endif
#if GET_STATE_DO_A_THING == 3
INIT_TEXTURE(0, tex_do_a_thing);
#endif
// the variable or the texture is available only when the corresponding condition is met
color.r = var_do_a_thing; // valid only when do_a_thing = 2
color.gb = TEXTURE(tex_do_a_thing, IN_UV); // valid only when do_a_thing = 3
#}
Usage Examples使用示例#
Int some_var = 1 <min=0 max=1>
Pass deferred if [some_var == 0]
{
Vertex = "shaders/a.vert"
Fragment = "shaders/a.frag"
}
Pass deferred if [some_var == 1]
{
Vertex = "shaders/b.vert"
Fragment = "shaders/b.frag"
}
Based on the value of some variable you can specify different shaders for the same render pass (deferred in our example).根据某些变量的值,您可以为同一渲染通道指定不同的着色器(在我们的示例中延迟)。