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

FrameGraph: refactor pass / passCube post processes for frame graph usage #16051

Merged
merged 2 commits into from
Jan 9, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// eslint-disable-next-line import/no-internal-modules
import type { NodeRenderGraphConnectionPoint, Scene, NodeRenderGraphBuildState, FrameGraphTextureHandle, FrameGraph, FrameGraphTask } from "core/index";
import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock";
import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes";
import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator";

interface IPostProcessLike {
sourceSamplingMode: number;
sourceTexture: FrameGraphTextureHandle;
destinationTexture?: FrameGraphTextureHandle;
outputTexture: FrameGraphTextureHandle;
}

/**
* @internal
*/
export class NodeRenderGraphBasePostProcessBlock extends NodeRenderGraphBlock {
protected override _frameGraphTask: IPostProcessLike & FrameGraphTask;

/**
* Create a new NodeRenderGraphBasePostProcessBlock
* @param name defines the block name
* @param frameGraph defines the hosting frame graph
* @param scene defines the hosting scene
*/
public constructor(name: string, frameGraph: FrameGraph, scene: Scene) {
super(name, frameGraph, scene);

this.registerInput("source", NodeRenderGraphBlockConnectionPointTypes.Texture);
this.registerInput("destination", NodeRenderGraphBlockConnectionPointTypes.Texture, true);

this.source.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer);
this.destination.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAll);
}

protected _finalizeInputOutputRegistering() {
this._addDependenciesInput();
this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput);

this.output._typeConnectionSource = () => {
return this.destination.isConnected ? this.destination : this.source;
};
}

/** Sampling mode used to sample from the source texture */
@editableInPropertyPage("Source sampling mode", PropertyTypeForEdition.SamplingMode, "PROPERTIES")
public get sourceSamplingMode() {
return this._frameGraphTask.sourceSamplingMode;
}

public set sourceSamplingMode(value: number) {
this._frameGraphTask.sourceSamplingMode = value;
}

/**
* Gets the source input component
*/
public get source(): NodeRenderGraphConnectionPoint {
return this._inputs[0];
}

/**
* Gets the destination input component
*/
public get destination(): 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.sourceTexture = this.source.connectedPoint?.value as FrameGraphTextureHandle;
this._frameGraphTask.destinationTexture = this.destination.connectedPoint?.value as FrameGraphTextureHandle;
}

protected override _dumpPropertiesCode() {
const codes: string[] = [];
codes.push(`${this._codeVariableName}.sourceSamplingMode = ${this.sourceSamplingMode};`);
return super._dumpPropertiesCode() + codes.join("\n");
}

public override serialize(): any {
const serializationObject = super.serialize();
serializationObject.sourceSamplingMode = this.sourceSamplingMode;
return serializationObject;
}

public override _deserialize(serializationObject: any) {
super._deserialize(serializationObject);
this.sourceSamplingMode = serializationObject.sourceSamplingMode;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// eslint-disable-next-line import/no-internal-modules
import type { NodeRenderGraphConnectionPoint, Scene, NodeRenderGraphBuildState, FrameGraphTextureHandle, FrameGraph } from "core/index";
import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock";
import type { Scene, FrameGraph } from "core/index";
import { RegisterClass } from "../../../../Misc/typeStore";
import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes";
import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator";
import { FrameGraphBlackAndWhiteTask } from "core/FrameGraph/Tasks/PostProcesses/blackAndWhiteTask";
import { ThinBlackAndWhitePostProcess } from "core/PostProcesses/thinBlackAndWhitePostProcess";
import { NodeRenderGraphBasePostProcessBlock } from "./basePostProcessBlock";

/**
* Block that implements the black and white post process
*/
export class NodeRenderGraphBlackAndWhitePostProcessBlock extends NodeRenderGraphBlock {
export class NodeRenderGraphBlackAndWhitePostProcessBlock extends NodeRenderGraphBasePostProcessBlock {
protected override _frameGraphTask: FrameGraphBlackAndWhiteTask;

/**
Expand All @@ -29,30 +28,11 @@ export class NodeRenderGraphBlackAndWhitePostProcessBlock extends NodeRenderGrap
public constructor(name: string, frameGraph: FrameGraph, scene: Scene) {
super(name, frameGraph, scene);

this.registerInput("source", NodeRenderGraphBlockConnectionPointTypes.Texture);
this.registerInput("destination", NodeRenderGraphBlockConnectionPointTypes.Texture, true);
this._addDependenciesInput();
this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput);

this.source.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer);
this.destination.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAll);
this.output._typeConnectionSource = () => {
return this.destination.isConnected ? this.destination : this.source;
};
this._finalizeInputOutputRegistering();

this._frameGraphTask = new FrameGraphBlackAndWhiteTask(this.name, frameGraph, new ThinBlackAndWhitePostProcess(name, scene.getEngine()));
}

/** Sampling mode used to sample from the source texture */
@editableInPropertyPage("Source sampling mode", PropertyTypeForEdition.SamplingMode, "PROPERTIES")
public get sourceSamplingMode() {
return this._frameGraphTask.sourceSamplingMode;
}

public set sourceSamplingMode(value: number) {
this._frameGraphTask.sourceSamplingMode = value;
}

/** Degree of conversion to black and white (default: 1 - full b&w conversion) */
@editableInPropertyPage("Degree", PropertyTypeForEdition.Float, "PROPERTIES", { min: 0, max: 1 })
public get degree(): number {
Expand All @@ -71,54 +51,21 @@ export class NodeRenderGraphBlackAndWhitePostProcessBlock extends NodeRenderGrap
return "NodeRenderGraphBlackAndWhitePostProcessBlock";
}

/**
* Gets the source input component
*/
public get source(): NodeRenderGraphConnectionPoint {
return this._inputs[0];
}

/**
* Gets the destination input component
*/
public get destination(): 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; // the value of the output connection point is the "output" texture of the task

this._frameGraphTask.sourceTexture = this.source.connectedPoint?.value as FrameGraphTextureHandle;
this._frameGraphTask.destinationTexture = this.destination.connectedPoint?.value as FrameGraphTextureHandle;
}

protected override _dumpPropertiesCode() {
const codes: string[] = [];
codes.push(`${this._codeVariableName}.degree = ${this.degree};`);
codes.push(`${this._codeVariableName}.sourceSamplingMode = ${this.sourceSamplingMode};`);
return super._dumpPropertiesCode() + codes.join("\n");
}

public override serialize(): any {
const serializationObject = super.serialize();
serializationObject.degree = this.degree;
serializationObject.sourceSamplingMode = this.sourceSamplingMode;
return serializationObject;
}

public override _deserialize(serializationObject: any) {
super._deserialize(serializationObject);
this.degree = serializationObject.degree;
this.sourceSamplingMode = serializationObject.sourceSamplingMode;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// eslint-disable-next-line import/no-internal-modules
import type { NodeRenderGraphConnectionPoint, Scene, NodeRenderGraphBuildState, FrameGraphTextureHandle, FrameGraph } from "core/index";
import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock";
import type { Scene, FrameGraph } from "core/index";
import { RegisterClass } from "../../../../Misc/typeStore";
import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes";
import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator";
import { FrameGraphBloomTask } from "../../../Tasks/PostProcesses/bloomTask";
import { NodeRenderGraphBasePostProcessBlock } from "./basePostProcessBlock";

/**
* Block that implements the bloom post process
*/
export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {
export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBasePostProcessBlock {
protected override _frameGraphTask: FrameGraphBloomTask;

/**
Expand All @@ -32,16 +31,7 @@ export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {

this._additionalConstructionParameters = [hdr, bloomScale];

this.registerInput("source", NodeRenderGraphBlockConnectionPointTypes.Texture);
this.registerInput("destination", NodeRenderGraphBlockConnectionPointTypes.Texture, true);
this._addDependenciesInput();
this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput);

this.source.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer);
this.destination.addAcceptedConnectionPointTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAll);
this.output._typeConnectionSource = () => {
return this.destination.isConnected ? this.destination : this.source;
};
this._finalizeInputOutputRegistering();

this._frameGraphTask = new FrameGraphBloomTask(this.name, frameGraph, scene.getEngine(), 0.75, 64, 0.2, hdr, bloomScale);
}
Expand Down Expand Up @@ -80,16 +70,6 @@ export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {
this._createTask(this._frameGraphTask.bloom.scale, value);
}

/** Sampling mode used to sample from the source texture */
@editableInPropertyPage("Source sampling mode", PropertyTypeForEdition.SamplingMode)
public get sourceSamplingMode() {
return this._frameGraphTask.sourceSamplingMode;
}

public set sourceSamplingMode(value: number) {
this._frameGraphTask.sourceSamplingMode = value;
}

/** The luminance threshold to find bright areas of the image to bloom. */
@editableInPropertyPage("Threshold", PropertyTypeForEdition.Float, "PROPERTIES", { min: 0, max: 2 })
public get threshold(): number {
Expand Down Expand Up @@ -128,42 +108,11 @@ export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {
return "NodeRenderGraphBloomPostProcessBlock";
}

/**
* Gets the source input component
*/
public get source(): NodeRenderGraphConnectionPoint {
return this._inputs[0];
}

/**
* Gets the destination input component
*/
public get destination(): 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; // the value of the output connection point is the "output" texture of the task

this._frameGraphTask.sourceTexture = this.source.connectedPoint?.value as FrameGraphTextureHandle;
this._frameGraphTask.destinationTexture = this.destination.connectedPoint?.value as FrameGraphTextureHandle;
}

protected override _dumpPropertiesCode() {
const codes: string[] = [];
codes.push(`${this._codeVariableName}.threshold = ${this.threshold};`);
codes.push(`${this._codeVariableName}.weight = ${this.weight};`);
codes.push(`${this._codeVariableName}.kernel = ${this.kernel};`);
codes.push(`${this._codeVariableName}.sourceSamplingMode = ${this.sourceSamplingMode};`);
return super._dumpPropertiesCode() + codes.join("\n");
}

Expand All @@ -172,7 +121,6 @@ export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {
serializationObject.threshold = this.threshold;
serializationObject.weight = this.weight;
serializationObject.kernel = this.kernel;
serializationObject.sourceSamplingMode = this.sourceSamplingMode;
return serializationObject;
}

Expand All @@ -181,7 +129,6 @@ export class NodeRenderGraphBloomPostProcessBlock extends NodeRenderGraphBlock {
this.threshold = serializationObject.threshold;
this.weight = serializationObject.weight;
this.kernel = serializationObject.kernel;
this.sourceSamplingMode = serializationObject.sourceSamplingMode;
}
}

Expand Down
Loading
Loading