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
13 changes: 3 additions & 10 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,14 +994,6 @@ class NodeMaterial extends Material {

const materialLightsNode = [];

if ( builder.renderer.lighting.enabled === false ) {

return materialLightsNode;

}

//

const envNode = this.setupEnvironment( builder );

if ( envNode && envNode.isLightingNode ) {
Expand Down Expand Up @@ -1087,9 +1079,10 @@ class NodeMaterial extends Material {

// OUTGOING LIGHT

const lights = this.lights === true || this.lightsNode !== null;
const sceneLighting = this.lights === true && builder.renderer.lighting.enabled;
const lights = sceneLighting || this.lightsNode !== null;

const materialLightings = this.lights === true ? this.setupMaterialLightings( builder ) : [];
const materialLightings = sceneLighting ? this.setupMaterialLightings( builder ) : [];
const lightsNode = lights ? ( this.lightsNode || builder.lightsNode ) : null;

let outgoingLightNode = this.setupOutgoingLight( builder );
Expand Down
10 changes: 10 additions & 0 deletions src/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class PassNode extends TempNode {
*/
this.opaque = true;

this.lighting = null;

/**
* Whether the renderer should automatically clear before rendering the pass.
*
Expand Down Expand Up @@ -844,6 +846,7 @@ class PassNode extends TempNode {
const currentAutoClearStencil = renderer.autoClearStencil;
const currentTransparent = renderer.transparent;
const currentOpaque = renderer.opaque;
const currentLighting = renderer.lighting;
const currentMask = camera.layers.mask;
const currentContextNode = renderer.contextNode;
const currentOverrideMaterial = scene.overrideMaterial;
Expand Down Expand Up @@ -878,6 +881,12 @@ class PassNode extends TempNode {
renderer.transparent = this.transparent;
renderer.opaque = this.opaque;

if ( this.lighting !== null ) {

renderer.lighting = this.lighting;

}

if ( this.contextNode !== null ) {

if ( this._contextNodeCache === null || this._contextNodeCache.version !== this.version ) {
Expand Down Expand Up @@ -911,6 +920,7 @@ class PassNode extends TempNode {
renderer.transparent = currentTransparent;
renderer.opaque = currentOpaque;
renderer.contextNode = currentContextNode;
renderer.lighting = currentLighting;

camera.layers.mask = currentMask;

Expand Down
15 changes: 11 additions & 4 deletions src/renderers/common/Lighting.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { LightsNode } from '../../nodes/Nodes.js';

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

/**
* This renderer module manages the lights nodes which are unique
* per scene and camera combination.
* per scene + camera + lighting combination.
*
* The lights node itself is later configured in the render list
* with the actual lights from the scene.
Expand Down Expand Up @@ -35,6 +34,14 @@ class Lighting {
*/
this._cache = [];

/**
* A map of lights nodes per scene.
*
* @private
* @type {WeakMap<Scene, LightsNode>}
*/
this._lightsNodeMap = new WeakMap();

}

/**
Expand All @@ -60,12 +67,12 @@ class Lighting {
// Ignore renderable objects, e.g: Mesh, Sprite, etc.
if ( scene.isScene !== true && scene.isGroup !== true ) return _defaultLights;

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

if ( node === undefined ) {

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

}

Expand Down
18 changes: 6 additions & 12 deletions src/renderers/common/RenderLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ class RenderLists {

/**
* Constructs a render lists management component.
*
* @param {Lighting} lighting - The lighting management component.
*/
constructor( lighting ) {

/**
* The lighting management component.
*
* @type {Lighting}
*/
this.lighting = lighting;
constructor() {

/**
* The internal chain map which holds the render lists.
Expand Down Expand Up @@ -56,26 +47,29 @@ class RenderLists {
*
* @param {Scene} scene - The scene.
* @param {Camera} camera - The camera.
* @param {Lighting} lighting - The lighting manager.
* @return {RenderList} The render list.
*/
get( scene, camera ) {
get( scene, camera, lighting ) {

const lists = this.lists;

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

let list = lists.get( _chainKeys );

if ( list === undefined ) {

list = new RenderList( this.lighting, scene, camera );
list = new RenderList( lighting, scene, camera );
lists.set( _chainKeys, list );

}

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

//

Expand Down
10 changes: 5 additions & 5 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class Renderer {
const useFrameBufferTarget = this.needsFrameBufferTarget && this._renderTarget === null;
const renderTarget = useFrameBufferTarget ? this._getFrameBufferTarget() : ( this._renderTarget || this._outputRenderTarget );

const renderList = this._renderLists.get( scene, camera );
const renderList = this._renderLists.get( scene, camera, this.lighting );
const renderContext = this._renderContexts.get( renderTarget, this._mrt );

const material = scene.overrideMaterial || object.material;
Expand Down Expand Up @@ -831,7 +831,7 @@ class Renderer {
this._pipelines = new Pipelines( backend, this._nodes, this.info );
this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
this._renderLists = new RenderLists( this.lighting );
this._renderLists = new RenderLists();
this._bundles = new RenderBundles();
this._renderContexts = new RenderContexts( this );

Expand Down Expand Up @@ -982,7 +982,7 @@ class Renderer {
}

// Use sceneRef for render list to ensure lightsNode matches between compileAsync and render
const renderList = this._renderLists.get( sceneRef, camera );
const renderList = this._renderLists.get( sceneRef, camera, this.lighting );
renderList.begin();

this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
Expand Down Expand Up @@ -1708,7 +1708,7 @@ class Renderer {

this._renderLists.update( nodeFrame.frameId );

const renderList = this._renderLists.get( scene, camera );
const renderList = this._renderLists.get( scene, camera, this.lighting );
renderList.begin();

this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
Expand Down Expand Up @@ -3235,7 +3235,7 @@ class Renderer {

// replace render list

renderList = this._renderLists.get( object, camera );
renderList = this._renderLists.get( object, camera, this.lighting );

const renderBundle = this._bundles.get( object, camera, this._currentRenderContext );
const renderBundleData = this.backend.get( renderBundle );
Expand Down