Fix non uniform scaling in 3D objects

* Flag was there, but not implemented.
* Fixed issue with base flags not being initialized.
This commit is contained in:
reduz 2021-06-29 11:45:07 -03:00
parent 83b3148b16
commit d55ebc3a5d
6 changed files with 15 additions and 6 deletions

View file

@ -903,6 +903,9 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con
uint32_t flags = inst->base_flags; //fill flags if appropriate 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_lightmap = false;
bool uses_gi = false; bool uses_gi = false;
@ -2594,6 +2597,8 @@ void RenderForwardClustered::_geometry_instance_update(GeometryInstance *p_geome
//Fill push constant //Fill push constant
ginstance->base_flags = 0;
bool store_transform = true; bool store_transform = true;
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { 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 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)); 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->non_uniform_scale = max_scale >= 0.0 && (min_scale / max_scale) < 0.9;
ginstance->lod_model_scale = max_scale; ginstance->lod_model_scale = max_scale;

View file

@ -184,6 +184,7 @@ class RenderForwardClustered : public RendererSceneRenderRD {
}; };
enum { enum {
INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5,
INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6,
INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7,
INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, 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_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15,
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16,
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF,
INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24,
}; };
struct SceneState { struct SceneState {

View file

@ -963,6 +963,10 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
uint32_t flags = inst->base_flags; //fill flags if appropriate 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_lightmap = false;
// bool uses_gi = false; // bool uses_gi = false;
@ -1995,6 +1999,7 @@ void RenderForwardMobile::_geometry_instance_update(GeometryInstance *p_geometry
//Fill push constant //Fill push constant
bool store_transform = true; bool store_transform = true;
ginstance->base_flags = 0;
if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) { if (ginstance->data->base_type == RS::INSTANCE_MULTIMESH) {
ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH; ginstance->base_flags |= INSTANCE_DATA_FLAG_MULTIMESH;

View file

@ -390,6 +390,7 @@ protected:
// check which ones of these apply, probably all except GI and SDFGI // check which ones of these apply, probably all except GI and SDFGI
enum { enum {
INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 5,
INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6, INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 6,
INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7, INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 7,
INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8, INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 8,
@ -402,7 +403,6 @@ protected:
INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15,
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16,
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF,
INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 24,
}; };
struct GeometryInstanceLightmapSH { struct GeometryInstanceLightmapSH {

View file

@ -52,6 +52,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12];
layout(set = 0, binding = 2) uniform sampler shadow_sampler; 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_GI_BUFFERS (1 << 6)
#define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
#define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) #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 //3 bits of stride
#define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF #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 { layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights {
LightData data[]; LightData data[];
} }

View file

@ -51,6 +51,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12];
layout(set = 0, binding = 2) uniform sampler shadow_sampler; 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_GI_BUFFERS (1 << 6)
#define INSTANCE_FLAGS_USE_SDFGI (1 << 7) #define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
#define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8) #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 //3 bits of stride
#define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF #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 { layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights {
LightData data[]; LightData data[];
} }