This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
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
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
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.

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. Shader is an interface for loading shaders, setting parameter values, binding graphic context.

To get loaded shader programs, use special methods for corresponding Direct3D11 shaders or use getGLProgramID() to get the OpenGL shaders.

Shader class provides a lot of methods to set parameters (or arrays of parameters) to shader programs.

Usage Example#

This example demonstrates how to use your custom shaders (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 given name.

Arguments

  • string name - Shader name.

static Shader ( string name, string defines ) #

Shader constructor. Loads all existing shaders with given name.

Arguments

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

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

Shader constructor. Loads only vertex and fragment shaders with given names.

Arguments

  • string vertex - Vertex shader name or source.
  • string fragment - Fragment shader name or source.
  • string defines - Shader 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 ( ) #

Compiles shader.

Return value

1 if the shader compiled successfully; otherwise, 0.

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.

int loadCompute ( string name, string defines ) #

Loads compute shader.

Arguments

  • string name - Compute shader name or source.
  • string defines - Shader defines.

Return value

1 if the compute shader was loaded successfully; otherwise, 0.

int loadControl ( string name, string defines ) #

Loads control shader.

Arguments

  • string name - Control shader name or source.
  • string defines - Shader defines.

Return value

1 if the control shader was loaded successfully; otherwise, 0.

int loadEvaluate ( string name, string defines ) #

Loads evaluate shader.

Arguments

  • string name - Evaluate shader name or source.
  • string defines - Shader defines.

Return value

1 if the evaluate shader was loaded successfully; otherwise, 0.

int loadFragment ( string name, string defines ) #

Loads fragment shader.

Arguments

  • string name - Fragment shader name or source.
  • string defines - Shader defines.

Return value

1 if the fragment shader was loaded successfully; otherwise, 0.

int loadGeometry ( string name, string defines ) #

Loads geometry shader.

Arguments

  • string name - Geometry shader name or source.
  • string defines - Shader defines.

Return value

1 if the geometry shader was loaded successfully; otherwise, 0.

int loadVertex ( string name, string defines ) #

Loads vertex shader.

Arguments

  • string name - Vertex shader name or source.
  • string defines - Shader defines.

Return value

1 if the vertex shader was loaded successfully; otherwise, 0.

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 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.
Last update: 2022-03-10
Build: ()