-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FrameGraph: add support for utility layer renderers (#16185)
* Add suport for utility layer renderers to frame graph * Fix inspector gizmos when using a frame graph at scene level
- Loading branch information
Showing
13 changed files
with
286 additions
and
24 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/dev/core/src/FrameGraph/Node/Blocks/Rendering/utilityLayerRendererBlock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// eslint-disable-next-line import/no-internal-modules | ||
import type { NodeRenderGraphConnectionPoint, Scene, FrameGraph, NodeRenderGraphBuildState, FrameGraphTextureHandle, Camera } from "core/index"; | ||
import { RegisterClass } from "../../../../Misc/typeStore"; | ||
import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator"; | ||
import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes"; | ||
import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock"; | ||
import { FrameGraphUtilityLayerRendererTask } from "../../../Tasks/Rendering/utilityLayerRendererTask"; | ||
|
||
/** | ||
* Block used to render an utility layer in the frame graph | ||
*/ | ||
export class NodeRenderGraphUtilityLayerRendererBlock extends NodeRenderGraphBlock { | ||
protected override _frameGraphTask: FrameGraphUtilityLayerRendererTask; | ||
|
||
/** | ||
* Gets the frame graph task associated with this block | ||
*/ | ||
public override get task() { | ||
return this._frameGraphTask; | ||
} | ||
|
||
/** | ||
* Creates a new NodeRenderGraphUtilityLayerRendererBlock | ||
* @param name defines the block name | ||
* @param frameGraph defines the hosting frame graph | ||
* @param scene defines the hosting scene | ||
* @param handleEvents If the utility layer should handle events. | ||
*/ | ||
public constructor(name: string, frameGraph: FrameGraph, scene: Scene, handleEvents = true) { | ||
super(name, frameGraph, scene); | ||
|
||
this._additionalConstructionParameters = [handleEvents]; | ||
|
||
this.registerInput("destination", NodeRenderGraphBlockConnectionPointTypes.Texture); | ||
this.registerInput("camera", NodeRenderGraphBlockConnectionPointTypes.Camera); | ||
this._addDependenciesInput(); | ||
this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput); | ||
|
||
this.destination.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAll); | ||
this.output._typeConnectionSource = this.destination; | ||
|
||
this._frameGraphTask = new FrameGraphUtilityLayerRendererTask(name, frameGraph, scene, handleEvents); | ||
} | ||
|
||
private _createTask(handleEvents: boolean) { | ||
this._frameGraphTask.dispose(); | ||
|
||
this._frameGraphTask = new FrameGraphUtilityLayerRendererTask(this.name, this._frameGraph, this._scene, handleEvents); | ||
|
||
this._additionalConstructionParameters = [handleEvents]; | ||
} | ||
|
||
/** If the utility layer should handle events */ | ||
@editableInPropertyPage("Handle events", PropertyTypeForEdition.Boolean, "PROPERTIES") | ||
public get handleEvents() { | ||
return this._frameGraphTask.layer.handleEvents; | ||
} | ||
|
||
public set handleEvents(value: boolean) { | ||
this._createTask(value); | ||
} | ||
|
||
/** | ||
* Gets the current class name | ||
* @returns the class name | ||
*/ | ||
public override getClassName() { | ||
return "NodeRenderGraphUtilityLayerRendererBlock"; | ||
} | ||
|
||
/** | ||
* Gets the destination input component | ||
*/ | ||
public get destination(): NodeRenderGraphConnectionPoint { | ||
return this._inputs[0]; | ||
} | ||
|
||
/** | ||
* Gets the camera input component | ||
*/ | ||
public get camera(): NodeRenderGraphConnectionPoint { | ||
return this._inputs[1]; | ||
} | ||
|
||
/** | ||
* Gets the output component | ||
*/ | ||
public get output(): NodeRenderGraphConnectionPoint { | ||
return this._outputs[0]; | ||
} | ||
|
||
protected override _buildBlock(state: NodeRenderGraphBuildState) { | ||
super._buildBlock(state); | ||
|
||
this.output.value = this._frameGraphTask.outputTexture; | ||
|
||
this._frameGraphTask.destinationTexture = this.destination.connectedPoint?.value as FrameGraphTextureHandle; | ||
this._frameGraphTask.camera = this.camera.connectedPoint?.value as Camera; | ||
} | ||
} | ||
|
||
RegisterClass("BABYLON.NodeRenderGraphUtilityLayerRendererBlock", NodeRenderGraphUtilityLayerRendererBlock); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/dev/core/src/FrameGraph/Tasks/Rendering/utilityLayerRendererTask.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// eslint-disable-next-line import/no-internal-modules | ||
import type { Camera, FrameGraph, FrameGraphTextureHandle, Scene } from "core/index"; | ||
import { FrameGraphTask } from "../../frameGraphTask"; | ||
import { UtilityLayerRenderer } from "core/Rendering/utilityLayerRenderer"; | ||
|
||
/** | ||
* Task used to render an utility layer. | ||
*/ | ||
export class FrameGraphUtilityLayerRendererTask extends FrameGraphTask { | ||
/** | ||
* The destination texture of the task. | ||
*/ | ||
public destinationTexture: FrameGraphTextureHandle; | ||
|
||
/** | ||
* The camera used to render the utility layer. | ||
*/ | ||
public camera: Camera; | ||
|
||
/** | ||
* The output texture of the task. | ||
* This is the same texture as the destination texture, but the handles are different! | ||
*/ | ||
public readonly outputTexture: FrameGraphTextureHandle; | ||
|
||
/** | ||
* The utility layer renderer. | ||
*/ | ||
public readonly layer: UtilityLayerRenderer; | ||
|
||
/** | ||
* Creates a new utility layer renderer task. | ||
* @param name The name of the task. | ||
* @param frameGraph The frame graph the task belongs to. | ||
* @param scene The scene the task belongs to. | ||
* @param handleEvents If the utility layer should handle events. | ||
*/ | ||
constructor(name: string, frameGraph: FrameGraph, scene: Scene, handleEvents = true) { | ||
super(name, frameGraph); | ||
|
||
this.layer = new UtilityLayerRenderer(scene, handleEvents, true); | ||
this.layer.utilityLayerScene._useCurrentFrameBuffer = true; | ||
|
||
this.outputTexture = this._frameGraph.textureManager.createDanglingHandle(); | ||
} | ||
|
||
public record(): void { | ||
if (!this.destinationTexture || !this.camera) { | ||
throw new Error("FrameGraphUtilityLayerRendererTask: destinationTexture and camera are required"); | ||
} | ||
|
||
this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, this.destinationTexture); | ||
|
||
const pass = this._frameGraph.addRenderPass(this.name); | ||
|
||
pass.setRenderTarget(this.outputTexture); | ||
pass.setExecuteFunc((context) => { | ||
this.layer.setRenderCamera(this.camera); | ||
|
||
context.render(this.layer); | ||
}); | ||
|
||
const passDisabled = this._frameGraph.addRenderPass(this.name + "_disabled", true); | ||
|
||
passDisabled.setRenderTarget(this.outputTexture); | ||
passDisabled.setExecuteFunc((_context) => {}); | ||
} | ||
|
||
public override dispose(): void { | ||
this.layer.dispose(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.