diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2022-08-04 21:29:53 +0200 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2022-08-04 23:10:04 +0200 |
commit | 74f41f8560b12e373c33de4d1be2d1382fdced7e (patch) | |
tree | 7eea854ec0976ca9c58c4028bc17d6aa1e9e1732 /scene/3d/soft_dynamic_body_3d.cpp | |
parent | 426240f18a1326ef31bbb45c65e6f556658d2519 (diff) |
Fix SoftDynamicBody3D normals
Store normal vector in A2B10G10R10 format.
Diffstat (limited to 'scene/3d/soft_dynamic_body_3d.cpp')
-rw-r--r-- | scene/3d/soft_dynamic_body_3d.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/scene/3d/soft_dynamic_body_3d.cpp b/scene/3d/soft_dynamic_body_3d.cpp index d68e7fd527..15f050defb 100644 --- a/scene/3d/soft_dynamic_body_3d.cpp +++ b/scene/3d/soft_dynamic_body_3d.cpp @@ -83,7 +83,16 @@ void SoftDynamicBodyRenderingServerHandler::set_vertex(int p_vertex_id, const vo } void SoftDynamicBodyRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { - memcpy(&write_buffer[p_vertex_id * stride + offset_normal], p_vector3, sizeof(float) * 3); + // Store normal vector in A2B10G10R10 format. + Vector3 n; + memcpy(&n, p_vector3, sizeof(Vector3)); + n *= Vector3(0.5, 0.5, 0.5); + n += Vector3(0.5, 0.5, 0.5); + uint32_t value = 0; + value |= CLAMP(int(n.x * 1023.0), 0, 1023); + value |= CLAMP(int(n.y * 1023.0), 0, 1023) << 10; + value |= CLAMP(int(n.z * 1023.0), 0, 1023) << 20; + memcpy(&write_buffer[p_vertex_id * stride + offset_normal], &value, sizeof(uint32_t)); } void SoftDynamicBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) { |