Class: LayerBRDF

LayerBRDF

LayerBRDF implements real-time BRDF (Bidirectional Reflectance Distribution Function) rendering.

The BRDF model describes how light reflects off a surface, taking into account:

  • Diffuse reflection (rough, matte surfaces)
  • Specular reflection (mirror-like reflections)
  • Surface normals (microscopic surface orientation)
  • Glossiness/roughness (surface micro-structure)

Features:

  • Real-time light direction control
  • Multiple material channels support
  • Customizable material properties
  • Interactive lighting model
  • Gamma correction
  • Ambient light component

Technical implementation:

  • Uses normal mapping for surface detail
  • Supports both linear and sRGB color spaces
  • Implements spherical light projection
  • Handles multi-channel textures
  • GPU-accelerated rendering

new LayerBRDF(options)

Creates a new LayerBRDF instance

Parameters:
Name Type Description
options LayerBRDFOptions

Configuration options

Source:
Throws:
  • If required channels (kd, normals) are not provided

    Type
    Error
  • If rasters option is not empty

    Type
    Error
Example
```javascript
// Create BRDF layer with all channels
const brdfLayer = new OpenLIME.LayerBRDF({
  channels: {
    kd: 'diffuse.jpg',
    ks: 'specular.jpg',
    normals: 'normals.jpg',
    gloss: 'gloss.jpg'
  },
  colorspaces: {
    kd: 'srgb',
    ks: 'linear'
  },
  brightness: 1.2,
  gamma: 2.2
});

// Update light direction
brdfLayer.setLight([0.5, 0.5], 500, 'ease-out');
```

Extends

Methods


<static> projectToFlattenedSphere(p)

Projects a 2D point onto a flattened sphere using SGI trackball algorithm. This provides more intuitive light control by avoiding acceleration near edges. Based on SIGGRAPH 1988 paper on SGI trackball implementation.

Parameters:
Name Type Description
p Array.<number>

2D point [x, y] in range [-1, 1]

Source:
Returns:

3D normalized vector [x, y, z] on flattened sphere

Type
Array.<number>

<static> projectToSphere(p)

Projects a 2D point onto a sphere surface Used for converting 2D mouse/touch input to 3D light direction

Parameters:
Name Type Description
p Array.<number>

2D point [x, y] in range [-1, 1]

Source:
Returns:

3D normalized vector [x, y, z] on sphere surface

Type
Array.<number>

addControl(name, value)

Adds a shader parameter control

Parameters:
Name Type Description
name string

Control identifier

value *

Initial value

Inherited From:
Overrides:
Source:
Throws:

If control already exists

Type
Error

addShaderFilter(filter)

Adds a filter to the current shader

Parameters:
Name Type Description
filter Object

Filter specification

Inherited From:
Overrides:
Source:
Throws:

If no shader is set

Type
Error

boundingBox()

Gets layer bounding box in scene coordinates

Inherited From:
Overrides:
Source:
Returns:

Bounding box

Type
BoundingBox

clearShaderFilters(name)

Removes all filters from the current shader

Parameters:
Name Type Description
name Object

Filter name

Inherited From:
Overrides:
Source:
Throws:

If no shader is set

Type
Error

getControl(name)

Gets the shader parameter control corresponding to name

Parameters:
Name Type Description
name *

The name of the control. return {*} The control

Inherited From:
Overrides:
Source:

getMode()

Gets the current shader visualization mode

Inherited From:
Overrides:
Source:
Returns:

Current mode or null if no shader

Type
string | null

getModes()

Gets available shader modes

Inherited From:
Overrides:
Source:
Returns:

Array of available modes

Type
Array.<string>

getState( [stateMask])

Gets the current layer state

Parameters:
Name Type Argument Default Description
stateMask Object <optional>
null

Optional mask to filter returned state properties

Inherited From:
Overrides:
Source:
Returns:

Current state object

Type
Object

pixelSizePerMM()

Gets pixel size in millimeters

Inherited From:
Overrides:
Source:
Returns:

Size of one pixel in mm

Type
number

removeShaderFilter(name)

Removes a filter from the current shader

Parameters:
Name Type Description
name Object

Filter name

Inherited From:
Overrides:
Source:
Throws:

If no shader is set

Type
Error

scale()

Gets layer scale

Inherited From:
Overrides:
Source:
Returns:

Current scale value

Type
number

setControl(name, value [, dt] [, easing])

Sets a shader control value with optional animation

Parameters:
Name Type Argument Default Description
name string

Control identifier

value *

New value

dt number <optional>

Animation duration in ms

easing string <optional>
'linear'

Easing function

Inherited From:
Overrides:
Source:
Fires:

setLight(light [, dt] [, easing])

Sets the light direction with optional animation

Parameters:
Name Type Argument Default Description
light Array.<number>

2D vector [x, y] representing light direction

dt number <optional>

Animation duration in milliseconds

easing string <optional>
'linear'

Animation easing function

Source:

setMode(mode)

Sets shader visualization mode

Parameters:
Name Type Description
mode string

Mode to set

Inherited From:
Overrides:
Source:
Fires:

setShader(id)

Sets the active shader

Parameters:
Name Type Description
id string

Shader identifier from registered shaders

Inherited From:
Overrides:
Source:
Fires:
Throws:

If shader ID is not found

Type
Error

setState(state [, dt] [, easing])

Sets the layer state with optional animation

Parameters:
Name Type Argument Default Description
state Object

State object with controls and mode

dt number <optional>

Animation duration in ms

easing string <optional>
'linear'

Easing function ('linear'|'ease-out'|'ease-in-out')

Inherited From:
Overrides:
Source:

setTransform(tx)

Sets the layer's transform

Parameters:
Name Type Description
tx Transform

New transform

Inherited From:
Overrides:
Source:
Fires:
  • Layer#event:updateSize

setViewport(view)

Sets the layer's viewport

Parameters:
Name Type Description
view Object

Viewport specification

Properties
Name Type Description
x number

X position

y number

Y position

dx number

Width

dy number

Height

Inherited From:
Overrides:
Source:
Fires:

setVisible(visible)

Sets layer visibility

Parameters:
Name Type Description
visible boolean

Whether layer should be visible

Inherited From:
Overrides:
Source:
Fires:

setZindex(zindex)

Sets layer rendering order

Parameters:
Name Type Description
zindex number

Stack order value

Inherited From:
Overrides:
Source:
Fires:

Events


ready

The event is fired when a layer is initialized.

Inherited From:
Overrides:
Source:

update

The event is fired if a redraw is needed.

Inherited From:
Overrides:
Source: