diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index 7226335f21f..0f03b0472ac 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -682,11 +682,10 @@ export function buildShadowPass ( ); } const queue = shadowPass.addQueue(QueueHint.RENDER_OPAQUE, 'shadow-caster'); - queue.addSceneOfCamera( + queue.addScene( camera, - new LightInfo(light, level), - SceneFlags.SHADOW_CASTER | SceneFlags.OPAQUE_OBJECT | SceneFlags.TRANSPARENT_OBJECT, - ); + SceneFlags.SHADOW_CASTER | SceneFlags.OPAQUE_OBJECT | SceneFlags.MASK, + ).useLightFrustum(light, light.type !== LightType.DIRECTIONAL ? 0 : level); queue.setViewport(new Viewport(area.x, area.y, area.width, area.height)); } diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index d4e18fda7c2..5e6f45aa2d5 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -1526,7 +1526,9 @@ class DeviceSceneTask extends WebSceneTask { const queueId = this._currentQueue.queueId; const queueRenderData = context.renderGraph.getData(queueId)!; this._updateGlobal(queueRenderData); - + const sceneId = this.graphScene.sceneID; + const sceneRenderData = context.renderGraph.getData(sceneId)!; + if (sceneRenderData) this._updateGlobal(sceneRenderData); const layoutName = context.renderGraph.getLayout(rasterId); const descSetData = getDescriptorSetDataFromLayout(layoutName); mergeSrcToTargetDesc(descSetData!.descriptorSet, context.descriptorSet, true); diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index bc3709cf8ce..0a76a1f7506 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -688,6 +688,8 @@ function setShadowUBOLightView ( Mat4.invert(_matView, spotLight.node!.getWorldMatrix()); } if (setter.hasUniform(matViewOffset)) setter.offsetMat4(_matView, matViewOffset); + let matShadowInvProj!: Mat4; + let matShadowProj!: Mat4; if (setter.hasUniform(matViewProOffset)) { Mat4.perspective( _mulMatView, @@ -700,6 +702,8 @@ function setShadowUBOLightView ( cap.clipSpaceSignY, 0, ); + matShadowProj = _mulMatView.clone(); + matShadowInvProj = _mulMatView.clone().invert(); Mat4.multiply(_matView, _mulMatView, _matView); setter.offsetMat4(_matView, matViewProOffset); } @@ -718,6 +722,47 @@ function setShadowUBOLightView ( _uboVec.set(LightType.SPOT, packing, spotLight.shadowNormalBias, 0.0); setter.offsetVec4(_uboVec, uniformOffset); } + uniformOffset = setter.getUniformOffset('cc_shadowProjDepthInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); + setter.offsetVec4(_uboVec, uniformOffset); + } + uniformOffset = setter.getUniformOffset('cc_shadowInvProjDepthInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(matShadowInvProj.m10, matShadowInvProj.m14, matShadowInvProj.m11, matShadowInvProj.m15); + setter.offsetVec4(_uboVec, uniformOffset); + } + uniformOffset = setter.getUniformOffset('cc_shadowProjInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); + setter.offsetVec4(_uboVec, uniformOffset); + } + } + break; + } + case LightType.SPHERE: { + uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); + setter.offsetVec4(_uboVec, uniformOffset); + } + uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(LightType.SPHERE, packing, 0.0, 0.0); + setter.offsetVec4(_uboVec, uniformOffset); + } + break; + } + case LightType.POINT: { + uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); + setter.offsetVec4(_uboVec, uniformOffset); + } + uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); + if (setter.hasUniform(uniformOffset)) { + _uboVec.set(LightType.POINT, packing, 0.0, 0.0); + setter.offsetVec4(_uboVec, uniformOffset); } break; } @@ -1226,7 +1271,7 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild camera.scene || (scene ? scene.renderScene : null), layoutName, ); - if (sceneFlags & SceneFlags.SHADOW_CASTER) { + if (sceneFlags & SceneFlags.SHADOW_CASTER || (lightTarget && lightTarget.type !== LightType.DIRECTIONAL)) { setShadowUBOLightView(this, camera, lightTarget!, light.level, layoutName); } else { setShadowUBOView(this, camera, layoutName); @@ -1253,7 +1298,8 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild camera.scene, layoutName, ); - setShadowUBOView(this, camera, layoutName); + if (light && light.type !== LightType.DIRECTIONAL) setShadowUBOLightView(this, camera, light, 0, layoutName); + else if (!(sceneFlags & SceneFlags.SHADOW_CASTER)) setShadowUBOView(this, camera, layoutName); setTextureUBOView(this, camera, this._pipeline); initGlobalDescBinding(this._data, layoutName); } diff --git a/cocos/rendering/post-process/passes/forward-pass.ts b/cocos/rendering/post-process/passes/forward-pass.ts index eac17607070..c16d0b493c7 100644 --- a/cocos/rendering/post-process/passes/forward-pass.ts +++ b/cocos/rendering/post-process/passes/forward-pass.ts @@ -75,7 +75,7 @@ export class ForwardPass extends BasePass { camera, new LightInfo(), SceneFlags.OPAQUE_OBJECT | SceneFlags.CUTOUT_OBJECT - | SceneFlags.DEFAULT_LIGHTING | SceneFlags.GEOMETRY, + | SceneFlags.GEOMETRY, ); const forwardAddQueue = pass.addQueue(QueueHint.RENDER_TRANSPARENT, 'forward-add'); passContext.addSceneLights(forwardAddQueue, camera); @@ -86,7 +86,7 @@ export class ForwardPass extends BasePass { camera, new LightInfo(camera.scene?.mainLight), SceneFlags.TRANSPARENT_OBJECT | SceneFlags.SHADOW_CASTER - | SceneFlags.DEFAULT_LIGHTING | SceneFlags.GEOMETRY, + | SceneFlags.GEOMETRY, ); } passContext.forwardPass = this;