Functions

shade.Functions (extern class)

Static Members

texture(sampler: Sampler2D, coord: Vec2): Vec4

Samples a texture at the given coordinate.

Name Type Description
sampler Sampler2D The texture sampler to read from
coord Vec2 The texture coordinates (0.0 to 1.0 range typically)
Returns Description
Vec4 The color value at the sampled location as a Vec4 (RGBA)

dFdx(p: Float): Float

Returns the partial derivative of p with respect to the window x coordinate. Only available in fragment shaders. Useful for computing rates of change for anti-aliasing.

Name Type
p Float
Returns
Float

dFdy(p: Float): Float

Returns the partial derivative of p with respect to the window y coordinate. Only available in fragment shaders. Useful for computing rates of change for anti-aliasing.

Name Type
p Float
Returns
Float

fwidth(p: Float): Float

Returns the sum of the absolute values of derivatives in x and y. Equivalent to abs(dFdx(p)) + abs(dFdy(p)). Useful for determining how fast a value is changing for anti-aliasing purposes.

Name Type
p Float
Returns
Float

discard(): Void

Discards the current fragment. The fragment will not be written to the framebuffer. Only available in fragment shaders. Cannot be called conditionally in all implementations.


float(x: Int): Float

Get a float value from an int.

Name Type
x Int
Returns
Float

vec2(x: Float, y: Float): Vec2

Constructs a 2-component vector from individual x and y values.

Name Type
x Float
y Float
Returns
Vec2

vec3(x: Float, y: Float, z: Float): Vec3

Constructs a 3-component vector from individual x, y, and z values.

Name Type
x Float
y Float
z Float
Returns
Vec3

vec4(x: Float, y: Float, z: Float, w: Float): Vec4

Constructs a 4-component vector from individual x, y, z, and w values.

Name Type
x Float
y Float
z Float
w Float
Returns
Vec4

mat2(v: Float): Mat2

Constructs a 2x2 diagonal matrix with the specified value on the diagonal.

Name Type
v Float
Returns
Mat2

mat3(v: Float): Mat3

Constructs a 3x3 diagonal matrix with the specified value on the diagonal.

Name Type
v Float
Returns
Mat3

mat4(v: Float): Mat4

Constructs a 4x4 diagonal matrix with the specified value on the diagonal.

Name Type
v Float
Returns
Mat4

radians(degrees: Float): Float

Converts degrees to radians. Returns (π/180) * degrees.

Name Type
degrees Float
Returns
Float

degrees(radians: Float): Float

Converts radians to degrees. Returns (180/π) * radians.

Name Type
radians Float
Returns
Float

sin(angle: Float): Float

Returns the sine of the angle (in radians).

Name Type
angle Float
Returns
Float

cos(angle: Float): Float

Returns the cosine of the angle (in radians).

Name Type
angle Float
Returns
Float

tan(angle: Float): Float

Returns the tangent of the angle (in radians).

Name Type
angle Float
Returns
Float

asin(x: Float): Float

Returns the arc sine (inverse sine) of x. The result is in radians, in the range [-π/2, π/2].

Name Type
x Float
Returns
Float

acos(x: Float): Float

Returns the arc cosine (inverse cosine) of x. The result is in radians, in the range [0, π].

Name Type
x Float
Returns
Float

atan(yOverX: Float): Float

Returns the arc tangent of y/x. The result is in radians, in the range [-π/2, π/2].

Name Type
yOverX Float
Returns
Float

pow(x: Float, y: Float): Float

Returns x raised to the power y (x^y).

Name Type
x Float
y Float
Returns
Float

exp(x: Float): Float

Returns the natural exponentiation of x (e^x).

Name Type
x Float
Returns
Float

log(x: Float): Float

Returns the natural logarithm of x (ln(x)). Results are undefined if x <= 0.

Name Type
x Float
Returns
Float

exp2(x: Float): Float

Returns 2 raised to the power x (2^x).

Name Type
x Float
Returns
Float

log2(x: Float): Float

Returns the base-2 logarithm of x (log₂(x)). Results are undefined if x <= 0.

Name Type
x Float
Returns
Float

sqrt(x: Float): Float

Returns the square root of x. Results are undefined if x < 0.

Name Type
x Float
Returns
Float

inversesqrt(x: Float): Float

Returns the inverse square root of x (1/√x). Results are undefined if x <= 0.

Name Type
x Float
Returns
Float

abs(x: Float): Float

Returns the absolute value of x.

Name Type
x Float
Returns
Float

sign(x: Float): Float

Returns -1.0, 0.0, or 1.0 depending on the sign of x. Returns -1.0 if x < 0, 0.0 if x == 0, and 1.0 if x > 0.

Name Type
x Float
Returns
Float

floor(x: Float): Float

Returns the largest integer value less than or equal to x.

Name Type
x Float
Returns
Float

ceil(x: Float): Float

Returns the smallest integer value greater than or equal to x.

Name Type
x Float
Returns
Float

fract(x: Float): Float

Returns the fractional part of x: x - floor(x).

Name Type
x Float
Returns
Float

mod(x: Float, y: Float): Float

Returns the modulus of x and y: x - y * floor(x/y).

Name Type
x Float
y Float
Returns
Float

min(x: Float, y: Float): Float

Returns the smaller of x and y.

Name Type
x Float
y Float
Returns
Float

max(x: Float, y: Float): Float

Returns the larger of x and y.

Name Type
x Float
y Float
Returns
Float

clamp(x: Float, minVal: Float, maxVal: Float): Float

Constrains x to the range [minVal, maxVal]. Returns min(max(x, minVal), maxVal).

Name Type
x Float
minVal Float
maxVal Float
Returns
Float

mix(x: Float, y: Float, a: Float): Float

Performs linear interpolation between x and y using a. Returns x*(1-a) + y*a.

Name Type
x Float
y Float
a Float
Returns
Float

step(edge: Float, x: Float): Float

Returns 0.0 if x < edge, otherwise returns 1.0.

Name Type
edge Float
x Float
Returns
Float

smoothstep(edge0: Float, edge1: Float, x: Float): Float

Performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. Returns 0 if x <= edge0, 1 if x >= edge1. Uses formula: tt(3-2*t) where t = clamp((x-edge0)/(edge1-edge0), 0, 1).

Name Type
edge0 Float
edge1 Float
x Float
Returns
Float

length(x: Float): Float

Returns the length (magnitude) of a scalar value (its absolute value).

Name Type
x Float
Returns
Float

distance(p0: Float, p1: Float): Float

Returns the distance between two scalar values.

Name Type
p0 Float
p1 Float
Returns
Float

dot(x: Float, y: Float): Float

Returns the dot product of two scalar values.

Name Type
x Float
y Float
Returns
Float

cross(x: Vec3, y: Vec3): Vec3

Returns the cross product of two 3-component vectors. The result is perpendicular to both input vectors.

Name Type
x Vec3
y Vec3
Returns
Vec3

normalize(x: Float): Float

Returns a normalized scalar (1.0 if x >= 0, -1.0 otherwise).

Name Type
x Float
Returns
Float

faceforward(N: Float, I: Float, Nref: Float): Float

Returns N if dot(Nref, I) < 0, otherwise returns -N. Used to orient a normal to face the viewer.

Name Type
N Float
I Float
Nref Float
Returns
Float

reflect(I: Float, N: Float): Float

Returns the reflection direction for an incident vector I and surface normal N. Computed as I - 2*dot(N,I)*N. N should be normalized.

Name Type
I Float
N Float
Returns
Float

refract(I: Vec2, N: Vec2, eta: Float): Vec2

Returns the refraction direction for an incident vector I, surface normal N, and ratio of indices of refraction eta. I and N should be normalized. Returns zero vector if total internal reflection occurs.

Name Type
I Vec2
N Vec2
eta Float
Returns
Vec2

matrixCompMult(x: Mat2, y: Mat2): Mat2

Performs component-wise multiplication of two matrices. This is NOT standard matrix multiplication - use the * operator for that.

Name Type
x Mat2
y Mat2
Returns
Mat2

transpose(m: Mat2): Mat2

Returns the transpose of the matrix (rows become columns, columns become rows).

Name Type
m Mat2
Returns
Mat2

determinant(m: Mat2): Float

Returns the determinant of the matrix.

Name Type
m Mat2
Returns
Float

inverse(m: Mat2): Mat2

Returns the inverse of the matrix. Results are undefined if the matrix is singular (determinant is zero).

Name Type
m Mat2
Returns
Mat2

Metadata

Name Parameters
:nativeGen -