AngouriMath

Navigation

Shaders


← Back to list of classes

Description

Summary

Expressions printed as shader source: straight-line HLSL or GLSL that computes each
output once, sharing every repeated subexpression.

Remarks

The use is to derive on the CPU what is expensive or error-prone to derive by hand —
an exact gradient, a Hessian, a closed form of a physical law — and run the result
on the GPU. Differentiate(AngouriMath.Entity.Variable) followed by one of these
is an analytic normal for a signed distance field.
The code computes the real-valued reading, the one Compile<double, …> computes; where that has no value the shader's is NaN, an infinity or
unspecified, as the language's own /, pow and sqrt leave it.
Three of those are worth naming, because a GPU does give them a value: a division by
zero, a / b at b = 0, is NaN compiled and ±infinity in the
shader; so is zero to a negative power, x^(-2) or x^(-1/2) at x = 0,
printed 1.0 / (x * x) and rsqrt(x); and an unsimplified x^0 is
printed 1.0, which is 1 at x = 0 where compiled it is NaN. A
branch on every quotient would cost more than the difference is worth, so the
difference is documented rather than paid for. Nor is pow of a negative base
defined in a shader, even where the exponent is a variable that happens to be whole.
A node with no faithful form — a complex constant, a set, a piecewise with inputs it
gives no value to, a function with no intrinsic and no straight-line form — is declined
with the node named, never printed approximately; and what Compile refuses, a
binder or a statement where a number is expected, is declined with Compile's
message.
Nothing is simplified. Call Simplify(System.Int32) first if a smaller
form is wanted: what is printed is the expression that was given. The only rewrites
are the ones Compile makes as well: an operation on matrices written out is
the number it gives, a membership in an interval or a finite set is the comparisons
it stands for, and (b^v + c1) / (b^v + c2), as tanh is spelled, is taken
as 1 + (c1 - c2) / (b^v + c2) so that it does not overflow.
The page Docs/Usage/Shaders.md works an example through.

Members

























Angouri © 2019-2026 · Project's repo · Site's repo · Octicons · Transparency · 6003 pages online