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.
#include <core/shaders/common/common.h>
For fragment shader features, use the core/shaders/common/fragment.h file.
Common Intrinsic Functions
overlay(value A, value B, value BLEND)
Performs overlay A over B with blending coefficient.Equivalents
saturate(A * lerp(float4_one * 0.5f,B,BLEND) * 2)
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
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.
value lerpOne(value value, float factor)
Performs such interpolation:Equivalents
value * (1.0f - factor) + factor;
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 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 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
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
pow(value,float_isrgb);
Arguments
- float value - Value to convert.
Return value
Inversed sRGB value.float2 srgbInv(float2 value)
Performs the following operation:Implementation
pow(value,float2_isrgb);
Arguments
- float2 value - Value to convert.
Return value
Inversed sRGB value.float3 srgbInv(float3 value)
Performs the following operation:Implementation
pow(value,float3_isrgb);
Arguments
- float3 value - Value to convert.
Return value
Inversed sRGB value.float4 srgbInv(float4 value)
Performs the following operation:Implementation
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
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.
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.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.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))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
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. 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
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
In case of float3 or float4 vectors, vector.xyvalues 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.// 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
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
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
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
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.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.
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
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
- GBuffer gbuffer - GBuffer struct
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.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 BRDFArguments
- 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
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:
#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.