From 7ef5b35c4c3813a9d2a8aff3ed6fcf8c0f05e083 Mon Sep 17 00:00:00 2001 From: QTEvD Date: Wed, 22 May 2024 16:52:40 +0800 Subject: [PATCH] fix --- src/layaAir/laya/d3/component/PostProcess.ts | 55 ++++++++++--------- .../d3/core/render/PostEffect/GaussianDoF.ts | 11 ---- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/layaAir/laya/d3/component/PostProcess.ts b/src/layaAir/laya/d3/component/PostProcess.ts index d97c4be4ba..cd218e6e52 100644 --- a/src/layaAir/laya/d3/component/PostProcess.ts +++ b/src/layaAir/laya/d3/component/PostProcess.ts @@ -89,7 +89,7 @@ export class PostProcess { _enableColorGrad: boolean = false; /**@internal */ - _context: PostProcessRenderContext | null = null; + _context: PostProcessRenderContext; /** * 重新计算CameraFlag @@ -158,8 +158,8 @@ export class PostProcess { *@internal */ _init(camera: Camera): void { - this._context!.camera = camera; - this._context!.command!._camera = camera; + this._context.camera = camera; + this._context.command!._camera = camera; } /** @@ -167,42 +167,45 @@ export class PostProcess { */ _render(camera: Camera): void { this._init(camera); - var camera = this._context!.camera; - var viewport: Viewport = camera!.viewport; + + let context = this._context; + + var camera = context.camera; + var viewport: Viewport = camera.viewport; var internalRT = camera._needInternalRenderTexture(); var cameraTarget: RenderTexture = !internalRT ? RenderTexture.createFromPool(camera._offScreenRenderTexture.width, camera._offScreenRenderTexture.height, camera._getRenderTextureFormat(), RenderTargetFormat.None, false, 1, false, true) : camera._internalRenderTexture; var screenTexture: RenderTexture = RenderTexture.createFromPool(cameraTarget.width, cameraTarget.height, camera._getRenderTextureFormat(), RenderTargetFormat.None, false, 1, false, true); var Indirect: RenderTexture[] = [RenderTexture.createFromPool(cameraTarget.width, cameraTarget.height, camera._getRenderTextureFormat(), RenderTargetFormat.None, false, 1, false, true), RenderTexture.createFromPool(cameraTarget.width, cameraTarget.height, camera._getRenderTextureFormat(), RenderTargetFormat.None, false, 1, false, true)]; //var screenTexture: RenderTexture = cameraTarget; - this._context!.command!.clear(); - this._context!.source = screenTexture; - this._context!.indirectTarget = screenTexture; - this._context!.destination = this._effects.length == 2 ? Indirect[0] : cameraTarget; - this._context!.compositeShaderData!.clearDefine(); + context.command!.clear(); + context.source = screenTexture; + context.indirectTarget = screenTexture; + context.destination = this._effects.length == 2 ? Indirect[0] : cameraTarget; + context.compositeShaderData!.clearDefine(); if (internalRT) { - this._context.command.blitScreenTriangle(camera._internalRenderTexture, screenTexture); + context.command.blitScreenTriangle(camera._internalRenderTexture, screenTexture); } else { - this._context.command.blitScreenTriangle(camera._offScreenRenderTexture, screenTexture); + context.command.blitScreenTriangle(camera._offScreenRenderTexture, screenTexture); } - this._context!.compositeShaderData!.setTexture(PostProcess.SHADERVALUE_AUTOEXPOSURETEX, Texture2D.whiteTexture);//TODO: + context.compositeShaderData!.setTexture(PostProcess.SHADERVALUE_AUTOEXPOSURETEX, Texture2D.whiteTexture);//TODO: if (this._enableColorGrad) { this._ColorGradEffect._buildLUT(); } for (var i: number = 0, n: number = this._effects.length; i < n; i++) { if (this._effects[i].active) { - this._effects[i].render(this._context!); + this._effects[i].render(context); if (i == n - 2) {//last effect:destination RenderTexture is CameraTarget - this._context.indirectTarget = this._context.destination; - this._context.destination = cameraTarget; + context.indirectTarget = context.destination; + context.destination = cameraTarget; } else { - this._context.indirectTarget = this._context.destination; - this._context.destination = Indirect[(i + 1) % 2]; + context.indirectTarget = context.destination; + context.destination = Indirect[(i + 1) % 2]; } } else if (i == n - 1) {//兼容最后一个Effect Active为false - this._context.command.blitScreenTriangle(this._context.indirectTarget, cameraTarget); + context.command.blitScreenTriangle(context.indirectTarget, cameraTarget); } } @@ -210,15 +213,15 @@ export class PostProcess { if (camera._offScreenRenderTexture) { if (internalRT) { - this._context!.destination = camera._offScreenRenderTexture; - var canvasWidth: number = camera!._getCanvasWidth(), canvasHeight: number = camera!._getCanvasHeight(); + context.destination = camera._offScreenRenderTexture; + var canvasWidth: number = camera._getCanvasWidth(), canvasHeight: number = camera._getCanvasHeight(); if (LayaGL.renderEngine._screenInvertY) { - camera!._screenOffsetScale.setValue(viewport.x / canvasWidth, viewport.y / canvasHeight, viewport.width / canvasWidth, viewport.height / canvasHeight); + camera._screenOffsetScale.setValue(viewport.x / canvasWidth, viewport.y / canvasHeight, viewport.width / canvasWidth, viewport.height / canvasHeight); } else { - camera!._screenOffsetScale.setValue(viewport.x / canvasWidth, 1.0 - viewport.y / canvasHeight, viewport.width / canvasWidth, -viewport.height / canvasHeight); + camera._screenOffsetScale.setValue(viewport.x / canvasWidth, 1.0 - viewport.y / canvasHeight, viewport.width / canvasWidth, -viewport.height / canvasHeight); } - this._context!.command!.blitScreenTriangle(cameraTarget, camera._offScreenRenderTexture, camera!._screenOffsetScale, null, this._compositeShaderData, 0); + context.command!.blitScreenTriangle(cameraTarget, camera._offScreenRenderTexture, camera._screenOffsetScale, null, this._compositeShaderData, 0); } } @@ -227,7 +230,7 @@ export class PostProcess { RenderTexture.recoverToPool(screenTexture); RenderTexture.recoverToPool(Indirect[0]); RenderTexture.recoverToPool(Indirect[1]); - var tempRenderTextures: RenderTexture[] = this._context!.deferredReleaseTextures; + var tempRenderTextures: RenderTexture[] = context.deferredReleaseTextures; for (i = 0, n = tempRenderTextures.length; i < n; i++) RenderTexture.recoverToPool(tempRenderTextures[i]); tempRenderTextures.length = 0; @@ -296,7 +299,7 @@ export class PostProcess { * @internal */ _applyPostProcessCommandBuffers(): void { - this._context!.command!._apply(); + this._context.command!._apply(); } } diff --git a/src/layaAir/laya/d3/core/render/PostEffect/GaussianDoF.ts b/src/layaAir/laya/d3/core/render/PostEffect/GaussianDoF.ts index ee71f1a873..df9f778ad5 100644 --- a/src/layaAir/laya/d3/core/render/PostEffect/GaussianDoF.ts +++ b/src/layaAir/laya/d3/core/render/PostEffect/GaussianDoF.ts @@ -57,9 +57,6 @@ export class GaussianDoF extends PostProcessEffect { /**@internal */ static SHADERDEFINE_DEPTHNORMALTEXTURE: ShaderDefine; - /**@internal */ - static PROJECTIONPARAM: number; - /** * GaussianDOF resource init */ @@ -73,7 +70,6 @@ export class GaussianDoF extends PostProcessEffect { GaussianDoF.DOWNSAMPLESCALE = Shader3D.propertyNameToID("u_DownSampleScale"); GaussianDoF.BLURCOCTEXTURE = Shader3D.propertyNameToID("u_BlurCoCTex"); GaussianDoF.SHADERDEFINE_DEPTHNORMALTEXTURE = Shader3D.getDefineByName("CAMERA_NORMALDEPTH"); - GaussianDoF.PROJECTIONPARAM = Shader3D.propertyNameToID("u_ProjectionParam"); let attributeMap: any = { 'a_PositionTexcoord': [VertexMesh.MESH_POSITION0, ShaderDataType.Vector4], @@ -84,7 +80,6 @@ export class GaussianDoF extends PostProcessEffect { "u_MainTex_TexelSize": ShaderDataType.Vector4, "u_OffsetScale": ShaderDataType.Vector4, "u_ZBufferParams": ShaderDataType.Vector4, - "u_ProjectionParam": ShaderDataType.Vector4, "u_CoCParams": ShaderDataType.Vector3, "u_FullCoCTex": ShaderDataType.Texture2D, "u_SourceSize": ShaderDataType.Vector4, @@ -154,8 +149,6 @@ export class GaussianDoF extends PostProcessEffect { /**@internal */ private _zBufferParams: Vector4; - private _projectionParams: Vector4; - /**@internal */ private _sourceSize: Vector4; @@ -171,7 +164,6 @@ export class GaussianDoF extends PostProcessEffect { this._shaderData = LayaGL.renderDeviceFactory.createShaderData(null); this._shaderData.setVector3(GaussianDoF.COCPARAMS, new Vector3(10, 30, 1)); this._zBufferParams = new Vector4(); - this._projectionParams = new Vector4(); this._sourceSize = new Vector4(); this._dowmSampleScale = new Vector4(); } @@ -227,9 +219,6 @@ export class GaussianDoF extends PostProcessEffect { let near = camera.nearPlane; this._zBufferParams.setValue(1.0 - far / near, far / near, (near - far) / (near * far), 1 / near); this._shaderData.setVector(GaussianDoF.ZBUFFERPARAMS, this._zBufferParams); - let invertY = !!camera._offScreenRenderTexture; - this._projectionParams.setValue(near, far, invertY ? -1 : 1, 1 / far); - this._shaderData.setVector(GaussianDoF.PROJECTIONPARAM, this._projectionParams); }