Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
QTED committed May 24, 2024
1 parent cd68ddd commit 7ef5b35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
55 changes: 29 additions & 26 deletions src/layaAir/laya/d3/component/PostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class PostProcess {
_enableColorGrad: boolean = false;

/**@internal */
_context: PostProcessRenderContext | null = null;
_context: PostProcessRenderContext;

/**
* 重新计算CameraFlag
Expand Down Expand Up @@ -158,67 +158,70 @@ 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;
}

/**
* @internal
*/
_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);
}
}

this._compositeShaderData.addDefine(PostProcess.SHADERDEFINE_FINALPASS);

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);
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -296,7 +299,7 @@ export class PostProcess {
* @internal
*/
_applyPostProcessCommandBuffers(): void {
this._context!.command!._apply();
this._context.command!._apply();
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/layaAir/laya/d3/core/render/PostEffect/GaussianDoF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export class GaussianDoF extends PostProcessEffect {
/**@internal */
static SHADERDEFINE_DEPTHNORMALTEXTURE: ShaderDefine;

/**@internal */
static PROJECTIONPARAM: number;

/**
* GaussianDOF resource init
*/
Expand All @@ -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],
Expand All @@ -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,
Expand Down Expand Up @@ -154,8 +149,6 @@ export class GaussianDoF extends PostProcessEffect {
/**@internal */
private _zBufferParams: Vector4;

private _projectionParams: Vector4;

/**@internal */
private _sourceSize: Vector4;

Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit 7ef5b35

Please sign in to comment.