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
26 changes: 5 additions & 21 deletions src/renderers/common/Lighting.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { LightsNode } from '../../nodes/Nodes.js';
import ChainMap from './ChainMap.js';

const _defaultLights = /*@__PURE__*/ new LightsNode();
const _chainKeys = [];
const _weakMap = /*@__PURE__*/ new WeakMap();

/**
* This renderer module manages the lights nodes which are unique
Expand All @@ -12,18 +11,8 @@ const _chainKeys = [];
* with the actual lights from the scene.
*
* @private
* @augments ChainMap
*/
class Lighting extends ChainMap {

/**
* Constructs a lighting management component.
*/
constructor() {

super();

}
class Lighting {

/**
* Creates a new lights node for the given array of lights.
Expand All @@ -44,26 +33,21 @@ class Lighting extends ChainMap {
* @param {Camera} camera - The camera.
* @return {LightsNode} The lights node.
*/
getNode( scene, camera ) {
getNode( scene ) {

// ignore post-processing

if ( scene.isQuadMesh ) return _defaultLights;

_chainKeys[ 0 ] = scene;
_chainKeys[ 1 ] = camera;

let node = this.get( _chainKeys );
let node = _weakMap.get( scene );

if ( node === undefined ) {

node = this.createNode();
this.set( _chainKeys, node );
_weakMap.set( scene, node );

}

_chainKeys.length = 0;

return node;

}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ class RenderObject {

}

cacheKey = hash( cacheKey, this.camera.id, this.renderer.contextNode.id, this.renderer.contextNode.version );
cacheKey = hash( cacheKey, this.renderer.contextNode.id, this.renderer.contextNode.version );

return cacheKey;

Expand Down
20 changes: 18 additions & 2 deletions src/renderers/common/RenderObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ class RenderObjects {

const chainMap = this.getChainMap( passId );

// reuse chainArray
// set chain keys

_chainKeys[ 0 ] = object;
_chainKeys[ 1 ] = material;
_chainKeys[ 2 ] = renderContext;
_chainKeys[ 3 ] = lightsNode;

//

let renderObject = chainMap.get( _chainKeys );

if ( renderObject === undefined ) {
Expand All @@ -107,6 +110,12 @@ class RenderObjects {

} else {

// update references

renderObject.camera = camera;

//

renderObject.updateClipping( clippingContext );

if ( renderObject.needsGeometryUpdate ) {
Expand All @@ -133,7 +142,14 @@ class RenderObjects {

}

_chainKeys.length = 0;
// reset chain array

_chainKeys[ 0 ] = null;
_chainKeys[ 1 ] = null;
_chainKeys[ 2 ] = null;
_chainKeys[ 3 ] = null;

//

return renderObject;

Expand Down
14 changes: 14 additions & 0 deletions src/renderers/common/UniformsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class UniformsGroup extends UniformBuffer {
b[ offset ] = a[ offset ] = v;
updated = true;

this.addUpdateRange( offset, 1 );

}

return updated;
Expand Down Expand Up @@ -265,6 +267,8 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 2 );

}

return updated;
Expand Down Expand Up @@ -296,6 +300,8 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 3 );

}

return updated;
Expand Down Expand Up @@ -328,6 +334,8 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 4 );

}

return updated;
Expand Down Expand Up @@ -358,6 +366,8 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 3 );

}

return updated;
Expand Down Expand Up @@ -396,6 +406,8 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 12 );

}

return updated;
Expand Down Expand Up @@ -423,6 +435,8 @@ class UniformsGroup extends UniformBuffer {
setArray( a, e, offset );
updated = true;

this.addUpdateRange( offset, 16 );

}

return updated;
Expand Down