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
8 changes: 4 additions & 4 deletions examples/jsm/inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ class Inspector extends RendererInspector {

resolveFrame( frame ) {

const nextFrame = this.getFrameById( frame.frameId + 1 );
const previousFrame = this.getFrameById( frame.frameId - 1 );

if ( ! nextFrame ) return;
if ( ! previousFrame ) return;

frame.cpu = 0;
frame.gpu = 0;
Expand All @@ -510,9 +510,9 @@ class Inspector extends RendererInspector {

}

// improve stats using next frame
// improve stats using previous frame

frame.deltaTime = nextFrame.startTime - frame.startTime;
frame.deltaTime = frame.startTime - previousFrame.startTime;
frame.miscellaneous = frame.deltaTime - frame.total;

if ( frame.miscellaneous < 0 ) {
Expand Down
10 changes: 8 additions & 2 deletions examples/jsm/inspector/RendererInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class RendererInspector extends InspectorBase {

begin() {

super.begin();

this.currentFrame = this._createFrame();
this.currentRender = this.currentFrame;
this.currentNodes = [];
Expand All @@ -108,6 +110,8 @@ export class RendererInspector extends InspectorBase {

finish() {

super.finish();

const now = performance.now();

const frame = this.currentFrame;
Expand Down Expand Up @@ -368,9 +372,9 @@ export class RendererInspector extends InspectorBase {

}

const nextFrame = this.getFrameById( frame.frameId + 1 );
const previousFrame = this.getFrameById( frame.frameId - 1 );

if ( nextFrame === null ) continue;
if ( previousFrame === null ) continue;

if ( frame.resolvedCompute === false ) {

Expand Down Expand Up @@ -453,6 +457,8 @@ export class RendererInspector extends InspectorBase {

inspect( node ) {

if ( this.enabled === false ) return;

const currentNodes = this.currentNodes;

if ( currentNodes !== null ) {
Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/lighting/LightProbeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ class LightProbeGrid extends Light {

const { cubemapSize = 8, near = 0.1, far = 100, bounces = 0, sampleCount = 512 } = options;

const currentInspectorEnabled = renderer.inspector.enabled;

renderer.inspector.enabled = false;

this._ensureTextures();
this.updateBoundingBox();

Expand Down Expand Up @@ -603,6 +607,8 @@ class LightProbeGrid extends Light {

this.visible = true;

renderer.inspector.enabled = currentInspectorEnabled;

}

}
Expand Down
16 changes: 12 additions & 4 deletions src/nodes/core/ContextNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,30 @@ class ContextNode extends Node {

analyze( builder ) {

const previousContext = builder.addContext( this.value );
const usageCount = builder.increaseUsage( this );

this.node.build( builder );
if ( usageCount === 1 ) {

builder.setContext( previousContext );
const previousContext = builder.addContext( this.value );

this.node.build( builder, this );

builder.setContext( previousContext );

}

}

setup( builder ) {

const previousContext = builder.addContext( this.value );

this.node.build( builder );
const node = this.node.build( builder );

builder.setContext( previousContext );

return node;

}

generate( builder, output ) {
Expand Down
46 changes: 44 additions & 2 deletions src/nodes/core/MRTNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OutputStructNode from './OutputStructNode.js';
import { nodeProxy } from '../tsl/TSLBase.js';
import { MaterialBlending, NoBlending } from '../../constants.js';
import BlendMode from '../../renderers/common/BlendMode.js';
import Color4 from '../../renderers/common/Color4.js';

// Predefined blend modes for MRT nodes.
const _noBlending = /**@__PURE__*/ new BlendMode( NoBlending );
Expand Down Expand Up @@ -78,6 +79,13 @@ class MRTNode extends OutputStructNode {
output: _materialBlending
};

/**
* A dictionary storing the clear colors for each output.
*
* @type {Object<string, Color4>}
*/
this.clearColors = {};

/**
* This flag can be used for type testing.
*
Expand Down Expand Up @@ -116,6 +124,38 @@ class MRTNode extends OutputStructNode {

}

/**
* Sets the clear color for the given output name.
*
* @param {string} name - The name of the output.
* @param {number|string|Color} color - The clear color.
* @param {number} [alpha=1] - The clear alpha.
* @return {MRTNode} The current MRT node.
*/
setClearColor( name, color, alpha = 1 ) {

const clearColor = this.clearColors[ name ] || ( this.clearColors[ name ] = new Color4() );

clearColor.set( color );
clearColor.a = alpha;

return this;

}

/**
* Returns the clear color for the given output name.
*
* @param {string} name - The name of the output.
* @return {?Color4} The clear color. Returns `null` if no clear color is defined
* which means the renderer's default clear policy is applied.
*/
getClearColor( name ) {

return this.clearColors[ name ] || null;

}

/**
* Returns `true` if the MRT node has an output with the given name.
*
Expand Down Expand Up @@ -149,10 +189,12 @@ class MRTNode extends OutputStructNode {
merge( mrtNode ) {

const outputs = { ...this.outputNodes, ...mrtNode.outputNodes };
const blendings = { ...this.blendModes, ...mrtNode.blendModes };
const blendModes = { ...this.blendModes, ...mrtNode.blendModes };
const clearColors = { ...this.clearColors, ...mrtNode.clearColors };

const mrtTarget = mrt( outputs );
mrtTarget.blendings = blendings;
mrtTarget.blendModes = blendModes;
mrtTarget.clearColors = clearColors;

return mrtTarget;

Expand Down
14 changes: 12 additions & 2 deletions src/renderers/common/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class Animation {

this._requestId = this._context.requestAnimationFrame( update );

if ( this.renderer._inspector.isRunning ) {

this.renderer._inspector.finish();

}

if ( this.info.autoReset === true ) this.info.reset();

this.nodes.nodeFrame.update();
Expand All @@ -80,9 +86,11 @@ class Animation {

this.renderer._inspector.begin();

if ( this._animationLoop !== null ) this._animationLoop( time, xrFrame );
if ( this._animationLoop !== null ) {

this.renderer._inspector.finish();
this._animationLoop( time, xrFrame );

}

};

Expand All @@ -95,6 +103,8 @@ class Animation {
*/
stop() {

if ( this.renderer._inspector.isRunning ) this.renderer._inspector.finish();

if ( this._context !== null ) this._context.cancelAnimationFrame( this._requestId );

this._requestId = null;
Expand Down
9 changes: 9 additions & 0 deletions src/renderers/common/Color4.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class Color4 extends Color {

}

*[ Symbol.iterator ]() {

yield this.r;
yield this.g;
yield this.b;
yield this.a;

}

}

export default Color4;
28 changes: 26 additions & 2 deletions src/renderers/common/InspectorBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ class InspectorBase extends EventDispatcher {
*/
this.currentFrame = null;

/**
* Indicates whether the inspector is running.
*
* @type {boolean}
* @default false
*/
this.isRunning = false;

/**
* Indicates whether the inspector is enabled.
*
* @type {boolean}
* @default true
*/
this.enabled = true;

}

/**
Expand Down Expand Up @@ -75,12 +91,20 @@ class InspectorBase extends EventDispatcher {
/**
* Called when a frame begins.
*/
begin() { }
begin() {

this.isRunning = true;

}

/**
* Called when a frame ends.
*/
finish() { }
finish() {

this.isRunning = false;

}

/**
* Inspects a node.
Expand Down
8 changes: 7 additions & 1 deletion src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,13 @@ class WebGLBackend extends Backend {

for ( let i = 0; i < descriptor.textures.length; i ++ ) {

if ( i === 0 ) {
const mrtClearColor = descriptor.mrt ? descriptor.mrt.getClearColor( descriptor.textures[ i ].name ) : null;

if ( mrtClearColor !== null ) {

gl.clearBufferfv( gl.COLOR, i, [ mrtClearColor.r, mrtClearColor.g, mrtClearColor.b, mrtClearColor.a ] );

} else if ( i === 0 ) {

gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );

Expand Down
15 changes: 11 additions & 4 deletions src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { error, warnOnce, warn } from '../../../utils.js';
import { error, warn } from '../../../utils.js';
import TimestampQueryPool from '../../common/TimestampQueryPool.js';

/**
Expand Down Expand Up @@ -58,11 +58,14 @@ class WebGLTimestampQueryPool extends TimestampQueryPool {

if ( ! this.trackTimestamp ) return null;

// Check if we have enough space for a new query pair
if ( this.currentQueryIndex + 2 > this.maxQueries ) {

warnOnce( `WebGLTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` );
return null;
this.resolveQueriesAsync();

this.currentQueryIndex = 0;
this.queryOffsets.clear();
this.queryStates.clear();
this.activeQuery = null;

}

Expand Down Expand Up @@ -222,6 +225,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool {

const frames = [];

this.timestamps.clear();

for ( const [ uid, promise ] of resolvePromises ) {

const match = uid.match( /^(.*):f(\d+)$/ );
Expand Down Expand Up @@ -386,6 +391,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool {
this.queries = [];
this.queryStates.clear();
this.queryOffsets.clear();
this.timestamps.clear();
this.frames = [];
this.lastValue = 0;
this.activeQuery = null;

Expand Down
8 changes: 7 additions & 1 deletion src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,13 @@ class WebGPUBackend extends Backend {

if ( renderContext.clearColor || discardColor || clearExternalColor ) {

if ( i === 0 ) {
const clearColor = renderContext.mrt ? renderContext.mrt.getClearColor( renderContext.textures[ i ].name ) : null;

if ( clearColor !== null ) {

colorAttachment.clearValue = clearColor;

} else if ( i === 0 ) {

colorAttachment.clearValue = renderContext.clearColorValue;

Expand Down
Loading