mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
Fix customize descriptor not bingding shadow map (#7836)
* fix Multiple light sources not bingding globle CC_SHADOW_MAP * update
This commit is contained in:
committed by
GitHub
parent
36675bac3a
commit
1848010664
@@ -48,9 +48,11 @@ import { SpotLight } from '../renderer/scene/spot-light';
|
||||
import { SubModel } from '../renderer/scene/submodel';
|
||||
import { getPhaseID } from './pass-phase';
|
||||
import { Light, LightType } from '../renderer/scene/light';
|
||||
import { IRenderObject, SetIndex, UBOForwardLight, UBOGlobal, UBOShadow, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from './define';
|
||||
import { IRenderObject, SetIndex, UBOForwardLight, UBOGlobal, UBOShadow, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from './define';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { genSamplerHash, samplerLib } from '../renderer/core/sampler-lib';
|
||||
import { builtinResMgr } from '../3d/builtin/init';
|
||||
import { Texture2D } from '../assets/texture-2d';
|
||||
|
||||
const _samplerInfo = [
|
||||
Filter.LINEAR,
|
||||
@@ -333,14 +335,14 @@ export class RenderAdditiveLightQueue {
|
||||
const shadowInfo = this._pipeline.shadows;
|
||||
|
||||
for (let i = 0; i < this._validLights.length; i++) {
|
||||
const light = this._validLights[i];
|
||||
let texture: Texture|null = null;
|
||||
if (this._pipeline.shadowFrameBufferMap.has(light)) {
|
||||
texture = this._pipeline.shadowFrameBufferMap.get(light)!.colorTextures[0]!;
|
||||
}
|
||||
|
||||
const light = this._validLights[i];
|
||||
const descriptorSet = this._getOrCreateDescriptorSet(light);
|
||||
if(!descriptorSet) { return; }
|
||||
|
||||
descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, this._sampler!);
|
||||
descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, this._sampler!);
|
||||
// Main light sampler binding
|
||||
descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
descriptorSet.update();
|
||||
this._updateGlobalDescriptorSet(view, cmdBuff);
|
||||
|
||||
@@ -353,6 +355,8 @@ export class RenderAdditiveLightQueue {
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 1] = shadowInfo.size.y;
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 2] = shadowInfo.pcf;
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 3] = shadowInfo.bias;
|
||||
// Spot light sampler binding
|
||||
descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
break;
|
||||
case LightType.SPOT:
|
||||
const spotLight = light as SpotLight;
|
||||
@@ -374,23 +378,15 @@ export class RenderAdditiveLightQueue {
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 1] = shadowInfo.size.y;
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 2] = shadowInfo.pcf;
|
||||
this._shadowUBO[UBOShadow.SHADOW_INFO_OFFSET + 3] = shadowInfo.bias;
|
||||
// Spot light sampler binding
|
||||
if (this._pipeline.shadowFrameBufferMap.has(light)) {
|
||||
descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, this._pipeline.shadowFrameBufferMap.get(light)?.colorTextures[0]!);
|
||||
} else {
|
||||
descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
// must binding a sampler
|
||||
if (texture === null) {
|
||||
let framebufferArray = Array.from(this._pipeline.shadowFrameBufferMap.values());
|
||||
for (let i = 0; i < framebufferArray.length; i++) {
|
||||
if (framebufferArray[i].colorTextures[0]) {
|
||||
texture = framebufferArray[i].colorTextures[0]!;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, this._sampler!);
|
||||
descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, texture!);
|
||||
descriptorSet.update();
|
||||
|
||||
cmdBuff.updateBuffer(descriptorSet.getBuffer(UBOGlobal.BINDING)!, this._globalUBO);
|
||||
|
||||
@@ -44,6 +44,8 @@ import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib';
|
||||
import { Light, LightType } from '../../renderer/scene/light';
|
||||
import { lightCollecting, shadowCollecting } from '../forward/scene-culling';
|
||||
import { Vec2 } from '../../math';
|
||||
import { builtinResMgr } from '../../3d/builtin/init';
|
||||
import { Texture2D } from '../../assets/texture-2d';
|
||||
|
||||
const _samplerInfo = [
|
||||
Filter.LINEAR,
|
||||
@@ -73,6 +75,7 @@ export class ShadowFlow extends RenderFlow {
|
||||
};
|
||||
|
||||
private _shadowRenderPass: RenderPass|null = null;
|
||||
private _globalBinding: boolean = false;
|
||||
|
||||
public initialize (info: IRenderFlowInfo): boolean {
|
||||
super.initialize(info);
|
||||
@@ -133,6 +136,8 @@ export class ShadowFlow extends RenderFlow {
|
||||
(this._pipeline as ForwardPipeline).shadowFrameBufferMap.clear();
|
||||
|
||||
if(this._shadowRenderPass) { this._shadowRenderPass.destroy() };
|
||||
|
||||
this._globalBinding = false;
|
||||
}
|
||||
|
||||
public _initShadowFrameBuffer (pipeline: ForwardPipeline, light: Light) {
|
||||
@@ -188,9 +193,16 @@ export class ShadowFlow extends RenderFlow {
|
||||
// Cache frameBuffer
|
||||
pipeline.shadowFrameBufferMap.set(light, shadowFrameBuffer);
|
||||
|
||||
const shadowMapSamplerHash = genSamplerHash(_samplerInfo);
|
||||
const shadowMapSampler = samplerLib.getSampler(device, shadowMapSamplerHash);
|
||||
pipeline.descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, shadowMapSampler);
|
||||
|
||||
if (!this._globalBinding) {
|
||||
const shadowMapSamplerHash = genSamplerHash(_samplerInfo);
|
||||
const shadowMapSampler = samplerLib.getSampler(device, shadowMapSamplerHash);
|
||||
pipeline.descriptorSet.bindSampler(UNIFORM_SHADOWMAP_BINDING, shadowMapSampler);
|
||||
pipeline.descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
pipeline.descriptorSet.bindSampler(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, shadowMapSampler);
|
||||
pipeline.descriptorSet.bindTexture(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
this._globalBinding = true;
|
||||
}
|
||||
|
||||
if (light && light.type === LightType.DIRECTIONAL) {
|
||||
pipeline.descriptorSet.bindTexture(UNIFORM_SHADOWMAP_BINDING, shadowFrameBuffer.colorTextures[0]!);
|
||||
|
||||
Reference in New Issue
Block a user