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

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(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 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).

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.

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.

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.

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.

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

Return value

The maximum value.

float max4(float4 value)

Selects the greater of the four vector components.

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.

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

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.

Return value

The minimum value.

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

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 getAnimationOffset(float angle)

Returns animation offset by using given angle.

Arguments

  • float angle - Angle

Return value

Animation offset.

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.

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.

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

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, float3 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
  • float3 vector - The 4-component vector.

Return value

The result of multiplication.

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 to 8-bit.

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.

Shading Functions

void loadEnvironmentCubeMap(inout float3 env, inout float3 ref, GBuffer gbuffer, Data data, TEXTURE_IN_CUBE (TEX_REFLECTION))

Loads environment cubemap.

Arguments

  • inout float3 env - ---
  • inout float3 ref - ---
  • GBuffer gbuffer - GBuffer struct.
  • Data data - Data struct.
  • TEXTURE_IN_CUBE (TEX_REFLECTION) - Environment cubemap texture.

float3 getEnvironmentReflectVector(GBuffer gbuffer, Data data)

Returns environment reflection vector.

Arguments

  • GBuffer gbuffer - GBuffer struct.
  • Data data - Data struct.

Return value

Environment reflection vector.

void environmentReflectionShading(inout float3 reflection, GBuffer gbuffer, Data data)

Calculates environment reflection shading.

Arguments

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

void gbufferSRGB(GBuffer gbuffer)

Converts GBuffer's albedo and f0 fields to sRGB.

Arguments

float getFresnelSchlick(float3 F0, float dotLH)

Calculates Fresnel factor (Schlick's approximation).

Arguments

  • float3 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|).

float3 getFresnel(float3 specular_color, float3 dotLH)

Calculates Fresnel for specular workflow.

Arguments

  • float3 specular_color - Specular color vector.
  • float3 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: normal vector 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 getBurley12(float roughness, float dotNV, float dotVH, 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 dotVH - Dot product of 2 vectors: vector to camera 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 - 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.

float2 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(float3 diffuse, float specular, Gbuffer gbuffer, Data data, float3 light_direction)

Calculates BRDF.

Arguments

  • float3 diffuse - Diffuse value.
  • 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, 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.
  • float3 dotLA - Dot product of 2 vectors: axis vector and vector to light source.

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

Calculates microfiber.

Arguments

  • color color - Color vector.
  • Data data - Data struct.
  • Gbuffer gbuffer - GBuffer struct.

Return value

Microfiber color vector.

float3 specularReflection(float4 specular, float dotVN, float exponent)

Calculates specular reflection with exponent.

Arguments

  • float4 specular - Specular value.
  • float dotVN - Dot product of 2 vectors: normal vector and vector to camera.
  • float exponent - Exponent value for pow(dotVN, exponent) operation.

Return value

Specular reflection vector.

float3 specularReflection(float4 specular, float dotVN)

Calculates specular reflection.

Arguments

  • float4 specular - Specular value.
  • float dotVN - Dot product of 2 vectors: normal vector and vector to camera.

Return value

Specular reflection vector.

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

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: 2018-04-26
Build: ()