diff options
author | reduz <reduzio@gmail.com> | 2021-06-29 11:45:07 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-06-29 11:45:59 -0300 |
commit | d55ebc3a5d2ebe87bce8e457634b6dd2819a9d39 (patch) | |
tree | e6a86b363ad825a76960f5fc3227e0a43674abbe /servers/rendering/renderer_rd | |
parent | 83b3148b16557e35e63f7a0020baabc171499e48 (diff) |
Fix non uniform scaling in 3D objects
* Flag was there, but not implemented.
* Fixed issue with base flags not being initialized.
Diffstat (limited to 'servers/rendering/renderer_rd')
6 files changed, 15 insertions, 6 deletions
diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 1653453c5c..b66b9b597c 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -903,6 +903,9 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con uint32_t flags = inst->base_flags; //fill flags if appropriate + if (inst->non_uniform_scale) { + flags |= INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE; + } bool uses_lightmap = false; bool uses_gi = false; @@ -2594,6 +2597,8 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome //Fill push constant + ginstance->base_flags = 0; + bool store_transform = true; if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { @@ -2737,6 +2742,7 @@ void RenderForwardClustered::geometry_instance_set_transform(GeometryInstance *p float max_scale = MAX(model_scale_vec.x, MAX(model_scale_vec.y, model_scale_vec.z)); float min_scale = MIN(model_scale_vec.x, MIN(model_scale_vec.y, model_scale_vec.z)); + ginstance->non_uniform_scale = max_scale >= 0.0 && (min_scale / max_scale) < 0.9; ginstance->lod_model_scale = max_scale; diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h index 579c8de05e..8fbe3935e8 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h @@ -184,6 +184,7 @@ class RenderForwardClustered : public RendererSceneRenderRD { }; enum { + INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, @@ -196,7 +197,6 @@ class RenderForwardClustered : public RendererSceneRenderRD { INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, - INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24, }; struct SceneState { diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index ae09d215ff..fdcf4394a7 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -963,6 +963,10 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const uint32_t flags = inst->base_flags; //fill flags if appropriate + if (inst->non_uniform_scale) { + flags |= INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE; + } + bool uses_lightmap = false; // bool uses_gi = false; @@ -1995,6 +1999,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry //Fill push constant bool store_transform = true; + ginstance->base_flags = 0; if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH; diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h index 99cbd45b10..35e62be281 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h @@ -390,6 +390,7 @@ protected: // check which ones of these apply, probably all except GI and SDFGI enum { + INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, @@ -402,7 +403,6 @@ protected: INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, - INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24, }; struct GeometryInstanceLightmapSH { diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl index e64e52623e..6599a42bab 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl @@ -52,6 +52,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12]; layout(set = 0, binding = 2) uniform sampler shadow_sampler; +#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5) #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) @@ -66,8 +67,6 @@ layout(set = 0, binding = 2) uniform sampler shadow_sampler; //3 bits of stride #define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF -#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 24) - layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights { LightData data[]; } diff --git a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl index 7fcd84695d..d4ebcbeec4 100644 --- a/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl +++ b/servers/rendering/renderer_rd/shaders/scene_forward_mobile_inc.glsl @@ -51,6 +51,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12]; layout(set = 0, binding = 2) uniform sampler shadow_sampler; +#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5) #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) @@ -65,8 +66,6 @@ layout(set = 0, binding = 2) uniform sampler shadow_sampler; //3 bits of stride #define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF -#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 24) - layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights { LightData data[]; } |