States
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.
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.
Types of States#
- StateToggle (bool) — a switch that enables/disables the state
- StateSwitch (integer) — a multiple-value switch based on array of items (mandatory argument)
- StateInt (integer) — a state with an integer number (used to pass the state value via the API to the shader)
- State — auto detection of the state type (if the items argument is present, then StateSwitch; otherwise 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#
- title (string) — title for the Editor
- tooltip (string) — tooltip for the Editor
- switch_group (string) — sets this state to be responsible for the toggle of the specified group
- hidden (bool) — hides the state in the Editor
- internal (bool) — hides the state in the Editor and the state values are not saved for the inherited materials
- items (array of strings) — items used for the StateSwitch type
-
pass (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]>