SphericalHarmonics3

Primary reference: https://graphics.stanford.edu/papers/envmap/envmap.pdf Secondary reference: https://www.ppsloan.org/publications/StupidSH36.pdf 3-band SH defined by 9 coefficients.

Constructor

new SphericalHarmonics3()

Creates a new instance of SphericalHarmonics3.

Members

coefficients :Array

An array holding the (9) SH coefficients. A single coefficient is represented as an instance of Vector3.

Type:
  • Array

Methods

add(sh) → {SphericalHarmonics3}

Adds the given SH to this instance.

Parameters:
NameTypeDescription
shSphericalHarmonics3

The SH to add.

Returns:
Type: 
SphericalHarmonics3

addScaledSH(sh, s) → {SphericalHarmonics3}

A convenience method for performing .add() and .scale() at once.

Parameters:
NameTypeDescription
shSphericalHarmonics3

The SH to add.

sVector3

The scale factor.

Returns:
Type: 
SphericalHarmonics3

clone() → {SphericalHarmonics3}

Returns a new instance of SphericalHarmonics3 with equal coefficients.

Returns:
Type: 
SphericalHarmonics3

copy(sh) → {SphericalHarmonics3}

Copies the given SH to this instance.

Parameters:
NameTypeDescription
shSphericalHarmonics3

The SH to compare with.

Returns:
Type: 
SphericalHarmonics3

equals(sh) → {boolean}

Returns true if the given SH and this instance have equal coefficients.

Parameters:
NameTypeDescription
shSphericalHarmonics3

The SH to compare with.

Returns:
Type: 
boolean

fromArray(array, offsetopt) → {SphericalHarmonics3}

Sets the coefficients of this instance from the given array.

Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<number>

The array holding the numbers of the SH coefficients.

offsetnumber<optional>
0

The array offset.

Returns:
Type: 
SphericalHarmonics3

getAt(normal, target) → {Vector3}

Returns the radiance in the direction of the given normal.

Parameters:
NameTypeDescription
normalVector3

The normal vector (assumed to be unit length).

targetVector3

The result vector.

Returns:
Type: 
Vector3

getIrradianceAt(normal, target) → {Vector3}

Reference: https://graphics.stanford.edu/papers/envmap/envmap.pdf Returns the irradiance (radiance convolved with cosine lobe) in the direction of the given normal.

Parameters:
NameTypeDescription
normalVector3

The normal vector (assumed to be unit length).

targetVector3

The result vector.

Returns:
Type: 
Vector3

lerp(sh, alpha) → {SphericalHarmonics3}

Linear interpolates between the given SH and this instance by the given alpha factor. Sets this coefficients vector to be the vector linearly interpolated between v1 and v2 where alpha is the percent distance along the line connecting the two vectors

  • alpha = 0 will be v1, and alpha = 1 will be v2.
Parameters:
NameTypeDescription
shSphericalHarmonics3

The SH to interpolate with.

alphanumber

The alpha factor.

Returns:
Type: 
SphericalHarmonics3

scale(s) → {SphericalHarmonics3}

Multiply the s to this SphericalHarmonics3.

Parameters:
NameTypeDescription
snumber

The scale factor.

Returns:
Type: 
SphericalHarmonics3

set(coefficients) → {SphericalHarmonics3}

Set this sphericalHarmonics3 value.

Parameters:
NameTypeDescription
coefficientsArray.<Vector3>

An array of SH coefficients.

Returns:
Type: 
SphericalHarmonics3

toArray(arrayopt, offsetopt) → {Array.<number>}

Returns an array with the coefficients, or copies them into the provided array. The coefficients are represented as numbers.

Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<number><optional>

The target array.

offsetnumber<optional>
0

The array offset.

Returns:
Type: 
Array.<number>

zero() → {SphericalHarmonics3}

Sets all SH coefficients to 0.

Returns:
Type: 
SphericalHarmonics3

(static) getBasisAt(normal, shBasis)

Computes the SH basis for the given normal vector.

Parameters:
NameTypeDescription
normalVector3

The normal vector (assumed to be unit length).

shBasisArray.<number>

The resulting SH basis.