From 64f5bd2339b8b3a4b6b89012c4e9db13f3996c7e Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 17 Sep 2022 10:22:26 +0200 Subject: [PATCH] Ported: Bind Physics Interpolation functions in VisualServer To allow maximum flexibility in the initial rollout, VisualServer functions were not bound in order to prevent compatibility issues if the API changed. These functions are now bound to allow direct use from the VisualServer. - lawnjelly https://github.com/godotengine/godot/commit/96a1b867176498daf169c4b31842aa498c35fb7d --- doc/classes/RenderingServer.xml | 74 ++++++++++++++++++++ scene/resources/multimesh.cpp | 2 +- servers/rendering/rasterizer.cpp | 4 +- servers/rendering/rasterizer.h | 2 +- servers/rendering/rendering_server_raster.h | 2 +- servers/rendering/rendering_server_wrap_mt.h | 2 +- servers/rendering_server.cpp | 12 +++- servers/rendering_server.h | 10 ++- 8 files changed, 99 insertions(+), 9 deletions(-) diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 7996efe12..684d0776a 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -45,6 +45,14 @@ Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] static method. + + + + + Prevents physics interpolation for the current physics tick. + This is useful when moving a [Camera] to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -72,6 +80,14 @@ Sets camera to use frustum projection. This mode allows adjusting the [code]offset[/code] argument to create "tilted frustum" effects. + + + + + + Turns on and off physics interpolation for the [Camera]. + + @@ -1209,6 +1225,14 @@ Sets a material that will override the material for all surfaces on the mesh associated with this instance. Equivalent to [member GeometryInstance.material_override]. + + + + + Prevents physics interpolation for the current physics tick. + This is useful when moving an instance to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -1250,6 +1274,14 @@ Sets a margin to increase the size of the AABB when culling objects from the view frustum. This allows you to avoid culling objects that fall outside the view frustum. Equivalent to [member GeometryInstance.extra_cull_margin]. + + + + + + Turns on and off physics interpolation for the instance. + + @@ -1792,6 +1824,15 @@ Returns the [Transform2D] of the specified instance. For use when the multimesh is set to use 2D transforms. + + + + + + Prevents physics interpolation for the specified instance during the current physics tick. + This is useful when moving an instance to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -1840,6 +1881,16 @@ [Transform] is stored as 12 floats, [Transform2D] is stored as 8 floats, [code]COLOR_8BIT[/code] / [code]CUSTOM_DATA_8BIT[/code] is stored as 1 float (4 bytes as is) and [code]COLOR_FLOAT[/code] / [code]CUSTOM_DATA_FLOAT[/code] is stored as 4 floats. + + + + + + + Alternative version of [method multimesh_set_as_bulk_array] for use with physics interpolation. + Takes both an array of current data and an array of data for the previous physics tick. + + @@ -1848,6 +1899,23 @@ Sets the mesh to be drawn by the multimesh. Equivalent to [member MultiMesh.mesh]. + + + + + + Turns on and off physics interpolation for the [MultiMesh]. + + + + + + + + Sets the physics interpolation quality for the [MultiMesh]. + A value of [code]0[/code] gives fast but low quality interpolation, a value of [code]1[/code] gives slower but higher quality interpolation. + + @@ -3267,6 +3335,12 @@ MultiMesh custom data uses a float per component. + + MultiMesh physics interpolation favours speed over quality. + + + MultiMesh physics interpolation favours quality over speed. + Reflection probe will update reflections once and then stop. diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index 091b7c4be..9b959d236 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -219,7 +219,7 @@ void MultiMesh::set_visible_instance_count(int p_count) { void MultiMesh::set_physics_interpolation_quality(PhysicsInterpolationQuality p_quality) { _physics_interpolation_quality = p_quality; - RenderingServer::get_singleton()->multimesh_set_physics_interpolation_quality(multimesh, (int)p_quality); + RenderingServer::get_singleton()->multimesh_set_physics_interpolation_quality(multimesh, (RS::MultimeshPhysicsInterpolationQuality)p_quality); } int MultiMesh::get_visible_instance_count() const { diff --git a/servers/rendering/rasterizer.cpp b/servers/rendering/rasterizer.cpp index 583e07927..a06babecb 100644 --- a/servers/rendering/rasterizer.cpp +++ b/servers/rendering/rasterizer.cpp @@ -452,11 +452,11 @@ void RasterizerStorage::multimesh_set_physics_interpolated(RID p_multimesh, bool } } -void RasterizerStorage::multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality) { +void RasterizerStorage::multimesh_set_physics_interpolation_quality(RID p_multimesh, RS::MultimeshPhysicsInterpolationQuality p_quality) { ERR_FAIL_COND((p_quality < 0) || (p_quality > 1)); MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh); if (mmi) { - mmi->quality = p_quality; + mmi->quality = (int) p_quality; } } diff --git a/servers/rendering/rasterizer.h b/servers/rendering/rasterizer.h index b5beb0895..806d2bd3f 100644 --- a/servers/rendering/rasterizer.h +++ b/servers/rendering/rasterizer.h @@ -370,7 +370,7 @@ public: virtual void multimesh_set_as_bulk_array_interpolated(RID p_multimesh, const PoolVector &p_array, const PoolVector &p_array_prev); virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated); - virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality); + virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, RS::MultimeshPhysicsInterpolationQuality p_quality); virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index); virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible); diff --git a/servers/rendering/rendering_server_raster.h b/servers/rendering/rendering_server_raster.h index 22557dc08..7b5b7716b 100644 --- a/servers/rendering/rendering_server_raster.h +++ b/servers/rendering/rendering_server_raster.h @@ -281,7 +281,7 @@ public: BIND3(multimesh_set_as_bulk_array_interpolated, RID, const PoolVector &, const PoolVector &) BIND2(multimesh_set_physics_interpolated, RID, bool) - BIND2(multimesh_set_physics_interpolation_quality, RID, int) + BIND2(multimesh_set_physics_interpolation_quality, RID, MultimeshPhysicsInterpolationQuality) BIND2(multimesh_instance_reset_physics_interpolation, RID, int) BIND2(multimesh_set_visible_instances, RID, int) diff --git a/servers/rendering/rendering_server_wrap_mt.h b/servers/rendering/rendering_server_wrap_mt.h index 400d3c768..b5e38e4ca 100644 --- a/servers/rendering/rendering_server_wrap_mt.h +++ b/servers/rendering/rendering_server_wrap_mt.h @@ -211,7 +211,7 @@ public: FUNC3(multimesh_set_as_bulk_array_interpolated, RID, const PoolVector &, const PoolVector &) FUNC2(multimesh_set_physics_interpolated, RID, bool) - FUNC2(multimesh_set_physics_interpolation_quality, RID, int) + FUNC2(multimesh_set_physics_interpolation_quality, RID, MultimeshPhysicsInterpolationQuality) FUNC2(multimesh_instance_reset_physics_interpolation, RID, int) FUNC2(multimesh_set_visible_instances, RID, int) diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 78d2db5ba..b38ffb1be 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -31,8 +31,8 @@ #include "rendering_server.h" #include "core/config/engine.h" -#include "core/object/method_bind_ext.gen.inc" #include "core/config/project_settings.h" +#include "core/object/method_bind_ext.gen.inc" #ifdef TOOLS_ENABLED #include "editor/editor_settings.h" @@ -1932,6 +1932,10 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &RenderingServer::multimesh_set_visible_instances); ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &RenderingServer::multimesh_get_visible_instances); ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array", "multimesh", "array"), &RenderingServer::multimesh_set_as_bulk_array); + ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array_interpolated", "multimesh", "array", "array_previous"), &RenderingServer::multimesh_set_as_bulk_array_interpolated); + ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolated", "multimesh", "interpolated"), &RenderingServer::multimesh_set_physics_interpolated); + ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolation_quality", "multimesh", "quality"), &RenderingServer::multimesh_set_physics_interpolation_quality); + ClassDB::bind_method(D_METHOD("multimesh_instance_reset_physics_interpolation", "multimesh", "index"), &RenderingServer::multimesh_instance_reset_physics_interpolation); #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("immediate_create"), &RenderingServer::immediate_create); ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &RenderingServer::immediate_begin, DEFVAL(RID())); @@ -1998,6 +2002,8 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &RenderingServer::camera_set_orthogonal); ClassDB::bind_method(D_METHOD("camera_set_frustum", "camera", "size", "offset", "z_near", "z_far"), &RenderingServer::camera_set_frustum); ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &RenderingServer::camera_set_transform); + ClassDB::bind_method(D_METHOD("camera_set_interpolated", "camera", "interpolated"), &RenderingServer::camera_set_interpolated); + ClassDB::bind_method(D_METHOD("camera_reset_physics_interpolation", "camera"), &RenderingServer::camera_reset_physics_interpolation); ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &RenderingServer::camera_set_cull_mask); ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &RenderingServer::camera_set_environment); ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &RenderingServer::camera_set_use_vertical_aspect); @@ -2073,6 +2079,8 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &RenderingServer::instance_set_scenario); ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &RenderingServer::instance_set_layer_mask); ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &RenderingServer::instance_set_transform); + ClassDB::bind_method(D_METHOD("instance_set_interpolated", "instance", "interpolated"), &RenderingServer::instance_set_interpolated); + ClassDB::bind_method(D_METHOD("instance_reset_physics_interpolation", "instance"), &RenderingServer::instance_reset_physics_interpolation); ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &RenderingServer::instance_attach_object_instance_id); ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &RenderingServer::instance_set_blend_shape_weight); ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &RenderingServer::instance_set_surface_material); @@ -2414,6 +2422,8 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_NONE); BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_8BIT); BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_FLOAT); + BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_FAST); + BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_HIGH); BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE); BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 742ecbcb6..71b7deac0 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -30,12 +30,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "core/containers/rid.h" #include "core/io/image.h" #include "core/math/bsp_tree.h" #include "core/math/geometry.h" #include "core/math/transform_2d.h" #include "core/object/object.h" -#include "core/containers/rid.h" #include "core/variant/variant.h" class RenderingServerCallbacks; @@ -361,6 +361,11 @@ public: MULTIMESH_CUSTOM_DATA_MAX, }; + enum MultimeshPhysicsInterpolationQuality { + MULTIMESH_INTERP_QUALITY_FAST, + MULTIMESH_INTERP_QUALITY_HIGH, + }; + virtual void multimesh_allocate(RID p_multimesh, int p_instances, MultimeshTransformFormat p_transform_format, MultimeshColorFormat p_color_format, MultimeshCustomDataFormat p_data_format = MULTIMESH_CUSTOM_DATA_NONE) = 0; virtual int multimesh_get_instance_count(RID p_multimesh) const = 0; @@ -383,7 +388,7 @@ public: // Interpolation virtual void multimesh_set_as_bulk_array_interpolated(RID p_multimesh, const PoolVector &p_array, const PoolVector &p_array_prev) = 0; virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated) = 0; - virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality) = 0; + virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, MultimeshPhysicsInterpolationQuality p_quality) = 0; virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index) = 0; virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0; @@ -1120,6 +1125,7 @@ VARIANT_ENUM_CAST(RenderingServer::Features); VARIANT_ENUM_CAST(RenderingServer::MultimeshTransformFormat); VARIANT_ENUM_CAST(RenderingServer::MultimeshColorFormat); VARIANT_ENUM_CAST(RenderingServer::MultimeshCustomDataFormat); +VARIANT_ENUM_CAST(RenderingServer::MultimeshPhysicsInterpolationQuality); VARIANT_ENUM_CAST(RenderingServer::LightOmniShadowMode); VARIANT_ENUM_CAST(RenderingServer::LightOmniShadowDetail); VARIANT_ENUM_CAST(RenderingServer::LightDirectionalShadowMode);