This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
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
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Shader Class

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

Interface for shader manipulation. Here, shader is a shader program that can contain several subshaders - vertex, fragment, geometry, etc.

This class allows compiling these shader programs, setting parameter values, and binding graphic context.

Also you can get the loaded DirectX 11 shaders using the corresponding getD3D11*() methods. For OpenGL shader programs, you can use getGLProgramID().

You can also set parameters (or arrays of parameters) to shader programs.

Usage Example#

This example demonstrates how to use your custom subshaders (UUSL, GLSL, HLSL) to render a post-effect.

Shader Class

Members


static Shader ( ) #

Default shader constructor.

static Shader ( string name ) #

Shader constructor. Loads all existing shaders with the given name.

Arguments

  • string name - Shader name.

static Shader ( string name, string defines ) #

Shader constructor. Loads all existing shaders with the given name.

Arguments

  • string name - Shader name.
  • string defines - User defines.

static Shader ( string vertex, string fragment, string defines ) #

Shader constructor. Loads only vertex and fragment subshaders with the given names.

Arguments

  • string vertex - Vertex subshader name or source.
  • string fragment - Fragment subshader name or source.
  • string defines - User defines.

void * getD3D11ComputeShader ( ) #

Returns Direct3D11 compute shader.

void * getD3D11ControlShader ( ) #

Returns Direct3D11 control shader.

void * getD3D11EvaluateShader ( ) #

Returns Direct3D11 evaluate shader.

void * getD3D11FragmentShader ( ) #

Returns Direct3D11 fragment shader.

void * getD3D11GeometryShader ( ) #

Returns Direct3D11 geometry shader.

void * getD3D11VertexShader ( ) #

Returns Direct3D11 vertex shader.

int getGLProgramID ( ) #

Returns OpenGL program identifier.

void bind ( ) #

Binds shader.

void clear ( ) #

Clears shader.

int compile ( string vertex, string geometry, string fragment, string compute, string control, string evaluate, string defines = "", long key_cache = 0 ) #

Compiles the shader with the specified subshaders. To skip a subshader, pass nullptr instead of an argument. Depending on the subshaders types, additional values are added automatically to the defines argument: VERTEX, CONTROL, EVALUATE, GEOMETRY, FRAGMENT.

Arguments

  • string vertex - Vertex subshader path.
  • string geometry - Geometry subshader path.
  • string fragment - Fragment subshader path.
  • string compute - Compute subshader path.
  • string control - Control subshader path.
  • string evaluate - Evaluation subshader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).
  • long key_cache - Key cache.

Return value

true if the shader is compiled successfully; otherwise, false.

void destroy ( ) #

Destroys shader.

int findParameter ( string name ) #

Finds shader parameter.

Arguments

  • string name - Fast identifier.

Return value

Parameter identifier, if found; otherwise, -1.

void flushParameters ( ) #

Flushes shader parameters.

void unbind ( ) #

Unbinds shader.

void setDisableCompileError ( int error ) #

Enables or disables the shader compile error output.

Arguments

  • int error - 1 to disable compile errors output; 0 - to enable.

int isDisableCompileError ( ) #

Returns a value indicating if the shader compile error output is disabled.

Return value

1 if the shader compile errors output is disabled; otherwise, 0.

void setOptimizationLevel ( int level ) #

Sets optimization level for the shader compiler.
Notice
Available for DirectX only.

Arguments

  • int level - Optimization level to be set. One of the following values:
    • 0 - Directs the compiler to skip optimization steps during code generation.
    • 1 - Directs the compiler to use the lowest optimization level. At this level the compiler might produce slower code but produces the code quicker.
    • 2 - Directs the compiler to use the second lowest optimization level.
    • 3 - Directs the compiler to use the second highest optimization level.
    • 4 - Directs the compiler to use the highest optimization level. At this level the compiler produces the best possible code but might take significantly longer to do so.

int getOptimizationLevel ( ) #

Returns the current optimization level of the shader compiler.
Notice
Available for DirectX only.

Return value

Current optimization level of the shader compiler. One of the following values:
  • 0 - skip optimization steps during code generation.
  • 1 - lowest optimization level. At this level the compiler might produce slower code but produces the code quicker.
  • 2 - second lowest optimization level.
  • 3 - second highest optimization level.
  • 4 - highest optimization level. At this level the compiler produces the best possible code but might take significantly longer to do so.

void setWarningMode ( int mode ) #

Sets warning mode for the shader compiler. You can choose modes from the lowest (all shader compilation warnings are ignored) up to the highest level, when warnings are treated as errors. By default the highest level is used, setting lower levels may result in driver and OS crashes, so you use them at your own risk. The soft level can be used if you have checked and you're absolutely sure that the warnings do not cause crashes.
Notice
Available for DirectX only.

Arguments

  • int mode - Warning mode to be used.

int getWarningMode ( ) #

Returns the current warning mode for the shader compiler: from the lowest (all shader compilation warnings are ignored) up to the highest level, when warnings are treated as errors. By default the highest level is used, setting lower levels may result in driver and OS crashes, so you use them at your own risk. The soft level can be used if you have checked and you're absolutely sure that the warnings do not cause crashes.
Notice
Available for DirectX only.

Return value

Current warning mode of the shader compiler.

void setDisableCompileCache ( int cache ) #

Sets a value indicating if compilation cache for the shader is disabled.

Arguments

  • int cache - 1 to disable compilation cache for the shader; otherwise, 0.

int isDisableCompileCache ( ) #

Returns a value indicating if compilation cache for the shader is disabled.

Return value

1 if compilation cache for the shader is disabled; otherwise, 0.

void setDisableExport ( int val ) #

Sets a value indicating if shader export to a file is disabled. By default UNIGINE enables exporting a shader program to a file (e.g. for debug purposes). Shader files are created in native languages for both graphic APIs (Direct3D - .hlsl extension, OpenGL - .glsl extension).

Arguments

  • int val - 1 to disable shader export to a file; otherwise, 0.

int isDisableExport ( ) #

Returns a value indicating if shader export to a file is disabled. By default UNIGINE enables exporting a shader program to a file (e.g. for debug purposes). Shader files are created in native languages for both graphic APIs (Direct3D - .hlsl extension, OpenGL - .glsl extension).

Return value

1 if shader export to a file is disabled; otherwise, 0.

void setIEEEStrictness ( int strictness ) #

Sets a value indicating if the shader compiler forces the IEEE strict compilation.
Notice
Available for DirectX only.

Arguments

  • int strictness - 1 to force the IEEE strict compilation by the shader compiler; otherwise, 0.

int isIEEEStrictness ( ) #

Returns a value indicating if the shader compiler forces the IEEE strict compilation.
Notice
Available for DirectX only.

Return value

1 if the shader compiler forces the IEEE strict compilation; otherwise, 0.

int compileCompute ( string compute, string defines = "", long key_cache = 0 ) #

Compiles the shader with the specified compute subshader. The additional COMPUTE value is added automatically to the defines argument. This function is the same as the compile() function called only with the compute argument.

Arguments

  • string compute - Compute subshader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).
  • long key_cache - Key cache.

Return value

true if the shader compiled successfully; otherwise, false.

int compileVertFrag ( string vertex, string fragment, string defines = "", long key_cache = 0 ) #

Compiles the shader with the specified vertex and fragment subshaders. The additional VERTEX and FRAGMENT values are added automatically to the defines argument. This function is the same as the compile() function called only with the vertex and fragment arguments.

Arguments

  • string vertex - Vertex subshader path.
  • string fragment - Fragment subshader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).
  • long key_cache - Key cache.

Return value

true if the shader compiled successfully; otherwise, false.

int compileVertGeomFrag ( string vertex, string geometry, string fragment, string defines = "", long key_cache = 0 ) #

Compiles the shader with the specified vertex, geometry, and fragment subshaders. The additional VERTEX, GEOMETRY, and FRAGMENT values are added automatically to the defines argument. This function is the same as the compile() function called only with the vertex, fragment, and geometry arguments.

Arguments

  • string vertex - Vertex subshader path.
  • string geometry - Geometry subshader path.
  • string fragment - Fragment subshader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).
  • long key_cache - Key cache.

Return value

true if the shader compiled successfully; otherwise, false.

int compileShader ( string shader, string defines = "", long key_cache = 0 ) #

Compiles the shader that includes subshaders. Depending on the types of the subshaders defined in the shader file, additional values are added to the defines argument automatically: VERTEX, CONTROL, EVALUATE, GEOMETRY, FRAGMENT.

Arguments

  • string shader - Shader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).
  • long key_cache - Key cache.

Return value

trueif the shader with all the subshaders compiled successfully; otherwise, false.

int validateShader ( int type, string shader, string defines = "" ) #

Validates the shader (whether it can be compiled or not).

Arguments

  • int type - Subshader type.
  • string shader - Shader path.
  • string defines - User defines (for example, "OPENGL", "DIRECT3D11", or any other).

Return value

true if the shader can be compiled; otherwise, false.
Last update: 2024-02-06
Build: ()