This page has been translated automatically.
编程
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::Material Class

Header:#include <UnigineMaterial.h>

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 set texture flags to the material's texture. We set the ANISOTROPY_8 flag to the albedo texture of the mesh_base_0 material.

Add the following code to the AppWorldLogic.cpp file.

Source code (C++)
// AppWorldLogic.cpp
#include "AppWorldLogic.h"
#include <UnigineMaterial.h>
#include <UnigineMaterials.h>

using namespace Unigine;

/* .. */

int AppWorldLogic::init() {
	// load materials
	Materials *materials = Materials::get();
	// get the mesh_base_0 material
	MaterialPtr m = materials->findMaterial("mesh_base_0");
	// get the number of albedo texture of the mesh_base_0 material
	int num = m->findTexture("albedo");
	// return the current flags and show them in console
	int flags = m->getTextureFlags(num);
	Log::message("Texture flags are:%i \n", flags);
	
	// set the ANISOTROPY_8 flag
	m->setTextureFlags(num, Texture::ANISOTROPY_8);
	
	// get the flags and show them in console
	int flagsSet = m->getTextureFlags(num);
	Log::message("Texture flags are:%i \n", flagsSet);
	
	return 1;
}

/* .. */

In the console, you can see the following result:

Output
Image texture flags are: 81920
Image texture flags are: 524288

Flags are bits of the integer variable: 81920 value means the FILTER_BILINEAR flag, 524288 value means the ANISOTROPY_8 flag.

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.cpp file.

Source code (C++)
// AppWorldLogic.cpp

#include "AppWorldLogic.h"
#include <UnigineMaterial.h>
#include <UnigineMaterials.h>
#include <UnigineConsole.h>
#include <UnigineEditor.h>

using namespace Unigine;

/* .. */

int AppWorldLogic::init() {

	Materials *materials = Materials::get();
	// find the mesh_base material
	MaterialPtr mesh_base = materials->findMaterial("mesh_base");
	// inherit a new material from it
	MaterialPtr reflector_material = mesh_base->inherit("planar_reflector", "unigine_project/materials/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
	reflector_material->setParameterSlider(reflector_material->findParameter("metalness"), 1.0f);
	reflector_material->setParameterSlider(reflector_material->findParameter("roughness"), 0.0f);
	
	// assign the mesh_base material to the material ball
	ObjectMeshStaticPtr material_ball = ObjectMeshStatic::cast(Editor::get()->getNodeByName("material_ball"));
	material_ball->setMaterial("mesh_base","*");
	//  new mirror material to the ground object
	ObjectMeshDynamicPtr ground = ObjectMeshDynamic::cast(Editor::get()->getNodeByName("ground"));
	ground->setRotation(Math::quat(90.0f, 90.0f, 0.0f));
	ground->setMaterial("planar_reflector", 0);

	// enable planar reflections rendering using the corresponding console command (render_reflection_dynamic)
	Console::get()->run("render_reflection_dynamic 1");
	
	return 1;
}

/* .. */

Material Class

Members


static MaterialPtr create()

Constructor. Creates a new material instance.

int isAlphaTest()

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

Return value

1 if the material has alpha test option enabled; otherwise, 0.

int getBlendDestFunc()

Returns the destination blending function.

Return value

The destination blending function (one of the BLEND_* variables).

void setBlendFunc(int src, int dest)

Sets the source and destination blending functions.

Arguments

  • int src - The source blending function (one of the BLEND_* values described in the State class).
  • int dest - The destination blending function (one of the BLEND_*values described in the State class).

int getBlendSrcFunc()

Returns the source blending function.

Return value

The source blending function (one of the BLEND_*values described in the State class).

void setCastShadow(int shadow)

Enables or disables the cast shadow option for an object with the material applied.

Arguments

  • int shadow - 1 to enable casting of shadows, 0 to disable it.

int getCastShadow()

Returns a value indicating if an object with the material applied casts shadows.

Return value

1 if casting of shadows is enabled; otherwise, 0.

void setCastWorldShadow(int shadow)

Enables or disables casting of shadows from the world light for an object with the material applied.

Arguments

  • int shadow - 1 to enable casting of shadows from the world light, 0 to disable it.

int getCastWorldShadow()

Returns a value indicating if an object with the material applied casts shadows from the world light.

Return value

1 if casting of shadows from the world light is enabled; otherwise, 0.

Ptr<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.

int isDeferred()

Returns a value indicating if the material is rendered in the deferred pass.

Return value

1 if the material is rendered in the deferred pass (non-transparent); otherwise, 0.

void setDepthMask(int mask)

Sets a value indicating if the material uses a depth mask.

Arguments

  • int mask - 1 to use the depth mask, 0 not to use.

int getDepthMask()

Returns a value indicating if the material uses a depth mask.

Return value

Positive number if the depth mask is used; otherwise, 0.

void setDepthTest(int test)

Enables or disables the depth testing option for the material. This option can be used to render certain objects, that are behind other ones.

Arguments

  • int test - 1 to enable depth testing for the material, 0 to disable it.

int getDepthTest()

Returns 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.

Return value

1 if depth testing is enabled for the material; otherwise, 0.

int isEditable()

Returns a value indicating if the material can be edited.

Return value

1 if the material is editable; otherwise, 0.

int isFilter()

Returns a value indicating if the material has filter texture.

Return value

1 if the material has a filter texture; otherwise, 0.

int isForward()

Returns a value indicating if the material is rendered in the forward pass.

Return value

1 if the material is rendered in the forward pass (transparent with blending func); otherwise, 0.

int isHidden()

Returns a value indicating if the material is hidden.

Return value

1 if the material is hidden; otherwise, 0.

void setImageTextureProcedural(int num, const Ptr<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.
  • const Ptr<Material> & procedural - Procedural material.
  • int procedural_num - Procedural texture number.

void setLightMask(int mask)

Sets a shadow mask for the material. 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.

Arguments

  • int mask - Integer value, each bit of which is a mask.

int getLightMask()

Returns a shadow mask of the material. 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.

Return value

Integer value, each bit of which is a mask.

const char * getName()

Returns the current material name.

Return value

Material name.

int getNumChildren()

Returns the number of child materials.

Return value

Number of child materials.

int getNumParameters()

Returns the number of material's parameters.

Return value

Number of material's parameters.

int getNumStates()

Returns the number of material's states.

Return value

Number of material's states.

int getNumTextures()

Returns the number of textures used by the material.

Return value

Number of used textures.

void setOffset(int offset)

Sets the rendering polygon offset for the material. Polygon offset is useful to prevent a Z-fighting effect.

Arguments

  • int offset - Rendering polygon offset in levels. Available values: 0 - 1024 (powers of 2).

int getOffset()

Returns the rendering polygon offset used for the material.

Return value

Rendering polygon offset in levels.

void setOrder(int order)

Sets the rendering order of material. The higher the rendering order, the lower the rendering priority (the material with the -8 order will be rendered first).

Arguments

  • int order - Rendering order.

int getOrder()

Returns the rendering order of materials.

Return value

Rendering order.

void setOverlap(int overlap)

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.

Arguments

  • int overlap - 1 to enable the overlap option for the material, 0 to disable it.

int getOverlap()

Returns 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.

Return value

1 if the overlap option is enabled for the material; otherwise, 0.

int isOwner()

Returns the owner flag. If the pointer is the owner, on its deletion the material also will be deleted. Use grab() and release() functions to change ownership.

Return value

Owner flag.

int isParameterOverridden(int num)

Returns a value indicating if a given parameter is overridden.

Arguments

  • int num - Parameter number.

Return value

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

void setParameter(int num, const Math::vec4 & value)

Sets a material's parameter value.

Arguments

  • int num - Parameter number.
  • const Math::vec4 & value - Parameter value.

void setParameter(const char * name, const Math::vec4 & value)

Sets the specified value to the parameter with the given name.

Arguments

  • const char * name - Parameter name.
  • const Math::vec4 & value - Parameter value to set.

Math::vec4 getParameter(const char * name)

Returns a value of the parameter with the given name.

Arguments

  • const char * name - Parameter name.

Return value

Parameter value.

Math::vec4 getParameter(int num)

Returns a value of the parameter with the given number.

Arguments

  • int num - Parameter number.

Return value

Parameter value.

void setParameterArray(int num, const Vector< Math::vec4 > & values)

Sets the values for a given array parameter.

Arguments

  • int num - Parameter number.
  • const Vector< Math::vec4 > & values - Array of parameter values.

void getParameterArray(int num, Vector< Math::vec4 > & values)

Returns the values of a given array parameter (the values are written into the specified array).

Arguments

  • int num - Parameter number.
  • Vector< Math::vec4 > & values - Array of parameter values.

int setParameterExpression(int num, const char * expression)

Sets the expression used as a parameter value.

Arguments

  • int num - Parameter number.
  • const char * expression - New expression.

Return value

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

const char * getParameterExpression(int num)

Returns an expression used as a parameter value.

Arguments

  • int num - Parameter number.

Return value

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

const char * getParameterGroup(int num)

Returns the group of the material parameter.

Arguments

  • int num - Parameter number.

Return value

The group of the material parameter.

int isParameterHidden(int num)

Returns a value indicating if a given parameter is hidden.

Arguments

  • int num - Parameter number.

Return value

1 if the parameter is hidden; otherwise, 0.

int setParameterMask(int num, int mask)

Sets a mask for a given parameter.

Arguments

  • int num - Parameter number.
  • int mask - Integer value, each bit of which is a mask.

Return value

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

int getParameterMask(int num)

Returns the mask for a given parameter.

Arguments

  • int num - Parameter number.

Return value

Integer value, each bit of which is a mask.

const char * getParameterName(int num)

Returns the name of a given parameter.

Arguments

  • int num - Parameter number.

Return value

Parameter name.

void setParameterSlider(const char * name, float value)

Sets the value of a given slider parameter.

Arguments

  • const char * name - Name of the target slider parameter.
  • float value - Slider parameter value.

void setParameterSlider(int num, float value)

Sets the value of a given slider parameter.

Arguments

  • int num - Parameter number.
  • float value - Slider parameter value.

float getParameterSlider(int num)

Returns the current value of a given slider parameter.

Arguments

  • int num - Parameter number.

Return value

Slider parameter value.

int getParameterSliderMaxExpand(int num)

Returns a value indicating if the maximum value of a given parameter can be increased.

Arguments

  • int num - Parameter number.

Return value

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

float getParameterSliderMaxValue(int num)

Returns the maximum allowed value of a slider parameter.

Arguments

  • int num - Parameter number.

Return value

Maximum value.

int getParameterSliderMinExpand(int num)

Returns a value indicating if the minimum value of a given parameter can be decreased.

Arguments

  • int num - Parameter number.

Return value

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

float getParameterSliderMinValue(int num)

Returns the minimum allowed value of a slider parameter.

Arguments

  • int num - Parameter number.

Return value

Minimum value.

const char * getParameterTitle(int num)

Returns the title of the material parameter.

Arguments

  • int num - Parameter number.

Return value

Material parameter title.

const char * getParameterTooltip(int num)

Returns the tooltip of the material parameter.

Arguments

  • int num - Parameter number.

Return value

The tooltip text of the material parameter.

int getParameterType(int num)

Returns the type of a given parameter.

Arguments

  • int num - Parameter number.

Return value

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

const char * getParameterWidget(int num)

Returns the widget for a given parameter.

Arguments

  • int num - Parameter number.

Return value

Widget name for a given parameter.

Ptr<Material> getParent()

Returns the parent material.

Return value

Parent material or NULL (0), if the current material has no parent.

int isParent(const char * name)

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

Arguments

  • const char * name - Material name.

Return value

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

int isParent(const UGUID & guid)

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

Arguments

  • const UGUID & guid - Material GUID.

Return value

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

int isProcedural()

Returns a value indicating if the material has procedural texture.

Return value

1 if the material has a procedural texture; otherwise, 0.

int setProceduralTextureImage(int num, const Ptr<Image> & image)

Replaces the procedural texture image with an Image smart pointer. Procedural textures are calculated in run-time on GPU, using custom shaders. So, for example, this function can be used to set the initial value for such texture.

Arguments

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

Return value

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

int getProceduralTextureImage(int num, const Ptr<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.
  • const Ptr<Image> & image - Image into which texture is read.

Return value

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

int isReflection2D()

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

Return value

1 if the material has a 2d reflection texture; otherwise, 0.

bool checkShader(int pass, int node)

Checks if there's a shader combination that can be possibly compiled for a given rendering pass and node type. This method does not change cache or create shaders.

Arguments

  • int pass - Rendering pass number in range [0;13).
  • int node - Node type.

Return value

0 if there's no possible shader combination for current material states and options; otherwise, 1, even if shaders are not compiled or have errors.

bool checkShader(int pass)

Checks if there's a shader combination that can be possibly compiled for a given rendering pass. This method does not change cache or create shaders.

Arguments

  • int pass - Rendering pass number in range [0;13).

Return value

0 if there's no possible shader combination for current material states and options; otherwise, 1, even if shaders are not compiled or have errors.

Ptr<Shader> fetchShader(int pass)

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

Arguments

  • int pass - Rendering pass number in range [0;13).

Return value

Shader smart pointer.

Ptr<Shader> fetchShader(int pass, int node)

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

Arguments

  • int pass - Rendering pass number in range [0;13).
  • int node - Node type.

Return value

Shader smart pointer.

int 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(const char * name, int value)

Sets the value of the given state.

Arguments

  • const char * 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(const char * name)

Returns the value of the given state.

Arguments

  • const char * name - State name.

Return value

State value.

const char * getStateGroup(int num)

Returns the group of the material state.

Arguments

  • int num - State number.

Return value

The group of the material state.

int 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.

const char * getStateName(int num)

Returns the name of a given state.

Arguments

  • int num - State number.

Return value

State name.

const char * 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 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.

const char * getStateTitle(int num)

Returns the title of the material state.

Arguments

  • int num - State number.

Return value

The title of the material state.

const char * 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 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.

const char * getTextureGroup(int num)

Returns the group of the material texture.

Arguments

  • int num - State number.

Return value

The group of the material texture.

int isTextureHidden(int num)

Returns a value indicating if the texture is hidden.

Arguments

  • int num - Texture number.

Return value

1 if the texture is hidden; otherwise, 0.

int isTextureOverridden(int num)

Returns a value indicating if a given texture is overridden.

Arguments

  • int num - Texture number.

Return value

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

const char * getTextureName(int num)

Returns the name of a given texture.

Arguments

  • int num - Texture number.

Return value

Texture name.

const char * getTextureTitle(int num)

Returns the title of the material texture.

Arguments

  • int num - Texture number.

Return value

Title of the material texture.

const char * getTextureTooltip(int num)

Returns the tooltip of the material texture.

Arguments

  • int num - Texture number.

Return value

Tooltip text of the 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.

void setTransparent(int transparent)

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.

Arguments

  • int transparent - The transparency option (one of the TRANSPARENT_* variables).

int getTransparent()

Returns a value indicating the transparency type of the material.

Return value

One of the TRANSPARENT_* variables.

void setTwoSided(int sided)

Enables or disables the two sided option for the material.

Arguments

  • int sided - 1 to make the material two-sided, 0 to make it one-sided.

int getTwoSided()

Returns a value indicating if the material is two-sided.

Return value

1 if the material is two-sided; otherwise, 0.

void setViewportMask(int mask)

Sets a bit mask for rendering into the viewport. The material is rendered, if its mask matches the player's one.

Arguments

  • int mask - Integer, each bit of which is a mask.

int getViewportMask()

Returns the current bit mask for rendering into the viewport. The material is rendered, if its mask matches the player's one.

Return value

Integer, each bit of which is a mask.

int isWater()

Returns a value indicating if the material is rendered in the water pass.

Return value

1 if the material is rendered in the water pass; otherwise, 0.

Ptr<Material> clone(const char * name)

Clones the material and assigns the given name to it.
Notice
A base material cannot be cloned: if you try to clone the base material, the new material will be inherited from the base one.

Arguments

  • const char * name - Cloned material name.

Return value

Cloned material.

Ptr<Material> clone(const char * name, const char * path, const 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: if you try to clone the base material, the new material will be inherited from the base one.

Arguments

  • const char * name - CLoned material name.
  • const char * path - Path to the cloned material.
  • const UGUID & guid - Cloned material GUID.

Return value

The cloned material.

Ptr<Material> clone(const char * name, const char * 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: if you try to clone the base material, the new material will be inherited from the base one.

Arguments

  • const char * name - Cloned material name.
  • const char * path - Path to save the cloned material

Return value

Cloned material.

Ptr<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 materials hierarchy.

Return value

Cloned material.

int fetchParameter(const char * name, int fast_id)

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

Arguments

  • const char * name - Parameter name.
  • int fast_id - Parameter number in users auxiliary parameters cache. The value must be in the range [0; 128]

Return value

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

int fetchState(const char * name, int fast_id)

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

Arguments

  • const char * name - State name.
  • int fast_id - State number in users auxiliary states cache. The value must be in the range [0; 128]

Return value

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

int fetchTexture(const char * name, int fast_id)

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

Arguments

  • const char * name - Texture name.
  • int fast_id - Texture number in users auxiliary textures cache. The value must be in the range [0; 128]

Return value

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

int findParameter(const char * name)

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

Arguments

  • const char * name - Parameter name.

Return value

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

int findState(const char * name)

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

Arguments

  • const char * name - State name.

Return value

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

int findTexture(const char * name)

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

Arguments

  • const char * name - Texture name.

Return value

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

void grab()

Grabs Material (sets the owner flag to 1). The Material should not be handled by the engine after this function is called.

Ptr<Material> inherit(const char * name)

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

Arguments

  • const char * name - Inherited material name.

Return value

Inherited material.

Ptr<Material> inherit(const char * name, const char * 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

  • const char * name - Inherited material name.
  • const char * path - Path to the inherited material.

Return value

Inherited material.

Ptr<Material> inherit(const char * name, const char * path, const 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

  • const char * name - Inherited material name.
  • const char * path - Path to the inherited material.
  • const UGUID & guid - Inherited material GUID.

Return value

Inherited material.

Ptr<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.

void release()

Releases Material (sets the owner flag to 0). The Material should be handled by the engine after this function is called.

int restoreState(const Ptr<Stream> & stream, int forced = 0)

Restores the state of a given material (all of its options, states and parameters) from a binary stream.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • const Ptr<Stream> & stream - Stream smart pointer.
  • int forced - Forced restoring of material settings.

Return value

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

int saveState(const Ptr<Stream> & stream, int forced = 0)

Saves the settings of a given material (all of its options, states and parameters) into a binary stream.
Warning
This function is deprecated and will be removed in the next release.

Arguments

  • const Ptr<Stream> & stream - Stream smart pointer.
  • int forced - Forced saving of material settings.

Return value

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

int 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 overriden value of the given state to the parent one.

Arguments

  • int num - State number.

void setTexturePath(int num, const char * path)

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

Arguments

  • int num - Texture number.
  • const char * path - A path to the texture or NULL to clear the path.

void setTexturePath(const char * name, const char * path)

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

Arguments

  • const char * name - Texture name.
  • const char * path - A path to the texture or NULL to clear the path.

void setName(const char * name)

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

Arguments

  • const char * name - Material name.

void resetTexture(int num)

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

Arguments

  • int num - Texture number.

const char * 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.

const char * getTexturePath(const char * name)

Returns a path to the texture with the specified name.

Arguments

  • const char * name - Texture name.

Return value

A path to the texture.

int setPath(const char * arg1, int rename_file = 0)

Sets a new path to the current material and renames the file on the disk if the rename_flag is set.
Notice
The material name won't be changed.

Arguments

  • const char * arg1 - New path to the material.
  • int rename_file - A flag indicating if the material file will be renamed on function call.

Return value

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

int isNodeTypeSupported(int 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.

void setParent(const Ptr<Material> & material, int save_all_values = 1)

Sets the given material as the parent for the current 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

  • const Ptr<Material> & material - A material.
  • int save_all_values - A flag indicating if the matarial's properties will be saved after reparenting.

int 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 isInternal()

Returns a value indicating if the current material is internal.

Return value

1 if the material is internal; 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(const Ptr<Xml> & xml)

Loads material settings from the Xml.

Arguments

  • const Ptr<Xml> & xml - An Xml node containing material settings.

Return value

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

int hasOverrides()

Returns a value indicating if the current material has the overriden properties.

Return value

1 if the material properties are overriden; otherwise, 0.

int canSave()

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

Return value

1 if the material can be saved; otherwise, 0.

int checkStateConditions(int num)

Checks if conditions set for the given state are met.

Arguments

  • int num - State number.

Return value

1 if conditions are met; otherwise, 0.

int isManual()

Returns a value indicating if the current material is manual.

Return value

1 if the material is manual; otherwise, 0.

int isAutoSave()

Returns 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.

Return value

1 if the material can be saved automatically; otherwise, 0.

int 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.

int 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.

int save(const char * path)

Save the material to the specified path.

Arguments

  • const char * path - A path to save the material

Return value

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

int 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.

int load(const char * 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

  • const char * path - A path to the material file.

Return value

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

int saveXml(const Ptr<Xml> & xml)

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

Arguments

  • const Ptr<Xml> & xml - An Xml node.

Return value

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

int isBase()

Returns a value indicating if the material is the base one.

Return value

1 if the material is the base one; otherwise, 0.

int isNodeSupported(const Ptr<Node> & node)

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

Arguments

  • const Ptr<Node> & node - A node.

Return value

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

int setTextureImage(int num, const Ptr<Image> & image)

Set a given image to a given texture.

Arguments

  • int num - Texture number.
  • const Ptr<Image> & image - An image to set.

Return value

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

Ptr<Material> getBaseMaterial()

Returns the base material of the current material.

Return value

A base material.

void setTextureFlags(int num, int flags)

Sets the specified texture flags to the given texture.

Arguments

void setTexture(int num, const Ptr<Texture> & texture)

Sets the given texture to the texture with the specified number.
Notice
This method only sets a pointer to the texture, so mind the scope of the source texture pointer.

Arguments

  • int num - Texture number.
  • const Ptr<Texture> & texture - A texture to be set.

Ptr<Texture> getTexture(int num)

Returns a texture set for the current material.

Arguments

  • int num - Texture number.

Return value

A texture.

const char * getPath()

Returns a path to the current material.

Return value

Path to the material.

void resetParameter(int num)

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

Arguments

  • int num - Parameter number.

int reload()

Reloads the current material and all its children.

Return value

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

int getTextureImage(int num, const Ptr<Image> & image)

Reads a given texture into a given image.

Arguments

  • int num - Texture number.
  • const Ptr<Image> & image - An image.

Return value

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

UGUID getGUID()

Returns the GUID of the material.

Return value

GUID of the material.

int isEngine()

Returns 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.

Return value

1 if the material is engine-related; otherwise, 0.

int PARAMETER_ARRAY

Description

Parameter of this type accepts vec4 data type.

int PARAMETER_COLOR

Description

Parameter of this type requires a color value—a quad of floats corresponding to RGBA color components.

int PARAMETER_COMBINER

Description

Parameter of this type allows you to combine some parameter values in one data type.

int PARAMETER_CONSTANT

Description

Parameter of this type accepts only a constant value.

int PARAMETER_EXPRESSION

Description

Parameter of this type accepts expressions, which may include any operators, functions, and constants from the UnigineScript core library plus additional variable time and functions random() and noise().

int PARAMETER_SLIDER

Description

Parameter of this type accepts values only from a continuous range of allowed values.

int STATE_INT

Description

State of this type allows specifying only one possible value.

int STATE_SWITCH

Description

State of this type allows specifying a set of more than two possible values.

int STATE_TOGGLE

Description

State of this type allows only two possible values.

int TEXTURE_AUTO_EXPOSURE

Description

An RG16F texture that stores intensity of the exposure (R) and luminance (G).

int TEXTURE_AUXILIARY

Description

Auxiliary texture is used for different post effects (auxiliary pass).

int TEXTURE_BENT_NORMAL

Description

An RG11B10F texture that stores bent normals (RGB) used for smooth ambient lighting.

int TEXTURE_CLOUDS_DYNAMIC_COVERAGE

Description

Texture of this type stores clouds dynamic coverage data.

int TEXTURE_CLOUDS_STATIC_COVERAGE

Description

Texture of this type stores clouds static coverage data.

int TEXTURE_CLOUDS_SCREEN

Description

An RGBA16F texture into which clouds are rendered.

int TEXTURE_CURRENT_DEPTH

Description

Texture of this type stores current depth data for all geometry on the scene.

int TEXTURE_DECAL_ALBEDO

Description

Texture of this type stores albedo color data for decals.

int TEXTURE_DECAL_DEPTH

Description

Texture of this type stores depth data for decals.

int TEXTURE_DECAL_NORMAL

Description

Texture of this type stores normal data for decals.

int TEXTURE_DECAL_SHADING

Description

Texture of this type stores shading data for decals.

int TEXTURE_DEFERRED_LIGHT

Description

Texture of this type uses a deferred buffer to store light values.

int TEXTURE_DEFERRED_REFLECTION

Description

Texture of this type uses a deferred buffer to store reflection values.

int TEXTURE_DOF_MASK

Description

Texture of this type stores a DoF (Depth of Field) mask.

int TEXTURE_ENVIRONMENT_PROBES

Description

A 2D array texture of the RGBA16F format that stores reflections in the first layer (RGBA) and ambient lights in the second layer (RGBA).

int TEXTURE_FIELD_HEIGHT_ARRAY

Description

A heightmap texture is used to create an additional height displacement for water surface. Field Height textures are rendered in a 2D array of R16F or R32F textures (depends on settings). All Field Height textures are packed into 2D array to pass the data to the shader.

int TEXTURE_FIELD_SHORELINE_ARRAY

Description

A field shoreline texture. All Field Shoreline textures are packed into 2D array (of RGBA8) to pass the data to the shader.

int TEXTURE_FILTER

Description

A filtering texture.

int TEXTURE_GBUFFER_ALBEDO

Description

Texture of this type uses a G-Buffer to store albedo values.

int TEXTURE_GBUFFER_GEODETIC_FLAT_POSITION

Description

Texture of this type uses the G-buffer to store flat plane coordinates.

int TEXTURE_GBUFFER_LIGHTMAP

Description

Texture of this type uses a G-Buffer to store light map values.

int TEXTURE_GBUFFER_MATERIAL_MASK

Description

Texture of this type uses a G-Buffer to store material mask data.

int TEXTURE_GBUFFER_NORMAL

Description

Texture of this type uses a G-Buffer to store normal values.

int TEXTURE_GBUFFER_SHADING

Description

Texture of this type uses a G-Buffer to store shading data.

int TEXTURE_GBUFFER_VELOCITY

Description

Texture of this type uses a G-Buffer to store velocity values.

int TEXTURE_GEODETIC_TOPOLOGY

Description

Texture of this type stores geodetic topology data.

int TEXTURE_IMAGE

Description

A standard bitmap image.

int TEXTURE_LIGHTS

Description

A 2D array texture of the RG11B10F format that stores diffuse light in the first layer (RGB) and specular light in the second layer (RGB).

int TEXTURE_LIGHT_DEPTH

Description

Texture of this type stores depth values (used to render shadows).

int TEXTURE_LIGHT_IMAGE

Description

Texture of this type stores the light values provided by projected light sources.

int TEXTURE_LINEAR_DEPTH

Description

Texture of this type stores linear depth data.

int TEXTURE_NORMAL_UNPACK

Description

a texture that stores unpacked normals. Available for the following post-effects: SSR, SSGI, SSRTGI, Shadows screen space.

int TEXTURE_OPACITY_DEPTH

Description

Texture of this type stores depth data for opacity geometry and can be used for soft particles and volumetrics.

int TEXTURE_OPACITY_SCREEN

Description

Texture of this type stores the deferred composite and emission data.

int TEXTURE_PROCEDURAL

Description

A procedurally generated texture.

int TEXTURE_REFLECTION_2D

Description

Texture of this type stores reflection values (used to render 2D reflections).

int TEXTURE_REFLECTION_CUBE

Description

Texture of this type stores reflection values (used to render cube-mapped reflections).

int TEXTURE_REFRACTION

Description

Texture of this type stores refraction data.

int TEXTURE_SCATTERING_GROUND_LUT

Description

Texture of this type stores ground scattering LUT data.

int TEXTURE_SCATTERING_SKY_LUT

Description

Texture of this type stores sky scattering LUT data.

int TEXTURE_SCREEN_COLOR

Description

Texture of this type stores screen color data and can be used for post effects.

int TEXTURE_SCREEN_COLOR_OLD

Description

Texture of this type stores Color Old (previous frame) data.

int TEXTURE_SCREEN_COLOR_OLD_REPROJECTION

Description

Texture of this type stores Color Old (previous frame) Reprojection data.

int TEXTURE_SSAO

Description

Texture of this type stores SSAO (Screen Space Ambient Occlusion) data.

int TEXTURE_SSGI

Description

Texture of this type stores SSGI (Screen Space Global Illumination) data.

int TEXTURE_SSR

Description

Texture of this type stores SSR (Screen Space Reflections) data.

int TEXTURE_SSR_DEPTH

Description

Texture of this type stores SSR (Screen Space Reflections) depth data.

int TEXTURE_TRANSPARENT_ENVIRONMENT_PROBES

Description

An RGBA16F texture that stores environment probes rendered on transparent objects. Available only for transparent materials rendered in the forward pass when Multiple environment probes are enabled.

int TEXTURE_TRANSPARENT_BLUR

Description

a 1-channel R16F mask that stores intensity of blurring for transparent materials. The mask specifies where to blur the material.

int TEXTURE_TRANSPARENT_ENVIRONMENT_PROBE

Description

Texture of this type stores an environment cube map.

int TEXTURE_WBUFFER_CONSTANT_ID

Description

Constant texture, R32U. A texture of this type stores the ID value of the water mesh which is used to load the corresponding textures and parameters for it.

int TEXTURE_WBUFFER_DIFFUSE

Description

Diffuse texture. The diffuse color of the water is black, and diffuse texture is necessary for decals, that will be displayed over the water surface.

int TEXTURE_WBUFFER_FOG

Description

Underwater fog texture, RGBA16.

int TEXTURE_WBUFFER_NORMAL

Description

Normal texture stores normal data for lighting, and alpha channel stores mesh transparency values (it can be used for soft intersections with water geometry).

int TEXTURE_WBUFFER_SS_ENVIRONMENT

Description

An RGBA16 underwater fog texture that stores water bottom coloring values (RGB) and fog transparency (A).

int TEXTURE_WBUFFER_WATER

Description

Water texture, RG8. It is used to create the procedural foam mask. The mask shows where the foam will be depicted.

int TEXTURE_WBUFFER_WU_MASK

Description

Underwater mask texture, RGB8. Underwater mask is used only for Global water, since water mesh doesn't have an underwater mode.

int TRANSPARENT_ALPHA_TEST

Description

Transparent material which uses alpha test.

int TRANSPARENT_BLEND

Description

Transparent material which is rendered in forward pass, uses blend func.

int TRANSPARENT_DEFERRED

Description

Transparent material which is rendered in deferred pass upon the deferred geometry into the g-buffer with alpha blend, doesn't use blend func.

int TRANSPARENT_NONE

Description

Opaque material (non-transparent), doesn't use blend func.

int TRANSPARENT_WATER

Description

Transparent material which is rendered in water pass.
Last update: 2017-10-20
Build: ()