Skip to content

Commit

Permalink
Merge pull request #13036 from carolhmj/renderUIAfterPostProcesses
Browse files Browse the repository at this point in the history
Add applyPostProcess flag on ADV to optionally draw it after the post…

Former-commit-id: 65b48dad5fdd605ecf428c00938c1df2939a9309
  • Loading branch information
sebavan authored Sep 28, 2022
2 parents b93e63d + 6d06f14 commit fec9648
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 11 deletions.
12 changes: 12 additions & 0 deletions packages/dev/core/src/Layers/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export class Layer {
*/
public isBackground: boolean;

private _applyPostProcess: boolean = true;
/**
* Determines if the layer is drawn before (true) or after (false) post-processing.
* If the layer is background, it is always before.
*/
public set applyPostProcess(value: boolean) {
this._applyPostProcess = value;
}
public get applyPostProcess(): boolean {
return this.isBackground || this._applyPostProcess;
}

/**
* Define the color of the layer (instead of texture).
*/
Expand Down
46 changes: 35 additions & 11 deletions packages/dev/core/src/Layers/layerSceneComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ export class LayerSceneComponent implements ISceneComponent {
*/
public register(): void {
this.scene._beforeCameraDrawStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER, this, this._drawCameraBackground);
this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER, this, this._drawCameraForeground);
this.scene._afterCameraDrawStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER, this, this._drawCameraForegroundWithPostProcessing);
this.scene._afterCameraPostProcessStage.registerStep(SceneComponentConstants.STEP_AFTERCAMERAPOSTPROCESS_LAYER, this, this._drawCameraForegroundWithoutPostProcessing);

this.scene._beforeRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_BEFORERENDERTARGETDRAW_LAYER, this, this._drawRenderTargetBackground);
this.scene._afterRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERTARGETDRAW_LAYER, this, this._drawRenderTargetForeground);
this.scene._afterRenderTargetDrawStage.registerStep(SceneComponentConstants.STEP_AFTERRENDERTARGETDRAW_LAYER, this, this._drawRenderTargetForegroundWithPostProcessing);
this.scene._afterRenderTargetPostProcessStage.registerStep(
SceneComponentConstants.STEP_AFTERRENDERTARGETPOSTPROCESS_LAYER,
this,
this._drawRenderTargetForegroundWithoutPostProcessing
);
}

/**
Expand Down Expand Up @@ -95,40 +101,58 @@ export class LayerSceneComponent implements ISceneComponent {
}
}

private _drawCameraPredicate(layer: Layer, isBackground: boolean, cameraLayerMask: number): boolean {
return !layer.renderOnlyInRenderTargetTextures && layer.isBackground === isBackground && (layer.layerMask & cameraLayerMask) !== 0;
private _drawCameraPredicate(layer: Layer, isBackground: boolean, applyPostProcess: boolean, cameraLayerMask: number): boolean {
return (
!layer.renderOnlyInRenderTargetTextures &&
layer.isBackground === isBackground &&
layer.applyPostProcess === applyPostProcess &&
(layer.layerMask & cameraLayerMask) !== 0
);
}

private _drawCameraBackground(camera: Camera): void {
this._draw((layer: Layer) => {
return this._drawCameraPredicate(layer, true, camera.layerMask);
return this._drawCameraPredicate(layer, true, true, camera.layerMask);
});
}

private _drawCameraForeground(camera: Camera): void {
private _drawCameraForegroundWithPostProcessing(camera: Camera): void {
this._draw((layer: Layer) => {
return this._drawCameraPredicate(layer, false, camera.layerMask);
return this._drawCameraPredicate(layer, false, true, camera.layerMask);
});
}

private _drawRenderTargetPredicate(layer: Layer, isBackground: boolean, cameraLayerMask: number, renderTargetTexture: RenderTargetTexture): boolean {
private _drawCameraForegroundWithoutPostProcessing(camera: Camera): void {
this._draw((layer: Layer) => {
return this._drawCameraPredicate(layer, false, false, camera.layerMask);
});
}

private _drawRenderTargetPredicate(layer: Layer, isBackground: boolean, applyPostProcess: boolean, cameraLayerMask: number, renderTargetTexture: RenderTargetTexture): boolean {
return (
layer.renderTargetTextures.length > 0 &&
layer.isBackground === isBackground &&
layer.applyPostProcess === applyPostProcess &&
layer.renderTargetTextures.indexOf(renderTargetTexture) > -1 &&
(layer.layerMask & cameraLayerMask) !== 0
);
}

private _drawRenderTargetBackground(renderTarget: RenderTargetTexture): void {
this._draw((layer: Layer) => {
return this._drawRenderTargetPredicate(layer, true, this.scene.activeCamera!.layerMask, renderTarget);
return this._drawRenderTargetPredicate(layer, true, true, this.scene.activeCamera!.layerMask, renderTarget);
});
}

private _drawRenderTargetForegroundWithPostProcessing(renderTarget: RenderTargetTexture): void {
this._draw((layer: Layer) => {
return this._drawRenderTargetPredicate(layer, false, true, this.scene.activeCamera!.layerMask, renderTarget);
});
}

private _drawRenderTargetForeground(renderTarget: RenderTargetTexture): void {
private _drawRenderTargetForegroundWithoutPostProcessing(renderTarget: RenderTargetTexture): void {
this._draw((layer: Layer) => {
return this._drawRenderTargetPredicate(layer, false, this.scene.activeCamera!.layerMask, renderTarget);
return this._drawRenderTargetPredicate(layer, false, false, this.scene.activeCamera!.layerMask, renderTarget);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,10 @@ export class RenderTargetTexture extends Texture implements IRenderTargetTexture
scene.postProcessManager._finalizeFrame(false, this._renderTarget ?? undefined, faceIndex);
}

for (const step of scene._afterRenderTargetPostProcessStage) {
step.action(this, faceIndex, layer);
}

if (this._texture) {
this._texture.generateMipMaps = saveGenerateMipMaps;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/dev/core/src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,20 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
* Defines the actions happening just after the active camera has been drawn.
*/
public _afterCameraDrawStage = Stage.Create<CameraStageAction>();
/**
* @internal
* Defines the actions happening just after the post processing
*/
public _afterCameraPostProcessStage = Stage.Create<CameraStageAction>();
/**
* @internal
* Defines the actions happening just after a render target has been drawn.
*/
public _afterRenderTargetDrawStage = Stage.Create<RenderTargetStageAction>();
/**
* Defines the actions happening just after the post processing on a render target
*/
public _afterRenderTargetPostProcessStage = Stage.Create<RenderTargetStageAction>();
/**
* @internal
* Defines the actions happening just after rendering all cameras and computing intersections.
Expand Down Expand Up @@ -4224,6 +4233,11 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
this.postProcessManager._finalizeFrame(camera.isIntermediate, texture);
}

// After post process
for (const step of this._afterCameraPostProcessStage) {
step.action(this.activeCamera);
}

// Reset some special arrays
this._renderTargets.reset();

Expand Down
4 changes: 4 additions & 0 deletions packages/dev/core/src/sceneComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class SceneComponentConstants {
public static readonly STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
public static readonly STEP_AFTERCAMERADRAW_LAYER = 4;

public static readonly STEP_AFTERCAMERAPOSTPROCESS_LAYER = 0;

public static readonly STEP_AFTERRENDERTARGETPOSTPROCESS_LAYER = 0;

public static readonly STEP_AFTERRENDER_AUDIO = 0;

public static readonly STEP_GATHERRENDERTARGETS_DEPTHRENDERER = 0;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/tools/tests/test/visualization/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,11 @@
"title": "Serialize scene without materials",
"playgroundId": "#PH4DEZ#1",
"referenceImage": "serializeWithoutMaterials.png"
},
{
"title": "UI unaffected by post-process",
"playgroundId": "#XJVHWQ",
"referenceImage": "uiUnaffected.png"
}
]
}

0 comments on commit fec9648

Please sign in to comment.