From 022566422aa8f0da09856a383e2a77779e53cc42 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Mon, 18 Nov 2024 16:58:05 +0800 Subject: [PATCH] refactor: opt code --- .../core/src/RenderPipeline/BasicRenderPipeline.ts | 7 ++++--- packages/core/src/RenderPipeline/RenderQueue.ts | 12 ++++++++---- packages/core/src/shader/state/RenderState.ts | 11 ++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts index e728b0465b..6d95edbdd2 100644 --- a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts +++ b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts @@ -1,7 +1,6 @@ import { Vector2 } from "@galacean/engine-math"; import { Background } from "../Background"; import { Camera } from "../Camera"; -import { Engine } from "../Engine"; import { BackgroundMode } from "../enums/BackgroundMode"; import { BackgroundTextureFillMode } from "../enums/BackgroundTextureFillMode"; import { CameraClearFlags } from "../enums/CameraClearFlags"; @@ -270,8 +269,10 @@ export class BasicRenderPipeline { const shaderPass = shaderPasses[i]; const renderState = shaderPass._renderState; if (renderState) { - renderState._applyRenderQueueByShaderData(shaderPass._renderStateDataMap, subRenderElement.material.shaderData); - renderQueueType = renderState.renderQueueType; + renderQueueType = renderState._getRenderQueueByShaderData( + shaderPass._renderStateDataMap, + subRenderElement.material.shaderData + ); } else { renderQueueType = renderStates[i].renderQueueType; } diff --git a/packages/core/src/RenderPipeline/RenderQueue.ts b/packages/core/src/RenderPipeline/RenderQueue.ts index bc1653d3b5..5ce8ab36c9 100644 --- a/packages/core/src/RenderPipeline/RenderQueue.ts +++ b/packages/core/src/RenderPipeline/RenderQueue.ts @@ -99,13 +99,17 @@ export class RenderQueue { if (shaderPass.getTagValue(pipelineStageKey) !== pipelineStageTagValue) { continue; } - const renderState = shaderPass._renderState ?? renderStates[j]; - if (shaderPass._renderState) { - renderState._applyRenderQueueByShaderData(shaderPass._renderStateDataMap, materialData); + let renderState = shaderPass._renderState; + let passQueueType: RenderQueueType; + if (renderState) { + passQueueType = renderState._getRenderQueueByShaderData(shaderPass._renderStateDataMap, materialData); + } else { + renderState = renderStates[j]; + passQueueType = renderState.renderQueueType; } - if (renderState.renderQueueType !== renderQueueType) { + if (passQueueType !== renderQueueType) { continue; } diff --git a/packages/core/src/shader/state/RenderState.ts b/packages/core/src/shader/state/RenderState.ts index 27af040234..5435f5c43e 100644 --- a/packages/core/src/shader/state/RenderState.ts +++ b/packages/core/src/shader/state/RenderState.ts @@ -56,10 +56,15 @@ export class RenderState { * @internal * @todo Should merge when we can delete material render state */ - _applyRenderQueueByShaderData(renderStateDataMap: Record, shaderData: ShaderData): void { + _getRenderQueueByShaderData( + renderStateDataMap: Record, + shaderData: ShaderData + ): RenderQueueType { const renderQueueType = renderStateDataMap[RenderStateElementKey.RenderQueueType]; - if (renderQueueType !== undefined) { - this.renderQueueType = shaderData.getFloat(renderQueueType) ?? RenderQueueType.Opaque; + if (renderQueueType === undefined) { + return this.renderQueueType; + } else { + return shaderData.getFloat(renderQueueType) ?? RenderQueueType.Opaque; } }