From 358658fa34b9907f03ab59c601e6777573525a04 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 1 Mar 2025 22:13:33 +0100 Subject: [PATCH] Fix cloud-related bugs First, this reverts 56123b2fbe1ad4e7878556f8d51c551d84fb92e7, which un-fixes #15031 but fixes #15798 and #15854. Then we disable culling for the cloud scene node which fixes #15031 again. --- src/client/clouds.cpp | 26 +++++++++++++++++++++++--- src/client/clouds.h | 7 +++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index b65970f95..18b1d281c 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -52,6 +52,13 @@ Clouds::Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc, updateBox(); + // Neither EAC_BOX (the default) nor EAC_FRUSTUM_BOX will correctly cull + // the clouds. + // And yes, the bounding box is correct. You can check using the #if 0'd + // code in render() and see for yourself. + // So I give up and let's disable culling. + setAutomaticCulling(scene::EAC_OFF); + m_meshbuffer.reset(new scene::SMeshBuffer()); m_meshbuffer->setHardwareMappingHint(scene::EHM_DYNAMIC); } @@ -366,6 +373,19 @@ void Clouds::render() if (SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT) return; +#if 0 + { + video::SMaterial tmp; + tmp.Thickness = 1.f; + driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); + driver->setMaterial(tmp); + aabb3f tmpbox = m_box; + tmpbox.MinEdge.X = tmpbox.MinEdge.Z = -1000 * BS; + tmpbox.MaxEdge.X = tmpbox.MaxEdge.Z = 1000 * BS; + driver->draw3DBox(tmpbox, video::SColor(255, 255, 0x4d, 0)); + } +#endif + updateMesh(); // Update position @@ -425,14 +445,14 @@ void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse) // is the camera inside the cloud mesh? m_camera_pos = camera_p; - m_camera_inside_cloud = false; // default + m_camera_inside_cloud = false; if (is3D()) { float camera_height = camera_p.Y - BS * m_camera_offset.Y; if (camera_height >= m_box.MinEdge.Y && camera_height <= m_box.MaxEdge.Y) { v2f camera_in_noise; - camera_in_noise.X = floor((camera_p.X - m_origin.X) / cloud_size + 0.5); - camera_in_noise.Y = floor((camera_p.Z - m_origin.Y) / cloud_size + 0.5); + camera_in_noise.X = floorf((camera_p.X - m_origin.X) / cloud_size + 0.5f); + camera_in_noise.Y = floorf((camera_p.Z - m_origin.Y) / cloud_size + 0.5f); bool filled = gridFilled(camera_in_noise.X, camera_in_noise.Y); m_camera_inside_cloud = filled; } diff --git a/src/client/clouds.h b/src/client/clouds.h index d081a4853..ea5c18394 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -134,8 +134,11 @@ private: { float height_bs = m_params.height * BS; float thickness_bs = m_params.thickness * BS; - m_box = aabb3f(-BS * 1000000.0f, height_bs, -BS * 1000000.0f, - BS * 1000000.0f, height_bs + thickness_bs, BS * 1000000.0f); + float far_bs = 1000000.0f * BS; + m_box = aabb3f(-far_bs, height_bs, -far_bs, + far_bs, height_bs + thickness_bs, far_bs); + m_box.MinEdge -= v3f::from(m_camera_offset) * BS; + m_box.MaxEdge -= v3f::from(m_camera_offset) * BS; } void updateMesh();