module
CrShader::Language::Functions
Overview
Built-in mathematical, geometric, matrix, texture, compute, and standard library functions.
Mirrored directly from the Godot Engine 4.8 Shading Language specification. All methods transpile 1:1 to hardware-accelerated GPU intrinsic operations.
Extended Modules
Direct including types
Defined in:
crshader/language/functions.crInstance Method Summary
-
#abs(x : Float32) : Float32
Returns the absolute value of
x. -
#aces_tonemap(x : Types::Vec3) : Types::Vec3
Standard library: Filmic ACES tonemapping curve for HDR to LDR display.
-
#acos(x : Float32) : Float32
Returns the arccosine of
xin radians in range[0, PI]. -
#adjust_contrast(c : Types::Vec3, contrast : Float32) : Types::Vec3
Standard library: Adjusts contrast of an RGB color around midpoint 0.5.
-
#adjust_saturation(c : Types::Vec3, saturation : Float32) : Types::Vec3
Standard library: Adjusts saturation of an RGB color.
-
#asin(x : Float32) : Float32
Returns the arcsine of
xin radians in range[-PI/2, PI/2]. -
#atan(y : Float32, x : Float32) : Float32
Returns the arctangent of
y/xin radians in range[-PI, PI]. -
#atan(y_over_x : Float32) : Float32
Returns the arctangent of
y_over_xin radians in range[-PI/2, PI/2]. -
#barrel_distortion(uv : Types::Vec2, k : Float32) : Types::Vec2
Standard library: Lens barrel / pincushion distortion for UV coordinate.
-
#blinn_phong(normal : Types::Vec3, light_dir : Types::Vec3, view_dir : Types::Vec3, shininess : Float32) : Float32
Standard library: Calculates Blinn-Phong specular highlight lobe.
-
#ceil(x : Float32) : Float32
Returns the smallest integer greater than or equal to
x. -
#cel_shade(n_dot_l : Float32, steps : Float32 = 3.0_f32) : Float32
Standard library: Quantizes lighting dot product into discrete cel/toon shading bands.
-
#clamp(x : Float32, min_val : Float32, max_val : Float32) : Float32
Clamps
xto range[min_val, max_val]. -
#cos(x : Float32) : Float32
Returns the cosine of
x(in radians). -
#cross(a : Types::Vec3, b : Types::Vec3) : Types::Vec3
Returns 3D cross product:
a x b. -
#degrees(rad : Float32) : Float32
Converts radians to degrees:
rad * (180.0 / PI). -
#determinant(m : Types::Mat3 | Types::Mat4) : Float32
Calculates scalar determinant of matrix
m. -
#distance(p0 : Types::Vec2 | Types::Vec3, p1 : Types::Vec2 | Types::Vec3) : Float32
Returns Euclidean distance between points
p0andp1:#length(p0 - p1). -
#dot(a : Types::Vec2, b : Types::Vec2) : Float32
Returns scalar dot product:
sum(a[i] * b[i]). - #dot(a : Types::Vec3, b : Types::Vec3) : Float32
- #dot(a : Types::Vec4, b : Types::Vec4) : Float32
-
#exp(x : Float32) : Float32
Returns natural exponential of
x(e^x). -
#exp2(x : Float32) : Float32
Returns base-2 exponential of
x(2^x). -
#faceforward(n : Types::Vec3, i : Types::Vec3, nref : Types::Vec3) : Types::Vec3
Orients vector
nto face away from a surface based on incident vectoriand reference normalnref. -
#fbm(p : Types::Vec2, octaves : Int32 = 4) : Float32
Standard library: Multi-octave Fractal Brownian Motion (FBM) noise.
-
#floor(x : Float32) : Float32
Returns the largest integer less than or equal to
x. -
#fract(x : Float32) : Float32
Returns the fractional part of
x:x - floor(x). -
#fresnel(power : Float32, normal : Types::Vec3, view : Types::Vec3) : Float32
Standard library: Computes power-law Fresnel reflection factor for view vector against surface normal.
-
#grayscale(c : Types::Vec3) : Float32
Standard library: Converts RGB color vector to scalar grayscale luminance.
-
#groupMemoryBarrier : Nil
Workgroup-wide execution and shared memory synchronization barrier.
-
#hash11(p : Float32) : Float32
Standard library: 1D -> 1D pseudo-random hash without texture lookups.
-
#hash12(p : Float32) : Types::Vec2
Standard library: 1D -> 2D pseudo-random hash.
-
#hash21(p : Types::Vec2) : Float32
Standard library: 2D -> 1D pseudo-random hash.
-
#hash22(p : Types::Vec2) : Types::Vec2
Standard library: 2D -> 2D pseudo-random hash.
-
#hash31(p : Types::Vec3) : Float32
Standard library: 3D -> 1D pseudo-random hash.
-
#hash33(p : Types::Vec3) : Types::Vec3
Standard library: 3D -> 3D pseudo-random hash.
-
#hsv2rgb(c : Types::Vec3) : Types::Vec3
Standard library: Converts HSV color vector to RGB.
-
#imageLoad(image : Symbol | String, coord : Types::IVec2) : Types::Vec4
Direct image fetch from a compute storage image binding at pixel coordinate
coord. -
#imageSize(image : Symbol | String) : Types::IVec2
Returns dimensions of storage image binding as
#ivec2(width, height). -
#imageStore(image : Symbol | String, coord : Types::IVec2, color : Types::Vec4) : Nil
Direct image write into a compute storage image binding at pixel coordinate
coord. -
#inverse(m : Types::Mat3) : Types::Mat3
Calculates inverse matrix of
m. - #inverse(m : Types::Mat4) : Types::Mat4
-
#inversesqrt(x : Float32) : Float32
Returns inverse square root of
x(1.0 / sqrt(x)). -
#ivec2(x : Int32 = 0, y : Int32 = 0) : Types::IVec2
Shorthand constructor for 2-component integer vector:
#ivec2(x, y). - #ivec2(v2 : Types::Vec2) : Types::IVec2
-
#ivec3(x : Int32 = 0, y : Int32 = 0, z : Int32 = 0) : Types::IVec3
Shorthand constructor for 3-component integer vector:
#ivec3(x, y, z). -
#ivec4(x : Int32 = 0, y : Int32 = 0, z : Int32 = 0, w : Int32 = 0) : Types::IVec4
Shorthand constructor for 4-component integer vector:
#ivec4(x, y, z, w). -
#length(v : Types::Vec2 | Types::Vec3 | Types::Vec4) : Float32
Returns vector magnitude / length:
sqrt(dot(v, v)). -
#lerp(a : Float32, b : Float32, t : Float32) : Float32
Standard library: Linear interpolation alias for
#mix. -
#linear_depth(depth : Float32, inv_proj : Types::Mat4) : Float32
Standard library: Linearizes non-linear screen depth buffer sample to camera-space distance.
-
#log(x : Float32) : Float32
Returns natural logarithm of
x(ln(x)). -
#log2(x : Float32) : Float32
Returns base-2 logarithm of
x(log2(x)). -
#luminance(col : Types::Vec3) : Float32
Standard library: Calculates perceptual luminance from RGB color using ITU-R BT.709 weights.
-
#mat2(col0 : Types::Vec2, col1 : Types::Vec2) : Types::Mat2
Shorthand constructor for 2x2 matrix.
-
#mat3(col0 : Types::Vec3, col1 : Types::Vec3, col2 : Types::Vec3) : Types::Mat3
Shorthand constructor for 3x3 matrix.
-
#mat4(col0 : Types::Vec4, col1 : Types::Vec4, col2 : Types::Vec4, col3 : Types::Vec4) : Types::Mat4
Shorthand constructor for 4x4 matrix.
-
#max(a : Float32, b : Float32) : Float32
Returns the maximum of
aandb. -
#memoryBarrier : Nil
Memory barrier ensuring global memory writes complete across all invocations.
-
#memoryBarrierImage : Nil
Memory barrier ensuring storage image writes complete.
-
#memoryBarrierShared : Nil
Memory barrier ensuring workgroup shared memory writes complete.
-
#min(a : Float32, b : Float32) : Float32
Returns the minimum of
aandb. -
#mix(x : Float32, y : Float32, a : Float32) : Float32
Linear interpolation between
xandyusing weighta:x * (1 - a) + y * a. - #mix(x : Types::Vec2, y : Types::Vec2, a : Float32) : Types::Vec2
- #mix(x : Types::Vec3, y : Types::Vec3, a : Float32) : Types::Vec3
- #mix(x : Types::Vec4, y : Types::Vec4, a : Float32) : Types::Vec4
- #mix(x : Types::Vec3, y : Types::Vec3, a : Types::Vec3) : Types::Vec3
-
#mod(x : Float32, y : Float32) : Float32
Returns
xmoduloy:x - y * floor(x / y). -
#normalize(v : Types::Vec2) : Types::Vec2
Returns vector
vscaled to unit length:v / length(v). - #normalize(v : Types::Vec3) : Types::Vec3
- #normalize(v : Types::Vec4) : Types::Vec4
-
#pow(x : Float32, y : Float32) : Float32
Returns
xraised to powery(x^y). -
#radians(deg : Float32) : Float32
Converts degrees to radians:
deg * (PI / 180.0). -
#rand(uv : Types::Vec2) : Float32
Standard library: Fast pseudo-random number generator for UV coordinates.
-
#reflect(i : Types::Vec3, n : Types::Vec3) : Types::Vec3
Calculates reflection vector for incident
iagainst surface normaln:i - 2.0 * dot(n, i) * n. -
#refract(i : Types::Vec3, n : Types::Vec3, eta : Float32) : Types::Vec3
Calculates refraction vector for incident
ithrough normalnwith refraction index ratioeta. -
#reinhard_tonemap(x : Types::Vec3) : Types::Vec3
Standard library: Reinhard tonemapping curve:
x / (1.0 + x). -
#remap(val : Float32, in_min : Float32, in_max : Float32, out_min : Float32, out_max : Float32) : Float32
Standard library: Remaps value from input range
[in_min, in_max]to output range[out_min, out_max]. -
#rgb2hsv(c : Types::Vec3) : Types::Vec3
Standard library: Converts RGB color vector to HSV.
-
#rotate_2d(p : Types::Vec2, angle : Float32) : Types::Vec2
Standard library: Rotates a 2D vector by
angleradians. -
#round(x : Float32) : Float32
Returns
xrounded to the nearest integer. -
#saturate(x : Float32) : Float32
Standard library: Clamps value between 0.0 and 1.0.
-
#sdf_box(p : Types::Vec3, b : Types::Vec3) : Float32
Standard library: Signed distance field calculation for a 3D box of half-extents
b. -
#sdf_sphere(p : Types::Vec3, radius : Float32) : Float32
Standard library: Signed distance field calculation for a sphere of
radius. -
#sign(x : Float32) : Float32
Returns 1.0 if
x > 0, 0.0 ifx == 0, and -1.0 ifx < 0. -
#simplex_noise_2d(p : Types::Vec2) : Float32
Standard library: Smooth 2D simplex noise gradient.
-
#sin(x : Float32) : Float32
Returns the sine of
x(in radians). -
#smax(a : Float32, b : Float32, k : Float32 = 0.1_f32) : Float32
Standard library: Polynomial smooth maximum for carving SDF surfaces.
-
#smin(a : Float32, b : Float32, k : Float32 = 0.1_f32) : Float32
Standard library: Polynomial smooth minimum for blending SDF surfaces.
-
#smoothstep(edge0 : Float32, edge1 : Float32, x : Float32) : Float32
Smooth Hermite interpolation between 0.0 and 1.0 when
edge0 < x < edge1. -
#sqrt(x : Float32) : Float32
Returns square root of
x. -
#step(edge : Float32, x : Float32) : Float32
Returns 0.0 if
x < edge, otherwise 1.0. -
#tan(x : Float32) : Float32
Returns the tangent of
x(in radians). -
#texelFetch(sampler : Types::Sampler2D, coord : Types::IVec2, lod : Int32 = 0) : Types::Vec4
Fetches texel at integer pixel coordinates
coordwithout bilinear filtering. -
#texture(sampler : Types::Sampler2D, uv : Types::Vec2) : Types::Vec4
Samples texture
samplerat normalized coordinatesuv, returning an RGBA vector. -
#textureLod(sampler : Types::Sampler2D, uv : Types::Vec2, lod : Float32) : Types::Vec4
Samples texture
samplerat normalized coordinatesuvwith explicit level-of-detaillod. -
#textureSize(sampler : Types::Sampler2D, lod : Int32 = 0) : Types::IVec2
Returns texture dimensions as
#ivec2(width, height)at mipmap levellod. -
#transpose(m : Types::Mat3) : Types::Mat3
Transposes matrix
m. - #transpose(m : Types::Mat4) : Types::Mat4
-
#triplanar_weights(normal : Types::Vec3) : Types::Vec3
Standard library: Computes blend weights for seamless triplanar texture mapping.
-
#trunc(x : Float32) : Float32
Returns
xtruncated towards zero. -
#uvec2(x : UInt32 = 0_u32, y : UInt32 = 0_u32) : Types::UVec2
Shorthand constructor for 2-component unsigned integer vector:
#uvec2(x, y). -
#uvec3(x : UInt32 = 0_u32, y : UInt32 = 0_u32, z : UInt32 = 0_u32) : Types::UVec3
Shorthand constructor for 3-component unsigned integer vector:
#uvec3(x, y, z). -
#uvec4(x : UInt32 = 0_u32, y : UInt32 = 0_u32, z : UInt32 = 0_u32, w : UInt32 = 0_u32) : Types::UVec4
Shorthand constructor for 4-component unsigned integer vector:
#uvec4(x, y, z, w). -
#value_noise(p : Types::Vec2) : Float32
Standard library: Smooth 2D value noise interpolation.
-
#vec2(x : Float32 = 0.0_f32, y : Float32 = 0.0_f32) : Types::Vec2
Shorthand constructor for 2-component vector:
#vec2(x, y). - #vec2(x : Number, y : Number) : Types::Vec2
-
#vec3(x : Float32 = 0.0_f32, y : Float32 = 0.0_f32, z : Float32 = 0.0_f32) : Types::Vec3
Shorthand constructor for 3-component vector:
#vec3(x, y, z). - #vec3(x : Number, y : Number, z : Number) : Types::Vec3
-
#vec4(x : Float32 = 0.0_f32, y : Float32 = 0.0_f32, z : Float32 = 0.0_f32, w : Float32 = 1.0_f32) : Types::Vec4
Shorthand constructor for 4-component vector:
#vec4(x, y, z, w). - #vec4(x : Number, y : Number, z : Number, w : Number = 1.0) : Types::Vec4
- #vec4(v3 : Types::Vec3, w : Float32 = 1.0_f32) : Types::Vec4
- #vec4(val : Float32 | Number) : Types::Vec4
-
#vignette(uv : Types::Vec2, radius : Float32 = 0.75_f32, softness : Float32 = 0.45_f32) : Float32
Standard library: Smooth radial vignette factor between 0.0 (edge) and 1.0 (center).
-
#voronoi(p : Types::Vec2) : Float32
Standard library: Cellular Voronoi distance calculation.
Instance Method Detail
Standard library: Filmic ACES tonemapping curve for HDR to LDR display.
Standard library: Adjusts contrast of an RGB color around midpoint 0.5.
Standard library: Adjusts saturation of an RGB color.
Returns the arctangent of y/x in radians in range [-PI, PI].
Returns the arctangent of y_over_x in radians in range [-PI/2, PI/2].
Standard library: Lens barrel / pincushion distortion for UV coordinate.
Standard library: Calculates Blinn-Phong specular highlight lobe.
Standard library: Quantizes lighting dot product into discrete cel/toon shading bands.
Clamps x to range [min_val, max_val].
Calculates scalar determinant of matrix m.
Orients vector n to face away from a surface based on incident vector i and reference normal nref.
Standard library: Multi-octave Fractal Brownian Motion (FBM) noise.
Standard library: Computes power-law Fresnel reflection factor for view vector against surface normal.
Standard library: Converts RGB color vector to scalar grayscale luminance.
Standard library: 1D -> 1D pseudo-random hash without texture lookups.
Direct image fetch from a compute storage image binding at pixel coordinate coord.
Returns dimensions of storage image binding as #ivec2(width, height).
Direct image write into a compute storage image binding at pixel coordinate coord.
Returns vector magnitude / length: sqrt(dot(v, v)).
Standard library: Linear interpolation alias for #mix.
Standard library: Linearizes non-linear screen depth buffer sample to camera-space distance.
Standard library: Calculates perceptual luminance from RGB color using ITU-R BT.709 weights.
Shorthand constructor for 2x2 matrix.
Shorthand constructor for 3x3 matrix.
Shorthand constructor for 4x4 matrix.
Memory barrier ensuring global memory writes complete across all invocations.
Linear interpolation between x and y using weight a: x * (1 - a) + y * a.
Returns vector v scaled to unit length: v / length(v).
Standard library: Fast pseudo-random number generator for UV coordinates.
Calculates reflection vector for incident i against surface normal n: i - 2.0 * dot(n, i) * n.
Calculates refraction vector for incident i through normal n with refraction index ratio eta.
Standard library: Reinhard tonemapping curve: x / (1.0 + x).
Standard library: Remaps value from input range [in_min, in_max] to output range [out_min, out_max].
Standard library: Rotates a 2D vector by angle radians.
Standard library: Signed distance field calculation for a 3D box of half-extents b.
Standard library: Signed distance field calculation for a sphere of radius.
Standard library: Smooth 2D simplex noise gradient.
Standard library: Polynomial smooth maximum for carving SDF surfaces.
Standard library: Polynomial smooth minimum for blending SDF surfaces.
Smooth Hermite interpolation between 0.0 and 1.0 when edge0 < x < edge1.
Fetches texel at integer pixel coordinates coord without bilinear filtering.
Samples texture sampler at normalized coordinates uv, returning an RGBA vector.
Samples texture sampler at normalized coordinates uv with explicit level-of-detail lod.
Standard library: Computes blend weights for seamless triplanar texture mapping.
Shorthand constructor for 4-component unsigned integer vector: #uvec4(x, y, z, w).
Shorthand constructor for 4-component vector: #vec4(x, y, z, w).
Standard library: Smooth radial vignette factor between 0.0 (edge) and 1.0 (center).