状态
State allows you to set a mode for rendering passes and a value for rendering options. States change a set of generated definitions passed to shaders, so any changes made to a state cause shaders recompilation. A material state generates defines for shaders only if the state meets the conditions. You can specify your own states or use and specify values for UNIGINE's internal states.状态允许您设置渲染通道的模式和渲染选项的值。状态会更改一组传递给着色器的生成定义,因此对状态所做的任何更改都会导致着色器重新编译。仅当状态满足条件时,材质状态才会为着色器生成定义。您可以指定自己的状态或使用并指定 UNIGINE 内部状态的值。
The syntax is the following:语法如下:
StateType state_name = value(s)
You can acces states in the shader using the following defines:您可以使用以下定义访问着色器中的状态:
GET_STATE_<state name in uppercase> = value // for all states
STATE_<state name> // if the state value is bigger than 0 (for example, StateToogle)
STATE_<state name>_<name of an element from the items array> // for State and StateSwitch
To change the state's values use the corresponding API methods.要更改状态的值,请使用相应的API 方法.
Types of States国家类型#
- StateToggle (bool) — a switch that enables/disables the stateStateToggle (bool) — 启用/禁用状态的开关
- StateSwitch (integer) — a multiple-value switch based on array of items (mandatory argument)StateSwitch (integer) — 基于项目数组的多值开关(强制参数)
- StateInt (integer) — a state with an integer number (used to pass the state value via the API to the shader)StateInt (integer) — 具有整数的状态(用于通过 API 将状态值传递给着色器)
- State — auto detection of the state type (if the items argument is present, then StateSwitch; otherwise StateToggle)State — 自动检测状态类型(如果存在 items 参数,则为 StateSwitch;否则为 StateToggle)
Usage Examples使用示例#
Suppose we got the base material with these states defined:假设我们得到了定义了这些状态的基础材料:
BaseMaterial
{
State my_state_switch = 4 <items = [a b c d e]> // or StateSwitch my_state_switch = 4 <items = [a b c d e]>
State my_state_toggle = 1
StateInt my_state_int = 256 <internal = true>
}
Then the following defines are available in the shaders:然后在着色器中可以使用以下定义:
#define GET_STATE_MY_STATE_SWITCH 4
#define GET_STATE_MY_STATE_TOGGLE 1
#define GET_STATE_MY_STATE_INT 256
#ifdef STATE_MY_STATE_SWITCH_A
/* some UUSL code */
#elif STATE_MY_STATE_SWITCH_B
/* some UUSL code */
#elif STATE_MY_STATE_SWITCH_E
/* some UUSL code */
#endif
#ifdef STATE_MY_STATE_TOGGLE
/*some UUSL code*/
#endif
int my_state_int = GET_STATE_MY_STATE_INT;
Arguments论据#
editableeditable#
Boolean
A flag indicating if state can be changed in the Parameters window or via API.指示状态是否可以在 Parameters 窗口或通过API .
Available values:可用值:
- false — unchangeablefalse — 不可更改
- true — changeable (by default)true — 可更改(默认)
titletitle#
String
Title for the Editor.编辑的标题。
tooltiptooltip#
String
Tooltip for the Editor.编辑器的工具提示。
switch_groupswitch_group#
String
Sets this state to be responsible for the toggle of the specified group.将此状态设置为负责指定组的切换。
hiddenhidden#
Boolean
A flag indicating if the state is hidden in the Editor.指示状态是否在编辑器中隐藏的标志。
Available values:可用值:
- false — shows the state in the Editorfalse — 显示编辑器中的状态
- true — hides the state in the Editortrue — 在编辑器中隐藏状态
internalinternal#
Boolean
A flag indicating if the state is hidden in the Editor and the state values are not saved for the inherited materials.一个标志,指示状态是否在编辑器中隐藏,并且不为继承的材质保存状态值。
Available values:可用值:
- false — shows the state in the Editor and saves the state values for the inherited materialsfalse — 在编辑器中显示状态并保存继承材质的状态值
- true — hides the state in the Editor and does not save the state values for the inherited materialstrue — 在编辑器中隐藏状态并且不保存继承材质的状态值
itemsitems#
Array of Strings字符串数组
Items used for the StateSwitch type.用于的项目状态开关类型。
passpass#
Array of Strings
Specifies what passes use this state.指定使用此状态的传递。
Available values:可用值:
- wireframe — the wireframe pass
- visualizer_solid — the visualizer solid pass
- deferred — the deferred pass
- auxiliary — the auxiliary pass
- emission — the emission pass
- refraction — the refraction pass
- reflection — the reflection pass
- transparent_blur — the transparent blur pass
- ambient — the ambient pass
- light_voxel_probe — the voxel probe light pass
- light_environment_probe — the environment probe pass
- light_omni — the omni-directional light pass
- light_proj — the projected light pass
- light_world — the world light pass
- depth_pre_pass — the native depth pre-pass
- shadow — the shadows pass
- post — the post-process pass
- light_all — the environment probe, omni-directional light, projected light, world light passes
- forward — the environment probe, omni-directional light, projected light, world light and ambient passes
- transparent — the forward, refraction, transparent blur passes
- custom_pass_name — name of a custom rendering pass (up to 32 custom passes are supported)
- object — deferred, auxiliary, emission, refraction, reflection, transparent blur, ambient, voxel probe light, environment probe, omni-directional light, projected light, world light, shadow and native depth passes
To make one or more passes use this state, write passes in square brackets and separate them with spaces. For example:要使一个或多个传递使用此状态,请将传递写在方括号中并用空格分隔它们。例如:
State wireframe_antialiasing <pass=[wireframe post custom_pass_name]>