Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Cherry-picks for the 4.3 (4.3.1) branch - 1st rendering bugs batch #942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6115712
Fix volumetric fog artifacts when inside the fog
ecmjohnson Dec 12, 2023
eac621a
Check device texture size limits in RenderingDevice::texture_create
Carbonyte Jun 30, 2024
6788299
Fix compatibility canvas background depth issue
BastiaanOlij Sep 18, 2024
38d92de
Fix hash calculation for NTSliceKey
jj11hh Sep 22, 2024
090d65d
Clamp UV-coordinates to centers of outermost texels when configured t…
patowen Sep 28, 2024
cd36b77
Improve the look of radiance map in Compatibility backend
clayjohn Sep 29, 2024
cd6e3a8
Lightmap Dynamic Bugfix
huwpascoe Oct 7, 2024
16efbfe
Fix incorrect depth comparison used to calculate volumetric fog shado…
m-pranav-r Oct 16, 2024
7e44ddf
Fixed light culling mask behavior in Mobile and Compat renderers
m-pranav-r Oct 17, 2024
b1883f9
Fix window exiting with no message to user if _create_window fails
Gromph Oct 22, 2024
f871a0b
Fix `MultiMesh` errors in editor and resource duplication
ydeltastar Oct 26, 2024
0ddf3cf
Fix inability to set TextureLayeredRD as TEXTURE_TYPE_CUBE or TEXTURE…
jadeharley2 Nov 11, 2024
649a263
Normalize normal tangent and binormal before interpolating in the mob…
clayjohn Nov 13, 2024
956a548
Fix SSS with reverse-z
Flarkk Nov 13, 2024
9254e2a
Fix updating lightmap captures on Mobile
BlueCube3310 Nov 17, 2024
cb7d88d
Fix gl_compatibility lightmap uniforms not being set
jamie-pate Nov 24, 2024
60b83b0
Fix ReflectionProbe AABB
lander-vr Nov 28, 2024
5b5723e
Fix a command buffer leak that occurs in dx12
alessand10 Dec 7, 2024
197be68
fix: canvas background mode not clearing correctly when using gles3 g…
Namey5 Dec 14, 2024
a0b8df5
fix: crash in scenes with more than 8 shadowed directional lights
Namey5 Dec 15, 2024
e9b781c
Implemented fix from #91219 in compatibility renderer by reversing the z
brandon515 Jan 5, 2025
832f0b3
Web: Export ASTC/BPTC compressed textures
BlueCube3310 Jan 6, 2025
af59e74
Correct aspect ratio used in FSR2 calculations to remove a source of …
clayjohn Jan 6, 2025
ece864e
Fix duplicated spec constant on SPIR-V reflection.
DarioSamo Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/classes/Sprite2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
If [code]true[/code], texture is cut from a larger atlas texture. See [member region_rect].
</member>
<member name="region_filter_clip_enabled" type="bool" setter="set_region_filter_clip_enabled" getter="is_region_filter_clip_enabled" default="false">
If [code]true[/code], the outermost pixels get blurred out. [member region_enabled] must be [code]true[/code].
If [code]true[/code], the area outside of the [member region_rect] is clipped to avoid bleeding of the surrounding texture pixels. [member region_enabled] must be [code]true[/code].
</member>
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2(0, 0, 0, 0)">
The region of the atlas texture to display. [member region_enabled] must be [code]true[/code].
Expand Down
18 changes: 17 additions & 1 deletion drivers/d3d12/rendering_device_driver_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,19 @@ RDD::CommandPoolID RenderingDeviceDriverD3D12::command_pool_create(CommandQueueF

void RenderingDeviceDriverD3D12::command_pool_free(CommandPoolID p_cmd_pool) {
CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id);

// Destroy all command buffers associated with this command pool, mirroring Vulkan's behavior.
SelfList<CommandBufferInfo> *cmd_buf_elem = command_pool->command_buffers.first();
while (cmd_buf_elem != nullptr) {
CommandBufferInfo *cmd_buf_info = cmd_buf_elem->self();
cmd_buf_elem = cmd_buf_elem->next();

cmd_buf_info->cmd_list.Reset();
cmd_buf_info->cmd_allocator.Reset();

VersatileResource::free(resources_allocator, cmd_buf_info);
}

memdelete(command_pool);
}

Expand All @@ -2356,7 +2369,7 @@ void RenderingDeviceDriverD3D12::command_pool_free(CommandPoolID p_cmd_pool) {
RDD::CommandBufferID RenderingDeviceDriverD3D12::command_buffer_create(CommandPoolID p_cmd_pool) {
DEV_ASSERT(p_cmd_pool);

const CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id);
CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id);
D3D12_COMMAND_LIST_TYPE list_type;
if (command_pool->buffer_type == COMMAND_BUFFER_TYPE_SECONDARY) {
list_type = D3D12_COMMAND_LIST_TYPE_BUNDLE;
Expand Down Expand Up @@ -2392,6 +2405,9 @@ RDD::CommandBufferID RenderingDeviceDriverD3D12::command_buffer_create(CommandPo
cmd_buf_info->cmd_allocator = cmd_allocator;
cmd_buf_info->cmd_list = cmd_list;

// Add this command buffer to the command pool's list of command buffers.
command_pool->command_buffers.add(&cmd_buf_info->command_buffer_info_elem);

return CommandBufferID(cmd_buf_info);
}

Expand Down
6 changes: 6 additions & 0 deletions drivers/d3d12/rendering_device_driver_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
struct CommandPoolInfo {
CommandQueueFamilyID queue_family;
CommandBufferType buffer_type = COMMAND_BUFFER_TYPE_PRIMARY;
// Since there are no command pools in D3D12, we need to track the command buffers created by this pool
// so that we can free them when the pool is freed.
SelfList<CommandBufferInfo>::List command_buffers;
};

public:
Expand Down Expand Up @@ -478,6 +481,9 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
// Leveraging knowledge of actual usage and D3D12 specifics (namely, command lists from the same allocator
// can't be freely begun and ended), an allocator per list works better.
struct CommandBufferInfo {
// Store a self list reference to be used by the command pool.
SelfList<CommandBufferInfo> command_buffer_info_elem{ this };

ComPtr<ID3D12CommandAllocator> cmd_allocator;
ComPtr<ID3D12GraphicsCommandList> cmd_list;

Expand Down
18 changes: 11 additions & 7 deletions drivers/gles3/effects/cubemap_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ CubemapFilter *CubemapFilter::singleton = nullptr;

CubemapFilter::CubemapFilter() {
singleton = this;
ggx_samples = GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples");
// Use a factor 4 larger for the compatibility renderer to make up for the fact
// That we don't use an array texture. We will reduce samples on low roughness
// to compensate.
ggx_samples = 4 * uint32_t(GLOBAL_GET("rendering/reflections/sky_reflections/ggx_samples"));

{
String defines;
Expand All @@ -59,10 +62,10 @@ CubemapFilter::CubemapFilter() {
const float qv[6] = {
-1.0f,
-1.0f,
3.0f,
-1.0f,
-1.0f,
3.0f,
3.0f,
-1.0f,
};

glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW);
Expand Down Expand Up @@ -148,10 +151,11 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem
}

if (p_layer > 0) {
const uint32_t sample_counts[4] = { 1, ggx_samples / 4, ggx_samples / 2, ggx_samples };
uint32_t sample_count = sample_counts[MIN(3, p_layer)];
const uint32_t sample_counts[5] = { 1, ggx_samples / 16, ggx_samples / 8, ggx_samples / 4, ggx_samples };
uint32_t sample_count = sample_counts[MIN(4, p_layer)];

float roughness = float(p_layer) / (p_mipmap_count);
float roughness = float(p_layer) / (p_mipmap_count - 1);
roughness *= roughness; // Convert to non-perceptual roughness.
float roughness4 = roughness * roughness;
roughness4 *= roughness4;

Expand All @@ -167,7 +171,7 @@ void CubemapFilter::filter_radiance(GLuint p_source_cubemap, GLuint p_dest_cubem
Vector3 dir = importance_sample_GGX(xi, roughness4);
Vector3 light_vec = (2.0 * dir.z * dir - Vector3(0.0, 0.0, 1.0));

if (light_vec.z < 0.0) {
if (light_vec.z <= 0.0) {
continue;
}

Expand Down
26 changes: 17 additions & 9 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
bool draw_sky = false;
bool draw_sky_fog_only = false;
bool keep_color = false;
bool draw_canvas = false;
float sky_energy_multiplier = 1.0;

if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) {
Expand Down Expand Up @@ -2436,12 +2437,13 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
draw_sky = !render_data.transparent_bg;
} break;
case RS::ENV_BG_CANVAS: {
keep_color = true;
draw_canvas = true;
} break;
case RS::ENV_BG_KEEP: {
keep_color = true;
} break;
case RS::ENV_BG_CAMERA_FEED: {
keep_color = true;
} break;
default: {
}
Expand Down Expand Up @@ -2553,10 +2555,14 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
glClear(GL_DEPTH_BUFFER_BIT);
}

if (!keep_color) {
// Need to clear framebuffer unless:
// a) We explicitly request not to (i.e. ENV_BG_KEEP).
// b) We are rendering to a non-intermediate framebuffer with ENV_BG_CANVAS (shared between 2D and 3D).
if (!keep_color && (!draw_canvas || fbo != rt->fbo)) {
clear_color.a = render_data.transparent_bg ? 0.0f : 1.0f;
glClearBufferfv(GL_COLOR, 0, clear_color.components);
} else if (fbo != rt->fbo) {
}
if ((keep_color || draw_canvas) && fbo != rt->fbo) {
// Need to copy our current contents to our intermediate/MSAA buffer
GLES3::CopyEffects *copy_effects = GLES3::CopyEffects::get_singleton();

Expand All @@ -2567,6 +2573,9 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
glBindTexture(rt->view_count > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D, rt->color);

copy_effects->copy_screen(render_data.luminance_multiplier);

scene_state.enable_gl_depth_test(true);
scene_state.enable_gl_depth_draw(true);
}

RENDER_TIMESTAMP("Render Opaque Pass");
Expand Down Expand Up @@ -3287,10 +3296,6 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
}

material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::OPAQUE_PREPASS_THRESHOLD, opaque_prepass_threshold, shader->version, instance_variant, spec_constants);

prev_shader = shader;
prev_variant = instance_variant;
prev_spec_constants = spec_constants;
}

// Pass in lighting uniforms.
Expand Down Expand Up @@ -3328,7 +3333,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
}

// Pass light count and array of light indices for base pass.
if ((prev_inst != inst || prev_shader != shader || prev_variant != instance_variant) && pass == 0) {
if ((prev_inst != inst || prev_shader != shader || prev_variant != instance_variant || prev_spec_constants != spec_constants) && pass == 0) {
// Rebind the light indices.
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::OMNI_LIGHT_COUNT, inst->omni_light_gl_cache.size(), shader->version, instance_variant, spec_constants);
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::SPOT_LIGHT_COUNT, inst->spot_light_gl_cache.size(), shader->version, instance_variant, spec_constants);
Expand Down Expand Up @@ -3380,11 +3385,14 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
} else if (inst->lightmap_sh) {
glUniform4fv(material_storage->shaders.scene_shader.version_get_uniform(SceneShaderGLES3::LIGHTMAP_CAPTURES, shader->version, instance_variant, spec_constants), 9, reinterpret_cast<const GLfloat *>(inst->lightmap_sh->sh));
}

prev_inst = inst;
}
}

prev_shader = shader;
prev_variant = instance_variant;
prev_spec_constants = spec_constants;

// Pass in reflection probe data
if constexpr (p_pass_mode == PASS_MODE_COLOR || p_pass_mode == PASS_MODE_COLOR_TRANSPARENT) {
if (pass == 0 && inst->reflection_probe_rid_cache.size() > 0) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/gles3/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ void main() {

#endif
if (bool(read_draw_data_flags & FLAGS_CLIP_RECT_UV)) {
uv = clamp(uv, read_draw_data_src_rect.xy, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw));
vec2 half_texpixel = read_draw_data_color_texture_pixel_size * 0.5;
uv = clamp(uv, read_draw_data_src_rect.xy + half_texpixel, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) - half_texpixel);
}

#endif
Expand Down
6 changes: 3 additions & 3 deletions drivers/gles3/shaders/particles.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,14 @@ void main() {

vec3 uvw_pos = vec3(local_pos_bottom / colliders[i].extents.xyz) * 0.5 + 0.5;

float y = 1.0 - texture(height_field_texture, uvw_pos.xz).r;
float y = texture(height_field_texture, uvw_pos.xz).r;

if (y + EPSILON > uvw_pos.y) {
//inside heightfield

vec3 pos1 = (vec3(uvw_pos.x, y, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;
vec3 pos2 = (vec3(uvw_pos.x + DELTA, 1.0 - texture(height_field_texture, uvw_pos.xz + vec2(DELTA, 0)).r, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;
vec3 pos3 = (vec3(uvw_pos.x, 1.0 - texture(height_field_texture, uvw_pos.xz + vec2(0, DELTA)).r, uvw_pos.z + DELTA) * 2.0 - 1.0) * colliders[i].extents.xyz;
vec3 pos2 = (vec3(uvw_pos.x + DELTA, texture(height_field_texture, uvw_pos.xz + vec2(DELTA, 0)).r, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;
vec3 pos3 = (vec3(uvw_pos.x, texture(height_field_texture, uvw_pos.xz + vec2(0, DELTA)).r, uvw_pos.z + DELTA) * 2.0 - 1.0) * colliders[i].extents.xyz;

normal = normalize(cross(pos1 - pos2, pos1 - pos3));
float local_y = (vec3(local_pos / colliders[i].extents.xyz) * 0.5 + 0.5).y;
Expand Down
7 changes: 0 additions & 7 deletions editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ void ReflectionProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
aabb.position = -size / 2;
aabb.size = size;

for (int i = 0; i < 12; i++) {
Vector3 a, b;
aabb.get_edge(i, a, b);
lines.push_back(a);
lines.push_back(b);
}

for (int i = 0; i < 8; i++) {
Vector3 ep = aabb.get_endpoint(i);
internal_lines.push_back(probe->get_origin_offset());
Expand Down
4 changes: 2 additions & 2 deletions platform/web/doc_classes/EditorExportPlatformWeb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
If [code]false[/code], the exported game will not support threads. As a result, it is more prone to performance and audio issues, but will only require to be run on an HTTPS website.
</member>
<member name="vram_texture_compression/for_desktop" type="bool" setter="" getter="">
If [code]true[/code], allows textures to be optimized for desktop through the S3TC algorithm.
If [code]true[/code], allows textures to be optimized for desktop through the S3TC/BPTC algorithm.
</member>
<member name="vram_texture_compression/for_mobile" type="bool" setter="" getter="">
If [code]true[/code] allows textures to be optimized for mobile through the ETC2 algorithm.
If [code]true[/code] allows textures to be optimized for mobile through the ETC2/ASTC algorithm.
</member>
</members>
</class>
2 changes: 2 additions & 0 deletions platform/web/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,11 @@ Error EditorExportPlatformWeb::_build_pwa(const Ref<EditorExportPreset> &p_prese
void EditorExportPlatformWeb::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
if (p_preset->get("vram_texture_compression/for_desktop")) {
r_features->push_back("s3tc");
r_features->push_back("bptc");
}
if (p_preset->get("vram_texture_compression/for_mobile")) {
r_features->push_back("etc2");
r_features->push_back("astc");
}
if (p_preset->get("variant/thread_support").operator bool()) {
r_features->push_back("threads");
Expand Down
5 changes: 4 additions & 1 deletion platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}

WindowID main_window = _create_window(p_mode, p_vsync_mode, p_flags, Rect2i(window_position, p_resolution), false, INVALID_WINDOW_ID);
ERR_FAIL_COND_MSG(main_window == INVALID_WINDOW_ID, "Failed to create main window.");
if (main_window == INVALID_WINDOW_ID) {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Failed to create main window.");
}

joypad = new JoypadWindows(&windows[MAIN_WINDOW_ID].hWnd);

Expand Down
4 changes: 2 additions & 2 deletions scene/3d/reflection_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const {

AABB ReflectionProbe::get_aabb() const {
AABB aabb;
aabb.position = -origin_offset;
aabb.size = origin_offset + size / 2;
aabb.position = -size / 2;
aabb.size = size;
return aabb;
}

Expand Down
3 changes: 3 additions & 0 deletions scene/resources/multimesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ Vector<Color> MultiMesh::_get_custom_data_array() const {
#endif // DISABLE_DEPRECATED

void MultiMesh::set_buffer(const Vector<float> &p_buffer) {
if (instance_count == 0) {
return;
}
RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer);
}

Expand Down
2 changes: 1 addition & 1 deletion scene/resources/texture_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void TextureLayeredRD::_set_texture_rd_rid(RID p_texture_rd_rid) {

RS::TextureLayeredType rs_layer_type;
RD::TextureFormat tf = RD::get_singleton()->texture_get_format(p_texture_rd_rid);
ERR_FAIL_COND(tf.texture_type != RD::TEXTURE_TYPE_2D_ARRAY);
ERR_FAIL_COND(tf.texture_type != RD::TEXTURE_TYPE_2D_ARRAY && tf.texture_type != RD::TEXTURE_TYPE_CUBE && tf.texture_type != RD::TEXTURE_TYPE_CUBE_ARRAY);
ERR_FAIL_COND(tf.depth > 1);
switch (layer_type) {
case LAYERED_TYPE_2D_ARRAY: {
Expand Down
Loading