From 1f7c8fa25b2300781ebe2ce32d43a8105912352b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 2 Jul 2024 23:43:25 +0800 Subject: [PATCH] Added frustum_planes in CameraInfo, added FrustumCheck function in MFCamera.h --- CMSceneGraph | 2 +- inc/hgl/graph/mtl/UBOCommon.h | 2 ++ src/ShaderGen/common/MFCamera.h | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CMSceneGraph b/CMSceneGraph index 3e2f129a..821bd3f4 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 3e2f129abf1b0480133010830b97f6eb902f960b +Subproject commit 821bd3f4f056ad344a45c631aeb6c5d94579f0ee diff --git a/inc/hgl/graph/mtl/UBOCommon.h b/inc/hgl/graph/mtl/UBOCommon.h index 3c87a22d..70a63e83 100644 --- a/inc/hgl/graph/mtl/UBOCommon.h +++ b/inc/hgl/graph/mtl/UBOCommon.h @@ -33,6 +33,8 @@ constexpr const ShaderBufferSource SBS_CameraInfo= mat4 vp; mat4 inverse_vp; + vec4 frustum_planes[6]; + mat4 sky; vec3 pos; //eye diff --git a/src/ShaderGen/common/MFCamera.h b/src/ShaderGen/common/MFCamera.h index 8e7f3589..4318490a 100644 --- a/src/ShaderGen/common/MFCamera.h +++ b/src/ShaderGen/common/MFCamera.h @@ -26,6 +26,20 @@ vec3 GetViewUp(mat4 cv) { return vec3(cv[0][1],cv[1][1],cv[2][1]); } +)"; + + constexpr const char *FrustumCheck=R"( +bool FrustumCheck(vec4 pos, float radius) +{ + for (int i = 0; i < 6; i++) + { + if (dot(pos, camera.frustum_planes[i]) + radius < 0.0) + { + return false; + } + } + return true; +} )"; }//namespace func STD_MTL_NAMESPACE_END