ShaderUtils Class
A bunch of utility functions used throughout the library.
Item Index
Methods
Attributes
- arrayValuesAreEqual
- clamp
- ensureArrayInstanceOf
- ensureArrayTypedArg
- ensureInstanceOf
- ensureValueOverLifetimeCompliance
- getPackedRotationAxis
- interpolateArray
- lerp
- lerpTypeAgnostic
- randomColor
- randomColorAsHex
- randomDirectionVector3OnDisc
- randomDirectionVector3OnSphere
- randomFloat
- randomVector3
- randomVector3OnDisc
- randomVector3OnSphere
- roundToNearestMultiple
- types
- zeroToEpsilon
Methods
ensureTypedArg
-
arg
-
type
-
defaultValue
Given a value, a type, and a default value to fallback to, ensure the given argument adheres to the type requesting, returning the default value if type check is false.
Parameters:
-
arg
(boolean | String | Number | Object)The value to perform a type-check on.
-
type
StringThe type the arg argument should adhere to.
-
defaultValue
(boolean | String | Number | Object)A default value to fallback on if the type check fails.
Returns:
The given value if type check passes, or the default value if it fails.
Attributes
ensureArrayInstanceOf
static
Given an array of values, ensure the instances of all items in the array matches the given instance constructor falling back to a default value if the check fails.
If given value isn't an Array, delegates to ShaderUtils.ensureInstanceOf.
ensureArrayTypedArg
static
Given an array of values, a type, and a default value, ensure the given array"s contents ALL adhere to the provided type, returning the default value if type check fails.
If the given value to check isn't an Array, delegates to ShaderUtils.ensureTypedArg.
ensureValueOverLifetimeCompliance
static
Ensures that any "value-over-lifetime" properties of an emitter are of the correct length (as dictated by valueOverLifetimeLength).
Delegates to ShaderUtils.interpolateArray for array resizing.
If properties aren't arrays, then property values are put into one.
getPackedRotationAxis
static
Given a rotation axis, and a rotation axis spread vector, calculate a randomised rotation axis, and pack it into a hexadecimal value represented in decimal form.
interpolateArray
static
Performs linear interpolation (lerp) on an array.
For example, lerping [1, 10], with a newLength of 10 will produce [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Delegates to ShaderUtils.lerpTypeAgnostic to perform the actual interpolation.
lerpTypeAgnostic
static
Linearly interpolates two values of various types. The given values must be of the same type for the interpolation to work.
randomColor
static
Given an Shader attribute instance, and various other settings, assign Color values to the attribute.
randomColorAsHex
static
Assigns a random color value, encoded as a hex value in decimal format, to a ShaderAttribute instance.
randomDirectionVector3OnDisc
static
Given an ShaderAttribute instance, create a direction vector from the given position, using speed as the magnitude. Values are saved to the attribute.
randomDirectionVector3OnSphere
static
Given an ShaderAttribute instance, create a direction vector from the given position, using speed as the magnitude. Values are saved to the attribute.
randomVector3
static
Given an ShaderAttribute instance, and various other settings, assign values to the attribute"s array in a vec3 format.
randomVector3OnDisc
static
Assigns a random vector 3 value to an ShaderAttribute instance, projecting the given values onto a 2d-disc.
randomVector3OnSphere
static
Assigns a random vector 3 value to an ShaderAttribute instance, projecting the given values onto a sphere.