This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Core Library
Containers
Engine Classes
Node-Related Classes
Rendering-Related Classes
Physics-Related Classes
Bounds-Related Classes
GUI-Related Classes
Controls-Related Classes
Pathfinding-Related Classes
Utility Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

UUSL Data Types and Common Intrinsic Functions

This documentation article contains information about data types, functions, pre-defined variables and other features of the UUSL. This information can be used as the reference document for writing shaders.

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

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

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

Data Types

UUSLOpenGLDirect3DDescription
int2ivec2int2A vector with two 32-bit signed integer components.
int3ivec3int3A vector with three 32-bit signed integer components.
int4ivec4int4A vector with four 32-bit signed integer components.
uint2uvec4int2A vector with two 32-bit unsigned integer components.
uint3uvec4uint3A vector with three 32-bit unsigned integer components.
uint4uvec4uint4A vector with four 32-bit unsigned integer components.
floatfloatfloatA 32-bit floating point value.
float2vec2float2A vector with two 32-bit floating point value components.
float3vec3float3A vector with three 32-bit floating point value components.
float4vec4float4A vector with four 32-bit floating point value components.
float2x2mat2float2x2A matrix with 2 rows, 2 column of 32-bit floating point value components.
float3x3mat3float3x3A matrix with 3 rows, 3 column of 32-bit floating point value components.
float4x4mat4float4x4A matrix with 4 rows, 4 column of 32-bit floating point value components.
UUSLOpenGLDirect3DDescription
TYPE_RfloatfloatA 32-bit floating point value.
TYPE_RGfloat2float2A vector with two 32-bit floating point value components.
TYPE_RGBfloat3float3A vector with three 32-bit floating point value components.
TYPE_RGBAfloat4float4A vector with four 32-bit floating point value components.
UUSLOpenGLDirect3DDescription
FLOAT(X)float(X)XConverts the value to float.
FLOAT2(X)vec2(X)XConverts the value to the two-component vector.
FLOAT3(X)vec3(X)XConverts the value to the three-component vector.
FLOAT4(X)vec4(X)XConverts the value to the four-component vector.
INT(X)int(X)XConverts the value to int.
INT2(X)int2(X)XConverts the value to the two component vector.
INT3(X)int3(X)XConverts the value to the three-component vector.
INT4(X)int4(X)XConverts the value to the three-component vector.
BOOL2(X)bvec2(X)XConverts the value to the two component boolean vector.
BOOL3(X)bvec3(X)XConverts the value to the three-component boolean vector.
BOOL4(X)bvec4(X)XConverts the value to the three-component boolean vector.

Predefined Values

UUSLValue
float_isrgb2.233333f
float4_zerofloat4(0.0f,0.0f,0.0f,0.0f)
float4_onefloat4(1.0f,1.0f,1.0f,1.0f)
float4_neg_onefloat4(-1.0f,-1.0f,-1.0f,-1.0f)
float4_isrgbfloat4(float_isrgb,float_isrgb,float_isrgb,float_isrgb)
float3_zerofloat3(0.0f,0.0f,0.0f)
float3_onefloat3(1.0f,1.0f,1.0f)
float3_neg_onefloat3(-1.0f,-1.0f,-1.0f)
float3_upfloat3(0.0f,0.0f,1.0f)
float3_isrgbfloat3float_isrgb,float_isrgb,float_isrgb)
float2_zerofloat3(2.2f,2.2f,2.2f)
float2_onefloat2(1.0f,1.0f)
float2_neg_onefloat2(-1.0f,-1.0f)
float2_isrgbfloat2(float_isrgb,float_isrgb)
int4_zeroint4(0,0,0,0)
int4_oneint4(1,1,1,1)
int4_neg_oneint4(-1,-1,-1,-1)
int3_zeroint3(0,0,0)
int3_oneint3(1,1,1)
int3_neg_oneint3(-1,-1,-1)
int2_zeroint2(0,0)
int2_oneint2(1,1)
int2_neg_oneint2(-1,-1)
PI3.141592654f
PI26.283185308f
PI051.570796327f
LOG20.693147181f
LOG102.302585093f
SQRT21.414213562f
EPSILON1e-6f
INFINITY1e+9f
STATICARRAY(float2,halton16,16)Array contains Halton sequence.
STATICARRAY(float2,halton8,8)Array contains Halton sequence.

Main Function

Void Main Function

To start and end the void Main function of the fragment shader (when you don't need to provide the output color value but depth), use the following instructions:

UUSL
MAIN_VOID_BEGIN(STRUCT_IN)
	<your code here>
MAIN_VOID_END
Warning
You should add a new line (press Enter) after closing the instruction.

This code is equivalent to:

OpenGL
void main() {
	<your code here>
}
Direct3D
void main(STRUCT_IN IN) {
	<your code here>
}

Main Function with Return Value

To start and end the Main function with return value, use the following instructions:

UUSL
MAIN_BEGIN(STRUCT_IN,STRUCT_OUT)
	<your code here>
MAIN_END
Warning
You should add a new line (press Enter) after closing the instruction.

This code is equivalent to:

OpenGL
void main() {
	<your code here>
}
Direct3D
STRUCT_OUT main(STRUCT_IN IN) { 
	STRUCT_OUT OUT;
	<your code here>
return OUT; }

Geometry Shader Main Function

To start and end the Main function of the geometry shader, use the following instructions:

UUSL
MAIN_GEOM_BEGIN(STRUCT_OUT,STRUCT_IN)
	<your code here>
END_GEOM
Warning
You should add a new line (press Enter) after closing the instruction.

This code is equivalent to:

OpenGL
layout(TYPE_GEOM_IN) in;
layout(TYPE_GEOM_OUT,max_vertices = MAX_VERTICES_GEOM) out;
void main() {
	<your code here>
}
Direct3D
[maxvertexcount(MAX_VERTICES_GEOM)]
void main(TYPE_GEOM_IN STRUCT_IN IN[COUNT_GEOM_IN],inout TYPE_GEOM_OUT<STRUCT_OUT> stream) {
	STRUCT_OUT OUT;
	<your code here>
}

Static Variables and Arrays

Static Variables

To define a static variable, use the following syntax:

UUSL
STATICVAR <your var>

This is equal to the following GLSL and HLSL commands:

OpenGL
const <your var>
Direct3D
static const <your var>

Static Arrays

To work with static arrays by using UUSL, use the following instructions:

UUSL
STATICARRAY(TYPE,NAME,SIZE)
	<your array members>
ENDARRAY
Warning
You should add a new line (press Enter) after closing the instruction.
  • TYPE - the type of the array (float, etc.).
  • NAME - the name of the array.
  • SIZE - the size of the array.

This code block is equivalent to:

OpenGL
TYPE NAME [SIZE] = TYPE[](<your array members>);
Direct3D
static const TYPE NAME [SIZE] = {<your array members>};

Blending Presets

UUSL contains blending presets. When you specify the type of blending in material, the USSL wrapper automatically defines a new definition, that you can use in your shader:

Blending typeUUSL
BLEND_SRC_FUNC_SRC_ALPHA && BLEND_DEST_FUNC_ONE_MINUS_SRC_ALPHABLEND_ALPHABLEND
BLEND_SRC_FUNC_ONE && BLEND_DEST_FUNC_ONEBLEND_ADDITIVE
BLEND_SRC_FUNC_DEST_COLOR && BLEND_DEST_FUNC_ZEROBLEND_MULTIPLICATIVE
BLEND_SRC_FUNC_NONE && BLEND_DEST_FUNC_NONEBLEND_NONE

HLSL features

HLSL Flow Control Attributes

UUSLOpenGLDirect3DDescription
branch-[branch]Performs branching using control flow instructions.
call-[call]Prevents inlining of a function.
flatten-[flatten]Performs branching using conditional move instructions.
ifAll-[ifAll]Executes the conditional part of an if statement when the condition is true for all threads on which the current shader is running.
ifAny-[ifAny]Executes the conditional part of an if statement when the condition is true for any thread on which the current shader is running.
isolate-[isolate]Optimizes the specified HLSL code independently of the surrounding code.
loop-[loop]Gives preference to flow control constructs.
maxexports-[maxexports]Specifies the maximum number of export instructions that will execute along any path from the entry point to an exit.
maxInstructionCount-[maxInstructionCount]Sets the maximum number of instructions available to a shader.
maxtempreg-[maxtempreg]Restricts temporary register usage to the number of registers specified. Generates a compiler error if unsuccessful.
noExpressionOptimizations-[noExpressionOptimizations]Avoids optimization of expressions.
predicate-[predicate]Performs branching by using predication.
predicateBlock-[predicateBlock]Performs branching by using predicated exec blocks.
reduceTempRegUsage-[reduceTempRegUsage]Restricts temporary register usage to the number of registers specified. Generates a compiler warning if unsuccessful.
removeUnusedInputs-[removeUnusedInputs]Removes unused interpolator inputs from pixel shaders.
sampreg-[sampreg]Sets the ranges of pixel sampler and vertex sampler registers used by the compiler.
unroll-[unroll]Avoids flow control constructs.
unused-[unused]Suppresses warnings about unused shader parameters.
xps-[xps]Specifies that all vertex fetch operations are done after the last vfetch instruction. This instruction is used to reduce the latency back to the command processor to free the vertex buffer.
earlydepthstencil-[earlydepthstencil]Forces depth-stencil testing before a shader executes. Doesn't work with custom depth.

Interpolation Modifiers

UUSLOpenGLDirect3DDescription
MODIFER_LINEAR-linearInterpolate between shader inputs; linear is the default value if no interpolation modifier is specified.
MODIFER_CENTROID-centroidInterpolate between samples that are somewhere within the covered area of the pixel (this may require extrapolating end points from a pixel center). Centroid sampling may improve antialiasing if a pixel is partially covered (even if the pixel center is not covered). The centroid modifier must be combined with either the linear or noperspective modifier.
MODIFER_NOINTERPOLATION-nointerpolationDo not interpolate.
MODIFER_NOPERSPECTIVE-noperspectiveDo not perform perspective-correction during interpolation. The noperspective modifier can be combined with the centroid modifier.
MODIFER_SAMPLE-sampleInterpolate at sample location rather than at the pixel center. This causes the pixel shader to execute per-sample rather than per-pixel.

See Also

See also the article on Interpolation Modifiers.

Constants and Structs

In USSL structures is the way to organize the bunch of input and output data.

To start using structures in your shader code, use the following instructions:

UUSL
STRUCT(NAME)
	<your data>
END
Warning
You should add a new line (press Enter) after closing the instruction.
  • NAME - the name of the struct.

Here is an example of vertex shader input structure:

UUSL
// Input vertex data
STRUCT(VERTEX_IN)
	INIT_ATTRIBUTE(float4,0,POSITION)	// Vertex position
	INIT_ATTRIBUTE(float4,1,TEXCOORD0)	// Vertex texcoord (uv)
	INIT_ATTRIBUTE(float4,2,TEXCOORD1)	// Vertex basis tangent
	INIT_ATTRIBUTE(float4,3,TEXCOORD2)	// Vertex color
END
Warning
You should add a new line (press Enter) after closing the instruction.

After that, you should pass the VERTEX_IN structure to the main function of the vertex shader.

For using constant buffer in your shader code, use the following instructions:

UUSL
CBUFFER(NAME)
	<your data>
END
Warning
You should add a new line (press Enter) after closing the instruction.
  • NAME - the name of the cbuffer.

Here is an example of using constant buffer:

UUSL
CBUFFER(parameters)
	UNIFORM float grayscale_power;
END
Warning
You should add a new line (press Enter) after closing the instruction.

If you defined this parameter in the material, you'll be able to specify this value.

See Also

  • How we use CBUFFER instruction in the tutorial on shaders for post-process pass.

Shader Export

To export shader, use the following command:

UUSL
EXPORT_SHADER(FILE)
  • FILE - The name of the file.

This command exports the shader program into a file: for Direct3D the file will have an .hlsl extension, for OpenGL the file will have an .glsl extension.

The command expands all of the predefined UUSL syntax and creates shader files in native languages for both graphic APIs.

Common Intrinsic Functions

fmod (X, Y)

Returns the floating-point remainder of x/y.

Equivalents

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

Arguments

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

frac (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 - The specified value.

lerp (X, Y, value)

Performs a linear interpolation.

Equivalents

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

Arguments

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

lerpOne (float value, float factor)

Performs such interpolation:

Equivalents

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

Arguments

  • float value - Value.
  • float factor - Interpolation factor.

float length2 (float3 vector)

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

Arguments

  • float3 vector - Vector.

Return value

Calculated dot product.

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)

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

Equivalents

OpenGL
inversesqrt(value)
Direct3D
rsqrt(value)

Arguments

  • value - The specified value.

saturate (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 - The specified value.

ddx (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 - The specified value.

ddy (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 - The specified value.

rcp (value)

Calculates a fast, approximate, per-component reciprocal.

Equivalents

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

Arguments

  • value - The specified value.

equal (X, Y)

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

Equivalents

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

Arguments

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

greaterThan (X, Y)

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

Equivalents

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

Arguments

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

atan2 (X, Y)

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

Equivalents

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

Arguments

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

any (value)

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

Equivalents

OpenGL
(value)
Direct3D
any(value)

Arguments

  • value - The specified value.

float max2 (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 - The specified vector (can be float2, float3 or float4 vector).

Return value

The maximum value.

float max3 (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 - 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)

Selects the lesser of the first two vector components.

Equivalents

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

Arguments

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

Return value

The minimum value.

float min3 (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 - 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.

pow2 (value)

Returns squared value.

Equivalents

OpenGL
value * value
Direct3D
value * value

Arguments

  • value - The specified value to be powered (can be float, float2, float3 or float4.

Return value

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

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 (X, 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

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

lerpFixed (X, Y, 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

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

float4 getPosition (vertex)

Returns the projected position of the vertex.

Arguments

  • vertex - The first specified vertex (float4 or float3 type).

Return value

The projected position of the vertex.

float3 getViewDirection (screen_position)

Returns the view direction.
OpenGL
float3((position + s_perspective.zw) / s_perspective.xy,-1.0f);
Direct3D
float3((position + s_perspective.zw) / s_perspective.xy,-1.0f);

Arguments

  • screen_position - Position (float2, float3 or float3 type).

Return value

The view direction.

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.

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.

Fragment Shader Functions

SET_DEPTH (value)

Sets the depth value.

Arguments

  • value - Depth value.

SET_DIFFUSE (value)

Sets the volumetric value.

Arguments

  • value - Diffuse value.

SET_MICROFIBER (value)

Sets the microfiber value.

Arguments

  • value - Microfiber value.

SET_NORMAL (value)

Sets the normal value.

Arguments

  • value - Normal value.

SET_GLOSS (value)

Sets the gloss value.

Arguments

  • value - .

SET_SPECULAR (value)

Sets the specular value.

Arguments

  • value - .

SET_TRANSLUCENT (value)

Sets the translucent value.

Arguments

  • value - Translucent value.

SET_OCCLUSION (value)

Sets the occlusion value.

Arguments

  • value - Occlusion value.

SET_LIGHT_MAP (value)

Sets the lightmap.

Arguments

  • value - Lightmap value.

SET_DECAL_MASK (value)

Sets the decal mask.

Arguments

  • value - Decal mask value.

SET_VELOCITY (value)

Sets the velocity value.

Arguments

  • value - Velocity value.

SET_ALPHA (value)

Sets the velocity value.

Arguments

  • value - Velocity value.

float GET_DEFERRED_DEPTH (TEX_DEPTH, COORD)

Gets the deferred depth value.

Arguments

  • TEX_DEPTH - Depth texture slot.
  • COORD - UV coordinates.

float FETCH_DEFERRED_DEPTH (TEX_DEPTH, COORD)

Fetches the deferred depth value.

Arguments

  • TEX_DEPTH - Depth texture slot.
  • COORD - UV coordinates.

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.

float3 conserveEnergy (float3 diffuse, float4 specular, float dotVN)

Corrects diffuse with taking into account energy conservation.

Arguments

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

Return value

Corrected diffuse vector.

float2 getBRDF (float4 specular, float translucent_scale, float3 N, float3 L, float3 V)

Calculates BRDF.

Arguments

  • float4 specular - Specular value.
  • float translucent_scale - Translucent scale value.
  • float3 N - Normal vector.
  • float3 L - Direction vector to light source.
  • float3 V - Direction vector to camera.

float2 getBRDF (float gloss, float F0, float translucent_scale, float dotNV, float dotVH, float dotNL, float dotNH, float dotVL)

Calculates BRDF.

Arguments

  • float gloss - Gloss value.
  • float F0 - Reflectance for H·V = 1.
  • float translucent_scale - Translucent scale 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 dotNH - Dot product of 2 vectors: normal vector and normalized halfway vector (H = (V + L) / |V + L|).
  • float dotVL - Dot product of 2 vectors: vector to camera and vector to light source.

float2 getBRDF (float gloss, float F0, float translucent_scale, float3 N, float3 L, float3 V)

Calculates BRDF.

Arguments

  • float gloss - Gloss value.
  • float F0 - Reflectance for H·V = 1.
  • float translucent_scale - Translucent scale value.
  • float3 N - Normal vector.
  • float3 L - Direction vector to light source.
  • float3 V - Direction vector to camera.

float getFresnelSchlick (float3 F0, float3 dotLH)

Calculates Fresnel factor (Schlick's approximation).

Arguments

  • float3 F0 - Reflectance for H·V = 1.
  • 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 getLightAttenuation (float3 position)

Calculates Light Attenuation by position.

Arguments

  • float3 position - Position value.

float getLightAttenuation (float light_distance)

Calculates Light Attenuation by distance.

Arguments

  • float light_distance - Light Distance value.

float getBarley12 (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 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)

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.

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: 2017-07-03
Build: ()