This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.Material Class

This class is used to create materials, which are assigned to each node (or each surface of the object) and define how they look like. They implement the shaders and control what options, states, parameters of different types and textures are used to render the node during the rendering passes.

The concepts of a path and a name of the material should be distinguished:

  • The path specifies where the material is stored on the disk. The path includes a material file name.
  • The name specifies how the material will be displayed in Materials Editor (the materials hierarchy, the nodes surface editor). The name can also be used to reference material from the code.
By default, the material name and the material file name coincide.

Usage Examples#

Changing Textures#

The first example describes how to inherit a material from a base one, change material's texture and set texture flags for it. We inherit a new material named material_ball_0 from the material_ball material, assign it to the default material ball object, change its albedo texture and set the FILTER_POINT flag for it.

Add the following code to the AppWorldLogic.cs file.

Source code (C#)
// AppWorldLogic.cs

/* .. */

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		/* .. */

		public override bool Init()
		{

            // inherit a new material from the material_ball
            Material m = Materials.FindMaterial("material_ball").Inherit("material_ball_0");

            // getting the material_ball object and assigning the material_ball_0 material to it
            ObjectMeshStatic material_ball = World.GetNodeByName("material_ball") as ObjectMeshStatic;
            material_ball.SetMaterial("material_ball_0", "*");

            // get the number of the albedo texture of the material_ball_0 material
            int num = m.FindTexture("albedo");

            // check if our material is editable and perform modifications
            if (m.IsEditable)
            {
                Log.Message("Material ({0}) is editable.\n", m.Name);

                // change albedo texture of the material to core/textures/common/checker_d.dds
                Image image = new Image("core/textures/common/checker_d.dds");
                m.SetTextureImage(num, image);

                // get current flags, check if point filtering is enabled and display the result in the console
                int flags = m.GetTextureFlags(num);
                Log.Message("Flags for {0} texture ({1}):{2} \n", m.GetTextureName(num), num, flags);
                Log.Message("FILTER_POINT {0}\n", (flags & Texture.FILTER_POINT) != 0 ? "enabled" : "disabled");

                // set the FILTER_POINT flag
                m.SetTextureFlags(num, Texture.FILTER_POINT);

                // get the flags, check if point filtering is enabled and display the result in the console
                int flagsSet = m.GetTextureFlags(num);
                Log.Message("Flags for {0} texture ({1}):{2} \n", m.GetTextureName(num), num, flagsSet);
                Log.Message("FILTER_POINT {0}\n", (flagsSet & Texture.FILTER_POINT) != 0 ? "enabled" : "disabled");
            }

            return true;
		}
		
		/* .. */
	}
}

As a result you'll see, that albedo texture of the material ball object has changed and the following result is displayed in the console:

Output
Material (material_ball_0) is editable.
Flags for albedo texture (1):2048000
FILTER_POINT disabled
Flags for albedo texture (1):4096
FILTER_POINT enabled

Changing States and Parameters#

The second example illustrates how to inherit a material from the mesh_base, enable the planar reflection state and change two parameters affecting the look of dynamic reflections.

Add the following code to the AppWorldLogic.cs file.

Source code (C#)
// AppWorldLogic.cs

/* .. */

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		/* .. */

		public override bool Init()
		{
			// find the mesh_base material
            Material mesh_base = Materials.FindMaterial("mesh_base");
            // inherit a new material from it and assign the path to asset to be created on save() call:
			// planar_reflector.mat in the data project folder
            Material reflector_material = mesh_base.Inherit("planar_reflector", "planar_reflector.mat");

            // enable planar reflections for the mirror material
            reflector_material.SetState("planar_reflection", 1);

            // set metallness and roughness parameters to make the surface look like a mirror
			// by the name of the parameter
            reflector_material.SetParameterFloat("metalness", 1.0f);
            // or by its id, which is the same
            reflector_material.SetParameterFloat(reflector_material.FindParameter("roughness"), 0.0f);

			// save the material asset to the path specified earlier
            reflector_material.Save();

            // assign the mesh_base material to the material ball by its name
            ObjectMeshStatic material_ball = World.GetNodeByName("material_ball") as ObjectMeshStatic;
            material_ball.SetMaterial("mesh_base", "*");
            // assign new mirror material to the ground object
            ObjectMeshDynamic ground = World.GetNodeByName("ground") as ObjectMeshDynamic;
            ground.SetMaterial(reflector_material, 0);

            // enable planar reflections rendering using the corresponding method of the Render class
            Render.ReflectionDynamic = true;

            return true;
		}
		
		/* .. */
	}
}

Material Class

Properties

bool IsEmpty#

A value indicating if an empty shader is used as a vertex shader in the current material.

bool IsEngine#

A value indicating if the current material is engine-related (i.e. required for engine operation). such materials are stored in the core, editor and editor2 folders.

bool IsAutoSave#

A value indicating if the material can be saved automatically to the path specified via setPath() (automatic material saving is performed, for example, on world's saving). The function will return 0 in the following cases:
  • The canSave() function returns 0 for the material.
  • The material is non-editable.
  • The path isn't specified for the material.

bool IsManual#

A value indicating if the current material is manual.

bool IsInternal#

A value indicating if the current material is internal.

bool IsReflection2D#

A value indicating if the material has a 2d reflection texture.

bool IsProcedural#

A value indicating if the material has procedural texture.

bool IsBrush#

A value indicating if the material is used for brushes (*.brush or *.basebrush file extension).

bool IsBase#

A value indicating if the material is the base one.

bool IsHidden#

A value indicating if the material is hidden.

bool IsFilter#

A value indicating if the material has filter texture.

bool IsEditable#

A value indicating if the material can be edited.

int ViewportMask#

The current bit mask for rendering into the viewport. the material is rendered, if its mask matches the player's one.
set
Sets a bit mask for rendering into the viewport. The material is rendered, if its mask matches the player's one.
set value - Integer, each bit of which is a mask.

int TwoSided#

A value indicating if the material is two-sided.
set
Enables or disables the two sided option for the material.
set value - 1 to make the material two-sided, 0 to make it one-sided.

bool IsAlphaTest#

A value indicating if the material has an alpha test option enabled.

bool IsForward#

A value indicating if the material is rendered in the forward pass.

bool IsDeferred#

A value indicating if the material is rendered in the deferred pass.

bool IsWater#

A value indicating if the material is rendered in the water pass.

int Transparent#

A value indicating the transparency type of the material.
set
Sets a value indicating the transparency type of the material. If the transparent option is set to TRANSPARENT_NONE or TRANSPARENT_DEFERRED, the blending function won't be used.
set value - The transparency option (one of the TRANSPARENT_* variables).

int NumTextures#

The number of textures used by the material.

int NumStates#

The number of material's states.

int NumParameters#

The number of material's parameters.

UGUID FileGUID#

The current guid of the material file.
set
Sets a new GUID for the material file.
set value - New GUID for the material file.

string Path#

A path to the current material.
set
Sets a new path for the material.
set value - New path to the material file.

UGUID GUID#

The GUID of the material.

string Name#

The current material name.
set
Sets a given name for the current material.
Notice
The method isn't available for the manual and base materials.
set value - Material name.

int NumChildren#

The number of child materials.

Material BaseMaterial#

The base material of the current material.

int Order#

The rendering order of materials.
set
Sets the rendering order of material. The higher the rendering order, the lower the rendering priority (the material with the -128 order will be rendered first).
set value - Rendering order, in the range from -128 to 127.

int Overlap#

A value indicating if the overlap option is enabled for the material. this option enables rendering the material over the final image and can be used for ui elements.
set
Enables or disables the overlap option for the material. This option enables rendering the material over the final image and can be used for UI elements.
set value - 1 to enable the overlap option for the material, 0 to disable it.

int DepthTest#

A value indicating if depth testing is enabled for the material. this option can be used to render certain objects, that are behind other ones.
set
Enables or disables the depth testing option for the material. This option can be used to render certain objects, that are behind other ones.
set value - 1 to enable depth testing for the material, 0 to disable it.

int DepthMask#

A value indicating if the material uses a depth mask.
set
Sets a value indicating if the material uses a depth mask.
set value - 1 to use the depth mask, 0 not to use.

int ShadowMask#

A shadow mask of the material.

For the shadow to be rendered for a light source from an object's surface having this material assigned, this mask must match the following ones (one bit, at least):

set
Sets a shadow mask for the material.

For the shadow to be rendered for a light source from an object's surface having this material assigned, this mask must match the following ones (one bit, at least):

The surface with the assigned material lit by a light source casts shadow if the shadow mask of the light source matches the corresponding masks of the surface and its material.
set value - Integer value, each bit of which is a mask.

int CastWorldShadow#

A value indicating if an object with the material applied casts shadows from the world light.
set
Enables or disables casting of shadows from the world light for an object with the material applied.
set value - 1 to enable casting of shadows from the world light, 0 to disable it.

int CastShadow#

A value indicating if an object with the material applied casts shadows.
set
Enables or disables the cast shadow option for an object with the material applied.
set value - 1 to enable casting of shadows, 0 to disable it.

bool IsPreviewHidden#

Returns a value indicating if preview in the UnigineEditor is disabled for the material. This method is used for custom materials (e.g., landscape terrain brushes).

bool IsOptionsHidden#

Returns a value indicating if Common material options (such as Transparency Preset, Material Mask, etc.) are not available for the material. This method is used for custom materials (e.g., landscape terrain brushes).

bool IsLegacy#

Returns a value indicating if the material is a legacy one. A legacy material is a non-ULON base material described in an XML file.

int BlendSrcFunc#

The source blending function.

int BlendDestFunc#

The destination blending function.

Material Parent#

The parent material.

Members


static Material ( ) #

Constructor. Creates a new material instance.

void SetBlendFunc ( int src, int dest ) #

Sets the source and destination blending functions.

Arguments

  • int src - Blend mode (one of the MATERIAL_BLEND_* variables) for the source color.
  • int dest - Blend mode (one of the MATERIAL_BLEND_* variables) for the destination color.

Material GetChild ( int num ) #

Returns a child material with a given number.

Arguments

  • int num - Child material number.

Return value

The child material smart pointer.

void SetImageTextureProcedural ( int num, Material procedural, int procedural_num ) #

Assigns the procedural texture of the given procedural material to the specified texture of the current material.

Arguments

  • int num - Number of the texture, to which the procedural texture will be assigned.
  • Material procedural - Procedural material.
  • int procedural_num - Procedural texture number.

bool IsParameterExpressionEnabled ( int num ) #

Returns a value indicating if the value of the specified material parameter is represented by an expression in UnigineScript. Values of certain parameters can be calculated by an arbitrary expression, written in UnigineScript. .

Arguments

Return value

true if the value of the specified material parameter is represented by an expression in UnigineScript; otherwise, false.

void SetParameterExpressionEnabled ( int num, bool enabled ) #

Sets a value indicating if the value of the specified material parameter is represented by an expression in UnigineScript. Values of certain parameters can be calculated by an arbitrary expression, written in UnigineScript. .

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • bool enabled - true to enable setting the values of the specified material parameter by an expression in UnigineScript; false - to disable.

bool IsParameterOverridden ( int num ) #

Returns a value indicating if a given parameter is overridden.

Arguments

Return value

1 if the given parameter is overridden; otherwise, 0.

bool IsParameterInt ( int num ) #

Returns a value indicating if the parameter with the specified number is an integer-type parameter.

Arguments

Return value

true if the parameter with the specified number is an integer-type parameter; otherwise, false.

bool IsParameterFloat ( int num ) #

Returns a value indicating if the parameter with the specified number is a float-type parameter.

Arguments

Return value

true if the parameter with the specified number is an float-type parameter; otherwise, false.

int GetParameterMinExpand ( int num ) #

Returns a value indicating if the minimum value of the parameter with the specified number can be decreased.

Arguments

Return value

1 if the minimum value can be changed; otherwise, 0.

int GetParameterMaxExpand ( int num ) #

Returns a value indicating if the maximum value of the parameter with the specified number can be increased.

Arguments

Return value

1 if the maximum value can be changed; otherwise, 0.

float GetParameterMinValue ( int num ) #

Returns the minimum allowed value for the parameter with the specified number.

Arguments

Return value

Minimum parameter value.

float GetParameterMaxValue ( int num ) #

Returns the maximum allowed value for the parameter with the specified number.

Arguments

Return value

Maximum parameter value.

float GetParameterFloat ( string name ) #

Returns a value of a float parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Float parameter value.

vec2 GetParameterFloat2 ( string name ) #

Returns a value of a FLOAT2 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as a vec2 vector.

vec3 GetParameterFloat3 ( string name ) #

Returns a value of a FLOAT3 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as a vec3 vector.

vec4 GetParameterFloat4 ( string name ) #

Returns a value of a FLOAT4 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as a vec4 vector.

int GetParameterInt ( string name ) #

Returns a value of an integer parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Integer parameter value.

ivec2 GetParameterInt2 ( string name ) #

Returns a value of a INT2 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as an ivec2 vector.

ivec3 GetParameterInt3 ( string name ) #

Returns a value of a INT3 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as an ivec3 vector.

ivec4 GetParameterInt4 ( string name ) #

Returns a value of a INT4 parameter with the specified name.

Arguments

  • string name - Parameter name.

Return value

Parameter value as an ivec4 vector.

int GetParameterArraySize ( int num ) #

Returns the number of elements in the array parameter with the specified number.

Arguments

Return value

Number of elements of the specified array parameter.

bool IsParameterArray ( int num ) #

Returns a value indicating if the parameter with the specified number is an array-type parameter, i.e., one of the following:

Arguments

Return value

true if the parameter is an array-type parameter; otherwise, false.

void GetParameterArray ( int num, float[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_FLOAT) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • float[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, float[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_FLOAT) with the specified number using the specified array.

Arguments

void GetParameterArray ( int num, vec2[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_FLOAT2) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • vec2[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, vec2[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_FLOAT2) with the specified number using the specified array.

Arguments

void GetParameterArray ( int num, vec4[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_FLOAT4) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • vec4[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, vec4[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_FLOAT4) with the specified number using the specified array.

Arguments

void GetParameterArray ( int num, int[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_INT) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • int[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, int[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_INT) with the specified number using the specified array.

Arguments

void GetParameterArray ( int num, ivec2[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_INT2) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • ivec2[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, ivec2[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_INT2) with the specified number using the specified array.

Arguments

void GetParameterArray ( int num, ivec4[] values ) #

Returns a value of the array parameter (type: PARAMETER_ARRAY_INT4) with the specified number and puts it to the specified buffer array.

Arguments

  • int num - Parameter number in the range from 0 to the total number of parameters.
  • ivec4[] values - Buffer array to store parameter values.

void SetParameterArray ( int num, ivec4[] values ) #

Sets a value of the array parameter (type: PARAMETER_ARRAY_INT4) with the specified number using the specified array.

Arguments

int SetParameterExpression ( int num, string expression ) #

Sets the expression used as a parameter value.

Arguments

Return value

1 if the expression is set successfully; otherwise, 0.

string GetParameterExpression ( int num ) #

Returns an expression used as a parameter value.

Arguments

Return value

Parameter expression, if it exists; otherwise, NULL (0).

string GetParameterGroup ( int num ) #

Returns the group of the material parameter.

Arguments

Return value

The group of the material parameter.

bool IsParameterHidden ( int num ) #

Returns a value indicating if a given parameter is hidden.

Arguments

Return value

1 if the parameter is hidden; otherwise, 0.

string GetParameterName ( int num ) #

Returns the name of a given parameter.

Arguments

Return value

Parameter name.

void SetParameterFloat ( int num, float value ) #

Sets the value of a given float parameter by its number.

Arguments

void SetParameterFloat ( string name, float value ) #

Sets the value of a given float parameter by its name.

Arguments

  • string name - Name of the target float parameter.
  • float value - Parameter value to be set.

float GetParameterFloat ( int num ) #

Returns the current value of a given float parameter.

Arguments

Return value

Current parameter value.

void SetParameterFloat2 ( int num, vec2 value ) #

Sets the value of a given float2 parameter by its number.

Arguments

void SetParameterFloat2 ( string name, vec2 value ) #

Sets the value of a given float2 parameter by its name.

Arguments

  • string name - Name of the target float2 parameter.
  • vec2 value - Parameter value to be set.

vec2 GetParameterFloat2 ( int num ) #

Returns the current value of a given float2 parameter.

Arguments

Return value

Current parameter value.

void SetParameterFloat3 ( int num, vec3 value ) #

Sets the value of a given float3 parameter by its number.

Arguments

void SetParameterFloat3 ( string name, vec3 value ) #

Sets the value of a given float3 parameter by its name.

Arguments

  • string name - Name of the target float3 parameter.
  • vec3 value - Parameter value to be set.

vec3 GetParameterFloat3 ( int num ) #

Returns the current value of a given float3 parameter.

Arguments

Return value

Current parameter value.

void SetParameterFloat4 ( int num, vec4 value ) #

Sets the value of a given float4 parameter by its number.

Arguments

void SetParameterFloat4 ( string name, vec4 value ) #

Sets the value of a given float4 parameter by its name.

Arguments

  • string name - Name of the target float4 parameter.
  • vec4 value - Parameter value to be set.

vec4 GetParameterFloat4 ( int num ) #

Returns the current value of a given float4 parameter.

Arguments

Return value

Current parameter value.

void SetParameterInt ( int num, int value ) #

Sets the value of a given int parameter by its number.

Arguments

void SetParameterInt ( string name, int value ) #

Sets the value of a given int parameter by its name.

Arguments

  • string name - Name of the target int parameter.
  • int value - Parameter value to be set.

int GetParameterInt ( int num ) #

Returns the current value of a given int parameter.

Arguments

Return value

Current parameter value.

void SetParameterInt2 ( int num, ivec2 value ) #

Sets the value of a given int2 parameter by its number.

Arguments

void SetParameterInt2 ( string name, ivec2 value ) #

Sets the value of a given int2 parameter by its name.

Arguments

  • string name - Name of the target int2 parameter.
  • ivec2 value - Parameter value to be set.

ivec2 GetParameterInt2 ( int num ) #

Returns the current value of a given int2 parameter.

Arguments

Return value

Current parameter value.

void SetParameterInt3 ( int num, ivec3 value ) #

Sets the value of a given int3 parameter by its number.

Arguments

void SetParameterInt3 ( string name, ivec3 value ) #

Sets the value of a given int3 parameter by its name.

Arguments

  • string name - Name of the target int3 parameter.
  • ivec3 value - Parameter value to be set.

ivec3 GetParameterInt3 ( int num ) #

Returns the current value of a given int3 parameter.

Arguments

Return value

Current parameter value.

void SetParameterInt4 ( int num, ivec4 value ) #

Sets the value of a given int4 parameter by its number.

Arguments

void SetParameterInt4 ( string name, ivec4 value ) #

Sets the value of a given int4 parameter by its name.

Arguments

  • string name - Name of the target int4 parameter.
  • ivec4 value - Parameter value to be set.

ivec4 GetParameterInt4 ( int num ) #

Returns the current value of a given int4 parameter.

Arguments

Return value

Current parameter value.

string GetParameterTitle ( int num ) #

Returns the title of the material parameter.

Arguments

Return value

Material parameter title.

string GetParameterTooltip ( int num ) #

Returns the tooltip of the material parameter.

Arguments

Return value

The tooltip text of the material parameter.

int GetParameterType ( int num ) #

Returns the type of a given parameter.

Arguments

Return value

One of the PARAMETER_* pre-defined variables or -1, if an error has occurred.

int GetParameterWidgetIndex ( int num ) #

Returns the index of the widget used to display the specified material parameter in UI.

Arguments

Return value

Index of the widget used for the specified material parameter.

string GetParameterWidget ( int num ) #

Returns the name of the widget used to display the specified material parameter in UI.

Arguments

Return value

Widget name for the specified material parameter.

bool IsParent ( string name ) #

Returns a value indicating if the material with the given name is a parent of the current material.

Arguments

  • string name - Material name.

Return value

1 if the material is the parent, otherwise - 0.

bool IsParent ( UGUID guid ) #

Returns a value indicating if the material with the given GUID is a parent of the current material.

Arguments

  • UGUID guid - Material GUID.

Return value

1 if the material is the parent; otherwise, 0.

void SetProceduralTexture ( int num, Texture texture ) #

Replaces a procedural texture having the specified number with the specified Texture. Procedural textures are calculated at run-time on GPU, using custom shaders. For example, this function allows to set the initial value for such texture.

Arguments

  • int num - Texture number. In materials, such texture should be declared with type="procedural" attribute.
  • Texture texture - Texture to be set.

int SetProceduralTextureImage ( int num, Image image ) #

Replaces a given procedural texture with an Image instance. Procedural textures are calculated at run-time on GPU, using custom shaders. For example, this function allows to set the initial value for such texture.

Arguments

  • int num - Texture number. In materials, such texture should be declared with type="procedural" attribute.
  • Image image - An image to set.

Return value

1 if the texture is replaced successfully; otherwise, 0.

int GetProceduralTextureImage ( int num, Image image ) #

Reads the given procedural texture into an Image smart pointer. Procedural textures are calculated in run-time on GPU, using custom shaders. So, for example, this function enables to read the value of such texture at any moment.

Arguments

  • int num - Texture number. In materials, such texture should be declared with type="procedural" attribute.
  • Image image - Image into which texture is read.

Return value

1 if the texture is read successfully; otherwise, 0.

bool CheckShaderCache ( ) #

Returns a value indicating if shader combination for current material states and options is already in cache.

Return value

1 if shader combination for current material states and options is already in cache; otherwise, 0.

bool CheckShaderCache ( Render.PASS pass, Node.TYPE node_type ) #

Returns a value indicating if shader combination for the given rendering pass and node type is already in cache.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).
  • Node.TYPE node_type - Node type.

Return value

1 if shader combination for the given rendering pass and node type is already in cache; otherwise, 0.

bool CompileShader ( Render.PASS pass, Node.TYPE node_type ) #

Compiles shader combination for the given rendering pass and node type.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).
  • Node.TYPE node_type - Node type.

Return value

1 if shader combination for the given rendering pass and node type was compiled successfully; otherwise, 0.

Shader FetchShader ( Render.PASS pass ) #

Returns the rendering shader for the specified rendering pass.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).

Return value

Shader for the specified rendering pass.

Shader FetchShader ( Render.PASS pass, Node.TYPE node_type ) #

Returns the rendering shader for the specified rendering pass and node type.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).
  • Node.TYPE node_type - Node type.

Return value

Shader for the specified rendering pass and node type.

Shader FetchShader ( string pass_name ) #

Returns the rendering shader for the specified rendering pass.

Arguments

  • string pass_name - Rendering pass name. One of the following:
    • wireframe
    • visualizer_solid
    • deferred
    • auxiliary
    • emission
    • reflection
    • refraction
    • transparent_blur
    • ambient
    • light_voxel_probe
    • light_environment_probe
    • light_omni
    • light_proj
    • light_world
    • shadow
    • depth_pre_pass
    • post
    • object_post

Return value

Shader for the specified rendering pass.

Shader FetchShader ( string pass_name, int node ) #

Returns the rendering shader for the specified rendering pass and node type.

Arguments

  • string pass_name - Rendering pass name. One of the following:
    • wireframe
    • visualizer_solid
    • deferred
    • auxiliary
    • emission
    • reflection
    • refraction
    • transparent_blur
    • ambient
    • light_voxel_probe
    • light_environment_probe
    • light_omni
    • light_proj
    • light_world
    • shadow
    • depth_pre_pass
    • post
    • object_post
  • int node - Node type.

Return value

Shader for the specified rendering pass and node type.

bool IsStateOverridden ( int num ) #

Returns a value indicating if a given state is overridden.

Arguments

  • int num - State number.

Return value

1 if the given state is overridden; otherwise, 0.

void SetState ( int num, int value ) #

Sets the state value.

Arguments

  • int num - State number.
  • int value - State value to be set.

void SetState ( string name, int value ) #

Sets the value of the given state.

Arguments

  • string name - State name.
  • int value - State value.

int GetState ( int num ) #

Returns the state value.

Arguments

  • int num - State number.

Return value

State value.

int GetState ( string name ) #

Returns the value of the given state.

Arguments

  • string name - State name.

Return value

State value.

string GetStateGroup ( int num ) #

Returns the group of the material state.

Arguments

  • int num - State number.

Return value

The group of the material state.

bool IsStateHidden ( int num ) #

Returns a value indicating if a given state is hidden.

Arguments

  • int num - State number.

Return value

1 is the state is hidden; otherwise, 0.

string GetStateName ( int num ) #

Returns the name of a given state.

Arguments

  • int num - State number.

Return value

State name.

string GetStateSwitchGroup ( int num ) #

Returns the switch group name for a given state.

Arguments

  • int num - State number.

Return value

State switch group name.

string GetStateSwitchItem ( int num, int item ) #

Returns the switch item name for a given state.

Arguments

  • int num - State number.
  • int item - Item number.

Return value

Switch item name or NULL (0), if an error has occurred.

int GetStateSwitchNumItems ( int num ) #

Returns the number of switch items for a given state.

Arguments

  • int num - State number.

Return value

Number of switch items.

string GetStateTitle ( int num ) #

Returns the title of the material state.

Arguments

  • int num - State number.

Return value

The title of the material state.

string GetStateTooltip ( int num ) #

Returns the tooltip of the material state.

Arguments

  • int num - State number.

Return value

The tooltip text of the material state.

int GetStateWidgetIndex ( int num ) #

Returns the index of the widget used to display the specified material state in UI.

Arguments

Return value

Index of the widget used for the specified material state.

int GetStateType ( int num ) #

Returns the type of a given state.

Arguments

  • int num - State number.

Return value

One of the MATERIAL_STATE_* pre-defined variables or -1, if an error occurred.

string GetTextureGroup ( int num ) #

Returns the group of the material texture.

Arguments

  • int num - State number.

Return value

The group of the material texture.

bool IsTextureHidden ( int num ) #

Returns a value indicating if the texture is hidden.

Arguments

  • int num - Texture number.

Return value

true if the given texture is hidden; otherwise, false.

bool IsTextureOverridden ( int num ) #

Returns a value indicating if a given texture is overridden.

Arguments

  • int num - Texture number.

Return value

true if the given texture is overridden; otherwise, false.

bool IsTextureLoaded ( int num ) #

Returns a value indicating if a given texture is loaded.

Arguments

  • int num

Return value

true if the given texture is loaded; otherwise, false.

string GetTextureName ( int num ) #

Returns the name of a given texture.

Arguments

  • int num - Texture number.

Return value

Texture name.

string GetTextureTitle ( int num ) #

Returns the title of the material texture.

Arguments

  • int num - Texture number.

Return value

Title of the material texture.

string GetTextureTooltip ( int num ) #

Returns the tooltip of the material texture.

Arguments

  • int num - Texture number.

Return value

Tooltip text of the material texture.

int GetTextureWidgetIndex ( int num ) #

Returns the index of the widget used to display the specified material texture in UI.

Arguments

Return value

Index of the widget used for the specified material texture.

int GetTextureType ( int num ) #

Returns the type of a given texture.

Arguments

  • int num - Texture number.

Return value

One of the TEXTURE_* pre-defined variables or -1, if an error occurred.

Material Clone ( string name ) #

Clones the material and assigns the given name to it.
Notice
A base material cannot be cloned.

Arguments

  • string name - Cloned material name.

Return value

Cloned material.

Material Clone ( string name, string path, UGUID guid ) #

Clones the material and assigns the given name, GUID and path to the cloned material. The cloned material will be saved to the specified path on saveMaterials() call. This method may be used, for example, to create a material missed during project's migration.
Notice
A base material cannot be cloned.

Arguments

  • string name - CLoned material name.
  • string path - Path to the cloned material.
  • UGUID guid - Cloned material GUID.

Return value

The cloned material.

Material Clone ( string name, string path ) #

Clones the material and assigns the given name and path to the cloned material. The cloned material will be saved to the specified path on saveMaterials() call.
Notice
A base material cannot be cloned.

Arguments

  • string name - Cloned material name.
  • string path - Path to save the cloned material

Return value

Cloned material.

Material Clone ( ) #

Clones the material. The cloned material will be empty: it won't have a name, path, textures and won't be displayed in the materials hierarchy.

Return value

Cloned material.

int FetchParameter ( string name, int fast_id ) #

Searches for a parameter by a given name among all parameters of the material.

Arguments

  • string name - Parameter name.
  • int fast_id - Parameter number in users auxiliary parameters cache. The value must be in the range [0; 512]

Return value

Parameter number, if it is found; otherwise, -1.

int FetchState ( string name, int fast_id ) #

Searches for a state by a given name among all states of the current material.

Arguments

  • string name - State name.
  • int fast_id - State number in users auxiliary states cache. The value must be in the range [0; 512]

Return value

State number, if it is found; otherwise, -1.

int FetchTexture ( string name, int fast_id ) #

Searches for a texture by a given name among all textures used by the current material.

Arguments

  • string name - Texture name.
  • int fast_id - Texture number in users auxiliary textures cache. The value must be in the range [0; 512]

Return value

Texture number, if it is found; otherwise, -1.

int FindParameter ( string name ) #

Searches for a parameter by a given name among all parameters of the current material.

Arguments

  • string name - Parameter name.

Return value

Parameter number, if it is found; otherwise, -1.

int FindState ( string name ) #

Searches for a state by a given name among all states of the current material.

Arguments

  • string name - State name.

Return value

State number, if it is found; otherwise, -1.

int FindTexture ( string name ) #

Searches for a texture by a given name among all textures used by the current material.

Arguments

  • string name - Texture name.

Return value

Texture number, if it is found; otherwise, -1.

Material Inherit ( string name ) #

Inherits a material from the current one and assigns the specified name to it.

Arguments

  • string name - Inherited material name.

Return value

Inherited material.

Material Inherit ( string name, string path ) #

Inherits a material from the current one and assigns the specified name and path to it. The inherited material will be saved to the specified path on saveMaterials() call.

Arguments

  • string name - Inherited material name.
  • string path - Path to the inherited material.

Return value

Inherited material.

Material Inherit ( string name, string path, UGUID guid ) #

Inherits a material from the current one and assigns the specified name, GUID and path to it. The inherited material will be saved to the specified path on saveMaterials() call.

Arguments

  • string name - Inherited material name.
  • string path - Path to the inherited material.
  • UGUID guid - Inherited material GUID.

Return value

Inherited material.

Material Inherit ( ) #

Inherits the material. The inherited material will be empty: it won't have a name, path, texture and won't be displayed in materials hierarchy.

Return value

Inherited material.

bool RestoreState ( Stream stream, bool forced = 0 ) #

Restores the state of a given material (all of its options, states and parameters) from a binary stream.

Arguments

  • Stream stream - The stream with saved material data.
  • bool forced - Forced restoring of material settings.

Return value

1 if the material settings are restored successfully; otherwise, 0.

bool SaveState ( Stream stream, bool forced = 0 ) #

Saves the settings of a given material (all of its options, states and parameters) into a binary stream.

Arguments

  • Stream stream - The stream to save material state data.
  • bool forced - Forced saving of material settings.

Return value

1 if the material settings are saved successfully; otherwise, 0.

bool CanRenderNode ( ) #

Returns a value indicating if the marial can be rendered for at least one type of nodes.

Return value

1 if the material is rendered for at least one type of nodes; otherwise, 0.

void ResetState ( int num ) #

Resets the overridden value of the given state to the parent one.

Arguments

  • int num - State number.

void SetTexturePath ( int num, string path ) #

Sets a new path to the texture with the given number.

Arguments

  • int num - Texture number.
  • string path - A path to the texture or NULL to clear the path.

void SetTexturePath ( string name, string path ) #

Sets a new path to the texture with the given name.

Arguments

  • string name - Texture name.
  • string path - A path to the texture or NULL to clear the path.

void ResetTexture ( int num ) #

Resets the overridden value of the given texture to the parent one.

Arguments

  • int num - Texture number.

string GetTexturePath ( int num ) #

Returns a path to the texture with the specified number.

Arguments

  • int num - Texture number.

Return value

A path to the texture.

string GetTexturePath ( string name ) #

Returns a path to the texture with the specified name.

Arguments

  • string name - Texture name.

Return value

A path to the texture.

bool IsNodeTypeSupported ( Node.TYPE type ) #

Returns a value indicating if the given type of nodes is supported by the material.

Arguments

Return value

1 if the node type is supported; otherwise, 0.

bool SetParent ( Material material, bool save_all_values = 1 ) #

Sets the given material as the parent for this material and saves the material's properties values (if the corresponding flag is set).
Notice
The method isn't available for the manual and base materials.

Arguments

  • Material material - Material to be set as the parent for this material.
  • bool save_all_values - Flag indicating if the material's properties will be saved after reparenting.

Return value

1 if the material's parent is changed; otherwise, 0.

bool CheckTextureConditions ( int num ) #

Checks if conditions set for the given texture are met.

Arguments

  • int num - Texture number.

Return value

1 if conditions are met; otherwise, 0.

int GetTextureFlags ( int num ) #

Returns the flags set on the given texture.

Arguments

  • int num - Texture number.

Return value

Texture flags bit mask.

void ReloadShaders ( ) #

Reloads shaders of the current material.

int LoadXml ( Xml xml ) #

Loads material settings from the Xml.

Arguments

  • Xml xml - An Xml node containing material settings.

Return value

1 if the material settings are loaded successfully; otherwise, 0.

bool HasOverrides ( ) #

Returns a value indicating if the material has at least one overridden property.

Return value

true if the material has at least one overridden property; otherwise, false.

bool CanSave ( ) #

Returns a value indicating if the material can be saved. For example, this function will return 0 for a base or manual material.

Return value

true if the material can be saved; otherwise, false.

bool CheckStateConditions ( int num ) #

Checks if conditions set for the given state are met.

Arguments

  • int num - State number.

Return value

true if conditions are met; otherwise, false.

bool CheckParameterConditions ( int num ) #

Checks if conditions set for the given parameter are met.

Arguments

  • int num - Parameter name.

Return value

1 if conditions are met; othersiwe, 0.

bool Save ( ) #

Save the material to the current path used for this material.
Notice
The method isn't available for the manual and base materials.

Return value

1 if the material is saved successfully; otherwise, 0.

bool Save ( string path ) #

Save the material to the specified path.

Arguments

  • string path - A path to save the material

Return value

1 if the material is saved successfully; otherwise, 0.

bool Load ( ) #

Loads the material from the file specified by the setPath() function. The function can be used to load materials created during application execution or stored outside the data directory.

Return value

1 if the material is loaded successfully; otherwise, 0.

bool Load ( string path ) #

Loads a material from the given file. The function can be used to load materials created during application execution or stored outside the data directory.

Arguments

  • string path - A path to the material file.

Return value

1 if the material is loaded successfully; otherwise, 0.

bool SaveXml ( Xml xml ) #

Saves the material into the given Xml.
Notice
The method isn't available for the manual and base materials.

Arguments

  • Xml xml - An Xml node.

Return value

1 if the material is saved successfully; otherwise, 0.

bool IsNodeSupported ( Node node ) #

Returns a value indicating if the material can be applied to the given node.

Arguments

  • Node node - A node.

Return value

1 if the given node is supported; otherwise, 0.

void SetTextureFlags ( int num, int flags ) #

Sets the specified texture flags to the given texture.

Arguments

void SetTexture ( int num, Texture texture ) #

Sets the given texture to the texture with the specified number.

Arguments

  • int num - Texture number.
  • Texture texture - Texture to be set.

void SetTexture ( string name, Texture texture ) #

Sets the given texture to the texture with the specified name.

Arguments

  • string name - Texture name (one of the textures used by the material, e.g.: albedo).
  • Texture texture - Texture to be set.

Texture GetTexture ( int num ) #

Returns a texture set for the current material.

Arguments

  • int num - Texture number.

Return value

A texture.

void ResetParameter ( int num ) #

Resets the overridden value of the given parameter to the parent one.

Arguments

bool Reload ( ) #

Reloads the material and all its children.

Return value

1 if the material is reloaded successfully; otherwise, 0.

int SetTextureImage ( int num, Image image ) #

Set a given image to a given texture.

Arguments

  • int num - Texture number.
  • Image image - An image to set.

Return value

1 if the image is set successfully; otherwise, 0.

int GetTextureImage ( int num, Image image ) #

Reads a given texture into a given image.

Arguments

  • int num - Texture number.
  • Image image - An image.

Return value

1 if the texture is read successfully; otherwise, 0.

TextureCurve GetTextureCurve ( int num ) #

Returns a curve texture instance for the data stored in the specified curve texture (gradient).
Notice
Modifications made to the curve shall propagate to the parent and sibling materials. To modify an overridden curve for this material only use the getTextureCurveOverride() method.

Arguments

  • int num - Texture number.

Return value

TextureCurve class instance for the data stored in the gradient texture with the specified number.

TextureCurve GetTextureCurveOverride ( int num ) #

Returns a new curve texture instance for the data stored in the specified curve texture (gradient) overriding the default one. This method enables you to set individual RGBA curves, adjusting color values of the resulting curve texture (gradient).
Notice
Modifications made to the curve shall not propagate to the parent and sibling materials.

Arguments

  • int num - Texture number.

Return value

New TextureCurve class instance overriding the data stored in the specified curve texture (gradient).

void DestroyShaders ( ) #

Deletes all shaders used for the current material and its children and clears shaders cache.

void CreateShaders ( bool recursive = 0 ) #

Creates all shaders for the current material and its children (if specified).

Arguments

  • bool recursive - true to create shaders for child materials of the current material; otherwise, false.

void DestroyTextures ( ) #

Deletes all textures used by the current material and its children.

void ReloadShader ( long num ) #

Reloads the shader with the given number.

Arguments

  • long num - Shader number.

void UpdateShadersHash ( ) #

Updates fast identifiers of shaders (hashes of names) of the material. The function is available only for base materials.

Render.PASS GetRenderPass ( string pass_name ) #

Returns the type of the rendering pass by its name (including custom passes).

Arguments

  • string pass_name - Name of the rendering pass.

Return value

Rendering pass number in the range from 0 to 18 + custom_passes_number, if it exists; otherwise -1.

string GetRenderPassName ( Render.PASS type ) #

Returns the name of the rendering pass by its number (including custom passes).

Arguments

  • Render.PASS type - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).

Return value

Rendering pass name if it exists; otherwise NULL.

bool RunExpression ( string name, int w, int h, int d = 1 ) #

Runs the material's expression with the specified name. An expression is a reference to a file containing code in UnigineScript, that can generate various elements used in the material (e.g., textures, texture arrays, unstructured buffers, etc.) or contain other logic. Expressions can be defined in the *.basemat file as follows:
Source code (XML)
<!--...-->
<expression name="expr_name" path="expression.usc"/>

An example of expression.usc code:

Source code (UnigineScript)
// typical most frequently used parameters passed to the expression automatically, when it is called.
int in_width;
int in_height;
int in_depth;
Material in_material;

// If you need extra parameters, you should set them via Material::setParameter*("param_name", value) before calling Material::runExpression()
// then you can access them in the expression via in_material.getParameter*("param_name")

// ...

// get a temporary texture
Texture texture = engine.render.getTemporaryTexture(in_width, in_height);

//get the value of the material parameter named "my_extra_param"
float my_param = in_material.getParameter("my_extra_param");

// modify the temporary texture using the my_param parameter somehow...

// set the modified texture as albedo texture of the material
in_material->setTexture("albedo", texture);

To execute this expression the following code can be used:

Source code (C++)
// ...
// setting the value of extra parameter
material->setParameterFloat("my_extra_param", 2.5f);

// running the expression 
material->runExpression("expr_name, 512, 512, 1);
// ...
Notice
Expressions can be executed only for base materials.

Arguments

  • string name - Expression name. Expression with this name must be defined in the material declaration (*.basemat file).
  • int w - Width, e.g. if a texture or a structured buffer is generated by the expression.
  • int h - Height, e.g. if a texture or a structured buffer is generated by the expression.
  • int d - Depth, e.g. if a 3D Texture, 2D array or a structured buffer is generated by the expression.

Return value

1 if the specified expression is executed successfully; otherwise, 0.

bool RenderScreen ( string pass_name ) #

Renders the screen-space material. The material must have a shader for the specified pass associated with it.

Arguments

  • string pass_name - Name of the rendering pass.

Return value

0 if the specified pass was not found; otherwise, 1.

void RenderScreen ( Render.PASS pass ) #

Renders the screen-space material. The material must have a shader for the specified pass associated with it.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).

bool RenderCompute ( string pass_name, int group_threads_x = 1, int group_threads_y = 1, int group_threads_z = 1 ) #

Renders the material using a compute shader. The material must have a compute shader for the specified pass associated with it.

Arguments

  • string pass_name - Name of the rendering pass.
  • int group_threads_x - Local X work-group size of the compute shader.
  • int group_threads_y - Local Y work-group size of the compute shader.
  • int group_threads_z - Local Z work-group size of the compute shader.

Return value

true if the specified pass was not found; otherwise, false.

void RenderCompute ( Render.PASS pass, int group_threads_x = 1, int group_threads_y = 1, int group_threads_z = 1 ) #

Renders the material using a compute shader. The material must have a compute shader for the specified pass associated with it.

Arguments

  • Render.PASS pass - Rendering pass number in range [0;NUM_PASSES) (one of the PASS_* variables).
  • int group_threads_x - Local X work-group size of the compute shader.
  • int group_threads_y - Local Y work-group size of the compute shader.
  • int group_threads_z - Local Z work-group size of the compute shader.

string GetOptionTitle ( int option ) #

Returns the title of the specified material option.

Arguments

  • int option - Material option: one of the OPTION_* values.

Return value

Material option title.

string GetOptionTooltip ( int option ) #

Returns the tooltip of the specified material option.

Arguments

  • int option - Material option: one of the OPTION_* values.

Return value

Tooltip text of the material's option.

string GetOptionGroup ( int option ) #

Returns the group to which the specified material option belongs.

Arguments

  • int option - Material option: one of the OPTION_* values.

Return value

The group of the material option.

int GetOptionWidgetIndex ( int option ) #

Returns the index of the widget used to display the specified material option in UI.

Arguments

  • int option - Material option: one of the OPTION_* values.

Return value

Index of the widget used for the specified material option.

bool IsOptionHidden ( int option ) #

Returns a value indicating if the specified material option is hidden.

Arguments

  • int option - Material option: one of the OPTION_* values.

Return value

1 if the option is hidden; otherwise, 0.
Last update: 2020-08-25
Build: ()