SphericalHarmonics3 - Verge3D User Manual - Soft8Soft
Description: Learn how to use SphericalHarmonics3 in your interactive 3D apps made with Verge3D

# SphericalHarmonics3

Represents a third-order spherical harmonics (SH). Light probes use this class to encode lighting information.

## Constructor

### SphericalHarmonics3()

Creates a new instance of SphericalHarmonics3.

## Properties

### # .coefficients : Array

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

### # .isSphericalHarmonics3 : Boolean

Read-only flag to check if a given object is of type SphericalHarmonics3.

## Methods

### # .add(sh : SphericalHarmonics3) → this

sh — the SH to add.

Adds the given SH to this instance.

### # .addScaledSH(sh : SphericalHarmonics3, scale : Float) → this

- sh — the SH to add.
- scale — the scale factor.

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

### # .clone() → SphericalHarmonics3

Returns a new instance of SphericalHarmonics3 with equal coefficients.

### # .copy(sh : SphericalHarmonics3) → this

sh — the SH to copy.

Copies the given SH to this instance.

### # .equals(sh : SphericalHarmonics3) → Boolean

sh — the SH to compare with.

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

### # .fromArray(array : Array, offset : Float) → this

- array — the array holding the numbers of the SH coefficients.
- offset — (optional) the array offset.

Sets the coefficients of this instance from the given array.

### # .getAt(normal : Vector3, target : Vector3) → Vector3

- normal — the normal vector (assumed to be unit length).
- target — the result vector.

Returns the radiance in the direction of the given normal.

### # .getIrradianceAt(normal : Vector3, target : Vector3) → Vector3

- normal — the normal vector (assumed to be unit length).
- target — the result vector.

Returns the irradiance (radiance convolved with cosine lobe) in the direction of the given normal.

### # .lerp(sh : SphericalHarmonics3, alpha : Float) → this

- sh — the SH to interpolate with.
- alpha — the alpha factor.

Linear interpolates between the given SH and this instance by the given alpha factor.

### # .scale(scale : Float) → this

scale — the scale factor.

Scales this SH by the given scale factor.

### # .set(coefficients : Array) → this

coefficients — an array of SH coefficients.

Sets the given SH coefficients to this instance.

### # .toArray(array : Array, offset : Float) → Array

- array — (optional) the target array.
- offset — (optional) the array offset.

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

### # .zero() → this

Sets all SH coefficients to `0`.

## Static Methods

### # .getBasisAt(normal : Vector3, shBasis : Array)

- normal — the normal vector (assumed to be unit length).
- shBasis — the resulting SH basis.

Computes the SH basis for the given normal vector.

## Source

For more info on how to obtain the source code of this module see this page.