Class: ShaderBRDF

ShaderBRDF

A shader class implementing various BRDF (Bidirectional Reflectance Distribution Function) rendering modes. Extends the base Shader class to provide specialized material rendering capabilities.

Shader Features:

  • Implements the Ward BRDF model for physically-based rendering
  • Supports both directional and spot lights
  • Handles normal mapping for more detailed surface rendering
  • Supports different color spaces (linear and sRGB) for input textures
  • Multiple visualization modes for material analysis (diffuse, specular, normals, monochrome, etc.)
  • Configurable surface roughness range for varying material appearance
  • Ambient light contribution to simulate indirect light

Required Textures:

  • uTexKd: Diffuse color texture (optional)
  • uTexKs: Specular color texture (optional)
  • uTexNormals: Normal map for surface detail
  • uTexGloss: Glossiness map (optional)

new ShaderBRDF( [options])

Creates a new ShaderBRDF instance.

Parameters:
Name Type Argument Default Description
options Object <optional>
{}

Configuration options for the shader.

Properties
Name Type Argument Default Description
mode string <optional>
'color'

Rendering mode to use:

  • 'color': Full BRDF rendering using Ward model with ambient light
  • 'diffuse': Shows only diffuse component (kd)
  • 'specular': Shows only specular component (ks * spec * NdotL)
  • 'normals': Visualizes surface normals
  • 'monochrome': Renders using a single material color with diffuse lighting
colorspaces Object <optional>

Color space configurations.

Properties
Name Type Argument Default Description
kd string <optional>
'sRGB'

Color space for diffuse texture ('linear' or 'sRGB').

ks string <optional>
'linear'

Color space for specular texture ('linear' or 'sRGB').

brightness number <optional>
1.0

Overall brightness multiplier.

gamma number <optional>
2.2

Gamma correction value.

alphaLimits Array.<number> <optional>
[0.01, 0.5]

Range for surface roughness [min, max].

monochromeMaterial Array.<number> <optional>
[0.80, 0.79, 0.75]

RGB color for monochrome mode.

kAmbient number <optional>
0.02

Ambient light coefficient.

Source:
Examples
// Create a basic BRDF shader with default settings
const shader = new ShaderBRDF({});
// Create a BRDF shader with custom settings
const shader = new ShaderBRDF({
  mode: 'color',
  colorspaces: { kd: 'sRGB', ks: 'linear' },
  brightness: 1.2,
  gamma: 2.2,
  alphaLimits: [0.05, 0.4],
  kAmbient: 0.03
});

Extends

Methods


addFilter(filter)

Adds a filter to the shader pipeline.

Parameters:
Name Type Description
filter Object

Filter to add

Inherited From:
Overrides:
Source:
Fires:

allUniforms()

Returns all uniform variables associated with the shader and its filters. Combines uniforms from both the base shader and all active filters into a single object.

Inherited From:
Overrides:
Source:
Returns:

Combined uniform variables

Type
Object.<string, Object>

clearFilters()

Clears all filters from the shader pipeline.

Inherited From:
Overrides:
Source:
Fires:

getUniform(name)

Gets a uniform variable by name. Searches both shader uniforms and filter uniforms.

Parameters:
Name Type Description
name string

Uniform variable name

Inherited From:
Overrides:
Source:
Returns:

Uniform object if found

Type
Object | undefined

removeFilter(name)

Removes a filter from the pipeline by name.

Parameters:
Name Type Description
name string

Name of filter to remove

Inherited From:
Overrides:
Source:
Fires:

setLight(light, light[0, light[1, light[2, light[3)

Sets the light properties for the shader.

Parameters:
Name Type Description
light Array.<number>

4D vector containing light information

light[0 number

X coordinate of light position/direction

light[1 number

Y coordinate of light position/direction

light[2 number

Z coordinate of light position/direction

light[3 number

Light type flag (0 for directional, 1 for spot)

Source:

setMode(mode)

Sets the rendering mode for the shader.

Parameters:
Name Type Description
mode string

The rendering mode to use

Overrides:
Source:
Throws:

If an invalid mode is specified

Type
Error

setTileSize(size)

Sets tile dimensions for shader calculations.

Parameters:
Name Type Description
size Array.<number>

[width, height] of tile

Inherited From:
Overrides:
Source:

setUniform(name, value)

Sets a uniform variable value.

Parameters:
Name Type Description
name string

Uniform variable name

value number | boolean | Array

Value to set

Inherited From:
Overrides:
Source:
Fires:
Throws:

If uniform doesn't exist

Type
Error

vertShaderSrc(gl)

Gets vertex shader source code. Default implementation provides basic vertex transformation and texture coordinate passing.

Parameters:
Name Type Description
gl WebGLRenderingContext

WebGL context

Inherited From:
Overrides:
Source:
Returns:

Vertex shader source code

Type
string

Events


update

Fired when shader state changes (uniforms, filters, etc).

Inherited From:
Overrides:
Source: