diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index 959424fdb8..ae7936b5d6 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -211,9 +211,6 @@ export class ForwardPipeline extends RenderPipeline { const shadowInfo = this.shadows; if (mainLight && shadowInfo.type === ShadowType.ShadowMap) { - if (this.shadowFrameBufferMap.has(mainLight)) { - this._descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, this.shadowFrameBufferMap.get(mainLight)!.colorTextures[0]!); - } // light view let shadowCameraView: Mat4; @@ -280,6 +277,8 @@ export class ForwardPipeline extends RenderPipeline { )); this._descriptorSet.bindBuffer(UBOShadow.BINDING, shadowUBO); + this._descriptorSet.update(); + // update global defines when all states initialized. this.macros.CC_USE_HDR = this._isHDR; this.macros.CC_SUPPORT_FLOAT_TEXTURE = this.device.hasFeature(Feature.TEXTURE_FLOAT); diff --git a/cocos/core/pipeline/shadow/shadow-flow.ts b/cocos/core/pipeline/shadow/shadow-flow.ts index d5ff071cb0..bea19564f9 100644 --- a/cocos/core/pipeline/shadow/shadow-flow.ts +++ b/cocos/core/pipeline/shadow/shadow-flow.ts @@ -41,7 +41,7 @@ import { ForwardPipeline } from '../forward/forward-pipeline'; import { RenderView } from '../render-view'; import { ShadowType } from '../../renderer/scene/shadows'; import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib'; -import { Light } from '../../renderer/scene/light'; +import { Light, LightType } from '../../renderer/scene/light'; import { lightCollecting, shadowCollecting } from '../forward/scene-culling'; import { Vec2 } from '../../math'; @@ -167,6 +167,10 @@ export class ShadowFlow extends RenderFlow { const shadowMapSamplerHash = genSamplerHash(_samplerInfo); const shadowMapSampler = samplerLib.getSampler(device, shadowMapSamplerHash); pipeline.descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, shadowMapSampler); + + if (light.type === LightType.DIRECTIONAL) { + pipeline.descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, shadowFrameBuffer.colorTextures[0]!); + } } private resizeShadowMap (light: Light, size: Vec2) {