Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More features for the aggressive performance mode #13014

Merged
merged 1 commit into from
Sep 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/dev/core/src/Materials/material.ts
Expand Up @@ -1013,11 +1013,15 @@ export class Material implements IAnimatable {
* @returns a boolean specifying if alpha blending is needed for the mesh
*/
public needAlphaBlendingForMesh(mesh: AbstractMesh): boolean {
if (this._disableAlphaBlending && mesh.visibility >= 1.0) {
if (mesh.visibility < 1.0) {
return true;
}

if (this._disableAlphaBlending) {
return false;
}

return this.needAlphaBlending() || mesh.visibility < 1.0 || mesh.hasVertexAlpha;
return mesh.hasVertexAlpha || this.needAlphaBlending();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Meshes/subMesh.ts
Expand Up @@ -141,6 +141,8 @@ export class SubMesh implements ICullable {
public _trianglePlanes: Plane[];
/** @internal */
public _lastColliderTransformMatrix: Nullable<Matrix> = null;
/** @internal */
public _wasDispatched = false;

/** @internal */
public _renderId = 0;
Expand Down
3 changes: 3 additions & 0 deletions packages/dev/core/src/Particles/IParticleSystem.ts
Expand Up @@ -278,6 +278,9 @@ export interface IParticleSystem {
/** Gets or sets a matrix to use to compute projection */
defaultProjectionMatrix: Matrix;

/** @internal */
_wasDispatched: boolean;

/**
* Gets the maximum number of particles active at the same time.
* @returns The max number of active particles.
Expand Down
3 changes: 3 additions & 0 deletions packages/dev/core/src/Particles/baseParticleSystem.ts
Expand Up @@ -202,6 +202,9 @@ export class BaseParticleSystem {
*/
public preventAutoStart: boolean = false;

/** @internal */
_wasDispatched = false;

protected _rootUrl = "";
private _noiseTexture: Nullable<ProceduralTexture>;

Expand Down
48 changes: 33 additions & 15 deletions packages/dev/core/src/Rendering/renderingManager.ts
Expand Up @@ -85,6 +85,12 @@ export class RenderingManager {
private _customTransparentSortCompareFn: { [id: number]: Nullable<(a: SubMesh, b: SubMesh) => number> } = {};
private _renderingGroupInfo: Nullable<RenderingGroupInfo> = new RenderingGroupInfo();

/**
* Gets or sets a boolean indicating that the manager will not reset between frames.
* This means that if a mesh becomes invisible or transparent it will not be visible until this boolean is set to false again.s
*/
public maintainStateBetweenFrames = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will need a setter that will reset all the _wasDispatched properties to false when maintainStateBetweenFrames is switched from true to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a good catch! PR is coming!


/**
* Instantiates a new rendering group for a particular scene
* @param scene Defines the scene the groups belongs to
Expand All @@ -97,6 +103,14 @@ export class RenderingManager {
}
}

public getRenderingGroup(id: number) {
const renderingGroupId = id || 0;

this._prepareRenderingGroup(renderingGroupId);

return this._renderingGroups[renderingGroupId];
}

private _clearDepthStencilBuffer(depth = true, stencil = true): void {
if (this._depthStencilBufferAlreadyCleaned) {
return;
Expand Down Expand Up @@ -178,6 +192,10 @@ export class RenderingManager {
* @internal
*/
public reset(): void {
if (this.maintainStateBetweenFrames) {
return;
}

for (let index = RenderingManager.MIN_RENDERINGGROUPS; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
const renderingGroup = this._renderingGroups[index];
if (renderingGroup) {
Expand Down Expand Up @@ -225,23 +243,23 @@ export class RenderingManager {
* @param spriteManager Define the sprite manager to render
*/
public dispatchSprites(spriteManager: ISpriteManager) {
const renderingGroupId = spriteManager.renderingGroupId || 0;

this._prepareRenderingGroup(renderingGroupId);

this._renderingGroups[renderingGroupId].dispatchSprites(spriteManager);
if (this.maintainStateBetweenFrames && spriteManager._wasDispatched) {
return;
}
spriteManager._wasDispatched = true;
this.getRenderingGroup(spriteManager.renderingGroupId).dispatchSprites(spriteManager);
}

/**
* Add a particle system to the rendering manager in order to render it this frame.
* @param particleSystem Define the particle system to render
*/
public dispatchParticles(particleSystem: IParticleSystem) {
const renderingGroupId = particleSystem.renderingGroupId || 0;

this._prepareRenderingGroup(renderingGroupId);

this._renderingGroups[renderingGroupId].dispatchParticles(particleSystem);
if (this.maintainStateBetweenFrames && particleSystem._wasDispatched) {
return;
}
particleSystem._wasDispatched = true;
this.getRenderingGroup(particleSystem.renderingGroupId).dispatchParticles(particleSystem);
}

/**
Expand All @@ -254,11 +272,11 @@ export class RenderingManager {
if (mesh === undefined) {
mesh = subMesh.getMesh();
}
const renderingGroupId = mesh.renderingGroupId || 0;

this._prepareRenderingGroup(renderingGroupId);

this._renderingGroups[renderingGroupId].dispatch(subMesh, mesh, material);
if (this.maintainStateBetweenFrames && subMesh._wasDispatched) {
return;
}
subMesh._wasDispatched = true;
this.getRenderingGroup(mesh.renderingGroupId).dispatch(subMesh, mesh, material);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/core/src/Sprites/spriteManager.ts
Expand Up @@ -69,6 +69,9 @@ export interface ISpriteManager extends IDisposable {
/** Defines the default height of a cell in the spritesheet */
cellHeight: number;

/** @internal */
_wasDispatched: boolean;

/**
* Tests the intersection of a sprite with a specific ray.
* @param ray The ray we are sending to test the collision
Expand Down Expand Up @@ -119,6 +122,9 @@ export class SpriteManager implements ISpriteManager {
/** Gets or sets a boolean indicating if the sprites are pickable */
public isPickable = false;

/** @internal */
public _wasDispatched = false;

/**
* An event triggered when the manager is disposed.
*/
Expand Down
22 changes: 20 additions & 2 deletions packages/dev/core/src/scene.ts
Expand Up @@ -283,10 +283,21 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
this._performancePriority = value;

switch (value) {
case ScenePerformancePriority.BackwardCompatible:
this.skipFrustumClipping = false;
this._renderingManager.maintainStateBetweenFrames = false;
this.skipPointerMovePicking = false;
this.autoClear = true;
break;
case ScenePerformancePriority.Intermediate:
sebavan marked this conversation as resolved.
Show resolved Hide resolved
this.skipFrustumClipping = false;
this._renderingManager.maintainStateBetweenFrames = false;
this.skipPointerMovePicking = true;
this.autoClear = false;
break;
case ScenePerformancePriority.Aggressive:
this.skipFrustumClipping = true;
// eslint-disable-next-line no-fallthrough
case ScenePerformancePriority.Intermediate:
this._renderingManager.maintainStateBetweenFrames = true;
this.skipPointerMovePicking = true;
this.autoClear = false;
break;
Expand Down Expand Up @@ -1323,6 +1334,13 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold

private _renderingManager: RenderingManager;

/**
* Gets the scene's rendering manager
*/
public get renderingManager() {
return this._renderingManager;
}

/** @internal */
public _activeAnimatables = new Array<Animatable>();

Expand Down