summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct1
-rw-r--r--core/io/packet_peer.cpp1
-rw-r--r--core/math/camera_matrix.cpp4
-rw-r--r--core/math/face3.cpp2
-rw-r--r--core/project_settings.cpp2
-rw-r--r--core/typedefs.h3
-rw-r--r--core/ustring.cpp2
-rw-r--r--doc/classes/EditorVCSInterface.xml2
-rw-r--r--doc/classes/Object.xml9
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.cpp4
-rw-r--r--drivers/gles2/shader_gles2.h1
-rw-r--r--drivers/gles2/shaders/scene.glsl180
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp29
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h2
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp151
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h1
-rw-r--r--drivers/gles3/shaders/cubemap_filter.glsl119
-rw-r--r--drivers/gles3/shaders/scene.glsl29
-rw-r--r--editor/doc/doc_data.h3
-rw-r--r--editor/editor_sectioned_inspector.cpp4
-rw-r--r--editor/editor_vcs_interface.cpp10
-rw-r--r--editor/editor_vcs_interface.h4
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp1
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp9
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h1
-rw-r--r--editor/plugins/version_control_editor_plugin.cpp5
-rw-r--r--editor/plugins/version_control_editor_plugin.h2
-rw-r--r--editor/script_create_dialog.cpp1
-rw-r--r--editor/script_editor_debugger.cpp1
-rw-r--r--modules/arkit/arkit_interface.mm19
-rw-r--r--modules/assimp/import_utils.h2
-rw-r--r--modules/mono/build_scripts/mono_configure.py5
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs4
-rw-r--r--modules/regex/SCsub4
-rw-r--r--platform/javascript/detect.py1
-rw-r--r--platform/osx/os_osx.h3
-rw-r--r--platform/osx/os_osx.mm54
-rw-r--r--platform/uwp/detect.py1
-rw-r--r--scene/2d/collision_object_2d.cpp10
-rw-r--r--scene/2d/collision_object_2d.h1
-rw-r--r--scene/2d/tile_map.cpp4
-rw-r--r--scene/3d/gi_probe.cpp4
-rw-r--r--scene/animation/tween.cpp2
-rw-r--r--scene/gui/gradient_edit.cpp5
-rw-r--r--scene/gui/range.cpp2
-rw-r--r--scene/gui/tree.h2
-rw-r--r--scene/main/viewport.cpp2
-rw-r--r--scene/resources/audio_stream_sample.cpp5
48 files changed, 470 insertions, 243 deletions
diff --git a/SConstruct b/SConstruct
index cdbb47faea..0e282a1f12 100644
--- a/SConstruct
+++ b/SConstruct
@@ -150,6 +150,7 @@ opts.Add(BoolVariable('builtin_mbedtls', "Use the built-in mbedTLS library", Tru
opts.Add(BoolVariable('builtin_miniupnpc', "Use the built-in miniupnpc library", True))
opts.Add(BoolVariable('builtin_opus', "Use the built-in Opus library", True))
opts.Add(BoolVariable('builtin_pcre2', "Use the built-in PCRE2 library", True))
+opts.Add(BoolVariable('builtin_pcre2_with_jit', "Use JIT compiler for the built-in PCRE2 library", True))
opts.Add(BoolVariable('builtin_recast', "Use the built-in Recast library", True))
opts.Add(BoolVariable('builtin_squish', "Use the built-in squish library", True))
opts.Add(BoolVariable('builtin_xatlas', "Use the built-in xatlas library", True))
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 821a04ebad..23dfc58385 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -279,6 +279,7 @@ Ref<StreamPeer> PacketPeerStream::get_stream_peer() const {
void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
+ ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0.");
//warning may lose packets
ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data.");
ring_buffer.resize(nearest_shift(p_max_size + 4));
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 30c0cab909..b9b0f4ac54 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -183,6 +183,10 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
+ ERR_FAIL_COND(p_right <= p_left);
+ ERR_FAIL_COND(p_top <= p_bottom);
+ ERR_FAIL_COND(p_far <= p_near);
+
real_t *te = &matrix[0][0];
real_t x = 2 * p_near / (p_right - p_left);
real_t y = 2 * p_near / (p_top - p_bottom);
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index ab09142b2d..666d214f98 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -393,7 +393,7 @@ Vector3 Face3::get_closest_point_to(const Vector3 &p_point) const {
s = CLAMP(numer / denom, 0.f, 1.f);
t = 1 - s;
} else {
- s = CLAMP(-e / c, 0.f, 1.f);
+ s = CLAMP(-d / a, 0.f, 1.f);
t = 0.f;
}
} else {
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 7704c7b377..ba5cdd782f 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -525,6 +525,8 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
set(key, value);
}
+ f->close();
+ memdelete(f);
return OK;
}
diff --git a/core/typedefs.h b/core/typedefs.h
index 767a97ac38..42f34c73cb 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -174,6 +174,9 @@ inline void __swap_tmpl(T &x, T &y) {
static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) {
+ if (x == 0)
+ return 0;
+
--x;
x |= x >> 1;
x |= x >> 2;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 0f82ca7e15..25930db201 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -1416,7 +1416,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
if (skip == 0) {
- uint8_t c = *ptrtmp;
+ uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp);
/* Determine the number of characters in sequence */
if ((c & 0x80) == 0)
diff --git a/doc/classes/EditorVCSInterface.xml b/doc/classes/EditorVCSInterface.xml
index f67c1c9eb5..3ae19e5dce 100644
--- a/doc/classes/EditorVCSInterface.xml
+++ b/doc/classes/EditorVCSInterface.xml
@@ -34,7 +34,7 @@
- [code]"offset"[/code] to store the offset of the line change since the first contextual line content.
</description>
</method>
- <method name="get_is_vcs_intialized">
+ <method name="is_vcs_initialized">
<return type="bool">
</return>
<description>
diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml
index 4b77197e29..5a09fe39c0 100644
--- a/doc/classes/Object.xml
+++ b/doc/classes/Object.xml
@@ -139,7 +139,7 @@
<argument index="4" name="flags" type="int" default="0">
</argument>
<description>
- Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants.
+ Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. These parameters will be passed to the method after any parameter used in the call to [method emit_signal]. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants.
A [code]signal[/code] can only be connected once to a [code]method[/code]. It will throw an error if already connected, unless the signal was connected with [constant CONNECT_REFERENCE_COUNTED]. To avoid this, first, use [method is_connected] to check for existing connections.
If the [code]target[/code] is destroyed in the game's lifecycle, the connection will be lost.
Examples:
@@ -148,6 +148,13 @@
connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
[/codeblock]
+ An example of the relationship between [code]binds[/code] passed to [method connect] and parameters used when calling [method emit_signal]:
+ [codeblock]
+ connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
+ emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
+ func _on_Player_hit(hit_by, level, weapon_type, damage):
+ print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
+ [/codeblock]
</description>
</method>
<method name="disconnect">
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp
index 325f2d6707..ac54af722c 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.cpp
+++ b/drivers/gles2/rasterizer_canvas_gles2.cpp
@@ -766,6 +766,10 @@ void RasterizerCanvasGLES2::_canvas_item_render_commands(Item *p_item, Item *cur
WARN_PRINT("NinePatch without texture not supported yet in GLES2 backend, skipping.");
continue;
}
+ if (tex->width == 0 || tex->height == 0) {
+ WARN_PRINT("Cannot set empty texture to NinePatch.");
+ continue;
+ }
Size2 texpixel_size(1.0 / tex->width, 1.0 / tex->height);
diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h
index 2456a83d35..c7a6465194 100644
--- a/drivers/gles2/shader_gles2.h
+++ b/drivers/gles2/shader_gles2.h
@@ -119,6 +119,7 @@ private:
bool ok;
Version() {
code_version = 0;
+ frag_id = 0;
ok = false;
uniform_location = NULL;
}
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index e36e776881..25dbbf3c90 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -1547,155 +1547,157 @@ FRAGMENT_SHADER_CODE
#endif // !USE_SHADOW_TO_OPACITY
#ifdef BASE_PASS
- //none
+ {
+ // IBL precalculations
+ float ndotv = clamp(dot(normal, eye_position), 0.0, 1.0);
+ vec3 f0 = F0(metallic, specular, albedo);
+ vec3 F = f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow(1.0 - ndotv, 5.0);
#ifdef AMBIENT_LIGHT_DISABLED
- ambient_light = vec3(0.0, 0.0, 0.0);
+ ambient_light = vec3(0.0, 0.0, 0.0);
#else
#ifdef USE_RADIANCE_MAP
- vec3 ref_vec = reflect(-eye_position, N);
- ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
+ vec3 ref_vec = reflect(-eye_position, N);
+ ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
- ref_vec.z *= -1.0;
+ ref_vec.z *= -1.0;
- specular_light = textureCubeLod(radiance_map, ref_vec, roughness * RADIANCE_MAX_LOD).xyz * bg_energy;
- {
- vec3 ambient_dir = normalize((radiance_inverse_xform * vec4(normal, 0.0)).xyz);
- vec3 env_ambient = textureCubeLod(radiance_map, ambient_dir, RADIANCE_MAX_LOD).xyz * bg_energy;
+ specular_light = textureCubeLod(radiance_map, ref_vec, roughness * RADIANCE_MAX_LOD).xyz * bg_energy;
+#ifndef USE_LIGHTMAP
+ {
+ vec3 ambient_dir = normalize((radiance_inverse_xform * vec4(normal, 0.0)).xyz);
+ vec3 env_ambient = textureCubeLod(radiance_map, ambient_dir, 4.0).xyz * bg_energy;
+ env_ambient *= 1.0 - F;
- ambient_light = mix(ambient_color.rgb, env_ambient, ambient_sky_contribution);
- }
+ ambient_light = mix(ambient_color.rgb, env_ambient, ambient_sky_contribution);
+ }
+#endif
#else
- ambient_light = ambient_color.rgb;
- specular_light = bg_color.rgb * bg_energy;
+ ambient_light = ambient_color.rgb;
+ specular_light = bg_color.rgb * bg_energy;
#endif
-
#endif // AMBIENT_LIGHT_DISABLED
- ambient_light *= ambient_energy;
+ ambient_light *= ambient_energy;
#if defined(USE_REFLECTION_PROBE1) || defined(USE_REFLECTION_PROBE2)
- vec4 ambient_accum = vec4(0.0);
- vec4 reflection_accum = vec4(0.0);
+ vec4 ambient_accum = vec4(0.0);
+ vec4 reflection_accum = vec4(0.0);
#ifdef USE_REFLECTION_PROBE1
- reflection_process(reflection_probe1,
+ reflection_process(reflection_probe1,
#ifdef USE_VERTEX_LIGHTING
- refprobe1_reflection_normal_blend.rgb,
+ refprobe1_reflection_normal_blend.rgb,
#ifndef USE_LIGHTMAP
- refprobe1_ambient_normal,
+ refprobe1_ambient_normal,
#endif
- refprobe1_reflection_normal_blend.a,
+ refprobe1_reflection_normal_blend.a,
#else
- normal_interp, vertex_interp, refprobe1_local_matrix,
- refprobe1_use_box_project, refprobe1_box_extents, refprobe1_box_offset,
+ normal_interp, vertex_interp, refprobe1_local_matrix,
+ refprobe1_use_box_project, refprobe1_box_extents, refprobe1_box_offset,
#endif
- refprobe1_exterior, refprobe1_intensity, refprobe1_ambient, roughness,
- ambient_light, specular_light, reflection_accum, ambient_accum);
+ refprobe1_exterior, refprobe1_intensity, refprobe1_ambient, roughness,
+ ambient_light, specular_light, reflection_accum, ambient_accum);
#endif // USE_REFLECTION_PROBE1
#ifdef USE_REFLECTION_PROBE2
- reflection_process(reflection_probe2,
+ reflection_process(reflection_probe2,
#ifdef USE_VERTEX_LIGHTING
- refprobe2_reflection_normal_blend.rgb,
+ refprobe2_reflection_normal_blend.rgb,
#ifndef USE_LIGHTMAP
- refprobe2_ambient_normal,
+ refprobe2_ambient_normal,
#endif
- refprobe2_reflection_normal_blend.a,
+ refprobe2_reflection_normal_blend.a,
#else
- normal_interp, vertex_interp, refprobe2_local_matrix,
- refprobe2_use_box_project, refprobe2_box_extents, refprobe2_box_offset,
+ normal_interp, vertex_interp, refprobe2_local_matrix,
+ refprobe2_use_box_project, refprobe2_box_extents, refprobe2_box_offset,
#endif
- refprobe2_exterior, refprobe2_intensity, refprobe2_ambient, roughness,
- ambient_light, specular_light, reflection_accum, ambient_accum);
+ refprobe2_exterior, refprobe2_intensity, refprobe2_ambient, roughness,
+ ambient_light, specular_light, reflection_accum, ambient_accum);
#endif // USE_REFLECTION_PROBE2
- if (reflection_accum.a > 0.0) {
- specular_light = reflection_accum.rgb / reflection_accum.a;
- }
+ if (reflection_accum.a > 0.0) {
+ specular_light = reflection_accum.rgb / reflection_accum.a;
+ }
#ifndef USE_LIGHTMAP
- if (ambient_accum.a > 0.0) {
- ambient_light = ambient_accum.rgb / ambient_accum.a;
- }
+ if (ambient_accum.a > 0.0) {
+ ambient_light = ambient_accum.rgb / ambient_accum.a;
+ }
#endif
#endif // defined(USE_REFLECTION_PROBE1) || defined(USE_REFLECTION_PROBE2)
- // environment BRDF approximation
-
- {
+ // environment BRDF approximation
+ {
#if defined(DIFFUSE_TOON)
- //simplify for toon, as
- specular_light *= specular * metallic * albedo * 2.0;
+ //simplify for toon, as
+ specular_light *= specular * metallic * albedo * 2.0;
#else
- // scales the specular reflections, needs to be be computed before lighting happens,
- // but after environment and reflection probes are added
- //TODO: this curve is not really designed for gammaspace, should be adjusted
- const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
- const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
- vec4 r = roughness * c0 + c1;
- float ndotv = clamp(dot(normal, eye_position), 0.0, 1.0);
- float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
- vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
-
- vec3 f0 = F0(metallic, specular, albedo);
- specular_light *= env.x * f0 + env.y;
+ // scales the specular reflections, needs to be be computed before lighting happens,
+ // but after environment and reflection probes are added
+ //TODO: this curve is not really designed for gammaspace, should be adjusted
+ const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
+ const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
+ vec4 r = roughness * c0 + c1;
+ float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
+ vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
+ specular_light *= env.x * F + env.y;
#endif
- }
+ }
#ifdef USE_LIGHTMAP
- //ambient light will come entirely from lightmap is lightmap is used
- ambient_light = texture2D(lightmap, uv2_interp).rgb * lightmap_energy;
+ //ambient light will come entirely from lightmap is lightmap is used
+ ambient_light = texture2D(lightmap, uv2_interp).rgb * lightmap_energy;
#endif
#ifdef USE_LIGHTMAP_CAPTURE
- {
- vec3 cone_dirs[12] = vec3[](
- vec3(0.0, 0.0, 1.0),
- vec3(0.866025, 0.0, 0.5),
- vec3(0.267617, 0.823639, 0.5),
- vec3(-0.700629, 0.509037, 0.5),
- vec3(-0.700629, -0.509037, 0.5),
- vec3(0.267617, -0.823639, 0.5),
- vec3(0.0, 0.0, -1.0),
- vec3(0.866025, 0.0, -0.5),
- vec3(0.267617, 0.823639, -0.5),
- vec3(-0.700629, 0.509037, -0.5),
- vec3(-0.700629, -0.509037, -0.5),
- vec3(0.267617, -0.823639, -0.5));
-
- vec3 local_normal = normalize(camera_matrix * vec4(normal, 0.0)).xyz;
- vec4 captured = vec4(0.0);
- float sum = 0.0;
- for (int i = 0; i < 12; i++) {
- float amount = max(0.0, dot(local_normal, cone_dirs[i])); //not correct, but creates a nice wrap around effect
- captured += lightmap_captures[i] * amount;
- sum += amount;
- }
+ {
+ vec3 cone_dirs[12] = vec3[](
+ vec3(0.0, 0.0, 1.0),
+ vec3(0.866025, 0.0, 0.5),
+ vec3(0.267617, 0.823639, 0.5),
+ vec3(-0.700629, 0.509037, 0.5),
+ vec3(-0.700629, -0.509037, 0.5),
+ vec3(0.267617, -0.823639, 0.5),
+ vec3(0.0, 0.0, -1.0),
+ vec3(0.866025, 0.0, -0.5),
+ vec3(0.267617, 0.823639, -0.5),
+ vec3(-0.700629, 0.509037, -0.5),
+ vec3(-0.700629, -0.509037, -0.5),
+ vec3(0.267617, -0.823639, -0.5));
+
+ vec3 local_normal = normalize(camera_matrix * vec4(normal, 0.0)).xyz;
+ vec4 captured = vec4(0.0);
+ float sum = 0.0;
+ for (int i = 0; i < 12; i++) {
+ float amount = max(0.0, dot(local_normal, cone_dirs[i])); //not correct, but creates a nice wrap around effect
+ captured += lightmap_captures[i] * amount;
+ sum += amount;
+ }
- captured /= sum;
+ captured /= sum;
- if (lightmap_capture_sky) {
- ambient_light = mix(ambient_light, captured.rgb, captured.a);
- } else {
- ambient_light = captured.rgb;
+ if (lightmap_capture_sky) {
+ ambient_light = mix(ambient_light, captured.rgb, captured.a);
+ } else {
+ ambient_light = captured.rgb;
+ }
}
- }
#endif
-
+ }
#endif //BASE PASS
//
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 0820997529..9815936d1e 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -2011,7 +2011,7 @@ void RasterizerSceneGLES3::_set_cull(bool p_front, bool p_disabled, bool p_rever
}
}
-void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows) {
+void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RasterizerStorageGLES3::Sky *p_sky, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows) {
glBindBufferBase(GL_UNIFORM_BUFFER, 0, state.scene_ubo); //bind globals ubo
@@ -2019,14 +2019,15 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_
if (!p_shadow && !p_directional_add) {
glBindBufferBase(GL_UNIFORM_BUFFER, 2, state.env_radiance_ubo); //bind environment radiance info
- if (p_base_env) {
+ if (p_sky != NULL) {
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
if (storage->config.use_texture_array_environment) {
- glBindTexture(GL_TEXTURE_2D_ARRAY, p_base_env);
+ glBindTexture(GL_TEXTURE_2D_ARRAY, p_sky->radiance);
} else {
- glBindTexture(GL_TEXTURE_2D, p_base_env);
+ glBindTexture(GL_TEXTURE_2D, p_sky->radiance);
}
-
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6);
+ glBindTexture(GL_TEXTURE_2D, p_sky->irradiance);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP, true);
state.scene_shader.set_conditional(SceneShaderGLES3::USE_RADIANCE_MAP_ARRAY, storage->config.use_texture_array_environment);
use_radiance_map = true;
@@ -4231,7 +4232,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
_fill_render_list(p_cull_result, p_cull_count, true, false);
render_list.sort_by_key(false);
state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, true);
- _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, 0, false, false, true, false, false);
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, NULL, false, false, true, false, false);
state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, false);
glColorMask(1, 1, 1, 1);
@@ -4355,7 +4356,6 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
RasterizerStorageGLES3::Sky *sky = NULL;
Ref<CameraFeed> feed;
- GLuint env_radiance_tex = 0;
if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_OVERDRAW) {
clear_color = Color(0, 0, 0, 0);
@@ -4409,9 +4409,6 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
sky = storage->sky_owner.getornull(env->sky);
- if (sky) {
- env_radiance_tex = sky->radiance;
- }
break;
case VS::ENV_BG_CANVAS:
//copy canvas to 3d buffer and convert it to linear
@@ -4505,7 +4502,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
}
if (probe && probe->probe_ptr->interior) {
- env_radiance_tex = 0; //for rendering probe interiors, radiance must not be used.
+ sky = NULL; //for rendering probe interiors, radiance must not be used.
}
state.texscreen_copied = false;
@@ -4524,7 +4521,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
if (state.directional_light_count == 0) {
directional_light = NULL;
- _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, false, shadow_atlas != NULL);
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, sky, false, false, false, false, shadow_atlas != NULL);
} else {
for (int i = 0; i < state.directional_light_count; i++) {
directional_light = directional_lights[i];
@@ -4532,7 +4529,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
glEnable(GL_BLEND);
}
_setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != NULL && shadow_atlas->size > 0);
- _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, false, false, i > 0, shadow_atlas != NULL);
+ _render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, sky, false, false, false, i > 0, shadow_atlas != NULL);
}
}
@@ -4610,12 +4607,12 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
if (state.directional_light_count == 0) {
directional_light = NULL;
- _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, false, shadow_atlas != NULL);
+ _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, sky, false, true, false, false, shadow_atlas != NULL);
} else {
for (int i = 0; i < state.directional_light_count; i++) {
directional_light = directional_lights[i];
_setup_directional_light(i, p_cam_transform.affine_inverse(), shadow_atlas != NULL && shadow_atlas->size > 0);
- _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, env_radiance_tex, false, true, false, i > 0, shadow_atlas != NULL);
+ _render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, sky, false, true, false, i > 0, shadow_atlas != NULL);
}
}
@@ -4898,7 +4895,7 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_
if (light->reverse_cull) {
flip_facing = !flip_facing;
}
- _render_list(render_list.elements, render_list.element_count, light_transform, light_projection, 0, flip_facing, false, true, false, false);
+ _render_list(render_list.elements, render_list.element_count, light_transform, light_projection, NULL, flip_facing, false, true, false, false);
state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH, false);
state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID, false);
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index e6d2449653..a756ce251e 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -837,7 +837,7 @@ public:
_FORCE_INLINE_ void _render_geometry(RenderList::Element *e);
_FORCE_INLINE_ void _setup_light(RenderList::Element *e, const Transform &p_view_transform);
- void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, GLuint p_base_env, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);
+ void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RasterizerStorageGLES3::Sky *p_sky, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);
_FORCE_INLINE_ void _add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_depth_pass, bool p_shadow_pass);
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 625bfb4554..ae53f54947 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -1757,6 +1757,7 @@ RID RasterizerStorageGLES3::sky_create() {
Sky *sky = memnew(Sky);
sky->radiance = 0;
+ sky->irradiance = 0;
return sky_owner.make_rid(sky);
}
@@ -1768,7 +1769,9 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
if (sky->panorama.is_valid()) {
sky->panorama = RID();
glDeleteTextures(1, &sky->radiance);
+ glDeleteTextures(1, &sky->irradiance);
sky->radiance = 0;
+ sky->irradiance = 0;
}
sky->panorama = p_panorama;
@@ -1791,10 +1794,14 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //need this for proper sampling
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10);
+ // Need Mipmaps regardless of whether they are set in import by user
+ glGenerateMipmap(texture->target);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameterf(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameterf(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (config.srgb_decode_supported && texture->srgb && !texture->using_srgb) {
@@ -1808,6 +1815,66 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
#endif
}
+ {
+ //Irradiance map
+ glActiveTexture(GL_TEXTURE1);
+ glGenTextures(1, &sky->irradiance);
+ glBindTexture(GL_TEXTURE_2D, sky->irradiance);
+
+ GLuint tmp_fb;
+
+ glGenFramebuffers(1, &tmp_fb);
+ glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb);
+
+ int size = 64;
+
+ bool use_float = config.framebuffer_half_float_supported;
+
+ GLenum internal_format = use_float ? GL_RGBA16F : GL_RGB10_A2;
+ GLenum format = GL_RGBA;
+ GLenum type = use_float ? GL_HALF_FLOAT : GL_UNSIGNED_INT_2_10_10_10_REV;
+
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size * 2, 0, format, type, NULL);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sky->irradiance, 0);
+
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::COMPUTE_IRRADIANCE, true);
+ shaders.cubemap_filter.bind();
+
+ // Very large Panoramas require way too much effort to compute irradiance so use a mipmap
+ // level that corresponds to a panorama of 1024x512
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_MIP_LEVEL, MAX(Math::log(float(texture->width)) / Math::log(2.0f) - 10.0f, 0.0f));
+
+ for (int i = 0; i < 2; i++) {
+ glViewport(0, i * size, size, size);
+ glBindVertexArray(resources.quadie_array);
+
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::Z_FLIP, i > 0);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glBindVertexArray(0);
+ }
+
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, false);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, false);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::COMPUTE_IRRADIANCE, false);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
+ glDeleteFramebuffers(1, &tmp_fb);
+ }
+
+ // Now compute radiance
+
glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &sky->radiance);
@@ -1833,8 +1900,8 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internal_format, size, size * 2, array_level, 0, format, type, NULL);
- glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLuint tmp_fb2;
GLuint tmp_tex;
@@ -1846,8 +1913,8 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glBindTexture(GL_TEXTURE_2D, tmp_tex);
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size * 2, 0, format, type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_tex, 0);
- glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
#ifdef DEBUG_ENABLED
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
@@ -1858,25 +1925,25 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb2);
- if (j == 0) {
+ if (j < 3) {
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, true);
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE, true);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_DUAL_PARABOLOID_ARRAY, false);
shaders.cubemap_filter.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id);
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_RESOLUTION, float(texture->width / 4));
} else {
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, false);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_DUAL_PARABOLOID_ARRAY, true);
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE, false);
shaders.cubemap_filter.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, sky->radiance);
shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_ARRAY_INDEX, j - 1); //read from previous to ensure better blur
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_RESOLUTION, float(size / 2));
}
for (int i = 0; i < 2; i++) {
@@ -1902,7 +1969,6 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, false);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, false);
shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_DUAL_PARABOLOID_ARRAY, false);
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DIRECT_WRITE, false);
//restore ranges
glActiveTexture(GL_TEXTURE0);
@@ -1947,23 +2013,64 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmaps - 1);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ GLuint tmp_fb2;
+ GLuint tmp_tex;
+ {
+ // Need a temporary framebuffer for rendering so we can read from previous iterations
+ glGenFramebuffers(1, &tmp_fb2);
+ glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb2);
+ glGenTextures(1, &tmp_tex);
+ glBindTexture(GL_TEXTURE_2D, tmp_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size * 2, 0, format, type, NULL);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_tex, 0);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+#ifdef DEBUG_ENABLED
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE);
+#endif
+ }
lod = 0;
mm_level = mipmaps;
size = p_radiance_size;
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
- shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, true);
- shaders.cubemap_filter.bind();
-
while (mm_level) {
-
+ glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sky->radiance, lod);
+
#ifdef DEBUG_ENABLED
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
ERR_CONTINUE(status != GL_FRAMEBUFFER_COMPLETE);
#endif
+ glBindTexture(GL_TEXTURE_2D, tmp_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size, size * 2, 0, format, type, NULL);
+ glBindFramebuffer(GL_FRAMEBUFFER, tmp_fb2);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_tex, 0);
+ if (lod < 3) {
+
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_DUAL_PARABOLOID, false);
+ shaders.cubemap_filter.bind();
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(texture->target, texture->tex_id);
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_RESOLUTION, float(texture->width / 4));
+ } else {
+
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_DUAL_PARABOLOID, true);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_PANORAMA, false);
+ shaders.cubemap_filter.set_conditional(CubemapFilterShaderGLES3::USE_SOURCE_DUAL_PARABOLOID, true);
+ shaders.cubemap_filter.bind();
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, sky->radiance);
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_MIP_LEVEL, float(lod - 1)); //read from previous to ensure better blur
+ shaders.cubemap_filter.set_uniform(CubemapFilterShaderGLES3::SOURCE_RESOLUTION, float(size));
+ }
for (int i = 0; i < 2; i++) {
glViewport(0, i * size, size, size);
@@ -1976,6 +2083,14 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glBindVertexArray(0);
}
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tmp_fb);
+ glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, sky->radiance, 0, lod);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, tmp_fb2);
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ glBlitFramebuffer(0, 0, size, size * 2, 0, 0, size, size * 2, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+
if (size > 1)
size >>= 1;
lod++;
@@ -1995,6 +2110,8 @@ void RasterizerStorageGLES3::sky_set_texture(RID p_sky, RID p_panorama, int p_ra
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
glDeleteFramebuffers(1, &tmp_fb);
+ glDeleteFramebuffers(1, &tmp_fb2);
+ glDeleteTextures(1, &tmp_tex);
}
}
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index 3b1021d0e1..350b259b2b 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -388,6 +388,7 @@ public:
RID panorama;
GLuint radiance;
+ GLuint irradiance;
int radiance_size;
};
diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl
index 619e29b130..d83a109cb9 100644
--- a/drivers/gles3/shaders/cubemap_filter.glsl
+++ b/drivers/gles3/shaders/cubemap_filter.glsl
@@ -30,12 +30,22 @@ uniform sampler2DArray source_dual_paraboloid_array; //texunit:0
uniform int source_array_index;
#endif
-#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA)
+#ifdef USE_SOURCE_DUAL_PARABOLOID
+uniform sampler2D source_dual_paraboloid; //texunit:0
+#endif
+
+#if defined(USE_SOURCE_DUAL_PARABOLOID) || defined(COMPUTE_IRRADIANCE)
+uniform int source_mip_level;
+#endif
+
+#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
uniform samplerCube source_cube; //texunit:0
#endif
uniform int face_id;
uniform float roughness;
+uniform float source_resolution;
+
in highp vec2 uv_interp;
layout(location = 0) out vec4 frag_color;
@@ -133,6 +143,19 @@ vec3 ImportanceSampleGGX(vec2 Xi, float Roughness, vec3 N) {
return TangentX * H.x + TangentY * H.y + N * H.z;
}
+float DistributionGGX(vec3 N, vec3 H, float roughness) {
+ float a = roughness * roughness;
+ float a2 = a * a;
+ float NdotH = max(dot(N, H), 0.0);
+ float NdotH2 = NdotH * NdotH;
+
+ float nom = a2;
+ float denom = (NdotH2 * (a2 - 1.0) + 1.0);
+ denom = M_PI * denom * denom;
+
+ return nom / denom;
+}
+
// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
float GGX(float NdotV, float a) {
float k = a / 2.0;
@@ -160,10 +183,12 @@ vec2 Hammersley(uint i, uint N) {
#ifdef LOW_QUALITY
#define SAMPLE_COUNT 64u
+#define SAMPLE_DELTA 0.05
#else
-#define SAMPLE_COUNT 1024u
+#define SAMPLE_COUNT 512u
+#define SAMPLE_DELTA 0.01
#endif
@@ -171,7 +196,7 @@ uniform bool z_flip;
#ifdef USE_SOURCE_PANORAMA
-vec4 texturePanorama(vec3 normal, sampler2D pano) {
+vec4 texturePanorama(vec3 normal, sampler2D pano, float mipLevel) {
vec2 st = vec2(
atan(normal.x, normal.z),
@@ -182,7 +207,7 @@ vec4 texturePanorama(vec3 normal, sampler2D pano) {
st /= vec2(M_PI * 2.0, M_PI);
- return textureLod(pano, st, 0.0);
+ return textureLod(pano, st, mipLevel);
}
#endif
@@ -202,6 +227,20 @@ vec4 textureDualParaboloidArray(vec3 normal) {
#endif
+#ifdef USE_SOURCE_DUAL_PARABOLOID
+vec4 textureDualParaboloid(vec3 normal) {
+
+ vec3 norm = normalize(normal);
+ norm.xy /= 1.0 + abs(norm.z);
+ norm.xy = norm.xy * vec2(0.5, 0.25) + vec2(0.5, 0.25);
+ if (norm.z < 0.0) {
+ norm.y = 0.5 - norm.y + 0.5;
+ }
+ return textureLod(source_dual_paraboloid, norm.xy, float(source_mip_level));
+}
+
+#endif
+
void main() {
#ifdef USE_DUAL_PARABOLOID
@@ -225,7 +264,7 @@ void main() {
#ifdef USE_SOURCE_PANORAMA
- frag_color = vec4(texturePanorama(N, source_panorama).rgb, 1.0);
+ frag_color = vec4(texturePanorama(N, source_panorama, 0.0).rgb, 1.0);
#endif
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
@@ -233,12 +272,51 @@ void main() {
frag_color = vec4(textureDualParaboloidArray(N).rgb, 1.0);
#endif
-#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA)
+#ifdef USE_SOURCE_DUAL_PARABOLOID
+
+ frag_color = vec4(textureDualParaboloid(N).rgb, 1.0);
+#endif
+
+#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
N.y = -N.y;
frag_color = vec4(texture(N, source_cube).rgb, 1.0);
#endif
+#else // USE_DIRECT_WRITE
+
+#ifdef COMPUTE_IRRADIANCE
+
+ vec3 irradiance = vec3(0.0);
+
+ // tangent space calculation from origin point
+ vec3 UpVector = vec3(0.0, 1.0, 0.0);
+ vec3 TangentX = cross(UpVector, N);
+ vec3 TangentY = cross(N, TangentX);
+
+ float num_samples = 0.0f;
+
+ for (float phi = 0.0; phi < 2.0 * M_PI; phi += SAMPLE_DELTA) {
+ for (float theta = 0.0; theta < 0.5 * M_PI; theta += SAMPLE_DELTA) {
+ // Calculate sample positions
+ vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
+ // Find world vector of sample position
+ vec3 H = tangentSample.x * TangentX + tangentSample.y * TangentY + tangentSample.z * N;
+
+ vec2 st = vec2(atan(H.x, H.z), acos(H.y));
+ if (st.x < 0.0) {
+ st.x += M_PI * 2.0;
+ }
+ st /= vec2(M_PI * 2.0, M_PI);
+
+ irradiance += texture(source_panorama, st, source_mip_level).rgb * cos(theta) * sin(theta);
+ num_samples++;
+ }
+ }
+ irradiance = M_PI * irradiance * (1.0 / float(num_samples));
+
+ frag_color = vec4(irradiance, 1.0);
+
#else
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
@@ -246,15 +324,26 @@ void main() {
for (uint sampleNum = 0u; sampleNum < SAMPLE_COUNT; sampleNum++) {
vec2 xi = Hammersley(sampleNum, SAMPLE_COUNT);
- vec3 H = ImportanceSampleGGX(xi, roughness, N);
+ vec3 H = normalize(ImportanceSampleGGX(xi, roughness, N));
vec3 V = N;
- vec3 L = (2.0 * dot(V, H) * H - V);
+ vec3 L = normalize(2.0 * dot(V, H) * H - V);
- float ndotl = clamp(dot(N, L), 0.0, 1.0);
+ float ndotl = max(dot(N, L), 0.0);
if (ndotl > 0.0) {
+
+ float D = DistributionGGX(N, H, roughness);
+ float ndoth = max(dot(N, H), 0.0);
+ float hdotv = max(dot(H, V), 0.0);
+ float pdf = D * ndoth / (4.0 * hdotv) + 0.0001;
+
+ float saTexel = 4.0 * M_PI / (6.0 * source_resolution * source_resolution);
+ float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);
+
+ float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel);
+
#ifdef USE_SOURCE_PANORAMA
- sum.rgb += texturePanorama(L, source_panorama).rgb * ndotl;
+ sum.rgb += texturePanorama(L, source_panorama, mipLevel).rgb * ndotl;
#endif
#ifdef USE_SOURCE_DUAL_PARABOLOID_ARRAY
@@ -262,7 +351,12 @@ void main() {
sum.rgb += textureDualParaboloidArray(L).rgb * ndotl;
#endif
-#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA)
+#ifdef USE_SOURCE_DUAL_PARABOLOID
+
+ sum.rgb += textureDualParaboloid(L).rgb * ndotl;
+#endif
+
+#if !defined(USE_SOURCE_DUAL_PARABOLOID_ARRAY) && !defined(USE_SOURCE_PANORAMA) && !defined(USE_SOURCE_DUAL_PARABOLOID)
L.y = -L.y;
sum.rgb += textureLod(source_cube, L, 0.0).rgb * ndotl;
#endif
@@ -273,5 +367,6 @@ void main() {
frag_color = vec4(sum.rgb, 1.0);
-#endif
+#endif // COMPUTE_IRRADIANCE
+#endif // USE_DIRECT_WRITE
}
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 403de25dd0..e1b0e9f595 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -627,6 +627,8 @@ layout(std140) uniform Radiance { // ubo:2
#define RADIANCE_MAX_LOD 5.0
+uniform sampler2D irradiance_map; // texunit:-6
+
#ifdef USE_RADIANCE_MAP_ARRAY
uniform sampler2DArray radiance_map; // texunit:-2
@@ -1766,6 +1768,11 @@ FRAGMENT_SHADER_CODE
vec3 eye_vec = view;
+ // IBL precalculations
+ float ndotv = clamp(dot(normal, eye_vec), 0.0, 1.0);
+ vec3 f0 = F0(metallic, specular, albedo);
+ vec3 F = f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow(1.0 - ndotv, 5.0);
+
#ifdef USE_RADIANCE_MAP
#ifdef AMBIENT_LIGHT_DISABLED
@@ -1775,22 +1782,27 @@ FRAGMENT_SHADER_CODE
{ //read radiance from dual paraboloid
- vec3 ref_vec = reflect(-eye_vec, normal); //2.0 * ndotv * normal - view; // reflect(v, n);
+ vec3 ref_vec = reflect(-eye_vec, normal);
ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
vec3 radiance = textureDualParaboloid(radiance_map, ref_vec, roughness) * bg_energy;
env_reflection_light = radiance;
}
- //no longer a cubemap
- //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y);
}
#ifndef USE_LIGHTMAP
{
- vec3 ambient_dir = normalize((radiance_inverse_xform * vec4(normal, 0.0)).xyz);
- vec3 env_ambient = textureDualParaboloid(radiance_map, ambient_dir, 1.0) * bg_energy;
+ vec3 norm = normal;
+ norm = normalize((radiance_inverse_xform * vec4(norm, 0.0)).xyz);
+ norm.xy /= 1.0 + abs(norm.z);
+ norm.xy = norm.xy * vec2(0.5, 0.25) + vec2(0.5, 0.25);
+ if (norm.z > 0.0) {
+ norm.y = 0.5 - norm.y + 0.5;
+ }
+
+ vec3 env_ambient = texture(irradiance_map, norm.xy).rgb * bg_energy;
+ env_ambient *= 1.0 - F;
ambient_light = mix(ambient_light_color.rgb, env_ambient, radiance_ambient_contribution);
- //ambient_light=vec3(0.0,0.0,0.0);
}
#endif
#endif //AMBIENT_LIGHT_DISABLED
@@ -1892,12 +1904,9 @@ FRAGMENT_SHADER_CODE
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);
vec4 r = roughness * c0 + c1;
- float ndotv = clamp(dot(normal, eye_vec), 0.0, 1.0);
float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
-
- vec3 f0 = F0(metallic, specular, albedo);
- specular_light *= env.x * f0 + env.y;
+ specular_light *= env.x * F + env.y;
#endif
}
diff --git a/editor/doc/doc_data.h b/editor/doc/doc_data.h
index 6d601f0dce..b722c324d6 100644
--- a/editor/doc/doc_data.h
+++ b/editor/doc/doc_data.h
@@ -78,6 +78,9 @@ public:
bool operator<(const PropertyDoc &p_prop) const {
return name < p_prop.name;
}
+ PropertyDoc() {
+ overridden = false;
+ }
};
struct ClassDoc {
diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp
index abff8190af..1993f24b24 100644
--- a/editor/editor_sectioned_inspector.cpp
+++ b/editor/editor_sectioned_inspector.cpp
@@ -177,7 +177,7 @@ String SectionedInspector::get_full_item_path(const String &p_item) {
void SectionedInspector::edit(Object *p_object) {
if (!p_object) {
- obj = -1;
+ obj = 0;
sections->clear();
filter->set_edited(NULL);
@@ -308,7 +308,7 @@ EditorInspector *SectionedInspector::get_inspector() {
}
SectionedInspector::SectionedInspector() :
- obj(-1),
+ obj(0),
sections(memnew(Tree)),
filter(memnew(SectionedInspectorFilter)),
inspector(memnew(EditorInspector)),
diff --git a/editor/editor_vcs_interface.cpp b/editor/editor_vcs_interface.cpp
index 4df2a06736..766f9c3913 100644
--- a/editor/editor_vcs_interface.cpp
+++ b/editor/editor_vcs_interface.cpp
@@ -36,7 +36,7 @@ void EditorVCSInterface::_bind_methods() {
// Proxy end points that act as fallbacks to unavailability of a function in the VCS addon
ClassDB::bind_method(D_METHOD("_initialize", "project_root_path"), &EditorVCSInterface::_initialize);
- ClassDB::bind_method(D_METHOD("_get_is_vcs_intialized"), &EditorVCSInterface::_get_is_vcs_intialized);
+ ClassDB::bind_method(D_METHOD("_is_vcs_initialized"), &EditorVCSInterface::_is_vcs_initialized);
ClassDB::bind_method(D_METHOD("_get_vcs_name"), &EditorVCSInterface::_get_vcs_name);
ClassDB::bind_method(D_METHOD("_shut_down"), &EditorVCSInterface::_shut_down);
ClassDB::bind_method(D_METHOD("_get_project_name"), &EditorVCSInterface::_get_project_name);
@@ -50,7 +50,7 @@ void EditorVCSInterface::_bind_methods() {
// API methods that redirect calls to the proxy end points
ClassDB::bind_method(D_METHOD("initialize", "project_root_path"), &EditorVCSInterface::initialize);
- ClassDB::bind_method(D_METHOD("get_is_vcs_intialized"), &EditorVCSInterface::get_is_vcs_intialized);
+ ClassDB::bind_method(D_METHOD("is_vcs_initialized"), &EditorVCSInterface::is_vcs_initialized);
ClassDB::bind_method(D_METHOD("get_modified_files_data"), &EditorVCSInterface::get_modified_files_data);
ClassDB::bind_method(D_METHOD("stage_file", "file_path"), &EditorVCSInterface::stage_file);
ClassDB::bind_method(D_METHOD("unstage_file", "file_path"), &EditorVCSInterface::unstage_file);
@@ -67,7 +67,7 @@ bool EditorVCSInterface::_initialize(String p_project_root_path) {
return true;
}
-bool EditorVCSInterface::_get_is_vcs_intialized() {
+bool EditorVCSInterface::_is_vcs_initialized() {
return false;
}
@@ -112,9 +112,9 @@ bool EditorVCSInterface::initialize(String p_project_root_path) {
return is_initialized;
}
-bool EditorVCSInterface::get_is_vcs_intialized() {
+bool EditorVCSInterface::is_vcs_initialized() {
- return call("_get_is_vcs_intialized");
+ return call("_is_vcs_initialized");
}
Dictionary EditorVCSInterface::get_modified_files_data() {
diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h
index 896193ed92..394a18f974 100644
--- a/editor/editor_vcs_interface.h
+++ b/editor/editor_vcs_interface.h
@@ -48,7 +48,7 @@ protected:
// Implemented by addons as end points for the proxy functions
bool _initialize(String p_project_root_path);
- bool _get_is_vcs_intialized();
+ bool _is_vcs_initialized();
Dictionary _get_modified_files_data();
void _stage_file(String p_file_path);
void _unstage_file(String p_file_path);
@@ -66,7 +66,7 @@ public:
// Proxy functions to the editor for use
bool initialize(String p_project_root_path);
- bool get_is_vcs_intialized();
+ bool is_vcs_initialized();
Dictionary get_modified_files_data();
void stage_file(String p_file_path);
void unstage_file(String p_file_path);
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index fcf0e4af6f..30e2aae020 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -229,6 +229,7 @@ Error EditorSceneImporterGLTF::_parse_scenes(GLTFState &state) {
ERR_FAIL_COND_V(!state.json.has("scenes"), ERR_FILE_CORRUPT);
const Array &scenes = state.json["scenes"];
+ ERR_FAIL_COND_V(!scenes.size(), ERR_FILE_CORRUPT);
for (int i = 0; i < 1; i++) { //only first scene is imported
const Dictionary &s = scenes[i];
ERR_FAIL_COND_V(!s.has("nodes"), ERR_UNAVAILABLE);
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index fcbd68a60f..20b4cf43bf 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -794,6 +794,7 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
editor_selection->add_node(item);
// Reselect
if (Engine::get_singleton()->is_editor_hint()) {
+ selected_from_canvas = true;
editor->call("edit_node", item);
}
}
@@ -3911,6 +3912,11 @@ void CanvasItemEditor::_selection_changed() {
}
anchors_mode = (nbValidControls == nbAnchorsMode);
anchor_mode_button->set_pressed(anchors_mode);
+
+ if (!selected_from_canvas) {
+ drag_type = DRAG_NONE;
+ }
+ selected_from_canvas = false;
}
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
@@ -5253,6 +5259,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
snap_target[0] = SNAP_TARGET_NONE;
snap_target[1] = SNAP_TARGET_NONE;
+ selected_from_canvas = false;
anchors_mode = false;
skeleton_show_bones = true;
@@ -5262,6 +5269,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
drag_to = Vector2();
dragged_guide_pos = Point2();
dragged_guide_index = -1;
+ is_hovering_h_guide = false;
+ is_hovering_v_guide = false;
panning = false;
pan_pressed = false;
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 3ba66c00f9..74adb882d1 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -252,6 +252,7 @@ private:
Point2 view_offset;
Point2 previous_update_view_offset;
+ bool selected_from_canvas;
bool anchors_mode;
Point2 grid_offset;
diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp
index 783797ada4..aa3bd74c49 100644
--- a/editor/plugins/version_control_editor_plugin.cpp
+++ b/editor/plugins/version_control_editor_plugin.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "version_control_editor_plugin.h"
+
#include "core/script_language.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
@@ -398,9 +399,9 @@ void VersionControlEditorPlugin::shut_down() {
}
}
-bool VersionControlEditorPlugin::get_is_vcs_intialized() const {
+bool VersionControlEditorPlugin::is_vcs_initialized() const {
- return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_is_vcs_intialized() : false;
+ return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->is_vcs_initialized() : false;
}
const String VersionControlEditorPlugin::get_vcs_name() const {
diff --git a/editor/plugins/version_control_editor_plugin.h b/editor/plugins/version_control_editor_plugin.h
index 450ebccce1..f9f8437e15 100644
--- a/editor/plugins/version_control_editor_plugin.h
+++ b/editor/plugins/version_control_editor_plugin.h
@@ -129,7 +129,7 @@ public:
PanelContainer *get_version_control_dock() const { return version_control_dock; }
List<StringName> get_available_vcs_names() const { return available_addons; }
- bool get_is_vcs_intialized() const;
+ bool is_vcs_initialized() const;
const String get_vcs_name() const;
void register_editor();
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 6522cf4d02..08bf52ab57 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -852,6 +852,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
hb->add_child(path_button);
gc->add_child(memnew(Label(TTR("Path:"))));
gc->add_child(hb);
+ re_check_path = false;
/* Dialog Setup */
diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp
index a7f338051a..8e7aac896a 100644
--- a/editor/script_editor_debugger.cpp
+++ b/editor/script_editor_debugger.cpp
@@ -2601,6 +2601,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
live_debug = true;
+ camera_override = OVERRIDE_NONE;
last_path_id = false;
error_count = 0;
warning_count = 0;
diff --git a/modules/arkit/arkit_interface.mm b/modules/arkit/arkit_interface.mm
index 9614f775a5..71642cfc30 100644
--- a/modules/arkit/arkit_interface.mm
+++ b/modules/arkit/arkit_interface.mm
@@ -37,6 +37,8 @@
#import <ARKit/ARKit.h>
#import <UIKit/UIKit.h>
+#include <dlfcn.h>
+
#include "arkit_interface.h"
#include "arkit_session_delegate.h"
@@ -53,7 +55,10 @@ void ARKitInterface::start_session() {
// Ignore this if we're not initialized...
if (initialized) {
print_line("Starting ARKit session");
- ARWorldTrackingConfiguration *configuration = [ARWorldTrackingConfiguration new];
+
+ Class ARWorldTrackingConfigurationClass = NSClassFromString(@"ARWorldTrackingConfiguration");
+ ARWorldTrackingConfiguration *configuration = [ARWorldTrackingConfigurationClass new];
+
configuration.lightEstimationEnabled = light_estimation_is_enabled;
if (plane_detection_is_enabled) {
configuration.planeDetection = ARPlaneDetectionVertical | ARPlaneDetectionHorizontal;
@@ -221,7 +226,17 @@ bool ARKitInterface::initialize() {
print_line("initializing ARKit");
// create our ar session and delegate
- ar_session = [ARSession new];
+ Class ARSessionClass = NSClassFromString(@"ARSession");
+ if (ARSessionClass == Nil) {
+ void *arkit_handle = dlopen("/System/Library/Frameworks/ARKit.framework/ARKit", RTLD_NOW);
+ if (arkit_handle) {
+ ARSessionClass = NSClassFromString(@"ARSession");
+ } else {
+ print_line("ARKit init failed");
+ return false;
+ }
+ }
+ ar_session = [ARSessionClass new];
ar_delegate = [ARKitSessionDelegate new];
ar_delegate.arkit_interface = this;
ar_session.delegate = ar_delegate;
diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h
index 7b14804ddc..8135b352c6 100644
--- a/modules/assimp/import_utils.h
+++ b/modules/assimp/import_utils.h
@@ -394,7 +394,9 @@ public:
return Ref<Image>();
} else {
Ref<Texture> texture = ResourceLoader::load(p_path);
+ ERR_FAIL_COND_V(texture.is_null(), Ref<Image>());
Ref<Image> image = texture->get_data();
+ ERR_FAIL_COND_V(image.is_null(), Ref<Image>());
state.path_to_image_cache.insert(p_path, image);
return image;
}
diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py
index e83c3f19a6..5388061f84 100644
--- a/modules/mono/build_scripts/mono_configure.py
+++ b/modules/mono/build_scripts/mono_configure.py
@@ -432,6 +432,11 @@ def copy_mono_shared_libs(env, mono_root, target_mono_root_dir):
os.makedirs(target_mono_bin_dir)
copy(os.path.join(mono_root, 'bin', 'MonoPosixHelper.dll'), target_mono_bin_dir)
+
+ # For newer versions
+ btls_dll_path = os.path.join(mono_root, 'bin', 'libmono-btls-shared.dll')
+ if os.path.isfile(btls_dll_path):
+ copy(btls_dll_path, target_mono_bin_dir)
else:
target_mono_lib_dir = get_android_out_dir(env) if platform == 'android' else os.path.join(target_mono_root_dir, 'lib')
diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
index f65d2a39f4..cf3823fd16 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
@@ -164,12 +164,12 @@ namespace GodotTools.Export
Directory.Delete(aotTempDir, recursive: true);
// TODO: Just a workaround until the export plugins can be made to abort with errors
- if (string.IsNullOrEmpty(maybeLastExportError)) // Check empty as well, because it's set to empty after hot-reloading
+ if (!string.IsNullOrEmpty(maybeLastExportError)) // Check empty as well, because it's set to empty after hot-reloading
{
string lastExportError = maybeLastExportError;
maybeLastExportError = null;
- GodotSharpEditor.Instance.ShowErrorDialog(lastExportError, "C# export failed");
+ GodotSharpEditor.Instance.ShowErrorDialog(lastExportError, "Failed to export C# project");
}
}
diff --git a/modules/regex/SCsub b/modules/regex/SCsub
index 1be5af02a5..6238cd3d9f 100644
--- a/modules/regex/SCsub
+++ b/modules/regex/SCsub
@@ -6,12 +6,10 @@ Import('env_modules')
env_regex = env_modules.Clone()
if env['builtin_pcre2']:
- jit_blacklist = ['javascript', 'uwp']
-
thirdparty_dir = '#thirdparty/pcre2/src/'
thirdparty_flags = ['PCRE2_STATIC', 'HAVE_CONFIG_H']
- if 'platform' in env and env['platform'] not in jit_blacklist:
+ if env['builtin_pcre2_with_jit']:
thirdparty_flags.append('SUPPORT_JIT')
thirdparty_sources = [
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index a63fa90067..c05b765c5e 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -24,6 +24,7 @@ def get_opts():
def get_flags():
return [
('tools', False),
+ ('builtin_pcre2_with_jit', False),
# Disabling the mbedtls module reduces file size.
# The module has little use due to the limited networking functionality
# in this platform. For the available networking methods, the browser
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 09a871f26c..a61b9234d1 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -113,9 +113,6 @@ public:
NSOpenGLContext *context;
bool layered_window;
- bool waiting_for_vsync;
- NSCondition *vsync_condition;
- CVDisplayLinkRef displayLink;
CursorShape cursor_shape;
NSCursor *cursors[CURSOR_MAX];
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index ba3ac9862e..e5166d102b 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -115,21 +115,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
return Vector2(mouse_x, mouse_y);
}
-// DisplayLinkCallback is called from our DisplayLink OS thread informing us right before
-// a screen update is required. We can use it to work around the broken vsync.
-static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) {
- OS_OSX *os = (OS_OSX *)displayLinkContext;
-
- // Set flag so we know we can output our next frame and signal our conditional lock
- // if we're not doing vsync this will be ignored
- [os->vsync_condition lock];
- os->waiting_for_vsync = false;
- [os->vsync_condition signal];
- [os->vsync_condition unlock];
-
- return kCVReturnSuccess;
-}
-
@interface GodotApplication : NSApplication
@end
@@ -1581,15 +1566,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
[context makeCurrentContext];
- // setup our display link, this will inform us when a refresh is needed
- CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
- CVDisplayLinkSetOutputCallback(displayLink, &DisplayLinkCallback, this);
- CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, context.CGLContextObj, pixelFormat.CGLPixelFormatObj);
- CVDisplayLinkStart(displayLink);
-
- // initialise a conditional lock object
- vsync_condition = [[NSCondition alloc] init];
-
set_use_vsync(p_desired.use_vsync);
[NSApp activateIgnoringOtherApps:YES];
@@ -1682,11 +1658,6 @@ void OS_OSX::finalize() {
midi_driver.close();
#endif
- if (displayLink) {
- CVDisplayLinkRelease(displayLink);
- }
- [vsync_condition release];
-
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL);
@@ -2258,18 +2229,6 @@ String OS_OSX::get_locale() const {
}
void OS_OSX::swap_buffers() {
- if (is_vsync_enabled()) {
- // Wait until our DisplayLink callback unsets our flag...
- [vsync_condition lock];
- while (waiting_for_vsync)
- [vsync_condition wait];
-
- // Make sure we wait again next frame around
- waiting_for_vsync = true;
-
- [vsync_condition unlock];
- }
-
[context flushBuffer];
}
@@ -3009,20 +2968,11 @@ Error OS_OSX::move_to_trash(const String &p_path) {
}
void OS_OSX::_set_use_vsync(bool p_enable) {
- // CGLCPSwapInterval broke in OSX 10.14 and it seems Apple is not interested in fixing
- // it as OpenGL is now deprecated and Metal solves this differently.
- // Following SDLs example we're working around this using DisplayLink
- // When vsync is enabled we set a flag "waiting_for_vsync" to true.
- // This flag is set to false when DisplayLink informs us our display is about to refresh.
-
- /* CGLContextObj ctx = CGLGetCurrentContext();
+ CGLContextObj ctx = CGLGetCurrentContext();
if (ctx) {
GLint swapInterval = p_enable ? 1 : 0;
CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
- }*/
-
- ///TODO Maybe pause/unpause display link?
- waiting_for_vsync = p_enable;
+ }
}
OS_OSX *OS_OSX::singleton = NULL;
diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py
index 7da93eafae..000bd18e7d 100644
--- a/platform/uwp/detect.py
+++ b/platform/uwp/detect.py
@@ -34,6 +34,7 @@ def get_flags():
return [
('tools', False),
('xaudio2', True),
+ ('builtin_pcre2_with_jit', False),
]
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 228b67990c..9f79691405 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -46,8 +46,6 @@ void CollisionObject2D::_notification(int p_what) {
else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
- last_transform = global_transform;
-
RID space = get_world_2d()->get_space();
if (area) {
Physics2DServer::get_singleton()->area_set_space(rid, space);
@@ -73,19 +71,17 @@ void CollisionObject2D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- Transform2D global_transform = get_global_transform();
-
- if (only_update_transform_changes && global_transform == last_transform) {
+ if (only_update_transform_changes) {
return;
}
+ Transform2D global_transform = get_global_transform();
+
if (area)
Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
- last_transform = global_transform;
-
} break;
case NOTIFICATION_EXIT_TREE: {
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index 4e7d01c8e6..0a9d33b8a6 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -67,7 +67,6 @@ class CollisionObject2D : public Node2D {
int total_subshapes;
Map<uint32_t, ShapeData> shapes;
- Transform2D last_transform;
bool only_update_transform_changes; //this is used for sync physics in KinematicBody
protected:
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 173214dfe4..d75d8cfc55 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1233,8 +1233,8 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
}
#endif
- int16_t x = decode_uint16(&local[0]);
- int16_t y = decode_uint16(&local[2]);
+ uint16_t x = decode_uint16(&local[0]);
+ uint16_t y = decode_uint16(&local[2]);
uint32_t v = decode_uint32(&local[4]);
bool flip_h = v & (1 << 29);
bool flip_v = v & (1 << 30);
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index ccc87b924c..ce7bb25665 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -386,11 +386,7 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
}
for (int i = 0; i < p_at_node->get_child_count(); i++) {
-
Node *child = p_at_node->get_child(i);
- if (!child->get_owner())
- continue; //maybe a helper
-
_find_meshes(child, plot_meshes);
}
}
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index a7d936fcd3..ce3f2b3b1a 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -63,6 +63,8 @@ void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const
count = 2;
else if (p_arg1.get_type() != Variant::NIL)
count = 1;
+ else
+ count = 0;
// Add the specified arguments to the command
// TODO: Make this a switch statement?
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 09ef6f26bf..5958106419 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -277,12 +277,13 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (points[i].offset == newofs && i != grabbed) {
valid = false;
+ break;
}
}
- if (!valid)
+ if (!valid || grabbed == -1) {
return;
-
+ }
points.write[grabbed].offset = newofs;
points.sort();
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 9c016b5a50..362697b4ad 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -173,6 +173,8 @@ void Range::set_as_ratio(double p_value) {
}
double Range::get_as_ratio() const {
+ ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, "Cannot get ratio when minimum and maximum value are equal.");
+
if (shared->exp_ratio && get_min() >= 0) {
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 361830173b..d5227f6e65 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -159,7 +159,7 @@ protected:
//bind helpers
Dictionary _get_range_config(int p_column) {
Dictionary d;
- double min, max, step;
+ double min = 0.0, max = 0.0, step = 0.0;
get_range_config(p_column, min, max, step);
d["min"] = min;
d["max"] = max;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 563fcb9961..3ad44a4a2e 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -3187,7 +3187,7 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally");
ADD_GROUP("Rendering", "");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,External 2x,External 4x"), "set_msaa", "get_msaa");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_3d_linear"), "set_keep_3d_linear", "get_keep_3d_linear");
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index 5b61654c5d..286f9e37cd 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -95,8 +95,8 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
// this function will be compiled branchless by any decent compiler
int32_t final, final_r, next, next_r;
- while (amount--) {
-
+ while (amount) {
+ amount--;
int64_t pos = offset >> MIX_FRAC_BITS;
if (is_stereo && !is_ima_adpcm)
pos <<= 1;
@@ -444,6 +444,7 @@ int AudioStreamSample::get_loop_end() const {
void AudioStreamSample::set_mix_rate(int p_hz) {
+ ERR_FAIL_COND(p_hz == 0);
mix_rate = p_hz;
}
int AudioStreamSample::get_mix_rate() const {