From 2f325e336d2dae85eb9b4ad19f8bf2efc1be77a8 Mon Sep 17 00:00:00 2001 From: troublemaker52025 Date: Thu, 28 Jan 2021 16:36:41 +0800 Subject: [PATCH] Optimize the shader acquisition of planar shadows (#8234) * Optimize the shader acquisition of planar shadows * update memeory-pool --- cocos/core/renderer/core/memory-pools.ts | 10 +++++----- cocos/core/renderer/scene/shadows.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cocos/core/renderer/core/memory-pools.ts b/cocos/core/renderer/core/memory-pools.ts index 0e55c77255..db7bc5e012 100644 --- a/cocos/core/renderer/core/memory-pools.ts +++ b/cocos/core/renderer/core/memory-pools.ts @@ -1175,11 +1175,11 @@ export enum ShadowsView { BIAS, ORTHO_SIZE, AUTO_ADAPT, // boolean - COLOR = 15, // Vec4 - SIZE = 19, // Vec2 - NORMAL = 21, // Vec3 - MAT_LIGHT = 24, // Mat4 - COUNT = 40 + COLOR = 14, // Vec4 + SIZE = 18, // Vec2 + NORMAL = 20, // Vec3 + MAT_LIGHT = 23, // Mat4 + COUNT = 39 } interface IShadowsViewType extends BufferTypeManifest { [ShadowsView.ENABLE]: number; diff --git a/cocos/core/renderer/scene/shadows.ts b/cocos/core/renderer/scene/shadows.ts index daf2198c7a..923e1686a8 100644 --- a/cocos/core/renderer/scene/shadows.ts +++ b/cocos/core/renderer/scene/shadows.ts @@ -319,9 +319,13 @@ export class Shadows { } public getPlanarShader (patches: IMacroPatch[] | null): ShaderHandle { - this._updatePlanarInfo(); + if (!this._material) { + this._material = new Material(); + this._material.initialize({ effectName: 'planar-shadow' }); + ShadowsPool.set(this._handle, ShadowsView.PLANAR_PASS, this._material.passes[0].handle); + } - return this._material!.passes[0].getShaderVariant(patches); + return this._material.passes[0].getShaderVariant(patches); } public initialize (shadowsInfo: ShadowsInfo) {