In the while we're refining rtoa v2.0 which features almost 50 new shaders (!) ..
we release for everyone a new spicy update to our mathparser.
This is Math Parser v2.0. It features a completely re-written core.
We enhanced the two stages "compiler/interpreter" architecture :
it strictly separates the CPU-intensive parsing setup from the performance-critical rendering loop.
A new custom parser tokenizes the math expression and compiles it into a linear array of integer-based bytecode.
We also do constant folding now and other optimizations.
The shader kernel reads this pre-compiled bytecode.
A tiny Virtual Machine executes the instructions for lighting speed renderings.
It now supports vector (3D) operations natively (component-wise math),
meaning sin(x) works whether x is a single float or a 3D vector.
Standard math functions can produce NaNs (Not a Number) or 'infinite' values if fed the wrong data.
MathParser uses "safe" versions of potential problematic functions that gracefully handle edge cases
by returning 0.0 or by clamping input values :
>> division by zero: returns 0.0 instead of crashing.
>> invalid roots: sqrt(-x) returns 0.0.
>> logarithms: log(0), log(-x) are handled safely.
>> trigonometry: asin/acos inputs > 1 are clamped.
>> power: pow(-x, float) returns 0.0.
>> modulo: fmod(x, 0) returns 0.0.
// Added new fncs :
dot(a, b) : Dot product. Returns scalar.
cross(a, b) : Cross product. Returns vector perpendicular to a and b.
length(v) : Returns the magnitude of vector v.
distance(a, b) : Distance between points a and b.
normalize(v) : Returns direction vector (length 1.0).
reflect(I, N) : Reflects vector I against normal N.
refract(I, N, ior) : Calculates refraction vector based on Index of Refraction.
smin(a, b, k), smax(...) : Smooth Minimum/Maximum. Blends a and b with factor k.
rotate(vec, axis, angle) : Rotates vector vec around axis by angle (radians).
translate(vec, vec) : Translate a vector vec by another vec.
scale(vec, vec) : Scale a vector vec by another vec.
vec(a, b, c) : Create a vector with a, b, c components.
rnd(x) : High quality random number generator
// Vector accessors
.x, .y, .z
// Added 3D shading globals :
SGP : shading point in world-space
SGPO : shading point in object-space
SGRO : ray origin
SGRD : ray direction
SGN, SGNF, SGNG, SGNGF : shading normals
SGDPDU, SGDPDV : surface derivatives
SGDDDX, SGDDDY : ray direction derivatives
SGDNDX, SGDNDY : surface normal derivatives
// Added new Constants :
TWOPI : 6.283.. (pi*2)
PITWO : 1.570.. (pi/2)
INVPI : 0.318.. (1/pi)
// Expression'recipes' :
Sine Wave Distortion
>> x + sin(y * 10.0 + z) * 0.1
Inputs: X=UV, Y=UV, Z=Time.
Adds a sine wave ripple traveling along the Y axis to the coordinate X.
Organic Soft Union (SDF)
>> smin(length(x) - 1.0, length(y) - 0.5, 0.2)
Inputs: X=Pos A, Y=Pos B.
Smoothly blends two spheres (radii 1.0 and 0.5) with a softness factor of 0.2.
Fresnel Term
>> pow(1.0 - max(0.0, dot(x, y)), 5.0)
Inputs: X=Normal, Y=View Vector.
Calculates a standard Fresnel edge glow effect manually.
Rounded Square
>> step(length(max(abs(rotate(UV - 0.5, N, X.x)) - Y, 0)), Z.x)
Inputs: X.x=Rotation, Y.x,Y.y=X,Y dimensions, Z.x=Rounded angle.
Draws a rounded square.
Concentric Shape
>> mod(length(PO + sin(PO * 5) * 0.2) * x, 1)
Inputs: X=Repetitions.
Draws concentric shapes.
Squares/Circles Pattern
>> mod(sin(U * Y.z) + sin(V * (X.z+1)), 1.0)
Inputs: X=Repetitions.
Draws a nice alternated pattern.
Diamond Checkboard
>> (floor((PO.x+2.5)*x-PO.y*y) + floor(PO.x*x+PO.y*y)) %2
Inputs: X=Repetitions.
Draws a diamond checkboard.
Origami Pattern
>> mod((((atanz(UV.y-.5, UV.x-.5) / (PI*2)) +0.5) *x), 1)
Inputs: X=Repetitions.
Draws a kind of origami pattern.
Bar Code
>> step(x.x, fract(sin(floor(WIN.x)*12.9898)*43758.453))
Inputs: y=Thickness.
Draws a kind of origami pattern.
Smooth Circular Grid
>> 1.0 - sstep(0.0, 0.5, ( length(( ((PO+z)*y-floor((PO+z)*y)) * 2.0) - 1) - 0.9) / 0.5)
Inputs:y=Repetitions; z=Position,
Draws a kind of origami pattern.

https://www.rombo.tools/downloads/romboMathParser.zip