diff --git a/doc/api/class_terrain3d.rst b/doc/api/class_terrain3d.rst index a2c23d03..af220ecb 100644 --- a/doc/api/class_terrain3d.rst +++ b/doc/api/class_terrain3d.rst @@ -386,7 +386,7 @@ Tells the renderer how to cast shadows from the terrain onto other objects. This - |void| **set_cull_margin**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_cull_margin**\ (\ ) -This margin is added to the terrain bounding box (AABB). The terrain already sets its AABB, so this setting only needs to be used if the shader has expanded the terrain beyond the AABB and the terrain meshes are being culled, as might happen from using :ref:`Terrain3DMaterial.world_background` with NOISE and a large height value. This sets ``GeometryInstance3D.extra_cull_margin`` in the engine. +This margin is added to the vertical component of the terrain bounding box (AABB). The terrain already sets its AABB from :ref:`Terrain3DStorage.height_range`, which is calculated while sculpting. This setting only needs to be used if the shader has expanded the terrain beyond the AABB and the terrain meshes are being culled at certain viewing angles. This might happen from using :ref:`Terrain3DMaterial.world_background` with NOISE and a height value larger than the terrain heights. This setting is similar to `GeometryInstance3D.extra_cull_margin`, but it only affects the Y axis. .. rst-class:: classref-item-separator diff --git a/doc/classes/Terrain3D.xml b/doc/classes/Terrain3D.xml index 1e3875a6..e56b0da4 100644 --- a/doc/classes/Terrain3D.xml +++ b/doc/classes/Terrain3D.xml @@ -134,7 +134,7 @@ Tells the renderer how to cast shadows from the terrain onto other objects. This sets [code skip-lint]GeometryInstance3D.ShadowCastingSetting[/code] in the engine. - This margin is added to the terrain bounding box (AABB). The terrain already sets its AABB, so this setting only needs to be used if the shader has expanded the terrain beyond the AABB and the terrain meshes are being culled, as might happen from using [member Terrain3DMaterial.world_background] with NOISE and a large height value. This sets [code skip-lint]GeometryInstance3D.extra_cull_margin[/code] in the engine. + This margin is added to the vertical component of the terrain bounding box (AABB). The terrain already sets its AABB from [member Terrain3DStorage.height_range], which is calculated while sculpting. This setting only needs to be used if the shader has expanded the terrain beyond the AABB and the terrain meshes are being culled at certain viewing angles. This might happen from using [member Terrain3DMaterial.world_background] with NOISE and a height value larger than the terrain heights. This setting is similar to `GeometryInstance3D.extra_cull_margin`, but it only affects the Y axis. The render layers the terrain is drawn on. This sets [code skip-lint]VisualInstance3D.layers[/code] in the engine. The defaults is layer 1 and 32 (for the mouse cursor). When you set this, make sure the layer for [member render_mouse_layer] is included, or set that variable again after this so that the mouse cursor works. diff --git a/src/terrain_3d.cpp b/src/terrain_3d.cpp index d03a00d6..eb32b41c 100644 --- a/src/terrain_3d.cpp +++ b/src/terrain_3d.cpp @@ -951,41 +951,36 @@ void Terrain3D::update_aabbs() { height_range.y += abs(height_range.x); // Add below zero to total size AABB aabb = RS->mesh_get_custom_aabb(_meshes[GeoClipMap::CROSS]); - aabb.position.y = height_range.x; - aabb.size.y = height_range.y; + aabb.position.y = height_range.x - _cull_margin; + aabb.size.y = height_range.y + _cull_margin * 2.f; RS->instance_set_custom_aabb(_data.cross, aabb); - RS->instance_set_extra_visibility_margin(_data.cross, _cull_margin); aabb = RS->mesh_get_custom_aabb(_meshes[GeoClipMap::TILE]); - aabb.position.y = height_range.x; - aabb.size.y = height_range.y; + aabb.position.y = height_range.x - _cull_margin; + aabb.size.y = height_range.y + _cull_margin * 2.f; for (int i = 0; i < _data.tiles.size(); i++) { RS->instance_set_custom_aabb(_data.tiles[i], aabb); - RS->instance_set_extra_visibility_margin(_data.tiles[i], _cull_margin); } aabb = RS->mesh_get_custom_aabb(_meshes[GeoClipMap::FILLER]); - aabb.position.y = height_range.x; - aabb.size.y = height_range.y; + aabb.position.y = height_range.x - _cull_margin; + aabb.size.y = height_range.y + _cull_margin * 2.f; for (int i = 0; i < _data.fillers.size(); i++) { RS->instance_set_custom_aabb(_data.fillers[i], aabb); - RS->instance_set_extra_visibility_margin(_data.fillers[i], _cull_margin); } aabb = RS->mesh_get_custom_aabb(_meshes[GeoClipMap::TRIM]); - aabb.position.y = height_range.x; - aabb.size.y = height_range.y; + aabb.position.y = height_range.x - _cull_margin; + aabb.size.y = height_range.y + _cull_margin * 2.f; for (int i = 0; i < _data.trims.size(); i++) { RS->instance_set_custom_aabb(_data.trims[i], aabb); - RS->instance_set_extra_visibility_margin(_data.trims[i], _cull_margin); } aabb = RS->mesh_get_custom_aabb(_meshes[GeoClipMap::SEAM]); - aabb.position.y = height_range.x; - aabb.size.y = height_range.y; + aabb.position.y = height_range.x - _cull_margin; + aabb.size.y = height_range.y + _cull_margin * 2.f; for (int i = 0; i < _data.seams.size(); i++) { RS->instance_set_custom_aabb(_data.seams[i], aabb); - RS->instance_set_extra_visibility_margin(_data.seams[i], _cull_margin); } } @@ -1329,7 +1324,7 @@ void Terrain3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "render_layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_render_layers", "get_render_layers"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_mouse_layer", PROPERTY_HINT_RANGE, "21, 32"), "set_mouse_layer", "get_mouse_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_cast_shadows", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows", "get_cast_shadows"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "render_cull_margin", PROPERTY_HINT_RANGE, "0, 10000, 1, or_greater"), "set_cull_margin", "get_cull_margin"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "render_cull_margin", PROPERTY_HINT_RANGE, "0.0,10000.0,.5,or_greater"), "set_cull_margin", "get_cull_margin"); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_enabled"), "set_collision_enabled", "get_collision_enabled");