Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"webgpu_lensflares",
"webgpu_lightprobe",
"webgpu_lightprobe_cubecamera",
"webgpu_lights_clustered",
"webgpu_lights_custom",
"webgpu_lights_dynamic",
"webgpu_lights_ies_spotlight",
Expand Down
55 changes: 55 additions & 0 deletions examples/jsm/lighting/ClusteredLighting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Lighting } from 'three/webgpu';
import ClusteredLightsNode from '../tsl/lighting/ClusteredLightsNode.js';

/**
* A custom lighting implementation based on Forward+ Clustered Shading that
* overwrites the default lighting system in {@link WebGPURenderer}. Suitable
* for 3D scenes with many point lights and real depth complexity — the view
* frustum is partitioned into a 3D cluster grid so only the lights actually
* reaching each fragment are evaluated.
*
* ```js
* const lighting = new ClusteredLighting();
* renderer.lighting = lighting; // set lighting system
* ```
*
* @augments Lighting
* @three_import import { ClusteredLighting } from 'three/addons/lighting/ClusteredLighting.js';
*/
export class ClusteredLighting extends Lighting {

/**
* Constructs a new clustered lighting system.
*
* @param {number} [maxLights=1024] - Maximum number of point lights.
* @param {number} [tileSize=32] - Screen tile size in pixels (cluster XY size).
* @param {number} [zSlices=24] - Number of exponential depth slices.
* @param {number} [maxLightsPerCluster=64] - Per-cluster light-list capacity.
*/
constructor( maxLights = 1024, tileSize = 32, zSlices = 24, maxLightsPerCluster = 64 ) {

super();

this.maxLights = maxLights;
this.tileSize = tileSize;
this.zSlices = zSlices;
this.maxLightsPerCluster = maxLightsPerCluster;

}

/**
* Creates a new clustered lights node for the given array of lights.
*
* This method is called internally by the renderer and must be overwritten by
* all custom lighting implementations.
*
* @param {Array<Light>} lights - The lights.
* @return {ClusteredLightsNode} The clustered lights node.
*/
createNode( lights = [] ) {

return new ClusteredLightsNode( this.maxLights, this.tileSize, this.zSlices, this.maxLightsPerCluster ).setLights( lights );

}

}
Loading
Loading