ShaderUtils Class

Module: Lights

A bunch of utility functions used throughout the library.

Methods

ensureTypedArg

(
  • arg
  • type
  • defaultValue
)
(boolean | String | Number | Object)

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 String

    The type the arg argument should adhere to.

  • defaultValue (boolean | String | Number | Object)

    A default value to fallback on if the type check fails.

Returns:

(boolean | String | Number | Object):

The given value if type check passes, or the default value if it fails.

Attributes

arrayValuesAreEqual

static

Check if all items in an array are equal. Uses strict equality.

clamp

static

Clamp a number to between the given min and max values.

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.

ensureInstanceOf

static

Ensures the given value is an instance of a constructor function.

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.

lerp

static

Perform a linear interpolation operation on two numbers.

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.

randomFloat

static

Given a start value and a spread value, create and return a random number.

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.

roundToNearestMultiple

static

Rounds a number to a nearest multiple.

types

Object static

A map of types used by ShaderUtils.ensureTypedArg and ShaderUtils.ensureArrayTypedArg to compare types against.

zeroToEpsilon

static

If the given value is less than the epsilon value, then return a randomised epsilon value if specified, or just the epsilon value if not.

Works for negative numbers as well as positive.