|
| 1 | +import type { FrameGraphPostProcessTask, IViewportLike } from "core/index"; |
| 2 | +import { editableInPropertyPage, PropertyTypeForEdition } from "../../../../Decorators/nodeDecorator"; |
| 3 | +import { NodeRenderGraphBasePostProcessBlock } from "./basePostProcessBlock"; |
| 4 | + |
| 5 | +/** |
| 6 | + * @internal |
| 7 | + */ |
| 8 | +export class NodeRenderGraphBaseWithPropertiesPostProcessBlock extends NodeRenderGraphBasePostProcessBlock { |
| 9 | + protected override _frameGraphTask: FrameGraphPostProcessTask; |
| 10 | + |
| 11 | + protected _useCurrentViewport = false; |
| 12 | + protected _useFullScreenViewport = true; |
| 13 | + protected _viewport: IViewportLike = { x: 0, y: 0, width: 1, height: 1 }; |
| 14 | + |
| 15 | + /** If true, the depth attachment will be read-only. */ |
| 16 | + @editableInPropertyPage("Depth Read Only", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 17 | + public get depthReadOnly(): boolean { |
| 18 | + return this._frameGraphTask.depthReadOnly; |
| 19 | + } |
| 20 | + |
| 21 | + public set depthReadOnly(value: boolean) { |
| 22 | + this._frameGraphTask.depthReadOnly = value; |
| 23 | + } |
| 24 | + |
| 25 | + /** If true, the stencil attachment will be read-only. */ |
| 26 | + @editableInPropertyPage("Stencil Read Only", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 27 | + public get stencilReadOnly(): boolean { |
| 28 | + return this._frameGraphTask.stencilReadOnly; |
| 29 | + } |
| 30 | + |
| 31 | + public set stencilReadOnly(value: boolean) { |
| 32 | + this._frameGraphTask.stencilReadOnly = value; |
| 33 | + } |
| 34 | + |
| 35 | + /** If true, color write will be disabled when applying the post process. */ |
| 36 | + @editableInPropertyPage("Disable Color Write", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 37 | + public get disableColorWrite(): boolean { |
| 38 | + return this._frameGraphTask.disableColorWrite; |
| 39 | + } |
| 40 | + |
| 41 | + public set disableColorWrite(value: boolean) { |
| 42 | + this._frameGraphTask.disableColorWrite = value; |
| 43 | + } |
| 44 | + |
| 45 | + /** If true, the post process will be generated by a back face full-screen quad (CW order). */ |
| 46 | + @editableInPropertyPage("Draw Back Face", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 47 | + public get drawBackFace(): boolean { |
| 48 | + return this._frameGraphTask.drawBackFace; |
| 49 | + } |
| 50 | + |
| 51 | + public set drawBackFace(value: boolean) { |
| 52 | + this._frameGraphTask.drawBackFace = value; |
| 53 | + } |
| 54 | + |
| 55 | + /** If depth testing should be enabled (default is true). */ |
| 56 | + @editableInPropertyPage("Depth Test", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 57 | + public get depthTest(): boolean { |
| 58 | + return this._frameGraphTask.depthTest; |
| 59 | + } |
| 60 | + |
| 61 | + public set depthTest(value: boolean) { |
| 62 | + this._frameGraphTask.depthTest = value; |
| 63 | + } |
| 64 | + |
| 65 | + private _setViewport() { |
| 66 | + if (this._useCurrentViewport) { |
| 67 | + this._frameGraphTask.viewport = null; |
| 68 | + } else if (this._useFullScreenViewport) { |
| 69 | + this._frameGraphTask.viewport = undefined; |
| 70 | + } else { |
| 71 | + this._frameGraphTask.viewport = this._viewport; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + /** If true, the current viewport will be left unchanged. */ |
| 76 | + @editableInPropertyPage("Use currently active viewport", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 77 | + public get useCurrentViewport(): boolean { |
| 78 | + return this._useCurrentViewport; |
| 79 | + } |
| 80 | + |
| 81 | + public set useCurrentViewport(value: boolean) { |
| 82 | + this._useCurrentViewport = value; |
| 83 | + this._setViewport(); |
| 84 | + } |
| 85 | + |
| 86 | + /** If true, a full screen viewport will be used. */ |
| 87 | + @editableInPropertyPage("Use full screen viewport", PropertyTypeForEdition.Boolean, "BASE PROPERTIES") |
| 88 | + public get useFullScreenViewport(): boolean { |
| 89 | + return this._useFullScreenViewport; |
| 90 | + } |
| 91 | + |
| 92 | + public set useFullScreenViewport(value: boolean) { |
| 93 | + this._useFullScreenViewport = value; |
| 94 | + this._setViewport(); |
| 95 | + } |
| 96 | + |
| 97 | + /** The viewport to use. */ |
| 98 | + @editableInPropertyPage("Viewport", PropertyTypeForEdition.Viewport, "BASE PROPERTIES") |
| 99 | + public get viewport(): IViewportLike { |
| 100 | + return this._viewport; |
| 101 | + } |
| 102 | + |
| 103 | + public set viewport(value: IViewportLike) { |
| 104 | + this._viewport = value; |
| 105 | + this._setViewport(); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Gets the current class name |
| 110 | + * @returns the class name |
| 111 | + */ |
| 112 | + public override getClassName() { |
| 113 | + return "NodeRenderGraphBaseWithPropertiesPostProcessBlock"; |
| 114 | + } |
| 115 | + |
| 116 | + protected override _dumpPropertiesCode() { |
| 117 | + const codes: string[] = []; |
| 118 | + codes.push(`${this._codeVariableName}.depthReadOnly = ${this.depthReadOnly};`); |
| 119 | + codes.push(`${this._codeVariableName}.stencilReadOnly = ${this.stencilReadOnly};`); |
| 120 | + codes.push(`${this._codeVariableName}.disableColorWrite = ${this.disableColorWrite};`); |
| 121 | + codes.push(`${this._codeVariableName}.drawBackFace = ${this.drawBackFace};`); |
| 122 | + codes.push(`${this._codeVariableName}.depthTest = ${this.depthTest};`); |
| 123 | + codes.push(`${this._codeVariableName}.viewport = ${this._useCurrentViewport ? "null" : this._useFullScreenViewport ? "undefined" : JSON.stringify(this._viewport)};`); |
| 124 | + return super._dumpPropertiesCode() + codes.join("\n"); |
| 125 | + } |
| 126 | + |
| 127 | + public override serialize(): any { |
| 128 | + const serializationObject = super.serialize(); |
| 129 | + serializationObject.depthReadOnly = this.depthReadOnly; |
| 130 | + serializationObject.stencilReadOnly = this.stencilReadOnly; |
| 131 | + serializationObject.disableColorWrite = this.disableColorWrite; |
| 132 | + serializationObject.drawBackFace = this.drawBackFace; |
| 133 | + serializationObject.depthTest = this.depthTest; |
| 134 | + serializationObject.useCurrentViewport = this._useCurrentViewport; |
| 135 | + serializationObject.useFullScreenViewport = this._useFullScreenViewport; |
| 136 | + serializationObject.viewport = this._viewport; |
| 137 | + return serializationObject; |
| 138 | + } |
| 139 | + |
| 140 | + public override _deserialize(serializationObject: any) { |
| 141 | + super._deserialize(serializationObject); |
| 142 | + this.depthReadOnly = !!serializationObject.depthReadOnly; |
| 143 | + this.stencilReadOnly = !!serializationObject.stencilReadOnly; |
| 144 | + this.disableColorWrite = !!serializationObject.disableColorWrite; |
| 145 | + this.drawBackFace = !!serializationObject.drawBackFace; |
| 146 | + this.depthTest = serializationObject.depthTest ?? true; |
| 147 | + if (serializationObject.useCurrentViewport !== undefined) { |
| 148 | + this._useCurrentViewport = serializationObject.useCurrentViewport; |
| 149 | + this._useFullScreenViewport = serializationObject.useFullScreenViewport; |
| 150 | + this._viewport = serializationObject.viewport; |
| 151 | + } |
| 152 | + this._setViewport(); |
| 153 | + } |
| 154 | +} |
0 commit comments