This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Программирование
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
File Formats
Rebuilding the Engine and 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
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

UUSL Common Intrinsic Functions

This documentation article contains information functions of the UUSL. This information can be used as the reference document for writing shaders.

To start using common UUSL functions, include the core/shaders/common/common.h file.

UUSL
#include <core/shaders/common/common.h>

For fragment shader features, use the core/shaders/common/fragment.h file.

Common Intrinsic Functions

Double Functions

These functions take one or more arguments that are double expressions and return a double value.

Notice
It is not recommended to use these functions, unless there is no other option. Operations with doubles are significantly more time consuming (e.g. addition and multiplication operations are 8 times slower).

double dabs(double x)

Returns the absolute value of a given value.

Arguments

  • double x - Value.

Return value

Absolute value of x.

double acos_double(double x)

Returns the arccosine of a given value.

Arguments

  • double x - Value.

Return value

Arccosine of x.

double ddot(double2 vector1, double2 vector2)

Returns the dot product of two given vectors: ddot(vector1, vector2).

Arguments

  • double2 vector1 - First vector of 2 double components.
  • double2 vector2 - Second vector of 2 double components.

Return value

Calculated dot product.

double ddot(double3 vector1, double3 vector2)

Returns the dot product of two given vectors: ddot(vector1, vector2).

Arguments

  • double3 vector1 - First vector of 3 double components.
  • double3 vector2 - Second vector of 3 double components.

Return value

Calculated dot product.

double ddot(double4 vector1, double4 vector2)

Returns the dot product of two given vectors: ddot(vector1, vector2).

Arguments

  • double4 vector1 - First vector of 4 double components.
  • double4 vector2 - Second vector of 4 double components.

Return value

Calculated dot product.

double dlength(double2 v)

Returns the length of a given vector.

Arguments

  • double2 v - Vector of 2 double components.

Return value

Length of v.

double dlength(double3 v)

Returns the length of a given vector.

Arguments

  • double3 v - Vector of 3 double components.

Return value

Length of v.

double dlength2(double2 v)

Returns the squared length of a given vector.

Arguments

  • double2 v - Vector of 2 double components.

Return value

Squared length of v.

double dlength2(double3 v)

Returns the squared length of a given vector.

Arguments

  • double3 v - Vector of 3 double components.

Return value

Squared length of v.

double dilength(double2 v)

Returns the inverse length of a given vector.

Arguments

  • double2 v - Vector of 2 double components.

Return value

Inverse length of v.

double dilength(double3 v)

Returns the inverse length of a given vector.

Arguments

  • double3 v - Vector of 3 double components.

Return value

Inverse length of v.

double dmad(double x, double y, double z)

Returns the value of (x * y + z) for given values of x, y, and z.

Arguments

  • double x - x value.
  • double y - y value.
  • double z - z value.

Return value

The value of (x * y + z).

double3 mul3(double4x4 matrix, double3 vector)

Performs the 3x3 matrix * vector multiplication.

Arguments

  • double4x4 matrix - The 3x3 matrix.
  • double3 vector - The vector of 3 double components.

Return value

The result of multiplication.

double3 mul3(double3 vector, double4x4 matrix)

Performs the vector * 3x3 matrix multiplication.

Arguments

  • double3 vector - The vector of 3 double components.
  • double4x4 matrix - The 3x3 matrix.

Return value

The result of multiplication.

double3 mul3(double3 vector, double3x3 matrix)

Performs the vector * matrix multiplication.

Arguments

  • double3 vector - The vector of 3 double components.
  • double3x3 matrix - The 3x3 matrix.

Return value

The result of multiplication.

double3 mul3(double3x3 matrix, double3 vector)

Performs the matrix * vector multiplication.

Arguments

  • double3x3 matrix - The 3x3 matrix.
  • double3 vector - The vector of 3 double components.

Return value

The result of multiplication.

double3x3 mul3x3(double3x3 matrix1, double3x3 matrix2)

Performs the matrix * matrix multiplication.

Arguments

  • double3x3 matrix1 - The first 3x3 matrix of double components.
  • double3x3 matrix2 - The second 3x3 matrix of double components.

Return value

The result of multiplication.

double3 mul4(double4x4 matrix, float4 vector)

Performs the 4x4 matrix * vector multiplication.

Implementation

UUSL
(m * double4(v)).xyz

Arguments

  • double4x4 matrix - The 4x4 matrix of double components.
  • float4 vector - The 4-component vector.

Return value

The result of multiplication.

double3 mul4(double4x4 matrix, double4 vector)

Performs the 4x4 matrix * vector multiplication.

Implementation

UUSL
(m * v).xyz

Arguments

  • double4x4 matrix - The 4x4 matrix of double components.
  • double4 vector - The 4-component vector.

Return value

The result of multiplication.

double3 mul4(float4 vector, double4x4 matrix)

Performs the vector * 4x4 matrix multiplication.

Implementation

UUSL
(double4(v) * m).xyz

Arguments

  • float4 vector - The 4-component vector.
  • double4x4 matrix - The 4x4 matrix of double components.

Return value

The result of multiplication.

double3 mul4(double4 vector, double4x4 matrix)

Performs the vector * 4x4 matrix multiplication.

Implementation

UUSL
(v * m).xyz

Arguments

  • double4 vector - The 4-component vector.
  • double4x4 matrix - The 4x4 matrix of double components.

Return value

The result of multiplication.

double3 mul4(double4x4 matrix, float3 vector)

Performs the 4x4 matrix * vector multiplication.

Implementation

UUSL
m * float4(v, 1.0f)

Arguments

  • double4x4 matrix - The 4x4 matrix of double components.
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

double3 mul4(double4x4 matrix, double3 vector)

Performs the 4x4 matrix * vector multiplication.

Implementation

UUSL
m * double4(v, DF(1.0f))

Arguments

  • double4x4 matrix - The 4x4 matrix of double components.
  • double3 vector - The 3-component vector.

Return value

The result of multiplication.

double3 mul4(float3 vector, double4x4 matrix)

Performs the vector * 4x4 matrix multiplication.

Implementation

UUSL
float4(v, 1.0f) * m

Arguments

  • float3 vector - The 3-component vector.
  • double4x4 matrix - The 4x4 matrix of double components.

Return value

The result of multiplication.

double3 mul4(double3 vector, double4x4 matrix)

Performs the vector * 4x4 matrix multiplication.

Implementation

UUSL
double4(v, DF(1.0f)) * m

Arguments

  • double3 vector - The 3-component vector.
  • double4x4 matrix - The 4x4 matrix of double components.

Return value

The result of multiplication.

double2 dnormalize(double2 v)

Normalizes a given vector.

Arguments

  • double2 v - Vector of 2 double components.

Return value

Normalized vector.

double3 dnormalize(double3 v)

Normalizes a given vector.

Arguments

  • double3 v - Vector of 3 double components.

Return value

Normalized vector.

double drcp(double x)

Returns the reciprocal of a given value.

Arguments

  • double x - Value.

Return value

Square root of x.

double drsqrt(double x)

Returns the reciprocal of the square root of a given value.

Arguments

  • double x - Value.

Return value

Reciprocal of the square root of x.

double dsign(double x)

Returns the sign of a given value.

Arguments

  • double x - Value.

Return value

-1 if x is less than zero; 0 if x equals zero; and 1 if x is greater than zero.

double dsqrt(double x)

Returns the square root of a given value.

Arguments

  • double x - Value.

Return value

Square root of x.

void setDMatCol(inout double3x3 matrix, uint column, double3 values)

Sets a specified column of a 3x3 matrix with values of a given vector.

Arguments

  • inout double3x3 matrix - 3x3 matrix of double components.
  • uint column - Column index.
  • double3 values - 3-component vector of double values.

double3 getDMatCol(inout double3x3 matrix, uint column)

Returns a column of a matrix with the specified index.

Arguments

  • inout double3x3 matrix - 3x3 matrix of double components.
  • uint column - Column index.

Return value

Column of a matrix.

double4 getDMatCol(inout double4x4 matrix, uint column)

Returns a column of a matrix with the specified index.

Arguments

  • inout double4x4 matrix - 4x4 matrix of double components.
  • uint column - Column index.

Return value

Column of a matrix.

Common Functions

overlay(value A, value B, value BLEND)

Performs overlay A over B with blending coefficient.

Equivalents

OpenGL
saturate(A * lerp(float4_one * 0.5f,B,BLEND) * 2);
Direct3D
saturate(A * lerp(float4_one * 0.5f,B,BLEND) * 2);

Arguments

  • value A - First value
  • value B - Value for overlay.
  • value BLEND - Blending coefficient.

fmod(value X, value Y)

Returns the floating-point remainder of x/y.

Equivalents

OpenGL
mod(X,Y);
Direct3D
fmod(X,Y);

Arguments

  • value X - The dividend value.
  • value Y - The divisor value.

frac(value value)

Returns the fractional (or decimal) part of x; which is greater than or equal to 0 and less than 1.

Equivalents

OpenGL
fract(value);
Direct3D
frac(value);

Arguments

  • value value - The specified value.

lerp(value X, value Y, value value)

Performs linear interpolation.

Equivalents

OpenGL
mix(X,Y,value);
Direct3D
lerp(X,Y,value);

Arguments

  • value X - The first value.
  • value Y - The second value.
  • value value - A value that linearly interpolates between the x parameter and the y parameter.

float4 lerp3(float4 v0, float4 v1, float4 v2, float a)

Performs linear interpolation between three vectors.

Equivalents

OpenGL
if (a < 0.5)
						{ 
						mix(v0, v1, a * 2.0f);
						} 
						else 
						{ 
						mix(v1, v2, a * 2.0f - 1.0f);
						}
Direct3D
if (a < 0.5)
						{ 
						lerp(v0, v1, a * 2.0f);
						} 
						else 
						{ 
						lerp(v1, v2, a * 2.0f - 1.0f);
						}

Arguments

  • float4 v0 - First vector.
  • float4 v1 - Second vector.
  • float4 v2 - Third vector.
  • float a - Interpolation factor in the range [0.0f, 1.0f].

Return value

Interpolated vector.

value lerpOne(value value, float factor)

Performs such interpolation:

Equivalents

OpenGL
value * (1.0f - factor) + factor;
Direct3D
value * (1.0f - factor) + factor;

Arguments

  • value value - Value for interpolation. Can be one of the following types:
    • float
    • float2
    • float3
    • float4
  • float factor - Interpolation factor.

Return value

Interpolated value. Can be one of the following types:
  • float
  • float2
  • float3
  • float4

float length2(float3 vector)

Returns dot product of the vector: dot(vector, vector).

Arguments

  • float3 vector - Vector.

Return value

Calculated dot product.

float smoothClamp(float value, float x, float y)

Clamps a given value in the range [x; (x + y)] with a smooth Hermite interpolation between 0.0f and 1.0f.

Equivalents

OpenGL
smoothstep(x, x + y, value);
Direct3D
smoothstep(x, x + y, value);

Arguments

  • float value - Value to be clamped.
  • float x - Lower bound of the clamping range.
  • float y - Clamping range size.

Return value

Clamped value with smoothing.

float gradient4(float a, float4 gradient)

Returns a gradient value for a given value using four key components.

Equivalents

OpenGL
smoothstep(gradient.x, gradient.y, a) - smoothstep(gradient.z, gradient.w, a);
Direct3D
smoothstep(gradient.x, gradient.y, a) - smoothstep(gradient.z, gradient.w, a);

Arguments

  • float a - Value to find the gradient value for.
  • float4 gradient - Vector with four key components.

Return value

Gradient value.

float4 texture2DArrayManualLinear(float2 uv, float index, float2 texture_size, TEXTURE_IN_ARRAY TEX_VALUE)

Returns a linearly filtered Texture2D array.

Arguments

  • float2 uv - UV.
  • float index - Index.
  • float2 texture_size - Size of the texture.
  • TEXTURE_IN_ARRAY TEX_VALUE - Texture array.

Return value

Texture2D Array manual linear value.

float3 texture_2d_cubic_filter(float value)

Returns a bicubically filtered value.

Arguments

  • float value - Value to be filtered.

Return value

Vector of bicubically filtered value.

float4 texture2DCubic(TEXTURE_IN s_texture, float2 texcoord, float4 texsize)

Returns a bicubically filtered value.

Arguments

  • TEXTURE_IN s_texture - Texture.
  • float2 texcoord - Texture coordinates.
  • float4 texsize - Size of the texture.

Return value

Bicubically filtered value.

float4 texture2DCubic(TEXTURE_IN_ARRAY s_texture, float3 texcoord, float4 texsize)

Returns a bicubically filtered texture.

Arguments

  • TEXTURE_IN_ARRAY s_texture - Texture array.
  • float3 texcoord - Texture coordinates.
  • float4 texsize - Size of the texture.

Return value

Bicubically filtered value.

float4 texture2DCatmull(TEXTURE_IN s_texture, value texcoord, float4 texsize)

Returns a catmull filtered value.

Arguments

  • TEXTURE_IN s_texture - Texture.
  • value texcoord - Texture coordinates. Can be float2 or float3 vector.
  • float4 texsize - Size of the texture.

Return value

Catmull filtered value.

float4 texture3DCubic(TEXTURE_IN_3D TEX_VALUE, float3 texcoord)

Returns a bicubically 3D texture filtered value.

Arguments

  • TEXTURE_IN_3D TEX_VALUE - 3D texture.
  • float3 texcoord - Texture coordinates.

Return value

Bicubically filtered value.

float calculate_dither_pattern(float2 uv)

Returns a dither value for a given UV value. Used for better gradients.

Arguments

  • float2 uv - UV value.

Return value

Dither value.

float4 getBlueNoise16x16(float2 coord)

Returns a blue noise value for a given UV value. Used for better alpha fading.

Arguments

  • float2 coord - UV value.

Return value

Blue noise value.

float isObliqueFrustumDiscard(value position)

Returns a value indicating whether the point is culled by the oblique frustum culling.

Arguments

  • value position - Position. Can be float3 or float4 vector.

Return value

Culling value.

void obliqueFrustumDiscard(value position)

Discards rendering of the fragment based on the oblique frustum culling.

Arguments

  • value position - Position. Can be float3 or float4 vector.

bool quad_frustum_culling(float4 p0, float4 p1, float4 p2, float4 p3, float screen_size)

Provides the frustum culling for a single quad by returning a value indicating whether the quad should be drawn.

Arguments

  • float4 p0 - Position vector.
  • float4 p1 - Position vector.
  • float4 p2 - Position vector.
  • float4 p3 - Position vector.
  • float screen_size - Screen size.

Return value

true if quad is out of screen bounds; otherwise, false.

bool quad_back_face_culling(float4 p0, float4 p1, float4 p2, float4 p3, float angle)

Provides the back-face culling for a single quad by returning a value indicating whether the quad should be drawn.

Arguments

  • float4 p0 - Position vector.
  • float4 p1 - Position vector.
  • float4 p2 - Position vector.
  • float4 p3 - Position vector.
  • float angle - Maximum angle at which the quad is visible, in radians.

Return value

true if the quad is rotated to face away from the camera and should not be drawn; otherwise, false.

bool quad_is_near(float2 p0, float2 p1, float2 p2, float2 p3, float angle)

Checks whether a quad is nearer than a specified distance.

Arguments

  • float2 p0 - Position vector.
  • float2 p1 - Position vector.
  • float2 p2 - Position vector.
  • float2 p3 - Position vector.
  • float angle - Maximum angle at which the quad is visible, in radians.

Return value

true if the quad is near; otherwise, false.

void setRow(inout float3x3 matrix, const int row, in float3 values)

Sets a specified row of a 3x3 matrix with values of a given vector.

Arguments

  • inout float3x3 matrix - 3x3 matrix of float components.
  • const int row - Row index.
  • in float3 values - 3-component vector of float values.

void setRow3(inout float4x4 matrix, const int row, in float3 values)

Sets 3 values of a specified row of a 4x4 matrix with a given 3-component vector.

Arguments

  • inout float4x4 matrix - 4x4 matrix of float components.
  • const int row - Row index.
  • in float3 values - 3-component vector of float values.

void setRow(inout float4x4 matrix, const int row, in float4 values)

Sets a specified row of a 4x4 matrix with values of a given vector.

Arguments

  • inout float4x4 matrix - 4x4 matrix of float components.
  • const int row - Row index.
  • in float4 values - 4-component vector of float values.

float3 getRow(in float3x3 matrix, const int row)

Returns a row of a matrix with the specified index.

Arguments

  • in float3x3 matrix - 3x3 matrix of float components.
  • const int row - Row index.

Return value

Row of the matrix.

float3 getRow3(in float4x4 matrix, const int row)

Returns first three values from a row of a matrix with the specified index.

Arguments

  • in float4x4 matrix - 4x4 matrix of float components.
  • const int row - Row index.

Return value

3-component vector containing first three values from a row of the matrix.

float4 getRow(in float4x4 matrix, const int row)

Returns a row of a matrix with the specified index.

Arguments

  • in float4x4 matrix - 4x4 matrix of float components.
  • const int row - Row index.

Return value

Row of the matrix.

void setColumn(inout float3x3 matrix, const int column, in float3 values)

Sets a specified column of a 3x3 matrix with values of a given vector.

Arguments

  • inout float3x3 matrix - 3x3 matrix of float components.
  • const int column - Column index.
  • in float3 values - 3-component vector of float values.

void setColumn3(inout float4x4 matrix, const int column, in float3 values)

Sets 3 values of a specified column of a 4x4 matrix with a given 3-component vector.

Arguments

  • inout float4x4 matrix - 4x4 matrix of float components.
  • const int column - Column index.
  • in float3 values - 3-component vector of float values.

void setColumn(inout float4x4 matrix, const int column, in float4 values)

Sets a specified column of a 4x4 matrix with values of a given vector.

Arguments

  • inout float4x4 matrix - 4x4 matrix of float components.
  • const int column - Column index.
  • in float4 values - 4-component vector of float values.

float3 getColumn(in float3x3 matrix, const int column)

Returns a column of a matrix with the specified index.

Arguments

  • in float3x3 matrix - 3x3 matrix of float components.
  • const int column - Column index.

Return value

Column of the matrix.

float3 getColumn3(in float4x4 matrix, const int column)

Returns first three values from a column of a matrix with the specified index.

Arguments

  • in float4x4 matrix - 4x4 matrix of float components.
  • const int column - Column index.

Return value

3-component vector containing first three values from a column of the matrix.

float4 getColumn(in float4x4 matrix, const int column)

Returns a column of a matrix with the specified index.

Arguments

  • in float4x4 matrix - 4x4 matrix of float components.
  • const int column - Column index.

Return value

Column of the matrix.

float getBasisX(float3x3 matrix)

Returns x-basis of the given 3x3 matrix.

Equivalents

OpenGL
m[0];
Direct3D
m._m00_m10_m20;

Arguments

  • float3x3 matrix - 3x3 matrix.

Return value

Matrix basis.

float getBasisX(float4x4 matrix)

Returns x-basis of the given 4x4 matrix.

Equivalents

OpenGL
m[0].xyz;
Direct3D
m._m00_m10_m20;

Arguments

  • float4x4 matrix - 3x3 matrix.

Return value

Matrix basis.

float getBasisY(float3x3 matrix)

Returns y-basis of the given 3x3 matrix.

Equivalents

OpenGL
m[1];
Direct3D
m._m01_m11_m21;

Arguments

  • float3x3 matrix - 3x3 matrix.

Return value

Matrix basis.

float getBasisY(float4x4 matrix)

Returns y-basis of the given 4x4 matrix.

Equivalents

OpenGL
m[1].xyz;
Direct3D
m._m01_m11_m21;

Arguments

  • float4x4 matrix - 3x3 matrix.

Return value

Matrix basis.

float getBasisZ(float3x3 matrix)

Returns z-basis of the given 3x3 matrix.

Equivalents

OpenGL
m[2];
Direct3D
m._m02_m12_m22;

Arguments

  • float3x3 matrix - 3x3 matrix.

Return value

Matrix basis.

float getBasisZ(float4x4 matrix)

Returns z-basis of the given 4x4 matrix.

Equivalents

OpenGL
m[2].xyz;
Direct3D
m._m02_m12_m22;

Arguments

  • float4x4 matrix - 3x3 matrix.

Return value

Matrix basis.

rsqrt(value value)

Returns the reciprocal of the square root of the specified value.

Equivalents

OpenGL
inversesqrt(value)
Direct3D
rsqrt(value)

Arguments

  • value value - The specified value.

saturate(value value)

Clamps the specified value within the range of 0 to 1.

Equivalents

OpenGL
clamp(value,0.0f,1.0f)
Direct3D
saturate(value)

Arguments

  • value value - The specified value.

ddx(value value)

Returns the partial derivative of the specified value with respect to the screen-space x-coordinate.

Equivalents

OpenGL
dFdx(value)
Direct3D
ddx(value)

Arguments

  • value value - The specified value.

ddy(value value)

Returns the partial derivative of the specified value with respect to the screen-space y-coordinate.

Equivalents

OpenGL
dFdy(value)
Direct3D
ddy(value)

Arguments

  • value value - The specified value.

rcp(value value)

Calculates a fast, approximate, per-component reciprocal.

Equivalents

OpenGL
(1.0f / (value))
Direct3D
rcp(value)

Arguments

  • value value - The specified value.

equal(value X, value Y)

Performs a component-wise equal-to comparison of two vectors.

Equivalents

OpenGL
equal(X,Y)
Direct3D
(X == Y)

Arguments

  • value X - The first specified value.
  • value Y - The second specified value.

greaterThan(value X, value Y)

Performs a component-wise greater-than comparison of two vectors.

Equivalents

OpenGL
greaterThan(X,Y)
Direct3D
(X > Y)

Arguments

  • value X - The first specified value.
  • value Y - The second specified value.

lessThanEqual(value X, value Y)

Performs a component-wise less-than-or-equal comparison of two vectors.

Equivalents

OpenGL
lessThanEqual(X,Y)
Direct3D
(X <= Y)

Arguments

  • value X - The first specified value.
  • value Y - The second specified value.

lessThan(value X, value Y)

Performs a component-wise less-than comparison of two vectors.

Equivalents

OpenGL
lessThan(X,Y)
Direct3D
(X < Y)

Arguments

  • value X - The first specified value.
  • value Y - The second specified value.

atan2(value X, value Y)

Returns the arctangent of two values (x,y).

Equivalents

OpenGL
atan(X,Y)
Direct3D
atan2(X,Y)

Arguments

  • value X - The first specified value.
  • value Y - The second specified value.

any(value value)

Determines if any components of the specified value are non-zero.

Equivalents

OpenGL
(value)
Direct3D
any(value)

Arguments

  • value value - The specified value.

float max2(value value)

Selects the greater of the first two vector components.

Equivalents

OpenGL
max(value.r,value.g)
Direct3D
max(value.r,value.g)

Arguments

  • value value - The specified vector (can be float2, float3 or float4 vector).

Return value

The maximum value.

float max3(value value)

Selects the greater of the first three vector components.

Equivalents

OpenGL
max(max(value.r,value.g),value.b)
Direct3D
max(max(value.r,value.g),value.b)

Arguments

  • value value - The specified vector (can be float3 or float4) or 3 float values.

Return value

The maximum value.

float max4(float4 value)

Selects the greater of the four values.

Equivalents

OpenGL
max(max(max(value.r,value.g),value.b),value.a)
Direct3D
max(max(max(value.r,value.g),value.b),value.a)

Arguments

  • float4 value - The specified vector (can be float4 vector) or 4 float values.

Return value

The maximum value.

float min2(value value)

Selects the lesser of the first two vector components.

Equivalents

OpenGL
min(value.r,value.g)
Direct3D
min(value.r,value.g)

Arguments

  • value value - The specified vector (can be float2, float3 or float4 vector).

Return value

The minimum value.

float min3(value value)

Selects the lesser of the first three vector components.

Equivalents

OpenGL
min(min(value.r,value.g),value.b)
Direct3D
min(min(value.r,value.g),value.b)

Arguments

  • value value - The specified vector (can be float3 or float4 vector) or 3 float values.

Return value

The minimum value.

float min4(float4 value)

Selects the lesser of the four vector components.

Equivalents

OpenGL
min(min(min(value.r,value.g),value.b),value.a)
Direct3D
min(min(min(value.r,value.g),value.b),value.a)

Arguments

  • float4 value - The specified vector (can be float4 vector) or 4 float values.

Return value

The minimum value.

float2 maxFloat2(float2 v0, float2 v1)

Returns a vector containing the greater values of the corresponding components of the 2 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.

Return value

The float2 vector with the maximum values of the corresponding components of the 2 float2 vectors.

float2 maxFloat2(float2 v0, float2 v1, float2 v2)

Returns a vector containing the greater values of the corresponding components of the 3 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.
  • float2 v2 - The third vector.

Return value

The float2 vector with the maximum values of the corresponding components of the 3 float2 vectors.

float2 maxFloat2(float2 v0, float2 v1, float2 v2, float2 v3)

Returns a vector containing the greater values of the corresponding components of the 4 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.
  • float2 v2 - The third vector.
  • float2 v3 - The fourth vector.

Return value

The float2 vector with the maximum values of the corresponding components of the 4 float2 vectors.

float3 maxFloat3(float3 v0, float3 v1)

Returns a vector containing the greater values of the corresponding components of the 2 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.

Return value

The float3 vector with the maximum values of the corresponding components of the 2 float3 vectors.

float3 maxFloat3(float3 v0, float3 v1, float3 v2)

Returns a vector containing the greater values of the corresponding components of the 3 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.
  • float3 v2 - The third vector.

Return value

The float3 vector with the maximum values of the corresponding components of the 3 float3 vectors.

float3 maxFloat3(float3 v0, float3 v1, float3 v2, float3 v3)

Returns a vector containing the greater values of the corresponding components of the 4 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.
  • float3 v2 - The third vector.
  • float3 v3 - The fourth vector.

Return value

The float3 vector with the maximum values of the corresponding components of the 4 float3 vectors.

float4 maxFloat4(float4 v0, float4 v1)

Returns a vector containing the greater values of the corresponding components of the 2 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.

Return value

The float4 vector with the maximum values of the corresponding components of the 2 float4 vectors.

float4 maxFloat4(float4 v0, float4 v1, float4 v2)

Returns a vector containing the greater values of the corresponding components of the 3 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.
  • float4 v2 - The third vector.

Return value

The float4 vector with the maximum values of the corresponding components of the 3 float4 vectors.

float4 maxFloat4(float4 v0, float4 v1, float4 v2, float4 v3)

Returns a vector containing the greater values of the corresponding components of the 4 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.
  • float4 v2 - The third vector.
  • float4 v3 - The fourth vector.

Return value

The float4 vector with the maximum values of the corresponding components of the 4 float4 vectors.

float2 minFloat2(float2 v0, float2 v1)

Returns a vector containing the lesser values of the corresponding components of the 2 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.

Return value

The float2 vector with the minimum values of the corresponding components of the 2 float2 vectors.

float2 minFloat2(float2 v0, float2 v1, float2 v2)

Returns a vector containing the lesser values of the corresponding components of the 3 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.
  • float2 v2 - The third vector.

Return value

The float2 vector with the minimum values of the corresponding components of the 3 float2 vectors.

float2 minFloat2(float2 v0, float2 v1, float2 v2, float2 v3)

Returns a vector containing the lesser values of the corresponding components of the 4 vectors.

Arguments

  • float2 v0 - The first vector.
  • float2 v1 - The second vector.
  • float2 v2 - The third vector.
  • float2 v3 - The fourth vector.

Return value

The float2 vector with the minimum values of the corresponding components of the 4 float2 vectors.

float3 minFloat3(float3 v0, float3 v1)

Returns a vector containing the lesser values of the corresponding components of the 2 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.

Return value

The float3 vector with the minimum values of the corresponding components of the 2 float3 vectors.

float3 minFloat3(float3 v0, float3 v1, float3 v2)

Returns a vector containing the lesser values of the corresponding components of the 3 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.
  • float3 v2 - The third vector.

Return value

The float3 vector with the minimum values of the corresponding components of the 3 float3 vectors.

float3 minFloat3(float3 v0, float3 v1, float3 v2, float3 v3)

Returns a vector containing the lesser values of the corresponding components of the 4 vectors.

Arguments

  • float3 v0 - The first vector.
  • float3 v1 - The second vector.
  • float3 v2 - The third vector.
  • float3 v3 - The fourth vector.

Return value

The float3 vector with the minimum values of the corresponding components of the 4 float3 vectors.

float4 minFloat4(float4 v0, float4 v1)

Returns a vector containing the lesser values of the corresponding components of the 2 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.

Return value

The float4 vector with the minimum values of the corresponding components of the 2 float4 vectors.

float4 minFloat4(float4 v0, float4 v1, float4 v2)

Returns a vector containing the lesser values of the corresponding components of the 3 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.
  • float4 v2 - The third vector.

Return value

The float4 vector with the minimum values of the corresponding components of the 3 float4 vectors.

float4 minFloat4(float4 v0, float4 v1, float4 v2, float4 v3)

Returns a vector containing the lesser values of the corresponding components of the 4 vectors.

Arguments

  • float4 v0 - The first vector.
  • float4 v1 - The second vector.
  • float4 v2 - The third vector.
  • float4 v3 - The fourth vector.

Return value

The float4 vector with the minimum values of the corresponding components of the 4 float4 vectors.

value pow2(value value)

Returns squared value.

Equivalents

OpenGL
value * value
Direct3D
value * value

Arguments

  • value value - The specified value to be powered. Can be one of the following types:
    • float
    • float2
    • float3
    • float4

Return value

Squared value (can be float, float2, float3 or float4).

value powMirror(value value, value power)

Perform the following operation:

Implementation

UUSL
1.0f - pow(1.0f - value,power);

Arguments

  • value value - The specified value to be powered. Can be one of the following types:
    • float
    • float2
    • float3
    • float4
  • value power - Power. Can be one of the following types:
    • float
    • float2
    • float3
    • float4

Return value

Mirrored powered value (can be float, float2, float3 or float4).

float4x4 rotate(float3 axis, float angle)

Returns a rotation matrix to rotate about an arbitrary axis.

Arguments

  • float3 axis - The specified axis.
  • float angle - Angle of rotation, in radians.

Return value

Rotation matrix.

bool isOrtho(float4x4 projection)

Returns a value indicating whether a projection matrix is for orthogonal projection.

Arguments

  • float4x4 projection - A projection matrix.

Return value

True is the projection matrix is orthogonal projection matrix; otherwise, false.

float3 srgb(float3 color)

Converts RGB color to sRGB.

Arguments

  • float3 color - RGB color to convert.

Return value

sRBG color.

float srgbInv(float value)

Performs the following operation:

Implementation

UUSL
pow(value,float_isrgb);

Arguments

  • float value - Value to convert.

Return value

Inversed sRGB value.

float2 srgbInv(float2 value)

Performs the following operation:

Implementation

UUSL
pow(value,float2_isrgb);

Arguments

  • float2 value - Value to convert.

Return value

Inversed sRGB value.

float3 srgbInv(float3 value)

Performs the following operation:

Implementation

UUSL
pow(value,float3_isrgb);

Arguments

  • float3 value - Value to convert.

Return value

Inversed sRGB value.

float4 srgbInv(float4 value)

Performs the following operation:

Implementation

UUSL
pow(value,float4_isrgb);

Arguments

  • float4 value - Value to convert.

Return value

Inversed sRGB value.

float nrand(float2 seed)

Returns the random value within the range of [0;1].

Equivalents

OpenGL
frac(sin(dot(seed,float2(12.9898f,78.233f))) * 43758.5453f)
Direct3D
frac(sin(dot(seed,float2(12.9898f,78.233f))) * 43758.5453f)

Arguments

  • float2 seed - The random seed.

float2 nrand(float2 seed_0, float2 seed_1)

Returns the float2 vector with random values within the range of [0;1].

Arguments

  • float2 seed_0 - The first random seed.
  • float2 seed_1 - The second random seed.

float2 nrand2(float2 seed)

Returns the random value within the range of [0;1] (For the second seed, the function shifts the vector: float2(x,y) -> float2(y,x))

Arguments

  • float2 seed - The random seed.

float nrandTiled(float2 seed_0, flaot tiled)

Returns the random value within the range of [0;1] divided by the tiled seed.

Arguments

  • float2 seed_0 - The first random seed.
  • flaot tiled - The seed of tiling (the number should be the power of two).

float2 nrandTiled(float2 seed_0, float2 seed_1, float tiled)

Returns the float2 vector with random values within the range of [0;1] divided by the tiled seed.

Arguments

  • float2 seed_0 - The first random seed.
  • float2 seed_1 - The second random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

float2 nrand2Tiled(float2 seed, float tiled)

Returns the float2 vector with random values within the range of [0;1] divided by the tiled seed (For the second seed, the function shifts the vector: float2(x,y) -> float2(y,x))

Arguments

  • float2 seed - The random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

float nrandTemporal(float2 seed_0, flaot tiled)

Returns the value (that changed each frame) within the range of [0;1] divided by the tiled seed.

Arguments

  • float2 seed_0 - The first random seed.
  • flaot tiled - The seed of tiling (the number should be the power of two).

float2 nrandTemporal(float2 seed_0, float2 seed_1, float tiled)

Returns the float2 vector with random values (that changed each frame) within the range of [0;1] divided by the tiled seed.

Arguments

  • float2 seed_0 - The first random seed.
  • float2 seed_1 - The second random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

float2 nrand2Temporal(float2 seed, float tiled)

Returns the float2 vector with random values (that changed each frame) within the range of [0;1] divided by the tiled seed (For the second seed, the function shifts the vector: float2(x,y) -> float2(y,x))

Arguments

  • float2 seed - The random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

float nrandTAA(float2 seed_0, flaot tiled)

Returns the value (that changed each frame) within the range of [0;1] divided by the tiled seed.
Notice
Works only if USE_TAA enabled. Otherwise, nrandTiled is used.

Arguments

  • float2 seed_0 - The first random seed.
  • flaot tiled - The seed of tiling (the number should be the power of two).

float2 nrandTAA(float2 seed_0, float2 seed_1, float tiled)

Returns the float2 vector with random values (that changed each frame) within the range of [0;1] divided by the tiled seed.
Notice
Works only if USE_TAA enabled. Otherwise, nrandTiled is used.

Arguments

  • float2 seed_0 - The first random seed.
  • float2 seed_1 - The second random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

float2 nrand2TAA(float2 seed, float tiled)

Returns the float2 vector with random values (that changed each frame) within the range of [0;1] divided by the tiled seed (For the second seed, the function shifts the vector: float2(x,y) -> float2(y,x))
Notice
Works only if USE_TAA enabled. Otherwise, nrand2Tiled is used.

Arguments

  • float2 seed - The random seed.
  • float tiled - The seed of tiling (the number should be the power of two).

dotFixed(value X, value Y)

Returns the dot product of two vectors within the range of 0 to 1.

Equivalents

OpenGL
saturate(dot(X,Y))
Direct3D
saturate(dot(X,Y)))

Arguments

  • value X - The first specified vector.
  • value Y - The second specified vector.

lerpFixed(value X, value Y, value FACTOR)

Performs a linear interpolation of two vectors with the factor in the range of 0 to 1.

Equivalents

OpenGL
lerp(X,Y,saturate(FACTOR))
Direct3D
lerp(X,Y,saturate(FACTOR))

Arguments

  • value X - The first specified vector.
  • value Y - The second specified vector.
  • value FACTOR - A value that linearly interpolates between the x parameter and the y parameter.

float4 getPosition(value vertex)

Returns the projected position of the vertex.

Arguments

  • value vertex - The first specified vertex. Can be one of the following types:
    • float3
    • float4

Return value

The projected position of the vertex.

float3 getDepthToPosition(float depth, float2 uv, float4x4 iprojection)

Returns the position according to depth value.

Arguments

  • float depth - Depth value.
  • float2 uv - UV position.
  • float4x4 iprojection - Inversed projection matrix.

Return value

Position vector.

float3 getDepthToPosition(float depth, float2 uv)

Returns the position according to depth value. The function uses s_camera_iprojection shader parameter.

Arguments

  • float depth - Depth value.
  • float2 uv - UV position.

Return value

Position vector.

float getLinearizedDepth(float native_depth, float2 uv)

Returns linearized depth value.

Arguments

  • float native_depth - Native depth value.
  • float2 uv - UV position.

Return value

Linearized depth value.

float getLinearizedDepth(TEXTURE_IN (depth_map), float2 uv)

Returns linearized depth value.

Arguments

  • TEXTURE_IN (depth_map) - Depth map texture.
  • float2 uv - UV position.

Return value

Linearized depth value.

float3 getViewDirection(value uv)

Returns the view direction vector.

Implementation

UUSL
mul4(s_camera_iprojection,float4(uv,0.0f,1.0f)).xyz

Arguments

  • value uv - UV position. Can be one of the following types:
    • float2
    • float3
    • float4
    Notice
    In case of float3 or float4 vectors, vector.xy values will be taken.

Return value

The view direction vector.

float2 getPositionToUV(float4 position)

Returns UV position by using given fragment position.

Arguments

  • float4 position - Fragment position.

Return value

UV position.

float2 getPositionToUV(float3 position)

Returns UV position by using given fragment position.

Arguments

  • float3 position - Fragment position.

Return value

UV position.

float2 getStaticVelocity(float3 position)

Returns screen-space velocity vector (change of the position relative to the previous frame) by using given view-space position.

Arguments

  • float3 position - View-space position.

Return value

Screen-space velocity.

float2 getStaticVelocity(float3 position, const bool cond_only_camera_rotation)

Returns screen-space velocity vector (change of the position relative to the previous frame) by using given view-space position.

Arguments

  • float3 position - View-space position.
  • const bool cond_only_camera_rotation - Flag indicating whether to take into account only the camera rotation.

Return value

Screen-space velocity.

float2 getAnimationOffset(float angle)

Returns animation offset by using given angle.

Arguments

  • float angle - Angle

Return value

Animation offset.

float getFieldAttenuation(float3 position, float4 x, float4 y, float4 z, float4 parameters, bool box)

Returns the attenuation of a field by using its size, position and parameters.

Arguments

  • float3 position - Position
  • float4 x - Field animation transform matrix
  • float4 y - Field animation transform matrix
  • float4 z - Field animation transform matrix
  • float4 parameters - Field animation parameters
  • bool box - Flag indicating whether the the shape of the field is box-shaped or ellipsoid-shaped.

Return value

Field attenuation.

float4 getBoundSphere(float4 row_0, float4 row_1, float4 row_2, float4 bound_sphere)

Returns the transformed bounding sphere.

Arguments

  • float4 row_0 - First row of a rotation matrix.
  • float4 row_1 - Second row of a rotation matrix.
  • float4 row_2 - Third row of a rotation matrix.
  • float4 bound_sphere - Bounding sphere to be transformed.

Return value

Bounding sphere.

float getAlphaFade(float4 row_0, float4 row_1, float4 row_2)

Returns the alpha fade value.

Arguments

  • float4 row_0 - First row of a transform matrix.
  • float4 row_1 - Second row of a transform matrix.
  • float4 row_2 - Third row of a transform matrix.

Return value

Alpha fade.

float getAlphaFade()

Returns the alpha fade.

Return value

Alpha the alpha fade value based on Model-View matrix.

void getTangentBasis(float4 basis, float3 out tangent, float3 out binormal, float3 out normal)

Returns the tangent basis.
UUSL
// Get normals
						float3 tangent,binormal,normal;

						// Getting normal in object-space
						getTangentBasis(IN_ATTRIBUTE(2),tangent,binormal,normal);

						// Transform object-space TBN into camera-space TBN
						normal = normalize(mul3(row_0,row_1,row_2,normal));
						tangent = normalize(mul3(row_0,row_1,row_2,tangent));
						binormal = normalize(mul3(row_0,row_1,row_2,binormal));

Arguments

  • float4 basis - Basis vector.
  • float3 out tangent - Empty vector for tangent.
  • float3 out binormal - Empty vector for binormal.
  • float3 out normal - Empty vector for normal.

void getTangentBasis(float4 basis, float3 out tangent, float3 out normal)

Returns the tangent basis.

Arguments

  • float4 basis - Basis vector.
  • float3 out tangent - Empty vector for tangent.
  • float3 out normal - Empty vector for normal.

void getTangentBasis(float4 basis, float3 out normal)

Returns the normal basis.

Arguments

  • float4 basis - Basis vector.
  • float3 out normal - Empty vector for normal.

float2 uvTransform(float2 uv, float2 tiling, float2 offset)

Transforms the UV by using given parameters.

Implementation

UUSL
uv * tiling + offset;

Arguments

  • float2 uv - UV position value.
  • float2 tiling - Tiling value.
  • float2 offset - Offset value.

Return value

Transformed UV position.

float2 uvTransform(float2 uv, float4 transform)

Transforms the UV by using given parameters.

Implementation

UUSL
uv * transform.xy + transform.zw;

Arguments

  • float2 uv - UV position value.
  • float4 transform - Transform vector value.

Return value

Transformed UV position.

float4 uvTransform(float4 uv, float2 tiling, float2 offset)

Transforms the UV by using given parameters.

Implementation

UUSL
uv * tiling.xyxy + offset.xyxy;

Arguments

  • float4 uv - UV position value.
  • float2 tiling - Tiling value.
  • float2 offset - Offset value.

Return value

Transformed UV position.

float4 uvTransform(float4 uv, float4 transform)

Transforms the UV by using given parameters.

Implementation

UUSL
uv * transform.xyxy + transform.zwzw;

Arguments

  • float4 uv - UV position value.
  • float4 transform - Transform vector value.

Return value

Transformed UV position.

float3 weightTriplanarFast(float3 normal, float blend)

Returns the unnormalized triplanar weight.

Arguments

  • float3 normal - Normal vector.
  • float blend - Blend level.

Return value

Unnormalized triplanar weight.

float3 weightTriplanar(float3 normal, float blend)

Returns normalized triplanar weight.

Arguments

  • float3 normal - Normal.
  • float blend - Blend level.

Return value

Normalized triplanar weight.

bool checkUV(float2 uv)

Checks if the UV position is correct (is it in [0;1] range).

Arguments

  • float2 uv - UV position.

Return value

1 if the UV is correct, otherwise, 0.

void normalizationTBN(inout float3 T, inout float3 B, inout float3 N, float sign_binormal, float front_face)

Calculates normalized TBN vectors.

Arguments

  • inout float3 T - Tangent vector.
  • inout float3 B - Binormal vector.
  • inout float3 N - Normal vector.
  • float sign_binormal - Binormal vector sign (ATTRIBUTE_BASIS.w).
  • float front_face - Flag indicated is the mesh two-sided or not. (1 is for front face, -1 for back face).

float getNormalZ(value normal)

Returns the Z component of a normal vector given it is normalized (its length is equal to 1) and the X and Y components are known.

Arguments

  • value normal - Normal vector (can be float2, float3 or float4 vector.

Return value

Z component of the specified normal vector.

float3 reorientNormalBlend(float3 detail, float3 base)

Performs blending of tangent-space normals and returns reoriented normal vector.

Arguments

  • float3 detail - Detail normal vector.
  • float3 base - Base normal vector.

Return value

Normal vector.

float3 reorientNormalBlend(float3 detail, float3 base, float3 geometric)

Performs blending of object-space normals and returns reoriented normal vector.

Arguments

  • float3 detail - Detail normal vector.
  • float3 base - Base normal vector.
  • float3 geometric - Source geometric object-space normal vector.

Return value

Normal vector.

float4 getTriplanarNormal(TEXTURE_IN TEX_VALUE, float4 texcoord, float3 weight, float3 object_normal)

Returns triplanar normal.

Arguments

  • TEXTURE_IN TEX_VALUE - Normal texture.
  • float4 texcoord - Vector with the texture coordinates.
  • float3 weight - Weight vector.
  • float3 object_normal - Object normal vector.

Return value

Triplanar normal.

bool checkMask(value mask, value bits)

Returns a value indicating whether a bit mask matches to a bit pattern.

Arguments

  • value mask - Bit mask to check. Can be int or uint value.
  • value bits - Bit pattern. Must be the same type as the mask value.

Return value

True if two masks have at least one matching bit; otherwise, false.

void sincos(float value, inout float sin, inout float cos)

Calculates the sine and cosine of the value.

Equivalents

Direct3D
sincos(value,sin,cos)

Arguments

  • float value - Value.
  • inout float sin - Sine of the value.
  • inout float cos - Cosine of the value.

float3 mul(float3 vector, float3x3 matrix)

Performs the vector * matrix multiplication.
Notice
Works only for OpenGL.

Arguments

  • float3 vector - The 3-component vector.
  • float3x3 matrix - The 3x3 matrix.

Return value

The result of multiplication.

float3 mul(float3x3 matrix, float3 vector)

Performs the matrix * vector multiplication.
Notice
Works only for OpenGL.

Arguments

  • float3x3 matrix - The 3x3 matrix.
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

float4 mul(float4 vector, float4x4 matrix)

Performs the vector * matrix multiplication.
Notice
Works only for OpenGL.

Arguments

  • float4 vector - The 4-component vector.
  • float4x4 matrix - The 4x4 matrix.

Return value

The result of multiplication.

float4 mul(float4x4 matrix, float4 vector)

Performs the matrix * vector multiplication.
Notice
Works only for OpenGL.

Arguments

  • float4x4 matrix - The 4x4 matrix.
  • float4 vector - The 4-component vector.

Return value

The result of multiplication.

float3 mul3(float4x4 matrix, float3 vector)

Performs the vector * matrix multiplication.

Arguments

  • float4x4 matrix - The 4x4 matrix.
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

float3 mul3(float3 vector, float4x4 matrix)

Performs the matrix * vector multiplication.

Arguments

  • float3 vector - The 3-component vector.
  • float4x4 matrix - The 4x4 matrix.

Return value

The result of multiplication.

float3 mul3(float4 row_0, float4 row_1, float4 row_2, float3 vector)

Performs the matrix * vector multiplication.

Arguments

  • float4 row_0 - The first row of the matrix
  • float4 row_1 - The second row of the matrix
  • float4 row_2 - The third row of the matrix
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

float3 mul3(float3x3 matrix, float3 vector)

Performs the matrix * vector multiplication.

Arguments

  • float3x3 matrix - The 3x3 matrix.
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

float4 mul4(float4x4 matrix, float3 vector)

Performs the matrix * vector multiplication.
OpenGL
(m * float4(v,1.0f)).xyz;
Direct3D
(m * float4(v,1.0f)).xyz;

Arguments

  • float4x4 matrix - The 4x4 matrix.
  • float3 vector - The 3-component vector.

Return value

The result of multiplication.

float4 mul4(float4x4 matrix, float4 vector)

Performs the matrix * vector multiplication.

Arguments

  • float4x4 matrix - The 4x4 matrix.
  • float4 vector - The 4-component vector.

Return value

The result of multiplication.

float4 mul4(float4 row_0, float4 row_1, float4 row_2, float4 vector)

Performs the matrix * vector multiplication.
OpenGL
float4(dot(row_0,v),dot(row_1,v),dot(row_2,v),v.w);
Direct3D
float4(dot(row_0,v),dot(row_1,v),dot(row_2,v),v.w);

Arguments

  • float4 row_0 - The first row of the matrix
  • float4 row_1 - The second row of the matrix
  • float4 row_2 - The third row of the matrix
  • float4 vector - The 4-component vector.

Return value

The result of multiplication.

Fragment Functions

For fragment shader features, use the core/shaders/common/fragment.h file.

UUSL
#include <core/shaders/common/fragment.h>

float3 getDepthToPosition(TEXTURE_IN (DEPTH_MAP), float2 uv, float4x4 projection)

Returns the position according to depth texture.

Arguments

  • TEXTURE_IN (DEPTH_MAP) - Depth texture.
  • float2 uv - UV position.
  • float4x4 projection - Projection matrix.

Return value

Position vector.

float3 getDepthToPosition(TEXTURE_IN (DEPTH_MAP), float2 uv)

Returns the position according to depth value. The function uses s_camera_iprojection shader parameter.

Arguments

  • TEXTURE_IN (DEPTH_MAP) - Depth texture.
  • float2 uv - UV position.

Return value

Position vector.

float3 getPositionToNormal(value position)

Returns normal position by using given fragment position.

Arguments

  • value position - Fragment position. Can be float3 or float4 vector.

Return value

Normal position.

void alphaFadeDiscard(float threshold, float2 uv)

Provides dithered alpha fading by discarding rendering of the fragment based on random noise.

Arguments

  • float threshold - Threshold of the fading.
  • float2 uv - The random seed.

void calculateTBN(inout float3 T, inout float3 B, inout float3 N, float3 position, float2 uv)

Calculates TBN vectors.

Arguments

  • inout float3 T - Tangent vector.
  • inout float3 B - Binormal vector.
  • inout float3 N - Normal vector.
  • float3 position - Position vector.
  • float2 uv - UV.

float getMipLevel(float2 pixel_position)

Calculates TBN vectors.

Arguments

  • float2 pixel_position - Pixel position.

Return value

Mip level.

float3x3 getNormalToTBN(float3 N)

Calculates TBN matrix containing Tangent, Binormal and Normal vectors out of a Normal vector.

Arguments

  • float3 N - Normal vector.

Return value

TBN matrix.

Geodetic Functions

double3 geodeticFlatToEllipsoid(double3 position, double4x4 planetview, double4x4 ipivotview)

Transforms a flat geodetic position into ellipsoid coordinate system.

Arguments

  • double3 position - Flat position vector.
  • double4x4 planetview - Planet view matrix.
  • double4x4 ipivotview - Inverse pivot view matrix.

Return value

Position in ellipsoid coordinate system.

double3 geodeticFlatToEllipsoid(double3 position)

Transforms a flat geodetic position into ellipsoid coordinate system by using s_geodetic_planetview and s_geodetic_ipivotview.

Arguments

  • double3 position - Flat position vector.

Return value

Position in ellipsoid coordinate system.

double3 geodeticFlatToEllipsoidOld(double3 position)

Transforms a flat geodetic position into ellipsoid coordinate system by using s_geodetic_old_planetview and s_geodetic_old_ipivotview.

Arguments

  • double3 position - Flat position vector.

Return value

Position in ellipsoid coordinate system.

double3 geodeticEllipsoidToFlatWorld(double3 position, double4x4 iplanetview)

Transforms a position in ellipsoid coordinate system into position in geodetic flat one.

Arguments

  • double3 position - Position vector.
  • double4x4 iplanetview - Inverse planet view matrix.

Return value

Position in geodetic flat coordinate system.

double3 geodeticEllipsoidToFlat(double3 position, double4x4 pivotview, double4x4 iplanetview)

Transforms a position in ellipsoid coordinate system into flat one.

Arguments

  • double3 position - Position vector.
  • double4x4 pivotview - Pivot view matrix.
  • double4x4 iplanetview - Inverse planet view matrix.

Return value

Position in geodetic flat coordinate system.

double3 geodeticEllipsoidToFlat(double3 position)

Transforms a position in ellipsoid coordinate system into flat one by using s_geodetic_pivotview and s_geodetic_iplanetview.

Arguments

  • double3 position - Position vector.

Return value

Position in geodetic flat coordinate system.

float3 geodeticEllipsoidToFlatCameraView(float3 position)

Transforms a position in ellipsoid coordinate system into flat camera-view space.

Arguments

  • float3 position - Position vector.

Return value

Position in geodetic flat camera-view space.

float3 geodeticEllipsoidToFlatNormal(float3 position)

Transforms a position in ellipsoid coordinate system into flat normal vector.

Arguments

  • float3 position - Position vector.

Return value

Position in geodetic flat normal vector.

float3x3 geodeticPositionToEllipsoidTBN(float3 position)

Calculates Tangent, Binormal and Normal vectors by using a position vector in ellipsoid coordinate system.

Arguments

  • float3 position - Position vector.

Return value

Matrix containing Tangent, Binormal and Normal vectors.

Packing Functions

float floatPack88To16(float2 value)

Packs RG8 into R16.

Arguments

  • float2 value - Value to pack.

float2 floatPack16To88(float value)

Unpacks R16 into RG8.

Arguments

  • float value - Value to pack.

float2 floatPack8888To1616(float4 value)

Packs normalized RGBA8 into R16G16.

Arguments

  • float4 value - Value to pack.

float4 floatPack1616To8888(float2 value)

Unpacks R16G16 into RGBA8.

Arguments

  • float2 value - Value to pack.

float3 floatPack1212To888(float2 value)

Packs RG12 to RGB8.

Arguments

  • float2 value - Value to pack.

float2 floatPack888To1212(float3 value)

Packs RGB8 to RG12.

Arguments

  • float3 value - Value to pack.

float floatPack44To8(float x, float y)

Packs two 4-bit values into an 8-bit one.

Arguments

  • float x - Value to pack.
  • float y - Value to pack.

float2 floatPack8To44(float value)

Unpacks 8-bit value into two 4-bit values.

Arguments

  • float value - Value to pack.

float2 floatPack32To1616(float value)

Unpacks 32-bit value into two 16-bit values.

Arguments

  • float value - Value to pack.

float floatPack1616To32(float2 value)

Packs two 16-bit values into a 32-bit one.

Arguments

  • float2 value - Value to pack.

float2 packUnitVectorToOctahedron(float3 normal)

Encodes a normal (unit) vector into two-component one using octahedron encoding.

Arguments

  • float3 normal - Normal vector.

Return value

Octahedron normal vector.

float3 unpackOctahedronToUnitVector(float2 normal)

Decodes an octahedron vector into three-component normal (unit) one.

Arguments

  • float2 normal - Octahedron normal vector.

Return value

Normal (unit) vector.

float3 getDeferredNormal(value deferred)

Returns a packed deferred normal vector.

Arguments

  • value deferred - Deferred vector. Can be float3 or float4 vector.

Return value

Deferred normal vector.

float3 setDeferredNormal(float3 deferred)

Returns an unpacked deferred vector.

Arguments

  • float3 deferred - Deferred normal vector.

Return value

Deferred vector.

float3 getScreenVelocity(float3 old_position, float3 new_position)

Returns a screen-space velocity vector.

Arguments

  • float3 old_position - Old view-space position vector.
  • float3 new_position - New view-space position vector.

Return value

Velocity vector.

Shading Functions

void loadEnvironmentCubeMap(inout float3 ambient, inout float3 reflection, GBuffer gbuffer, Data data, TEXTURE_IN_CUBE (TEX_REFLECTION))

Loads environment cubemap.

Arguments

  • inout float3 ambient - Environment ambient vector.
  • inout float3 reflection - Environment reflection vector.
  • GBuffer gbuffer - GBuffer struct.
  • Data data - Data struct.
  • TEXTURE_IN_CUBE (TEX_REFLECTION) - Environment cubemap texture.

float3 getEnvironmentReflectVector(float3 normal, float3 reflection, float roughness)

Returns environment reflection vector.

Arguments

  • float3 normal - Normal vector.
  • float3 reflection - Reflection vector.
  • float roughness - Roughness vector.

Return value

Environment reflection vector.

void environmentShading(inout float3 ambient, inout float3 reflection, GBuffer gbuffer, Data data)

Calculates environment ambient and reflection shading.

Arguments

  • inout float3 ambient - Environment ambient.
  • inout float3 reflection - Environment reflection.
  • GBuffer gbuffer - GBuffer struct.
  • Data data - Data struct

void gbufferSRGB(inout GBuffer gbuffer)

Converts GBuffer's albedo and f0 fields to sRGB.

Arguments

float getFresnelSchlick(float F0, float dotLH)

Calculates Fresnel factor (Schlick's approximation).

Arguments

  • float F0 - Reflectance for H·V = 1.
  • float dotLH - Dot product of 2 vectors: vector to light source and normalized halfway vector (H = (V + L) / |V + L|).

float getGGX(float roughness, float dotNV, float dotNL, float dotNH)

Calculates specular lighting.

Arguments

  • float roughness - Roughness value.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).

float getGGX(float roughness, float dotNV, float dotNL, float dotNH, float translucent_scale)

Calculates specular lighting.

Arguments

  • float roughness - Roughness value.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).
  • float translucent_scale - Translucent scale value.

float getAreaLightGGX(float roughness, float dotNV, float dotNL, float dotLR, float size)

Calculates area light specular lighting.

Arguments

  • float roughness - Roughness value.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotLR - Dot product of 2 vectors: normal vector and reflected vector.
  • float size - The size of specular lighting.

float getAreaLightGGX(float roughness, float dotNV, float dotNL, float dotLR, float size, float translucent_scale)

Calculates area light specular lighting.

Arguments

  • float roughness - Roughness value.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotLR - Dot product of 2 vectors: vector to light source and reflected vector.
  • float size - The size of specular lighting.
  • float translucent_scale - Translucent scale value.

float getPhong(float dotLR, float power)

Calculates Phong shading.

Arguments

  • float dotLR - Dot product of 2 vectors: vector to light source and reflected vector.
  • float power - The specular power value.

float getBlinn(float dotNH, float power)

Calculates Blinn shading.

Arguments

  • float dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).
  • float power - The specular power value.

float getBurley(float roughness, float dotNV, float dotLH, float dotNL)

Calculates diffuse lighting.
Notice
Read more about Diffuse BRDF lighting.

Arguments

  • float roughness - Roughness value.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotLH - Dot product of 2 vectors: vector to light source and normalized halfway vector (H = (V + L) / |V + L|).
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.

float getWrapAround(float dotNL, float factor)

Calculates Energy-Conserving Wrapped Diffuse.

Arguments

  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float factor - Energy conservation factor.

float getTranslucent(float translucent_scale, float dotVL, float dotNL)

Calculates translucent.

Arguments

  • float translucent_scale - Translucent scale value.
  • float dotVL - Dot product of 2 vectors: vector to camera and vector to light source.
  • float dotNL - Negative dot product of 2 vectors: normal vector and vector to light source.

float3 getSpecularBRDF(Gbuffer gbuffer, float3 specular_color, float dotNV, float dotLH, float dotNL, float dotNH)

Calculates BRDF for specular workflow.

Arguments

  • Gbuffer gbuffer - GBuffer struct.
  • float3 specular_color - Specular color vector.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotLH - Dot product of 2 vectors: vector to light source and normalized halfway vector.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).

float3 getAreaLightSpecularBRDF(Gbuffer gbuffer, float3 specular_color, float dotNV, float dotLH, float dotNL, float dotNH, float size)

Calculates area light specular BRDF.

Arguments

  • Gbuffer gbuffer - GBuffer struct.
  • float3 specular_color - Specular color vector.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotLH - Dot product of 2 vectors: vector to light source and normalized halfway vector.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).
  • float size - The size of specular lighting.

float getDiffuseBRDF(Gbuffer gbuffer, float dotNV, float dotLH, float dotNL, float dotVL)

Calculates diffuse BRDF

Arguments

  • Gbuffer gbuffer - GBuffer struct.
  • float dotNV - Dot product of 2 vectors: normal vector and vector to camera.
  • float dotLH - Dot product of 2 vectors: vector to light source and normalized halfway vector.
  • float dotNL - Dot product of 2 vectors: normal vector and vector to light source.
  • float dotVL - Dot product of 2 vectors: vector to camera and vector to light source.

void getBRDF(inout float3 diffuse, inout float specular, Gbuffer gbuffer, Data data, float3 light_direction)

Calculates BRDF.

Arguments

  • inout float3 diffuse - Diffuse value.
  • inout float specular - Specular value.
  • Gbuffer gbuffer - GBuffer struct.
  • Data data - Data struct.
  • float3 light_direction - Light direction vector.

float getLightAttenuation(float distance, float light_attenuation)

Calculates sRGB Light Attenuation by using calculated attenuation value and distance.

Arguments

  • float distance - Light distance value.
  • float light_attenuation - Light attenuation value.

Return value

Light attenuation value.

float getLightAttenuation(float3 position)

Calculates Light Attenuation by given position.

Arguments

  • float3 position - Position value.

Return value

Light attenuation.

float getLightAttenuation(float light_distance)

Calculates Light Attenuation by distance.

Arguments

  • float light_distance - Light Distance value.

Return value

Light attenuation.

float3 sphereLightToLight(float3 L, float3 direction)

Returns normalized shift of L vector.

Arguments

  • float3 L - Vector to the light source.
  • float3 direction - Shift direction vector.

float3 capsuleLightToLight(float3 L, float3 direction, float3 axis, float size, float3 dotLA)

Returns normalized shift of L vector (depends on given axis and direction vector).

Arguments

  • float3 L - Vector to the light source.
  • float3 direction - Shift direction vector.
  • float3 axis - Axis of shift.
  • float size - Size.
  • float3 dotLA - Dot product of 2 vectors: axis vector and vector to light source.

void getMicrofiber(inout float3 color, Data data, Gbuffer gbuffer)

Calculates microfiber.

Arguments

  • inout float3 color - Microfiber color vector.
  • Data data - Data struct.
  • Gbuffer gbuffer - GBuffer struct.

Scattering Functions

Here is an example of scattering functions usage:

UUSL
#ifdef USE_HAZE
			#ifdef USE_HAZE_SCATTERING
			float4 haze = hazeScattering(depth,camera_dir,TEXTURE_OUT_3(TEX_BASE_LUT,TEX_MIE_SUN_LUT,TEX_MIE_MOON_LUT));
			#elif USE_HAZE_SOLID
			float4 haze = hazeSolid(depth);
			#endif

			OUT_COLOR.rgb = OUT_COLOR.rgb * haze.a + haze.rgb;
			#endif

			// forward
			#ifdef USE_HAZE && !STAR_AMBIENT
			OUT_COLOR = hazeForward(OUT_COLOR,depth,camera_dir,TEXTURE_OUT_3(TEX_BASE_LUT,TEX_MIE_SUN_LUT,TEX_MIE_MOON_LUT));
			#endif

float scatteringMie(float dotLD, float dotLUP)

Calculates the Mie scattering value.

Arguments

  • float dotLD - Dot product of 2 vectors: vector to light source and camera direction?.
  • float dotLUP - Dot product of 2 vectors: vector to light source and up vector.

Return value

Mie scattering value.

float scatteringMie(float3 light_dir, float3 camera_dir)

Calculates the Mie scattering value.

Arguments

  • float3 light_dir - Light direction vector.
  • float3 camera_dir - Camera direction vector.

Return value

Mie scattering value.

float scatteringMieDisk(float3 light_dir, float3 camera_dir, float3 disk_intensity)

Calculates the value of Mie Light Scattering by non-spherical (disk-shaped) particles.

Arguments

  • float3 light_dir - Light direction vector.
  • float3 camera_dir - Camera direction vector.
  • float3 disk_intensity - Disk intensity.

Return value

Mie scattering value.

float4 hazeScattering(float depth, float3 camera_dir, TEXTURE_IN_3 (base,mie_sun,mie_moon))

Calculates the haze in the scattering mode.

Arguments

  • float depth - Depth value.
  • float3 camera_dir - Camera direction vector.
  • TEXTURE_IN_3 (base,mie_sun,mie_moon) - Set of 3 LUT textures: base, mie sun and mie moon.

Return value

Haze vector.

float4 hazeForward(float4 color, float depth, float3 camera_dir, TEXTURE_IN_3 (base,mie_sun,mie_moon))

Calculates the haze for objects rendered in the forward mode.

Arguments

  • float4 color - Color
  • float depth - Depth value.
  • float3 camera_dir - Camera direction vector.
  • TEXTURE_IN_3 (base,mie_sun,mie_moon) - Set of 3 LUT textures: base, mie sun and mie moon.

Return value

Haze vector.

float hazeAlpha(float depth)

Calculates transparency alpha value of the haze.

Arguments

  • float depth - Depth value.

Return value

Haze alpha value.

float hazeAlpha(float3 position)

Calculates transparency alpha value of the haze.

Arguments

  • float3 position - Position.

Return value

Haze alpha value.

float hazeAlpha(float4 position)

Calculates transparency alpha value of the haze.

Arguments

  • float4 position - Position.

Return value

Haze alpha value.

float4 hazeSolid(float depth)

Calculates completely solid haze.

Arguments

  • float depth - Depth value.

Return value

Haze solid vector.

float4 hazeSolid(float position)

Calculates completely solid haze.

Arguments

  • float position - Position.

Return value

Haze solid vector.

float4 hazeSolid(float position)

Calculates completely solid haze.

Arguments

  • float position - Position.

Return value

Haze solid vector.

float4 hazeForwardSimple(float4 color, float depth)

Calculates haze for objects rendered in the forward mode, can be used in the vertex shader, turns objects to transparency.

Arguments

  • float4 color - Color vector.
  • float depth - Depth value.

Return value

Haze solid vector.

float4 hazeForwardSimple(float4 color, float3 position)

Calculates haze for objects rendered in the forward mode, can be used in the vertex shader, turns objects to transparency.

Arguments

  • float4 color - Color vector.
  • float3 position - Position.

Return value

Haze solid vector.

float4 hazeForwardSimple(float4 color, float4 position)

Calculates haze for objects rendered in the forward mode, can be used in the vertex shader, turns objects to transparency.

Arguments

  • float4 color - Color vector.
  • float4 position - Position.

Return value

Haze solid vector.
Last update: 04.06.2018
Build: ()