diff --git a/EngineErrorMap.md b/EngineErrorMap.md index dd4a573786..63044a3c4d 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -245,6 +245,13 @@ Director.runSceneImmediate: scene is not valid ### 1217 Director._initOnEngineInitialized: renderer root initialization failed +### 1218 + +Forward render pipeline initialized. + +### 1219 + +Deferred render pipeline initialized. Note that non-transparent materials with no lighting will not be rendered, such as builtin-unlit. ### 1300 diff --git a/cocos/core/pipeline/deferred/deferred-pipeline-scene-data.ts b/cocos/core/pipeline/deferred/deferred-pipeline-scene-data.ts new file mode 100644 index 0000000000..538c0eeae7 --- /dev/null +++ b/cocos/core/pipeline/deferred/deferred-pipeline-scene-data.ts @@ -0,0 +1,105 @@ +/* + Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { JSB } from 'internal:constants'; +import { Device } from '../../gfx'; +import { RenderPipeline } from '../render-pipeline'; +import { builtinResMgr } from '../../builtin/builtin-res-mgr'; +import { Material } from '../../assets'; +import { PipelineSceneData } from '../pipeline-scene-data'; + +export class DeferredPipelineSceneData extends PipelineSceneData { + public get deferredLightingMaterial () { + return this._deferredLightingMaterial; + } + + public set deferredLightingMaterial (mat: Material) { + if (this._deferredLightingMaterial === mat) return; + this._deferredLightingMaterial = (mat && mat.effectAsset) ? mat : builtinResMgr.get('builtin-deferred-material'); + this.updateDeferredPassInfo(); + } + + public get deferredPostMaterial () { + return this._deferredPostMaterial; + } + + public set deferredPostMaterial (mat: Material) { + if (this._deferredPostMaterial === mat) return; + this._deferredPostMaterial = (mat && mat.effectAsset) ? mat : builtinResMgr.get('builtin-post-process-material'); + this.updateDeferredPassInfo(); + } + + protected declare _deferredLightingMaterial: Material; + protected declare _deferredPostMaterial: Material; + + public onGlobalPipelineStateChanged () { + this.updateDeferredPassInfo(); + } + + public initPipelinePassInfo () { + this._deferredLightingMaterial = builtinResMgr.get('builtin-deferred-material'); + this._deferredPostMaterial = builtinResMgr.get('builtin-post-process-material'); + this.updateDeferredPassInfo(); + } + + public activate (device: Device, pipeline: RenderPipeline) { + super.activate(device, pipeline); + this.initPipelinePassInfo(); + return true; + } + + private updateDeferredPassInfo () { + this.updateDeferredLightPass(); + this.updateDeferredPostPass(); + } + + private updateDeferredLightPass () { + if (!this._deferredLightingMaterial) return; + + const passLit = this._deferredLightingMaterial.passes[0]; + passLit.beginChangeStatesSilently(); + passLit.tryCompile(); + passLit.endChangeStatesSilently(); + + if (JSB) { + this._nativeObj!.deferredLightPassShader = passLit.getShaderVariant(); + this._nativeObj!.deferredLightPass = passLit.native; + } + } + + private updateDeferredPostPass () { + if (!this.deferredPostMaterial) return; + + const passPost = this.deferredPostMaterial.passes[0]; + passPost.beginChangeStatesSilently(); + passPost.tryCompile(); + passPost.endChangeStatesSilently(); + + if (JSB) { + this._nativeObj!.deferredPostPassShader = passPost.getShaderVariant(); + this._nativeObj!.deferredPostPass = passPost.native; + } + } +} diff --git a/cocos/core/pipeline/deferred/deferred-pipeline.ts b/cocos/core/pipeline/deferred/deferred-pipeline.ts index 9b2fa1ec3d..07e1b1f49f 100644 --- a/cocos/core/pipeline/deferred/deferred-pipeline.ts +++ b/cocos/core/pipeline/deferred/deferred-pipeline.ts @@ -28,25 +28,28 @@ */ import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; +import { EDITOR } from 'internal:constants'; import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib'; import { builtinResMgr } from '../../builtin/builtin-res-mgr'; import { Texture2D } from '../../assets/texture-2d'; import { RenderPipeline, IRenderPipelineInfo } from '../render-pipeline'; import { GbufferFlow } from './gbuffer-flow'; import { LightingFlow } from './lighting-flow'; -import { RenderTextureConfig, MaterialConfig } from '../pipeline-serialization'; +import { RenderTextureConfig } from '../pipeline-serialization'; import { ShadowFlow } from '../shadow/shadow-flow'; import { BufferUsageBit, Format, MemoryUsageBit, ClearFlagBit, ClearFlags, StoreOp, Filter, Address, SurfaceTransform, ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, RenderPassInfo, BufferInfo, Texture, InputAssembler, InputAssemblerInfo, Attribute, Buffer, AccessType, Framebuffer, TextureInfo, TextureType, TextureUsageBit, FramebufferInfo, Rect } from '../../gfx'; import { UBOGlobal, UBOCamera, UBOShadow, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, UNIFORM_GBUFFER_ALBEDOMAP_BINDING, - UNIFORM_GBUFFER_POSITIONMAP_BINDING, UNIFORM_GBUFFER_NORMALMAP_BINDING, UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, - UNIFORM_LIGHTING_RESULTMAP_BINDING } from '../define'; + UNIFORM_GBUFFER_POSITIONMAP_BINDING, UNIFORM_GBUFFER_NORMALMAP_BINDING, UNIFORM_GBUFFER_EMISSIVEMAP_BINDING, UNIFORM_LIGHTING_RESULTMAP_BINDING } from '../define'; import { SKYBOX_FLAG } from '../../renderer/scene/camera'; import { Camera } from '../../renderer/scene'; -import { errorID } from '../../platform/debug'; +import { errorID, warnID } from '../../platform/debug'; import { sceneCulling } from '../scene-culling'; +import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data'; + +const PIPELINE_TYPE = 1; const _samplerInfo = [ Filter.POINT, @@ -95,11 +98,6 @@ export class DeferredPipeline extends RenderPipeline { @serializable @displayOrder(2) protected renderTextures: RenderTextureConfig[] = []; - - @type([MaterialConfig]) - @serializable - @displayOrder(3) - protected materials: MaterialConfig[] = []; protected _renderPasses = new Map(); /** @@ -135,7 +133,10 @@ export class DeferredPipeline extends RenderPipeline { } public activate (): boolean { - this._macros.CC_PIPELINE_TYPE = 1; + if (EDITOR) { warnID(1219); } + + this._macros = { CC_PIPELINE_TYPE: PIPELINE_TYPE }; + this._pipelineSceneData = new DeferredPipelineSceneData(); if (!super.activate()) { return false; diff --git a/cocos/core/pipeline/deferred/lighting-stage.ts b/cocos/core/pipeline/deferred/lighting-stage.ts index c75eccc002..e3c72170fe 100644 --- a/cocos/core/pipeline/deferred/lighting-stage.ts +++ b/cocos/core/pipeline/deferred/lighting-stage.ts @@ -28,7 +28,6 @@ */ import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; -import { builtinResMgr } from '../../builtin/builtin-res-mgr'; import { Camera } from '../../renderer/scene'; import { localDescriptorSetLayout, UBODeferredLight, SetIndex, UBOForwardLight } from '../define'; import { getPhaseID } from '../pass-phase'; @@ -44,12 +43,12 @@ import { PipelineStateManager } from '../pipeline-state-manager'; import { intersect, Sphere } from '../../geometry'; import { Vec3, Vec4 } from '../../math'; import { SRGBToLinear } from '../pipeline-funcs'; +import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data'; import { Pass } from '../../renderer/core/pass'; import { renderQueueClearFunc, RenderQueue, convertRenderQueue, renderQueueSortFunc } from '../render-queue'; import { RenderQueueDesc } from '../pipeline-serialization'; const colors: Color[] = [new Color(0, 0, 0, 1)]; -const LIGHTINGPASS_INDEX = 1; /** * @en The lighting render stage @@ -84,20 +83,10 @@ export class LightingStage extends RenderStage { priority: DeferredStagePriority.LIGHTING, tag: 0, }; - - set material (val) { - if (this._deferredMaterial === val) { - return; - } - - this._deferredMaterial = val; - } - public initialize (info: IRenderStageInfo): boolean { super.initialize(info); return true; } - public gatherLights (camera: Camera) { const pipeline = this._pipeline as DeferredPipeline; const cmdBuff = pipeline.commandBuffers[0]; @@ -218,6 +207,8 @@ export class LightingStage extends RenderStage { this._descriptorSet.bindBuffer(UBOForwardLight.BINDING, deferredLitsBufView); this._planarQueue = new PlanarShadowQueue(this._pipeline as DeferredPipeline); + + if (this._deferredMaterial) { (pipeline.pipelineSceneData as DeferredPipelineSceneData).deferredLightingMaterial = this._deferredMaterial; } } public destroy () { @@ -231,8 +222,8 @@ export class LightingStage extends RenderStage { const device = pipeline.device; const cmdBuff = pipeline.commandBuffers[0]; - - const renderObjects = pipeline.pipelineSceneData.renderObjects; + const sceneData = pipeline.pipelineSceneData; + const renderObjects = sceneData.renderObjects; if (renderObjects.length === 0) { return; } @@ -248,9 +239,9 @@ export class LightingStage extends RenderStage { this._renderArea = pipeline.generateRenderArea(camera); if (camera.clearFlag & ClearFlagBit.COLOR) { - if (pipeline.pipelineSceneData.isHDR) { + if (sceneData.isHDR) { SRGBToLinear(colors[0], camera.clearColor); - const scale = pipeline.pipelineSceneData.fpScale / camera.exposure; + const scale = sceneData.fpScale / camera.exposure; colors[0].x *= scale; colors[0].y *= scale; colors[0].z *= scale; @@ -272,16 +263,10 @@ export class LightingStage extends RenderStage { cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, pipeline.descriptorSet); // Lighting - let pass: Pass; - let shader: Shader; - const builinDeferred = builtinResMgr.get('builtin-deferred-material'); - if (builinDeferred) { - pass = builinDeferred.passes[0]; - shader = pass.getShaderVariant()!; - } else { - pass = this._deferredMaterial!.passes[LIGHTINGPASS_INDEX]; - shader = this._deferredMaterial!.passes[LIGHTINGPASS_INDEX].getShaderVariant()!; - } + const lightingMat = (sceneData as DeferredPipelineSceneData).deferredLightingMaterial; + const pass = lightingMat.passes[0]; + const shader = pass.getShaderVariant(); + cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet); const inputAssembler = pipeline.quadIAOffscreen; let pso:PipelineState|null = null; diff --git a/cocos/core/pipeline/deferred/postprocess-stage.ts b/cocos/core/pipeline/deferred/postprocess-stage.ts index 7bae771ff9..2f13510992 100644 --- a/cocos/core/pipeline/deferred/postprocess-stage.ts +++ b/cocos/core/pipeline/deferred/postprocess-stage.ts @@ -28,7 +28,6 @@ */ import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; -import { builtinResMgr } from '../../builtin'; import { Camera } from '../../renderer/scene'; import { SetIndex } from '../define'; import { Color, Rect, Shader, PipelineState, ClearFlagBit } from '../../gfx'; @@ -38,11 +37,13 @@ import { LightingFlow } from './lighting-flow'; import { DeferredPipeline } from './deferred-pipeline'; import { Material } from '../../assets/material'; import { PipelineStateManager } from '../pipeline-state-manager'; -import { Pass } from '../../renderer'; import { UIPhase } from '../forward/ui-phase'; +import { opaqueCompareFn, RenderQueue, transparentCompareFn } from '../render-queue'; +import { RenderQueueDesc, RenderQueueSortMode } from '../pipeline-serialization'; +import { getPhaseID } from '../pass-phase'; +import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data'; const colors: Color[] = [new Color(0, 0, 0, 1)]; -const POSTPROCESSPASS_INDEX = 0; /** * @en The postprocess render stage @@ -59,18 +60,16 @@ export class PostprocessStage extends RenderStage { @type(Material) @serializable @displayOrder(3) - private _postprocessMaterial: Material | null = null; + private _postProcessMaterial: Material | null = null; + + @type([RenderQueueDesc]) + @serializable + @displayOrder(2) + private renderQueues: RenderQueueDesc[] = []; + private _renderArea = new Rect(); private _uiPhase: UIPhase; - set material (val) { - if (this._postprocessMaterial === val) { - return; - } - - this._postprocessMaterial = val; - } - constructor () { super(); this._uiPhase = new UIPhase(); @@ -84,6 +83,7 @@ export class PostprocessStage extends RenderStage { public activate (pipeline: DeferredPipeline, flow: LightingFlow) { super.activate(pipeline, flow); this._uiPhase.activate(pipeline); + if (this._postProcessMaterial) { (pipeline.pipelineSceneData as DeferredPipelineSceneData).deferredPostMaterial = this._postProcessMaterial; } } public destroy () { @@ -92,7 +92,7 @@ export class PostprocessStage extends RenderStage { public render (camera: Camera) { const pipeline = this._pipeline as DeferredPipeline; const device = pipeline.device; - + const sceneData = pipeline.pipelineSceneData; const cmdBuff = pipeline.commandBuffers[0]; pipeline.pipelineUBO.updateCameraUBO(camera); @@ -100,8 +100,8 @@ export class PostprocessStage extends RenderStage { const vp = camera.viewport; this._renderArea.x = vp.x * camera.width; this._renderArea.y = vp.y * camera.height; - this._renderArea.width = vp.width * camera.width * pipeline.pipelineSceneData.shadingScale; - this._renderArea.height = vp.height * camera.height * pipeline.pipelineSceneData.shadingScale; + this._renderArea.width = vp.width * camera.width * sceneData.shadingScale; + this._renderArea.height = vp.height * camera.height * sceneData.shadingScale; const framebuffer = camera.window!.framebuffer; const renderPass = framebuffer.colorTextures[0] ? framebuffer.renderPass : pipeline.getRenderPass(camera.clearFlag); @@ -120,16 +120,10 @@ export class PostprocessStage extends RenderStage { cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, pipeline.descriptorSet); // Postprocess - let pass: Pass; - let shader: Shader; - const builtinPostProcess = builtinResMgr.get('builtin-post-process-material'); - if (builtinPostProcess) { - pass = builtinPostProcess.passes[0]; - shader = pass.getShaderVariant()!; - } else { - pass = this._postprocessMaterial!.passes[POSTPROCESSPASS_INDEX]; - shader = this._postprocessMaterial!.passes[POSTPROCESSPASS_INDEX].getShaderVariant()!; - } + const builtinPostProcess = (sceneData as DeferredPipelineSceneData).deferredPostMaterial; + const pass = builtinPostProcess.passes[0]; + const shader = pass.getShaderVariant(); + cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet); const inputAssembler = camera.window!.hasOffScreenAttachments ? pipeline.quadIAOffscreen : pipeline.quadIAOnscreen; let pso:PipelineState|null = null; diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index f3b9eb84bf..96df5524c7 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -29,20 +29,24 @@ */ import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; +import { EDITOR } from 'internal:constants'; import { RenderPipeline, IRenderPipelineInfo } from '../render-pipeline'; import { ForwardFlow } from './forward-flow'; -import { RenderTextureConfig, MaterialConfig } from '../pipeline-serialization'; +import { RenderTextureConfig } from '../pipeline-serialization'; import { ShadowFlow } from '../shadow/shadow-flow'; import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from '../define'; import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, - RenderPassInfo, Feature, ClearFlagBit, ClearFlags, Filter, Address, StoreOp, AccessType } from '../../gfx'; + RenderPassInfo, ClearFlagBit, ClearFlags, Filter, Address, StoreOp, AccessType } from '../../gfx'; import { SKYBOX_FLAG } from '../../renderer/scene/camera'; import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib'; import { builtinResMgr } from '../../builtin'; import { Texture2D } from '../../assets/texture-2d'; import { Camera } from '../../renderer/scene'; -import { errorID } from '../../platform/debug'; +import { errorID, warnID } from '../../platform/debug'; import { sceneCulling } from '../scene-culling'; +import { PipelineSceneData } from '../pipeline-scene-data'; + +const PIPELINE_TYPE = 0; const _samplerInfo = [ Filter.POINT, @@ -64,10 +68,6 @@ export class ForwardPipeline extends RenderPipeline { @displayOrder(2) protected renderTextures: RenderTextureConfig[] = []; - @type([MaterialConfig]) - @serializable - @displayOrder(3) - protected materials: MaterialConfig[] = []; protected _renderPasses = new Map(); public initialize (info: IRenderPipelineInfo): boolean { @@ -87,6 +87,11 @@ export class ForwardPipeline extends RenderPipeline { } public activate (): boolean { + if (EDITOR) { warnID(1218); } + + this._macros = { CC_PIPELINE_TYPE: PIPELINE_TYPE }; + this._pipelineSceneData = new PipelineSceneData(); + if (!super.activate()) { return false; } diff --git a/cocos/core/pipeline/index.jsb.ts b/cocos/core/pipeline/index.jsb.ts index 65d49bf4e1..30e927cf99 100644 --- a/cocos/core/pipeline/index.jsb.ts +++ b/cocos/core/pipeline/index.jsb.ts @@ -27,9 +27,11 @@ declare const nr: any; import { getPhaseID } from './pass-phase' -import { setClassName } from '../../core/utils/js'; +import { setClassName, mixin } from '../../core/utils/js'; import { PipelineSceneData } from './pipeline-scene-data'; +import { DeferredPipelineSceneData } from './deferred/deferred-pipeline-scene-data'; import { legacyCC } from '../../core/global-exports'; +import { Asset } from '../assets/asset'; nr.getPhaseID = getPhaseID; @@ -91,8 +93,16 @@ export class ForwardPipeline extends nr.ForwardPipeline { super.destroy(); } } + +mixin(ForwardPipeline, Asset); + +const ForwardOnLoaded = ForwardPipeline.prototype.onLoaded; + // hook to invoke init after deserialization -ForwardPipeline.prototype.onAfterDeserialize_JSB = ForwardPipeline.prototype.init; +ForwardPipeline.prototype.onLoaded = function () { + if (ForwardOnLoaded) ForwardOnLoaded.call(this); + this.init(); +} export class ForwardFlow extends nr.ForwardFlow { constructor() { @@ -176,7 +186,7 @@ export class RenderQueueDesc { } export class DeferredPipeline extends nr.DeferredPipeline { - public pipelineSceneData = new PipelineSceneData(); + public pipelineSceneData = new DeferredPipelineSceneData(); constructor() { super(); this._tag = 0; @@ -188,7 +198,7 @@ export class DeferredPipeline extends nr.DeferredPipeline { init() { this.setPipelineSharedSceneData(this.pipelineSceneData.native); for (let i = 0; i < this._flows.length; i++) { - this._flows[i].init(); + this._flows[i].init(this); } let info = new nr.RenderPipelineInfo(this._tag, this._flows); this.initialize(info); @@ -217,8 +227,15 @@ export class DeferredPipeline extends nr.DeferredPipeline { } +mixin(DeferredPipeline, Asset); + +const DeferredOnLoaded = DeferredPipeline.prototype.onLoaded; + // hook to invoke init after deserialization -DeferredPipeline.prototype.onAfterDeserialize_JSB = DeferredPipeline.prototype.init; +DeferredPipeline.prototype.onLoaded = function () { + if (DeferredOnLoaded) DeferredOnLoaded.call(this); + this.init(); +} export class GbufferFlow extends nr.GbufferFlow { constructor() { @@ -229,9 +246,9 @@ export class GbufferFlow extends nr.GbufferFlow { this._stages = []; } - init() { + init(pipeline) { for (let i = 0; i < this._stages.length; i++) { - this._stages[i].init(); + this._stages[i].init(pipeline); } let info = new nr.RenderFlowInfo( this._name, this._priority, this._tag, this._stages); @@ -248,7 +265,7 @@ export class GbufferStage extends nr.GbufferStage { this.renderQueues = [] } - init() { + init(pipeline) { const queues = []; for (let i = 0; i < this.renderQueues.length; i++) { queues.push(this.renderQueues[i].init()); @@ -267,9 +284,9 @@ class LightingFlow extends nr.LightingFlow { this._tag = 0; this._stages = []; } - init() { + init(pipeline) { for (let i = 0; i < this._stages.length; i++) { - this._stages[i].init(); + this._stages[i].init(pipeline); } let info = new nr.RenderFlowInfo( this._name, this._priority, this._tag, this._stages); @@ -284,12 +301,14 @@ export class LightingStage extends nr.LightingStage { this._priority = 0; this._tag = 0; this.renderQueues = []; + this._deferredMaterial = null; } - init() { + init(pipeline) { const queues = []; for (let i = 0; i < this.renderQueues.length; i++) { queues.push(this.renderQueues[i].init()); } + pipeline.pipelineSceneData.deferredLightingMaterial = this._deferredMaterial; let info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues); this.initialize(info); @@ -303,12 +322,14 @@ export class PostprocessStage extends nr.PostprocessStage { this._priority = 0; this._tag = 0; this.renderQueues = []; + this._postProcessMaterial = null; } - init() { + init(pipeline) { const queues = []; for (let i = 0; i < this.renderQueues.length; i++) { queues.push(this.renderQueues[i].init()); } + pipeline.pipelineSceneData.deferredPostMaterial = this._postProcessMaterial; let info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues); this.initialize(info); diff --git a/cocos/core/pipeline/pipeline-scene-data.ts b/cocos/core/pipeline/pipeline-scene-data.ts index 365d2bea84..f35917ee05 100644 --- a/cocos/core/pipeline/pipeline-scene-data.ts +++ b/cocos/core/pipeline/pipeline-scene-data.ts @@ -32,8 +32,6 @@ import { IRenderObject } from './define'; import { Device, Framebuffer } from '../gfx'; import { RenderPipeline } from './render-pipeline'; import { Light } from '../renderer/scene/light'; -import { builtinResMgr } from '../builtin/builtin-res-mgr'; -import { Material } from '../assets'; import { NativePipelineSharedSceneData } from '../renderer/scene'; export class PipelineSceneData { @@ -79,13 +77,13 @@ export class PipelineSceneData { public get fpScale () { return this._fpScale; } - public set fpScale (val: number) { this._fpScale = val; if (JSB) { this._fpScale = val; } } + public fog: Fog = new Fog(); public ambient: Ambient = new Ambient(); public skybox: Skybox = new Skybox(); @@ -110,44 +108,15 @@ export class PipelineSceneData { this.fpScale = 1.0 / 1024.0; } - public initDeferredPassInfo () { - const builinDeferred = builtinResMgr.get('builtin-deferred-material'); - if (builinDeferred) { - const passLit = builinDeferred.passes[0]; - passLit.beginChangeStatesSilently(); - passLit.tryCompile(); - passLit.endChangeStatesSilently(); - } - - const builtinPostProcess = builtinResMgr.get('builtin-post-process-material'); - if (builtinPostProcess) { - const passPost = builtinPostProcess.passes[0]; - passPost.beginChangeStatesSilently(); - passPost.tryCompile(); - passPost.endChangeStatesSilently(); - } - - if (builinDeferred && JSB) { - const passLit = builinDeferred.passes[0]; - this._nativeObj!.deferredLightPassShader = passLit.getShaderVariant(); - this._nativeObj!.deferredLightPass = passLit.native; - } - - if (builtinPostProcess && JSB) { - const passPost = builtinPostProcess.passes[0]; - const shaderHandle = passPost.getShaderVariant(); - this._nativeObj!.deferredPostPassShader = passPost.getShaderVariant(); - this._nativeObj!.deferredPostPass = passPost.native; - } - } - public activate (device: Device, pipeline: RenderPipeline) { this._device = device; this._pipeline = pipeline; - this.initDeferredPassInfo(); return true; } + public onGlobalPipelineStateChanged () { + } + public destroy () { this.ambient.destroy(); this.skybox.destroy(); diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index d298cb3c3b..3944248d56 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -150,9 +150,9 @@ export abstract class RenderPipeline extends Asset { protected _descriptorSet!: DescriptorSet; protected _commandBuffers: CommandBuffer[] = []; protected _pipelineUBO = new PipelineUBO(); - protected _pipelineSceneData = new PipelineSceneData(); protected _macros: MacroRecord = {}; protected _constantMacros = ''; + protected declare _pipelineSceneData: PipelineSceneData; /** * @en The initialization process, user shouldn't use it in most case, only useful when need to generate render pipeline programmatically. diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 72f1f78c30..443d66c80b 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -372,7 +372,7 @@ export class Root { this._scenes[i].onGlobalPipelineStateChanged(); } - this._pipeline!.pipelineSceneData.initDeferredPassInfo(); + this._pipeline!.pipelineSceneData.onGlobalPipelineStateChanged(); } /**