diff --git a/cocos/render-scene/scene/camera.ts b/cocos/render-scene/scene/camera.ts index 436b512375..cc3d269914 100644 --- a/cocos/render-scene/scene/camera.ts +++ b/cocos/render-scene/scene/camera.ts @@ -1346,6 +1346,10 @@ export class Camera { this._matProj.m14 = m3.w; } + public getClipSpaceMinz () { + return this._device.capabilities.clipSpaceMinZ; + } + /** * @en Set exposure with actual value. * @zh 设置相机的曝光值 diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index 35cb21a365..e6c30aee53 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -2018,7 +2018,7 @@ export function buildLightClusterBuildPass (camera: Camera, clusterData: Cluster const width = camera.width * ppl.pipelineSceneData.shadingScale; const height = camera.height * ppl.pipelineSceneData.shadingScale; - clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, 0, 0)); + clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0)); clusterPass.setVec4('cc_viewPort', new Vec4(0, 0, width, height)); clusterPass.setVec4('cc_workGroup', new Vec4(CLUSTERS_X, CLUSTERS_Y, CLUSTERS_Z, 0)); clusterPass.setMat4('cc_matView', camera.matView); @@ -2055,7 +2055,7 @@ export function buildLightClusterCullingPass (camera: Camera, clusterData: Clust const width = camera.width * ppl.pipelineSceneData.shadingScale; const height = camera.height * ppl.pipelineSceneData.shadingScale; - clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, 0, 0)); + clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0)); clusterPass.setVec4('cc_viewPort', new Vec4(width, height, width, height)); clusterPass.setVec4('cc_workGroup', new Vec4(CLUSTERS_X, CLUSTERS_Y, CLUSTERS_Z, 0)); clusterPass.setMat4('cc_matView', camera.matView); diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 58c24a9a5b..8881a7ab77 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -716,7 +716,7 @@ function setCameraUBOValues (setter: WebSetter, if (camera) { uniformOffset = setter.getUniformOffset('cc_nearFar', Type.FLOAT4); if (setter.hasUniform(uniformOffset)) { - _uboVec.set(camera.nearClip, camera.farClip, 0.0, 0.0); + _uboVec.set(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0.0); setter.offsetVec4(_uboVec, uniformOffset); } uniformOffset = setter.getUniformOffset('cc_viewPort', Type.FLOAT4); diff --git a/cocos/rendering/pipeline-ubo.ts b/cocos/rendering/pipeline-ubo.ts index b173fdc3a6..840c8f1ebe 100644 --- a/cocos/rendering/pipeline-ubo.ts +++ b/cocos/rendering/pipeline-ubo.ts @@ -185,6 +185,7 @@ export class PipelineUBO { cv[UBOCamera.NEAR_FAR_OFFSET] = camera.nearClip; cv[UBOCamera.NEAR_FAR_OFFSET + 1] = camera.farClip; + cv[UBOCamera.NEAR_FAR_OFFSET + 2] = camera.getClipSpaceMinz(); cv[UBOCamera.VIEW_PORT_OFFSET] = sceneData.shadingScale * camera.window.width * camera.viewport.x; cv[UBOCamera.VIEW_PORT_OFFSET + 1] = sceneData.shadingScale * camera.window.height * camera.viewport.y; diff --git a/editor/assets/chunks/builtin/uniforms/cc-global.chunk b/editor/assets/chunks/builtin/uniforms/cc-global.chunk index 508a9f22a3..4cf88e7b8f 100644 --- a/editor/assets/chunks/builtin/uniforms/cc-global.chunk +++ b/editor/assets/chunks/builtin/uniforms/cc-global.chunk @@ -31,6 +31,6 @@ layout(set = 0, binding = 1) uniform CCCamera { mediump vec4 cc_fogColor; // xyz: global fog color mediump vec4 cc_fogBase; // xyz: fogStart, fogEnd, fogDensity mediump vec4 cc_fogAdd; // xyz: fogTop, fogRange, fogAtten - mediump vec4 cc_nearFar; // xy: frustum near, frustum far + mediump vec4 cc_nearFar; // xy: frustum near, frustum far z: clipspace minz (vulkan: 0 metal: 0 other: -1) mediump vec4 cc_viewPort; // xyzw: camera view port, default(0, 0, 1, 1) }; diff --git a/editor/assets/chunks/legacy/main-functions/outline-vs.chunk b/editor/assets/chunks/legacy/main-functions/outline-vs.chunk index 4bf1d02f6f..3a24fe065b 100644 --- a/editor/assets/chunks/legacy/main-functions/outline-vs.chunk +++ b/editor/assets/chunks/legacy/main-functions/outline-vs.chunk @@ -28,8 +28,9 @@ vec4 vert () { In.position.xyz += normalize(In.normal) * width; vec4 pos = cc_matProj * (cc_matView * matWorld) * In.position; #endif - - pos.z -= outlineParams.y * 0.002; + + float scaleZ = cc_nearFar.z == 0.0 ? 0.5 : 1.0; + pos.z -= outlineParams.y * 0.002 * scaleZ; v_uv = a_texCoord; diff --git a/editor/assets/effects/builtin-toon.effect b/editor/assets/effects/builtin-toon.effect index 6fc7ca06a6..f585b46487 100644 --- a/editor/assets/effects/builtin-toon.effect +++ b/editor/assets/effects/builtin-toon.effect @@ -398,7 +398,8 @@ CCProgram surface-vertex-silhouette-edge %{ vec4 SurfacesVertexModifyClipPos(in SurfacesStandardVertexIntermediate In) { vec4 clipPos = In.clipPos; - clipPos.z -= outlineParams.y * 0.002; + float scaleZ = cc_nearFar.z == 0.0 ? 0.5 : 1.0; + clipPos.z -= outlineParams.y * 0.002 * scaleZ; return clipPos; } }% diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 89018accf2..3693ab6ff5 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -202,6 +202,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out output[UBOCamera::GLOBAL_NEAR_FAR_OFFSET + 0] = static_cast(camera->getNearClip()); output[UBOCamera::GLOBAL_NEAR_FAR_OFFSET + 1] = static_cast(camera->getFarClip()); + output[UBOCamera::GLOBAL_NEAR_FAR_OFFSET + 2] = static_cast(camera->getClipSpaceMinz()); output[UBOCamera::GLOBAL_VIEW_PORT_OFFSET + 0] = sceneData->getShadingScale() * static_cast(camera->getWindow()->getWidth()) * camera->getViewport().x; output[UBOCamera::GLOBAL_VIEW_PORT_OFFSET + 1] = sceneData->getShadingScale() * static_cast(camera->getWindow()->getHeight()) * camera->getViewport().y; diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp index 97bc3089a2..95eb96c6bf 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp @@ -255,7 +255,7 @@ void setCameraUBOValues( setVec4Impl(data, layoutGraph, "cc_fogAdd", Vec4(fog.getFogTop(), fog.getFogRange(), fog.getFogAtten(), 0.0F)); setVec4Impl(data, layoutGraph, "cc_nearFar", - Vec4(camera.getNearClip(), camera.getFarClip(), 0.0F, 0.0F)); + Vec4(camera.getNearClip(), camera.getFarClip(), camera.getClipSpaceMinz(), 0.0F)); setVec4Impl(data, layoutGraph, "cc_viewPort", Vec4( camera.getViewport().x, diff --git a/native/cocos/scene/Camera.cpp b/native/cocos/scene/Camera.cpp index 1984e553f1..272cde121a 100644 --- a/native/cocos/scene/Camera.cpp +++ b/native/cocos/scene/Camera.cpp @@ -406,6 +406,10 @@ void Camera::calculateObliqueMat(const Vec4 &viewSpacePlane) { _matProj.m[14] = m3.w; } +float Camera::getClipSpaceMinz() const { + return _device->getCapabilities().clipSpaceMinZ; +} + void Camera::setNode(Node *val) { _node = val; } void Camera::setExposure(float ev100) { diff --git a/native/cocos/scene/Camera.h b/native/cocos/scene/Camera.h index 36439e3158..bb645d9295 100644 --- a/native/cocos/scene/Camera.h +++ b/native/cocos/scene/Camera.h @@ -366,6 +366,8 @@ public: void calculateObliqueMat(const Vec4 &viewSpacePlane); + float getClipSpaceMinz() const; + protected: void setExposure(float ev100);