HELPERS
Before I get to the shaping functions, SDFs and other cool stuff, I thought it'd be useful to first mention some helpful general-purpose methods that can be proven useful later.
#glsl #shaderbasics #shaders
These are fairly intuitive and common; they take 2 parameters and return the minimum or the maximum of the two respectively. They're useful for masking things in/out and blending them.
These methods are used for rounding values down and up respectively. They're useful for quantizing values and getting bands of your colors. Obviously you can find other use cases too.
This is used to prevent your car wheels from locking up while braking. In the context of shader coding, though, it's a method used to get the absolute value of its parameter. Meaning, if the parameter value is negative, it returns the value as a positive number.
This is used to restrict the range of a value. When used as clamp(t, a, ), the method will return
a if t <= a
b if t >= b
t otherwise
It's worth mentioning that CG (so, unity shaders too) also has the "saturate" method, which basically clamps a value from 0.0 to 1.0.
It's used to get the sign of its parameter by returning
-1.0 if the value is negative
0.0 if the value is zero
1.0 if the value is positive