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.
#include <core/shaders/common/common.h>
For fragment shader functions, use the core/shaders/common/fragment.h file.
Data Types
UUSL | OpenGL | Direct3D | Description |
---|---|---|---|
int2 | ivec2 | int2 | A vector with two 32-bit signed integer components. |
int3 | ivec3 | int3 | A vector with three 32-bit signed integer components. |
int4 | ivec4 | int4 | A vector with four 32-bit signed integer components. |
uint2 | uvec4 | int2 | A vector with two 32-bit unsigned integer components. |
uint3 | uvec4 | uint3 | A vector with three 32-bit unsigned integer components. |
uint4 | uvec4 | uint4 | A vector with four 32-bit unsigned integer components. |
float | float | float | A 32-bit floating point value. |
float2 | vec2 | float2 | A vector with two 32-bit floating point value components. |
float3 | vec3 | float3 | A vector with three 32-bit floating point value components. |
float4 | vec4 | float4 | A vector with four 32-bit floating point value components. |
float2x2 | mat2 | float2x2 | A matrix with 2 rows, 2 column of 32-bit floating point value components. |
float3x3 | mat3 | float3x3 | A matrix with 3 rows, 3 column of 32-bit floating point value components. |
float4x4 | mat4 | float4x4 | A matrix with 4 rows, 4 column of 32-bit floating point value components. |
UUSL | OpenGL | Direct3D | Description |
---|---|---|---|
TYPE_R | float | float | A 32-bit floating point value. |
TYPE_RG | float2 | float2 | A vector with two 32-bit floating point value components. |
TYPE_RGB | float3 | float3 | A vector with three 32-bit floating point value components. |
TYPE_RGBA | float4 | float4 | A vector with four 32-bit floating point value components. |
UUSL | OpenGL | Direct3D | Description |
---|---|---|---|
FLOAT(X) | float(X) | X | Converts the value to float. |
FLOAT2(X) | vec2(X) | X | Converts the value to the two-component vector. |
FLOAT3(X) | vec3(X) | X | Converts the value to the three-component vector. |
FLOAT4(X) | vec4(X) | X | Converts the value to the four-component vector. |
INT(X) | int(X) | X | Converts the value to int. |
INT2(X) | int2(X) | X | Converts the value to the two component vector. |
INT3(X) | int3(X) | X | Converts the value to the three-component vector. |
INT4(X) | int4(X) | X | Converts the value to the three-component vector. |
BOOL2(X) | bvec2(X) | X | Converts the value to the two component boolean vector. |
BOOL3(X) | bvec3(X) | X | Converts the value to the three-component boolean vector. |
BOOL4(X) | bvec4(X) | X | Converts the value to the three-component boolean vector. |
Predefined Values
UUSL | Value |
---|---|
float_isrgb | 2.233333f |
float4_zero | float4(0.0f,0.0f,0.0f,0.0f) |
float4_one | float4(1.0f,1.0f,1.0f,1.0f) |
float4_neg_one | float4(-1.0f,-1.0f,-1.0f,-1.0f) |
float4_isrgb | float4(float_isrgb,float_isrgb,float_isrgb,float_isrgb) |
float3_zero | float3(0.0f,0.0f,0.0f) |
float3_one | float3(1.0f,1.0f,1.0f) |
float3_neg_one | float3(-1.0f,-1.0f,-1.0f) |
float3_up | float3(0.0f,0.0f,1.0f) |
float3_isrgb | float3float_isrgb,float_isrgb,float_isrgb) |
float2_zero | float3(2.2f,2.2f,2.2f) |
float2_one | float2(1.0f,1.0f) |
float2_neg_one | float2(-1.0f,-1.0f) |
float2_isrgb | float2(float_isrgb,float_isrgb) |
int4_zero | int4(0,0,0,0) |
int4_one | int4(1,1,1,1) |
int4_neg_one | int4(-1,-1,-1,-1) |
int3_zero | int3(0,0,0) |
int3_one | int3(1,1,1) |
int3_neg_one | int3(-1,-1,-1) |
int2_zero | int2(0,0) |
int2_one | int2(1,1) |
int2_neg_one | int2(-1,-1) |
PI | 3.141592654f |
PI2 | 6.283185308f |
PI05 | 1.570796327f |
LOG2 | 0.693147181f |
LOG10 | 2.302585093f |
SQRT2 | 1.414213562f |
EPSILON | 1e-6f |
INFINITY | 1e+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:
MAIN_VOID_BEGIN(STRUCT_IN)
<your code here>
MAIN_VOID_END
This code is equivalent to:
void main() {
<your code here>
}
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:
MAIN_BEGIN(STRUCT_IN,STRUCT_OUT)
<your code here>
MAIN_END
This code is equivalent to:
void main() {
<your code here>
}
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:
MAIN_GEOM_BEGIN(STRUCT_OUT,STRUCT_IN)
<your code here>
END_GEOM
This code is equivalent to:
layout(TYPE_GEOM_IN) in;
layout(TYPE_GEOM_OUT,max_vertices = MAX_VERTICES_GEOM) out;
void main() {
<your code here>
}
[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:
STATICVAR <your var>
This is equal to the following GLSL and HLSL commands:
const <your var>
static const <your var>
Static Arrays
To work with static arrays by using UUSL, use the following instructions:
STATICARRAY(TYPE,NAME,SIZE)
<your array members>
ENDARRAY
- 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:
TYPE NAME [SIZE] = TYPE[](<your array members>);
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 type | UUSL |
---|---|
BLEND_SRC_FUNC_SRC_ALPHA && BLEND_DEST_FUNC_ONE_MINUS_SRC_ALPHA | BLEND_ALPHABLEND |
BLEND_SRC_FUNC_ONE && BLEND_DEST_FUNC_ONE | BLEND_ADDITIVE |
BLEND_SRC_FUNC_DEST_COLOR && BLEND_DEST_FUNC_ZERO | BLEND_MULTIPLICATIVE |
BLEND_SRC_FUNC_NONE && BLEND_DEST_FUNC_NONE | BLEND_NONE |
HLSL features
HLSL Flow Control Attributes
UUSL | OpenGL | Direct3D | Description |
---|---|---|---|
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
UUSL | OpenGL | Direct3D | Description |
---|---|---|---|
MODIFER_LINEAR | - | linear | Interpolate between shader inputs; linear is the default value if no interpolation modifier is specified. |
MODIFER_CENTROID | - | centroid | Interpolate 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 | - | nointerpolation | Do not interpolate. |
MODIFER_NOPERSPECTIVE | - | noperspective | Do not perform perspective-correction during interpolation. The noperspective modifier can be combined with the centroid modifier. |
MODIFER_SAMPLE | - | sample | Interpolate 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:
STRUCT(NAME)
<your data>
END
- NAME - the name of the struct.
Here is an example of vertex shader input structure:
// 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
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:
CBUFFER(NAME)
<your data>
END
- NAME - the name of the cbuffer.
Here is an example of using constant buffer:
CBUFFER(parameters)
UNIFORM float grayscale_power;
END
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:
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 (value X, value Y)
Returns the floating-point remainder of x/y.Equivalents
mod(X,Y)
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
fract(value)
frac(value)
Arguments
- value value - The specified value.
lerp (value X, value Y, value value)
Performs a linear interpolation.Equivalents
mix(X,Y,value)
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.
lerpOne (float value, float factor)
Performs such interpolation:Equivalents
value * (1.0f - factor) + factor;
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
m[0];
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
m[0].xyz;
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
m[1];
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
m[1].xyz;
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
m[2];
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
m[2].xyz;
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
inversesqrt(value)
rsqrt(value)
Arguments
- value value - The specified value.
saturate (value value)
Clamps the specified value within the range of 0 to 1.Equivalents
clamp(value,0.0f,1.0f)
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
dFdx(value)
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
dFdy(value)
ddy(value)
Arguments
- value value - The specified value.
rcp (value value)
Calculates a fast, approximate, per-component reciprocal.Equivalents
(1.0f / (value))
rcp(value)
Arguments
- value value - The specified value.
equal (value X, value Y)
Performs a component-wise equal-to comparison of two vectors.Equivalents
equal(X,Y)
(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
greaterThan(X,Y)
(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
atan(X,Y)
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
(value)
any(value)
Arguments
- value value - The specified value.
float max2 (value value)
Selects the greater of the first two vector components.Equivalents
max(value.r,value.g)
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
max(max(value.r,value.g),value.b)
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
max(max(max(value.r,value.g),value.b),value.a)
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
min(value.r,value.g)
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
min(min(value.r,value.g),value.b)
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
min(min(min(value.r,value.g),value.b),value.a)
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
value * value
value * value
Arguments
- value 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
frac(sin(dot(seed,float2(12.9898f,78.233f))) * 43758.5453f)
frac(sin(dot(seed,float2(12.9898f,78.233f))) * 43758.5453f)
Arguments
- float2 seed - The random seed.
Return value
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.
Return value
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.
Return value
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).
Return value
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).
Return value
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).
Return value
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).
Return value
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).
Return value
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).
Return value
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.Arguments
- float2 seed_0 - The first random seed.
- flaot tiled - The seed of tiling (the number should be the power of two).
Return value
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.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).
Return value
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))Arguments
- float2 seed - The random seed.
- float tiled - The seed of tiling (the number should be the power of two).
Return value
dotFixed (value X, value Y)
Returns the dot product of two vectors within the range of 0 to 1.Equivalents
saturate(dot(X,Y))
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
lerp(X,Y,saturate(FACTOR))
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 (float4 or float3 type).
Return value
The projected position of the vertex.float3 getViewDirection (value screen_position)
Returns the view direction.float3((position + s_perspective.zw) / s_perspective.xy,-1.0f);
float3((position + s_perspective.zw) / s_perspective.xy,-1.0f);
Arguments
- value 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.// 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.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.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.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.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.(m * float4(v,1.0f)).xyz;
(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.float4(dot(row_0,v),dot(row_1,v),dot(row_2,v),v.w);
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.
Return value
float2 floatPack16To88 (float value)
Unpacks R16 into RG8.Arguments
- float value - Value to pack.
Return value
float2 floatPack8888To1616 (float4 value)
Packs normalized RGBA8 into R16G16.Arguments
- float4 value - Value to pack.
Return value
float4 floatPack1616To8888 (float2 value)
Unpacks R16G16 into RGBA8.Arguments
- float2 value - Value to pack.
Return value
float3 floatPack1212To888 (float2 value)
Packs RG12 to RGB8.Arguments
- float2 value - Value to pack.
Return value
float2 floatPack888To1212 (float3 value)
Packs RGB8 to RG12.Arguments
- float3 value - Value to pack.
Return value
Fragment Shader Functions
SET_DEPTH (value value)
Sets the depth value.Arguments
- value value - Depth value.
SET_DIFFUSE (value value)
Sets the volumetric value.Arguments
- value value - Diffuse value.
SET_MICROFIBER (value value)
Sets the microfiber value.Arguments
- value value - Microfiber value.
SET_NORMAL (value value)
Sets the normal value.Arguments
- value value - Normal value.
SET_GLOSS (value value)
Sets the gloss value.Arguments
- value value - Gloss value.
SET_SPECULAR (value value)
Sets the specular value.Arguments
- value value - Specular value.
SET_TRANSLUCENT (value value)
Sets the translucent value.Arguments
- value value - Translucent value.
SET_OCCLUSION (value value)
Sets the occlusion value.Arguments
- value value - Occlusion value.
SET_LIGHT_MAP (value value)
Sets the lightmap.Arguments
- value value - Lightmap value.
SET_DECAL_MASK (value value)
Sets the decal mask.Arguments
- value value - Decal mask value.
SET_VELOCITY (value value)
Sets the velocity value.Arguments
- value value - Velocity value.
SET_ALPHA (value value)
Sets the alpha value.Arguments
- value value - Alpha value.
float GET_DEFERRED_DEPTH (value TEX_DEPTH, value COORD)
Gets the deferred depth value.Arguments
- value TEX_DEPTH - Depth texture slot.
- value COORD - UV coordinates.
Return value
float FETCH_DEFERRED_DEPTH (value TEX_DEPTH, value COORD)
Fetches the deferred depth value.Arguments
- value TEX_DEPTH - Depth texture slot.
- value COORD - UV coordinates.
Return value
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
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.
Return value
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.
Return value
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.
Return value
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|).
Return value
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|).
Return value
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.
Return 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.
Return value
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.
Return 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.
Return 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.
Return value
float getLightAttenuation (float3 position)
Calculates Light Attenuation by 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.float getBarley12 (float roughness, float dotNV, float dotVH, float dotNL)
Calculates diffuse 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.
Return value
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.
Return value
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.
Return value
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.
Return value
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.
Return value
Scattering Functions
Here is an example of scattering functions usage:
#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.