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) |
textureLod(sampler: Sampler2D, coord: Vec2, lod: Float): Vec4
Samples a texture at the given coordinate using an explicit mipmap level of detail.
| Name |
Type |
Description |
sampler |
Sampler2D |
The texture sampler to read from |
coord |
Vec2 |
The texture coordinates (0.0 to 1.0 range typically) |
lod |
Float |
The mipmap level to sample (0.0 = base/highest resolution) |
| Returns |
Description |
| Vec4 |
The color value at the sampled location as a Vec4 (RGBA) |
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.
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.
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.
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.
Tells if the current fragment belongs to a front-facing primitive.
Only available in fragment shaders.
Fetches one exact texel at integer coordinates (no filtering, no
wrapping), from mip level 0, for data textures (light lists, cluster
tables...). Coordinates are Floats in the DSL (exact up to 2^24); each
backend converts them to integers.
The sampler's @param declaration must carry the @fetch annotation:
backends whose fetched textures need a different declaration form than
filtered samplers (HLSL Texture2D + Load vs sampler2D + tex2D)
switch on it. A @fetch sampler must not also be used with texture().
Only available in fragment shaders.
Computes the flat (per-face) normal of the current triangle from
screen-space derivatives of the given position (typically a world-space
position varying). The result points out of the front face. The argument
may be evaluated more than once, so it should be a simple expression
without side effects.
Backend note: the sign of the cross product depends on the raster-space
y orientation of the pipeline that consumes the generated shader. Each
shade backend must emit it accordingly: GLSL assumes the GL 3D pipeline,
which always renders into render textures through a mirrored viewport
(shouldFlipRenderTargetY()); Unity gates on UNITY_UV_STARTS_AT_TOP
(no viewport mirror there). A new backend (e.g. PSSL) must pick the
orientation matching its engine pipeline conventions.
Only available in fragment shaders.
Get a float value from an int.
Constructs a 2-component vector from individual x and y values.
Constructs a 3-component vector from individual x, y, and z values.
Constructs a 4-component vector from individual x, y, z, and w values.
Constructs a 2x2 diagonal matrix with the specified value on the diagonal.
Constructs a 3x3 diagonal matrix with the specified value on the diagonal.
Constructs a 4x4 diagonal matrix with the specified value on the diagonal.
Converts degrees to radians. Returns (π/180) * degrees.
Converts radians to degrees. Returns (180/π) * radians.
Returns the sine of the angle (in radians).
Returns the cosine of the angle (in radians).
Returns the tangent of the angle (in radians).
Returns the arc sine (inverse sine) of x. The result is in radians, in the range [-π/2, π/2].
Returns the arc cosine (inverse cosine) of x. The result is in radians, in the range [0, π].
Returns the arc tangent of y/x. The result is in radians, in the range [-π/2, π/2].
Returns x raised to the power y (x^y).
Returns the natural exponentiation of x (e^x).
Returns the natural logarithm of x (ln(x)). Results are undefined if x <= 0.
Returns 2 raised to the power x (2^x).
Returns the base-2 logarithm of x (log₂(x)). Results are undefined if x <= 0.
Returns the square root of x. Results are undefined if x < 0.
Returns the inverse square root of x (1/√x). Results are undefined if x <= 0.
Returns the absolute value of x.
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.
Returns the largest integer value less than or equal to x.
Returns the smallest integer value greater than or equal to x.
Returns the fractional part of x: x - floor(x).
Returns the modulus of x and y: x - y * floor(x/y).
Returns the smaller of x and y.
Returns the larger of x and y.
Constrains x to the range [minVal, maxVal]. Returns min(max(x, minVal), maxVal).
Performs linear interpolation between x and y using a. Returns x*(1-a) + y*a.
Returns 0.0 if x < edge, otherwise returns 1.0.
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).
Returns the length (magnitude) of a scalar value (its absolute value).
Returns the distance between two scalar values.
Returns the dot product of two scalar values.
Returns the cross product of two 3-component vectors. The result is perpendicular to both input vectors.
Returns a normalized scalar (1.0 if x >= 0, -1.0 otherwise).
Returns N if dot(Nref, I) < 0, otherwise returns -N. Used to orient a normal to face the viewer.
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.
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.
Performs component-wise multiplication of two matrices. This is NOT standard matrix multiplication - use the * operator for that.
Returns the transpose of the matrix (rows become columns, columns become rows).
Returns the determinant of the matrix.
Returns the inverse of the matrix. Results are undefined if the matrix is singular (determinant is zero).