summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md127
-rw-r--r--core/color.h34
-rw-r--r--core/image.cpp50
-rw-r--r--core/image.h8
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/image_loader.h4
-rw-r--r--core/method_ptrcall.h1
-rw-r--r--core/os/file_access.cpp21
-rw-r--r--core/os/file_access.h1
-rw-r--r--core/os/os.h2
-rw-r--r--core/ustring.cpp12
-rw-r--r--core/variant_parser.cpp159
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp11
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h4
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp35
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp5
-rw-r--r--drivers/gles3/shader_gles3.cpp16
-rw-r--r--drivers/gles3/shaders/canvas.glsl18
-rw-r--r--drivers/gles3/shaders/copy.glsl9
-rw-r--r--drivers/gles3/shaders/particles.glsl4
-rw-r--r--drivers/gles3/shaders/resolve.glsl2
-rw-r--r--drivers/gles3/shaders/scene.glsl184
-rw-r--r--drivers/gles3/shaders/ssao_blur.glsl2
-rw-r--r--drivers/png/image_loader_png.cpp3
-rw-r--r--drivers/png/image_loader_png.h2
-rw-r--r--editor/editor_help.cpp12
-rw-r--r--editor/editor_help.h2
-rw-r--r--editor/editor_node.cpp32
-rw-r--r--editor/editor_node.h1
-rw-r--r--editor/import/editor_import_collada.cpp11
-rw-r--r--editor/import/resource_importer_texture.cpp6
-rw-r--r--editor/plugins/color_ramp_editor_plugin.cpp4
-rw-r--r--editor/plugins/color_ramp_editor_plugin.h2
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp151
-rw-r--r--editor/plugins/spatial_editor_plugin.h20
-rw-r--r--editor/project_manager.cpp15
-rw-r--r--main/tests/test_math.cpp53
-rw-r--r--misc/dist/osx_template.app/Contents/Resources/icon.icnsbin120942 -> 67500 bytes
-rw-r--r--misc/dist/osx_tools.app/Contents/Resources/Godot.icnsbin120942 -> 67500 bytes
-rw-r--r--misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.pngbin7001 -> 5645 bytes
-rw-r--r--misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.pngbin14490 -> 16169 bytes
-rw-r--r--misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.pngbin2067 -> 1619 bytes
-rw-r--r--misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.pngbin3369 -> 2483 bytes
-rw-r--r--misc/dist/uwp_template/Assets/StoreLogo.scale-100.pngbin2339 -> 1792 bytes
-rw-r--r--misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.pngbin7390 -> 6772 bytes
-rw-r--r--modules/dds/texture_loader_dds.cpp2
-rw-r--r--modules/gdnative/godot/godot_array.cpp6
-rw-r--r--modules/gdnative/godot/godot_array.h1
-rw-r--r--modules/gdnative/godot/godot_dictionary.cpp6
-rw-r--r--modules/gdnative/godot/godot_dictionary.h1
-rw-r--r--modules/gdnative/godot/godot_pool_arrays.cpp58
-rw-r--r--modules/gdnative/godot/godot_pool_arrays.h7
-rw-r--r--modules/hdr/SCsub9
-rw-r--r--modules/hdr/config.py7
-rw-r--r--modules/hdr/image_loader_hdr.cpp161
-rw-r--r--modules/hdr/image_loader_hdr.h46
-rw-r--r--modules/hdr/register_types.cpp45
-rw-r--r--modules/hdr/register_types.h31
-rw-r--r--modules/jpg/image_loader_jpegd.cpp2
-rw-r--r--modules/jpg/image_loader_jpegd.h2
-rw-r--r--modules/squish/image_compress_squish.cpp23
-rw-r--r--modules/squish/image_compress_squish.h2
-rw-r--r--modules/tinyexr/image_loader_tinyexr.cpp16
-rw-r--r--modules/tinyexr/image_loader_tinyexr.h2
-rw-r--r--modules/webp/image_loader_webp.cpp2
-rw-r--r--modules/webp/image_loader_webp.h2
-rw-r--r--platform/windows/godot.icobin370070 -> 370070 bytes
-rw-r--r--platform/x11/os_x11.cpp4
-rw-r--r--scene/2d/line_2d.cpp4
-rw-r--r--scene/2d/line_2d.h6
-rw-r--r--scene/2d/line_builder.h2
-rw-r--r--scene/2d/particles_2d.cpp6
-rw-r--r--scene/2d/particles_2d.h6
-rw-r--r--scene/3d/gi_probe.cpp14
-rw-r--r--scene/animation/animation_player.cpp1
-rw-r--r--scene/gui/color_ramp_edit.cpp18
-rw-r--r--scene/gui/color_ramp_edit.h6
-rw-r--r--scene/gui/control.cpp2
-rw-r--r--scene/main/scene_main_loop.cpp60
-rw-r--r--scene/register_scene_types.cpp3
-rw-r--r--scene/resources/color_ramp.cpp56
-rw-r--r--scene/resources/color_ramp.h10
-rw-r--r--scene/resources/environment.cpp76
-rw-r--r--scene/resources/material.cpp105
-rw-r--r--scene/resources/material.h31
-rw-r--r--scene/resources/sky_box.cpp391
-rw-r--r--scene/resources/sky_box.h112
-rw-r--r--scene/resources/texture.cpp4
-rw-r--r--scene/resources/world.cpp17
-rw-r--r--scene/resources/world.h5
-rw-r--r--servers/visual/rasterizer.cpp4
-rw-r--r--servers/visual/rasterizer.h6
-rw-r--r--servers/visual/shader_types.cpp10
-rw-r--r--signal_renames.txt21
-rw-r--r--thirdparty/README.md2
-rw-r--r--thirdparty/opus/celt/arch.h13
-rw-r--r--thirdparty/opus/celt/arm/arm_celt_map.c24
-rw-r--r--thirdparty/opus/celt/arm/armcpu.c49
-rw-r--r--thirdparty/opus/celt/arm/armcpu.h6
-rw-r--r--thirdparty/opus/celt/arm/celt_neon_intr.c61
-rw-r--r--thirdparty/opus/celt/arm/pitch_arm.h68
-rw-r--r--thirdparty/opus/celt/bands.c4
-rw-r--r--thirdparty/opus/celt/celt.h2
-rw-r--r--thirdparty/opus/celt/celt_decoder.c10
-rw-r--r--thirdparty/opus/celt/celt_encoder.c13
-rw-r--r--thirdparty/opus/celt/celt_lpc.c3
-rw-r--r--thirdparty/opus/celt/cwrs.c2
-rw-r--r--thirdparty/opus/celt/fixed_generic.h16
-rw-r--r--thirdparty/opus/celt/kiss_fft.c2
-rw-r--r--thirdparty/opus/celt/mathops.c2
-rw-r--r--thirdparty/opus/celt/pitch.c67
-rw-r--r--thirdparty/opus/celt/pitch.h20
-rw-r--r--thirdparty/opus/celt/rate.c2
-rw-r--r--thirdparty/opus/celt/vq.c2
-rw-r--r--thirdparty/opus/celt/x86/pitch_sse.h34
-rw-r--r--thirdparty/opus/celt/x86/x86_celt_map.c2
-rw-r--r--thirdparty/opus/celt/x86/x86cpu.c2
-rw-r--r--thirdparty/opus/opus_multistream_encoder.c2
-rw-r--r--thirdparty/opus/silk/CNG.c61
-rw-r--r--thirdparty/opus/silk/NLSF_del_dec_quant.c14
-rw-r--r--thirdparty/opus/silk/NLSF_encode.c5
-rw-r--r--thirdparty/opus/silk/NSQ.c58
-rw-r--r--thirdparty/opus/silk/NSQ_del_dec.c40
-rw-r--r--thirdparty/opus/silk/PLC.c3
-rw-r--r--thirdparty/opus/silk/decode_core.c2
-rw-r--r--thirdparty/opus/silk/fixed/burg_modified_FIX.c21
-rw-r--r--thirdparty/opus/silk/fixed/x86/burg_modified_FIX_sse.c14
-rw-r--r--thirdparty/opus/silk/macros.h22
-rw-r--r--thirdparty/opus/silk/mips/NSQ_del_dec_mipsr1.h6
-rw-r--r--thirdparty/opus/silk/process_NLSFs.c6
-rw-r--r--thirdparty/opus/silk/sort.c2
-rw-r--r--thirdparty/opus/silk/stereo_LR_to_MS.c8
-rw-r--r--thirdparty/opus/silk/x86/NSQ_sse.c2
-rw-r--r--thirdparty/opus/silk/x86/main_sse.h3
134 files changed, 2195 insertions, 918 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 23ab874a2e..a9ada58e64 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -4,69 +4,110 @@ Sections covered in this file:
* [Reporting bugs or proposing features](#reporting-bugs-or-proposing-features)
* [Contributing pull requests](#contributing-pull-requests)
+* [Contributing to Godot's translation](#contributing-to-godots-translation)
* [Communicating with developers](#communicating-with-developers)
**Please read the first section before reporting a bug!**
## Reporting bugs or proposing features
-The golden rule is to **always open *one* issue for *one* bug**. If you notice several bugs and want to report them, make sure to create one new issue for each of them.
+The golden rule is to **always open *one* issue for *one* bug**. If you notice
+several bugs and want to report them, make sure to create one new issue for
+each of them.
Everything referred to hereafter as "bug" also applies for feature requests.
-If you are reporting a new issue, you will make our life much simpler (and the fix come much sooner) by following those guidelines:
+If you are reporting a new issue, you will make our life much simpler (and the
+fix come much sooner) by following those guidelines:
#### Search first in the existing database
-Issues are often reported several times by various users. It's a good practice to **search first** in the issues database before reporting your issue. If you don't find a relevant match or if you are unsure, don't hesitate to **open a new issue**. The bugsquad will handle it from there if it's a duplicate.
+Issues are often reported several times by various users. It's a good practice
+to **search first** in the issues database before reporting your issue. If you
+don't find a relevant match or if you are unsure, don't hesitate to **open a
+new issue**. The bugsquad will handle it from there if it's a duplicate.
-#### Specify the platform
-
-Godot runs on a large variety of platforms and operating systems and devices. If you believe your issue is device/platform dependent (for example if it is related to the rendering, crashes or compilation errors), please specify:
+#### Specify the platform
+
+Godot runs on a large variety of platforms and operating systems and devices.
+If you believe your issue is device/platform dependent (for example if it is
+related to the rendering, crashes or compilation errors), please specify:
* Operating system
* Device (including architecture, e.g. x86, x86_64, arm, etc.)
* GPU model (and driver in use if you know it)
#### Specify steps to reproduce
-Many bugs can't be reproduced unless specific steps are taken. Please **specify the exact steps** that must be taken to reproduce the condition, and try to keep them as minimal as possible.
+Many bugs can't be reproduced unless specific steps are taken. Please **specify
+the exact steps** that must be taken to reproduce the condition, and try to
+keep them as minimal as possible.
#### Provide a simple, example project
-Sometimes an unexpected behavior happens in your project. In such case, understand that:
-
+Sometimes an unexpected behavior happens in your project. In such case,
+understand that:
* What happens to you may not happen to other users.
-* We can't take the time to look at your project, understand how it is set up and then figure out why it's failing.
-
-To speed up our work, please prepare for us **a simple project** that isolates and reproduces the issue. This is always the **the best way for us to fix it**. You can attach a zip file with the minimal project directly to the bug report, by drag and dropping the file in the GitHub edition field.
+* We can't take the time to look at your project, understand how it is set up
+ and then figure out why it's failing.
+
+To speed up our work, please prepare for us **a simple project** that isolates
+and reproduces the issue. This is always the **the best way for us to fix it**.
+You can attach a zip file with the minimal project directly to the bug report,
+by drag and dropping the file in the GitHub edition field.
## Contributing pull requests
If you want to add new engine functionalities, please make sure that:
* This functionality is desired.
-* You talked to other developers on how to implement it best (on either communication channel, and maybe in a GitHub issue first before making your PR).
-* Even if it does not get merged, your PR is useful for future work by another developer.
+* You talked to other developers on how to implement it best (on either
+ communication channel, and maybe in a GitHub issue first before making your
+ PR).
+* Even if it does not get merged, your PR is useful for future work by another
+ developer.
-Similar rules can be applied when contributing bug fixes - it's always best to discuss the implementation in the bug report first if you are not 100% about what would be the best fix.
+Similar rules can be applied when contributing bug fixes - it's always best to
+discuss the implementation in the bug report first if you are not 100% about
+what would be the best fix.
#### Be nice to the git history
-Try to make simple PRs with that handle one specific topic. Just like for reporting issues, it's better to open 3 different PRs that each address a different issue than one big PR with three commits.
+Try to make simple PRs with that handle one specific topic. Just like for
+reporting issues, it's better to open 3 different PRs that each address a
+different issue than one big PR with three commits.
-When updating your fork with upstream changes, please use ``git pull --rebase`` to avoid creating "merge commits". Those commits unnecessarily pollute the git history when coming from PRs.
+When updating your fork with upstream changes, please use ``git pull --rebase``
+to avoid creating "merge commits". Those commits unnecessarily pollute the git
+history when coming from PRs.
-Also try to make commits that bring the engine from one stable state to another stable state, i.e. if your first commit has a bug that you fixed in the second commit, try to merge them together before making your pull request (see ``git rebase -i`` and relevant help about rebasing or ammending commits on the Internet).
+Also try to make commits that bring the engine from one stable state to another
+stable state, i.e. if your first commit has a bug that you fixed in the second
+commit, try to merge them together before making your pull request (see ``git
+rebase -i`` and relevant help about rebasing or ammending commits on the
+Internet).
-This git style guide has some good practices to have in mind: https://github.com/agis-/git-style-guide
+This git style guide has some good practices to have in mind:
+https://github.com/agis-/git-style-guide
#### Format your commit logs with readability in mind
-The way you format your commit logs is quite important to ensure that the commit history and changelog will be easy to read and understand. A git commit log is formatted as a short title (first line) and an extended description (everything after the first line and an empty separation line).
+The way you format your commit logs is quite important to ensure that the
+commit history and changelog will be easy to read and understand. A git commit
+log is formatted as a short title (first line) and an extended description
+(everything after the first line and an empty separation line).
-The short title is the most important part, as it is what will appear in the `shortlog` changelog (one line per commit, so no description shown) or in the GitHub interface unless you click the "expand" button. As the name tells it, try to keep that first line relatively short (ideally <= 50 chars, though it's rare to be able to tell enough in so few characters, so you can go a bit higher) - it should describe what the commit does globally, while details would go in the description. Typically, if you can't keep the title short because you have too much stuff to mention, it means that you should probably split your changes in several commits :)
+The short title is the most important part, as it is what will appear in the
+`shortlog` changelog (one line per commit, so no description shown) or in the
+GitHub interface unless you click the "expand" button. As the name tells it,
+try to keep that first line relatively short (ideally <= 50 chars, though it's
+rare to be able to tell enough in so few characters, so you can go a bit
+higher) - it should describe what the commit does globally, while details would
+go in the description. Typically, if you can't keep the title short because you
+have too much stuff to mention, it means that you should probably split your
+changes in several commits :)
-Here's an example of a well-formatted commit log (note how the extended description is also manually wrapped at 80 chars for readability):
+Here's an example of a well-formatted commit log (note how the extended
+description is also manually wrapped at 80 chars for readability):
```
Prevent French fries carbonization by fixing heat regulation
@@ -82,16 +123,44 @@ of cooking oil under normal atmospheric conditions.
Fixes #1789, long live the Realm!
```
-*Note:* When using the GitHub online editor (or worse, the drag and drop feature), *please* edit the commit title to something meaningful. Commits named "Update my_file.cpp" will not be accepted.
+*Note:* When using the GitHub online editor (or worse, the drag and drop
+feature), *please* edit the commit title to something meaningful. Commits named
+"Update my_file.cpp" will not be accepted.
-## Communicating with developers
+## Contributing to Godot's translation
+
+You can contribute to Godot's translation from the [Hosted
+Weblate](https://hosted.weblate.org/projects/godot-engine/godot), an open
+source and web-based translation platform. Please refer to the [translation
+readme](editor/translations/README.md) for more information.
-The Godot Engine community has [many communication channels](https://godotengine.org/community), some used more for user-level discussions and support, others more for development discussions.
+## Communicating with developers
-To communicate with developers (e.g. to discuss a feature you want to implement or a bug you want to fix), the following channels can be used:
-- [GitHub issues](https://github.com/godotengine/godot/issues): If there is an existing issue about a topic you want to discuss, just add a comment to it - all developers watch the repository and will get an email notification. You can also create a new issue - please keep in mind to create issues only to discuss quite specific points about the development, and not general user feedback or support requests.
-- [#godotengine-devel IRC channel on Freenode](https://webchat.freenode.net/?channels=godotengine-devel): You will find most core developers there, so it's the go-to channel for direct chat about Godot Engine development. Feel free to start discussing something there to get some early feedback before writing up a detailed proposal in a GitHub issue.
-- [devel@godotengine.org mailing list](https://listengine.tuxfamily.org/godotengine.org/devel/): Mailing list for Godot developers, used primarily to announce developer meetings on IRC and other important discussions that need to reach people directly in their mailbox. See the [index page](https://listengine.tuxfamily.org/godotengine.org/devel/) for subscription instructions.
+The Godot Engine community has [many communication
+channels](https://godotengine.org/community), some used more for user-level
+discussions and support, others more for development discussions.
+
+To communicate with developers (e.g. to discuss a feature you want to implement
+or a bug you want to fix), the following channels can be used:
+- [GitHub issues](https://github.com/godotengine/godot/issues): If there is an
+ existing issue about a topic you want to discuss, just add a comment to it -
+ all developers watch the repository and will get an email notification. You
+ can also create a new issue - please keep in mind to create issues only to
+ discuss quite specific points about the development, and not general user
+ feedback or support requests.
+- [#godotengine-devel IRC channel on
+ Freenode](https://webchat.freenode.net/?channels=godotengine-devel): You will
+ find most core developers there, so it's the go-to channel for direct chat
+ about Godot Engine development. Feel free to start discussing something there
+ to get some early feedback before writing up a detailed proposal in a GitHub
+ issue.
+- [devel@godotengine.org mailing
+ list](https://listengine.tuxfamily.org/godotengine.org/devel/): Mailing list
+ for Godot developers, used primarily to announce developer meetings on IRC
+ and other important discussions that need to reach people directly in their
+ mailbox. See the [index
+ page](https://listengine.tuxfamily.org/godotengine.org/devel/) for
+ subscription instructions.
Thanks!
diff --git a/core/color.h b/core/color.h
index 46386fac64..c83dcda4b4 100644
--- a/core/color.h
+++ b/core/color.h
@@ -83,6 +83,40 @@ struct Color {
return res;
}
+ _FORCE_INLINE_ uint32_t to_rgbe9995() const {
+
+ const float pow2to9 = 512.0f;
+ const float B = 15.0f;
+ //const float Emax = 31.0f;
+ const float N = 9.0f;
+
+ float sharedexp = 65408.000f; //(( pow2to9 - 1.0f)/ pow2to9)*powf( 2.0f, 31.0f - 15.0f);
+
+ float cRed = MAX(0.0f, MIN(sharedexp, r));
+ float cGreen = MAX(0.0f, MIN(sharedexp, g));
+ float cBlue = MAX(0.0f, MIN(sharedexp, b));
+
+ float cMax = MAX(cRed, MAX(cGreen, cBlue));
+
+ // expp = MAX(-B - 1, log2(maxc)) + 1 + B
+
+ float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B;
+
+ float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
+
+ float exps = expp + 1.0f;
+
+ if (0.0 <= sMax && sMax < pow2to9) {
+ exps = expp;
+ }
+
+ float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f);
+ float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f);
+ float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f);
+
+ return (uint32_t(Math::fast_ftoi(sRed)) & 0x1FF) | ((uint32_t(Math::fast_ftoi(sGreen)) & 0x1FF) << 9) | ((uint32_t(Math::fast_ftoi(sBlue)) & 0x1FF) << 18) | ((uint32_t(Math::fast_ftoi(exps)) & 0x1F) << 27);
+ }
+
_FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
diff --git a/core/image.cpp b/core/image.cpp
index 2496fd136c..2640c6be2a 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -59,8 +59,6 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"DXT1 RGB8", //s3tc
"DXT3 RGBA8",
"DXT5 RGBA8",
- "LATC Lum8",
- "LATC LumAlpha8",
"RGTC Red8",
"RGTC RedGreen8",
"BPTC_RGBA",
@@ -131,10 +129,8 @@ int Image::get_format_pixel_size(Format p_format) {
return 1; //bc2
case FORMAT_DXT5:
return 1; //bc3
- case FORMAT_LATC_L:
case FORMAT_RGTC_R:
return 1; //bc4
- case FORMAT_LATC_LA:
case FORMAT_RGTC_RG:
return 1; //bc5
case FORMAT_BPTC_RGBA:
@@ -171,8 +167,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
case FORMAT_DXT1: //s3tc bc1
case FORMAT_DXT3: //bc2
case FORMAT_DXT5: //bc3
- case FORMAT_LATC_L: //bc4
- case FORMAT_LATC_LA: //bc4
case FORMAT_RGTC_R: //bc4
case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1:
@@ -225,7 +219,7 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
int Image::get_format_pixel_rshift(Format p_format) {
- if (p_format == FORMAT_DXT1 || p_format == FORMAT_LATC_L || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
+ if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
return 1;
else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A)
return 2;
@@ -239,8 +233,6 @@ int Image::get_format_block_size(Format p_format) {
case FORMAT_DXT1: //s3tc bc1
case FORMAT_DXT3: //bc2
case FORMAT_DXT5: //bc3
- case FORMAT_LATC_L: //bc4
- case FORMAT_LATC_LA: //bc4
case FORMAT_RGTC_R: //bc4
case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1:
@@ -1500,14 +1492,14 @@ Error Image::decompress() {
return OK;
}
-Error Image::compress(CompressMode p_mode) {
+Error Image::compress(CompressMode p_mode, bool p_for_srgb) {
switch (p_mode) {
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
- _image_compress_bc_func(this);
+ _image_compress_bc_func(this, p_for_srgb);
} break;
case COMPRESS_PVRTC2: {
@@ -1657,7 +1649,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
Ref<Image> (*Image::_png_mem_loader_func)(const uint8_t *, int) = NULL;
Ref<Image> (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL;
-void (*Image::_image_compress_bc_func)(Image *) = NULL;
+void (*Image::_image_compress_bc_func)(Image *, bool) = NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL;
void (*Image::_image_compress_etc_func)(Image *) = NULL;
@@ -1981,35 +1973,7 @@ void Image::put_pixel(int p_x, int p_y, const Color &p_color) {
} break;
case FORMAT_RGBE9995: {
- const float pow2to9 = 512.0f;
- const float B = 7.0f;
- //const float Emax = 31.0f;
- const float N = 9.0f;
-
- float sharedexp = 65408.000f; //(( pow2to9 - 1.0f)/ pow2to9)*powf( 2.0f, 31.0f - 15.0f);
-
- float cRed = MAX(0.0f, MIN(sharedexp, p_color.r));
- float cGreen = MAX(0.0f, MIN(sharedexp, p_color.g));
- float cBlue = MAX(0.0f, MIN(sharedexp, p_color.b));
-
- float cMax = MAX(cRed, MAX(cGreen, cBlue));
-
- // expp = MAX(-B - 1, log2(maxc)) + 1 + B
- float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math::log(2.0))) + 1.0f + B;
-
- float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
-
- float exps = expp + 1.0f;
-
- if (0.0 <= sMax && sMax < pow2to9) {
- exps = expp;
- }
-
- float sRed = (cRed / pow(2.0f, exps - B - N)) + 0.5f;
- float sGreen = (cGreen / pow(2.0f, exps - B - N)) + 0.5f;
- float sBlue = (cBlue / pow(2.0f, exps - B - N)) + 0.5f;
-
- ((uint32_t *)ptr)[ofs] = ((uint32_t)(sRed)&0x1FF) | (((uint32_t)(sGreen)&0x1FF) << 9) | (((uint32_t)(sBlue)&0x1FF) << 18) | (((uint32_t)(exps)&0x1F) << 27);
+ ((uint32_t *)ptr)[ofs] = p_color.to_rgbe9995();
} break;
default: {
@@ -2144,8 +2108,6 @@ void Image::_bind_methods() {
BIND_CONSTANT(FORMAT_DXT1); //s3tc bc1
BIND_CONSTANT(FORMAT_DXT3); //bc2
BIND_CONSTANT(FORMAT_DXT5); //bc3
- BIND_CONSTANT(FORMAT_LATC_L);
- BIND_CONSTANT(FORMAT_LATC_LA);
BIND_CONSTANT(FORMAT_RGTC_R);
BIND_CONSTANT(FORMAT_RGTC_RG);
BIND_CONSTANT(FORMAT_BPTC_RGBA); //btpc bc6h
@@ -2180,7 +2142,7 @@ void Image::_bind_methods() {
BIND_CONSTANT(COMPRESS_ETC2);
}
-void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
+void Image::set_compress_bc_func(void (*p_compress_func)(Image *, bool)) {
_image_compress_bc_func = p_compress_func;
}
diff --git a/core/image.h b/core/image.h
index 9ea01a94d4..2a78870f53 100644
--- a/core/image.h
+++ b/core/image.h
@@ -80,8 +80,6 @@ public:
FORMAT_DXT1, //s3tc bc1
FORMAT_DXT3, //bc2
FORMAT_DXT5, //bc3
- FORMAT_LATC_L,
- FORMAT_LATC_LA,
FORMAT_RGTC_R,
FORMAT_RGTC_RG,
FORMAT_BPTC_RGBA, //btpc bc7
@@ -116,7 +114,7 @@ public:
static Ref<Image> (*_png_mem_loader_func)(const uint8_t *p_png, int p_size);
static Ref<Image> (*_jpg_mem_loader_func)(const uint8_t *p_png, int p_size);
- static void (*_image_compress_bc_func)(Image *);
+ static void (*_image_compress_bc_func)(Image *, bool p_srgb);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
@@ -269,7 +267,7 @@ public:
COMPRESS_ETC2,
};
- Error compress(CompressMode p_mode = COMPRESS_S3TC);
+ Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false);
Error decompress();
bool is_compressed() const;
@@ -283,7 +281,7 @@ public:
Rect2 get_used_rect() const;
Ref<Image> get_rect(const Rect2 &p_area) const;
- static void set_compress_bc_func(void (*p_compress_func)(Image *));
+ static void set_compress_bc_func(void (*p_compress_func)(Image *, bool));
static String get_format_name(Format p_format);
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 6ed20ac015..23719940be 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -43,7 +43,7 @@ bool ImageFormatLoader::recognize(const String &p_extension) const {
return false;
}
-Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom) {
+Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom, bool p_force_linear) {
ERR_FAIL_COND_V(p_image.is_null(), ERR_INVALID_PARAMETER);
FileAccess *f = p_custom;
@@ -62,7 +62,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
if (!loader[i]->recognize(extension))
continue;
- Error err = loader[i]->load_image(p_image, f);
+ Error err = loader[i]->load_image(p_image, f, p_force_linear);
if (err != ERR_FILE_UNRECOGNIZED) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 7114cbf8ad..e528d1423b 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -56,7 +56,7 @@ class ImageFormatLoader {
friend class ImageLoader;
protected:
- virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess) = 0;
+ virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess, bool p_force_linear) = 0;
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
bool recognize(const String &p_extension) const;
@@ -75,7 +75,7 @@ class ImageLoader {
protected:
public:
- static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL);
+ static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL, bool p_force_linear = false);
static void get_recognized_extensions(List<String> *p_extensions);
static bool recognize(const String &p_extension);
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index bcbf2e4531..c6dbfc2a7a 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -115,7 +115,6 @@ MAKE_PTRARG(PoolVector2Array);
MAKE_PTRARG(PoolVector3Array);
MAKE_PTRARG(PoolColorArray);
MAKE_PTRARG(Variant);
-MAKE_PTRARG(PowerState);
//this is for Object
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 375121c0cc..805b66b983 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -252,6 +252,27 @@ double FileAccess::get_double() const {
return m.d;
};
+String FileAccess::get_token() const {
+
+ CharString token;
+
+ CharType c = get_8();
+
+ while (!eof_reached()) {
+
+ if (c <= ' ') {
+ if (!token.empty())
+ break;
+ } else {
+ token.push_back(c);
+ }
+ c = get_8();
+ }
+
+ token.push_back(0);
+ return String::utf8(token.get_data());
+}
+
String FileAccess::get_line() const {
CharString line;
diff --git a/core/os/file_access.h b/core/os/file_access.h
index da15ddc544..6d3e491167 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -106,6 +106,7 @@ public:
virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes
virtual String get_line() const;
+ virtual String get_token() const;
virtual Vector<String> get_csv_line(String delim = ",") const;
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
diff --git a/core/os/os.h b/core/os/os.h
index 037ce436c1..11fe8b44e3 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -413,4 +413,6 @@ public:
virtual ~OS();
};
+VARIANT_ENUM_CAST(PowerState);
+
#endif
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 7a5129962b..6a93d7789e 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -489,6 +489,18 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
const CharType *that_str = p_str.c_str();
if (this_str && that_str) {
+
+ while (*this_str == '.' || *that_str == '.') {
+ if (*this_str++ != '.')
+ return 1;
+ if (*that_str++ != '.')
+ return -1;
+ if (!*that_str)
+ return 1;
+ if (!*this_str)
+ return -1;
+ }
+
while (*this_str) {
if (!*that_str)
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 0d4d0429e7..55e2bb42e3 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -695,6 +695,106 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
return OK;
+ } else if (id == "Object") {
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_PARENTHESIS_OPEN) {
+ r_err_str = "Expected '('";
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+
+ if (token.type != TK_IDENTIFIER) {
+ r_err_str = "Expected identifier with type of object";
+ return ERR_PARSE_ERROR;
+ }
+
+ String type = token.value;
+
+ Object *obj = ClassDB::instance(type);
+
+ if (!obj) {
+ r_err_str = "Can't instance Object() of type: " + type;
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_COMMA) {
+ r_err_str = "Expected ',' after object type";
+ return ERR_PARSE_ERROR;
+ }
+
+ bool at_key = true;
+ String key;
+ Token token;
+ bool need_comma = false;
+
+ while (true) {
+
+ if (p_stream->is_eof()) {
+ r_err_str = "Unexpected End of File while parsing Object()";
+ return ERR_FILE_CORRUPT;
+ }
+
+ if (at_key) {
+
+ Error err = get_token(p_stream, token, line, r_err_str);
+ if (err != OK)
+ return err;
+
+ if (token.type == TK_PARENTHESIS_CLOSE) {
+
+ return OK;
+ }
+
+ if (need_comma) {
+
+ if (token.type != TK_COMMA) {
+
+ r_err_str = "Expected '}' or ','";
+ return ERR_PARSE_ERROR;
+ } else {
+ need_comma = false;
+ continue;
+ }
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_STRING) {
+ r_err_str = "Expected property name as string";
+ return ERR_PARSE_ERROR;
+ }
+
+ key = token.value;
+
+ err = get_token(p_stream, token, line, r_err_str);
+
+ if (err != OK)
+ return err;
+ if (token.type != TK_COLON) {
+
+ r_err_str = "Expected ':'";
+ return ERR_PARSE_ERROR;
+ }
+ at_key = false;
+ } else {
+
+ Error err = get_token(p_stream, token, line, r_err_str);
+ if (err != OK)
+ return err;
+
+ Variant v;
+ err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
+ if (err)
+ return err;
+ obj->set(key, v);
+ need_comma = true;
+ at_key = true;
+ }
+ }
+
+ return OK;
} else if (id == "Resource" || id == "SubResource" || id == "ExtResource") {
@@ -1611,30 +1711,63 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::OBJECT: {
- RES res = p_variant;
- if (res.is_null()) {
+ Object *obj = p_variant;
+
+ if (!obj) {
p_store_string_func(p_store_string_ud, "null");
break; // don't save it
}
- String res_text;
+ RES res = p_variant;
+ if (res.is_valid()) {
+ //is resource
+ String res_text;
- if (p_encode_res_func) {
+ //try external function
+ if (p_encode_res_func) {
- res_text = p_encode_res_func(p_encode_res_ud, res);
- }
+ res_text = p_encode_res_func(p_encode_res_ud, res);
+ }
+
+ //try path because it's a file
+ if (res_text == String() && res->get_path().is_resource_file()) {
- if (res_text == String() && res->get_path().is_resource_file()) {
+ //external resource
+ String path = res->get_path();
+ res_text = "Resource( \"" + path + "\")";
+ }
- //external resource
- String path = res->get_path();
- res_text = "Resource( \"" + path + "\")";
+ //could come up with some sort of text
+ if (res_text != String()) {
+ p_store_string_func(p_store_string_ud, res_text);
+ break;
+ }
}
- if (res_text == String())
- res_text = "null";
+ //store as generic object
+
+ p_store_string_func(p_store_string_ud, "Object(" + obj->get_class() + ",");
+
+ List<PropertyInfo> props;
+ obj->get_property_list(&props);
+ bool first = true;
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+
+ if (E->get().usage & PROPERTY_USAGE_STORAGE || E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE) {
+ //must be serialized
+
+ if (first) {
+ first = false;
+ } else {
+ p_store_string_func(p_store_string_ud, ",");
+ }
+
+ p_store_string_func(p_store_string_ud, "\"" + E->get().name + "\":");
+ write(obj->get(E->get().name), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
+ }
+ }
- p_store_string_func(p_store_string_ud, res_text);
+ p_store_string_func(p_store_string_ud, ")\n");
} break;
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 5214de6d06..9037f68dad 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -2120,7 +2120,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo
}
}
-void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale) {
+void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale, float p_energy) {
if (!p_sky)
return;
@@ -2188,13 +2188,16 @@ void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const C
glBindVertexArray(state.sky_array);
storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_PANORAMA, true);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_MULTIPLIER, true);
storage->shaders.copy.bind();
+ storage->shaders.copy.set_uniform(CopyShaderGLES3::MULTIPLIER, p_energy);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
glColorMask(1, 1, 1, 1);
+ storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_MULTIPLIER, false);
storage->shaders.copy.set_conditional(CopyShaderGLES3::USE_PANORAMA, false);
}
@@ -3148,6 +3151,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_
//copy reflection over diffuse, resolving SSR if needed
state.resolve_shader.set_conditional(ResolveShaderGLES3::USE_SSR, env->ssr_enabled);
state.resolve_shader.bind();
+ state.resolve_shader.set_uniform(ResolveShaderGLES3::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height));
+
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color);
if (env->ssr_enabled) {
@@ -3885,7 +3890,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->buffers.fbo); //switch to alpha fbo for sky, only diffuse/ambient matters
*/
- _draw_sky(sky, p_cam_projection, p_cam_transform, storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP], env->sky_scale);
+ _draw_sky(sky, p_cam_projection, p_cam_transform, storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP], env->sky_scale, env->bg_energy);
}
//_render_list_forward(&alpha_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting,true);
@@ -4832,7 +4837,7 @@ void RasterizerSceneGLES3::initialize() {
glGenTextures(1, &e.color);
glBindTexture(GL_TEXTURE_2D, e.color);
#ifdef IPHONE_ENABLED
- ///@TODO ugly hack to get around iOS not supporting 32bit single channel floating point textures...
+ ///@TODO ugly hack to get around iOS not supporting 32bit single channel floating point textures...
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, max_exposure_shrink_size, max_exposure_shrink_size, 0, GL_RED, GL_FLOAT, NULL);
#else
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, max_exposure_shrink_size, max_exposure_shrink_size, 0, GL_RED, GL_FLOAT, NULL);
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index 69a7e40604..322343bc89 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -131,8 +131,6 @@ public:
struct EnvironmentRadianceUBO {
float transform[16];
- float box_min[4]; //unused for now
- float box_max[4];
float ambient_contribution;
} env_radiance_data;
@@ -700,7 +698,7 @@ public:
_FORCE_INLINE_ void _add_geometry(RasterizerStorageGLES3::Geometry *p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner, int p_material, bool p_shadow);
- void _draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale);
+ void _draw_sky(RasterizerStorageGLES3::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_scale, float p_energy);
void _setup_environment(Environment *env, const CameraMatrix &p_cam_projection, const Transform &p_cam_transform);
void _setup_directional_light(int p_index, const Transform &p_camera_inverse_transformm, bool p_use_shadows);
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 3f28ae25f2..a3f1873eae 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -283,36 +283,6 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_
}
} break;
- case Image::FORMAT_LATC_L: {
-
- if (config.latc_supported) {
-
- r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_LATC1_EXT;
- r_gl_format = GL_RGBA;
- r_gl_type = GL_UNSIGNED_BYTE;
- r_compressed = true;
- srgb = true;
-
- } else {
-
- need_decompress = true;
- }
-
- } break;
- case Image::FORMAT_LATC_LA: {
-
- if (config.latc_supported) {
-
- r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
- r_gl_format = GL_RGBA;
- r_gl_type = GL_UNSIGNED_BYTE;
- r_compressed = true;
- } else {
-
- need_decompress = true;
- }
-
- } break;
case Image::FORMAT_RGTC_R: {
if (config.rgtc_supported) {
@@ -321,7 +291,6 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_
r_gl_format = GL_RGBA;
r_gl_type = GL_UNSIGNED_BYTE;
r_compressed = true;
- srgb = true;
} else {
@@ -5553,7 +5522,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) {
Image::Format image_format;
bool hdr = rt->flags[RENDER_TARGET_HDR] && config.hdr_supported;
- hdr = false;
+ //hdr = false;
if (!hdr || rt->flags[RENDER_TARGET_NO_3D]) {
@@ -6403,6 +6372,8 @@ void RasterizerStorageGLES3::initialize() {
config.etc2_supported = true;
config.hdr_supported = false;
#endif
+
+ print_line("hdr supported: " + itos(config.hdr_supported));
config.pvrtc_supported = config.extensions.has("GL_IMG_texture_compression_pvrtc");
config.srgb_decode_supported = config.extensions.has("GL_EXT_texture_sRGB_decode");
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index 23bcb79b46..7771405bb0 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -723,6 +723,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth";
actions[VS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo";
actions[VS::SHADER_SPATIAL].renames["ALPHA"] = "alpha";
+ actions[VS::SHADER_SPATIAL].renames["METALLIC"] = "metallic";
actions[VS::SHADER_SPATIAL].renames["SPECULAR"] = "specular";
actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness";
actions[VS::SHADER_SPATIAL].renames["RIM"] = "rim";
@@ -762,6 +763,10 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].render_mode_defines["skip_default_transform"] = "#define SKIP_TRANSFORM_USED\n";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_half_lambert"] = "#define DIFFUSE_HALF_LAMBERT\n";
+
/* PARTICLES SHADER */
actions[VS::SHADER_PARTICLES].renames["COLOR"] = "out_color";
diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp
index bebc006032..8c6d15c3b7 100644
--- a/drivers/gles3/shader_gles3.cpp
+++ b/drivers/gles3/shader_gles3.cpp
@@ -100,14 +100,14 @@ void ShaderGLES3::bind_uniforms() {
};
uniforms_dirty = false;
-};
+}
GLint ShaderGLES3::get_uniform_location(int p_idx) const {
ERR_FAIL_COND_V(!version, -1);
return version->uniform_location[p_idx];
-};
+}
bool ShaderGLES3::bind() {
@@ -399,14 +399,14 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() {
strings.push_back(fragment_code2.get_data());
if (cc) {
- code_string = cc->fragment.ascii();
+ code_string = cc->light.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(fragment_code3.get_data());
if (cc) {
- code_string2 = cc->light.ascii();
+ code_string2 = cc->fragment.ascii();
strings.push_back(code_string2.get_data());
}
@@ -666,7 +666,7 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co
//print_line("CODE1:\n"+String(fragment_code1.get_data()));
String code2 = code.substr(cpos + material_tag.length(), code.length());
- cpos = code2.find(code_tag);
+ cpos = code2.find(light_code_tag);
if (cpos == -1) {
fragment_code2 = code2.ascii();
@@ -675,16 +675,16 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co
fragment_code2 = code2.substr(0, cpos).ascii();
//print_line("CODE2:\n"+String(fragment_code2.get_data()));
- String code3 = code2.substr(cpos + code_tag.length(), code2.length());
+ String code3 = code2.substr(cpos + light_code_tag.length(), code2.length());
- cpos = code3.find(light_code_tag);
+ cpos = code3.find(code_tag);
if (cpos == -1) {
fragment_code3 = code3.ascii();
} else {
fragment_code3 = code3.substr(0, cpos).ascii();
//print_line("CODE3:\n"+String(fragment_code3.get_data()));
- fragment_code4 = code3.substr(cpos + light_code_tag.length(), code3.length()).ascii();
+ fragment_code4 = code3.substr(cpos + code_tag.length(), code3.length()).ascii();
//print_line("CODE4:\n"+String(fragment_code4.get_data()));
}
}
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl
index e6c72da8f1..017009015e 100644
--- a/drivers/gles3/shaders/canvas.glsl
+++ b/drivers/gles3/shaders/canvas.glsl
@@ -211,6 +211,18 @@ MATERIAL_UNIFORMS
#endif
+
+void light_compute(inout vec3 light,vec3 light_vec,float light_height,vec4 light_color,vec2 light_uv,vec4 shadow,vec3 normal,vec2 uv,vec2 screen_uv,vec4 color) {
+
+#if defined(USE_LIGHT_SHADER_CODE)
+
+LIGHT_SHADER_CODE
+
+#endif
+
+}
+
+
void main() {
vec4 color = color_interp;
@@ -285,11 +297,7 @@ FRAGMENT_SHADER_CODE
#if defined(USE_LIGHT_SHADER_CODE)
//light is written by the light shader
- {
- vec4 light_out=light*color;
-LIGHT_SHADER_CODE
- color=light_out;
- }
+ light_compute(light,light_vec,light_height,light_color,light_uv,shadow,normal,uv,screen_uv,color);
#else
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl
index f3c72a4e6f..c8985e6902 100644
--- a/drivers/gles3/shaders/copy.glsl
+++ b/drivers/gles3/shaders/copy.glsl
@@ -45,6 +45,11 @@ uniform samplerCube source_cube; //texunit:0
uniform sampler2D source; //texunit:0
#endif
+
+#ifdef USE_MULTIPLIER
+uniform float multiplier;
+#endif
+
#ifdef USE_PANORAMA
vec4 texturePanorama(vec3 normal,sampler2D pano ) {
@@ -130,7 +135,9 @@ void main() {
color+=texture( source, uv_interp+vec2( 0.0,-2.0)*pixel_size )*0.06136;
#endif
-
+#ifdef USE_MULTIPLIER
+ color.rgb*=multiplier;
+#endif
frag_color = color;
}
diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl
index fa12dd7408..5d8a532f87 100644
--- a/drivers/gles3/shaders/particles.glsl
+++ b/drivers/gles3/shaders/particles.glsl
@@ -244,6 +244,10 @@ MATERIAL_UNIFORMS
void main() {
{
+LIGHT_SHADER_CODE
+ }
+
+ {
FRAGMENT_SHADER_CODE
}
}
diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl
index 6acc712299..181a3c99ec 100644
--- a/drivers/gles3/shaders/resolve.glsl
+++ b/drivers/gles3/shaders/resolve.glsl
@@ -20,7 +20,7 @@ in vec2 uv_interp;
uniform sampler2D source_specular; //texunit:0
uniform sampler2D source_ssr; //texunit:1
-uniform float stuff;
+uniform vec2 pixel_size;
in vec2 uv2_interp;
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 43a391631f..f35e04c5e4 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -380,8 +380,6 @@ uniform sampler2D radiance_map; //texunit:-2
layout(std140) uniform Radiance { //ubo:2
mat4 radiance_inverse_xform;
- vec3 radiance_box_min;
- vec3 radiance_box_max;
float radiance_ambient_contribution;
};
@@ -598,7 +596,6 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
return 1.0;
}
-
// GGX Specular
// Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl
float G1V(float dotNV, float k)
@@ -624,17 +621,68 @@ float GTR1(float NdotH, float a)
-void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, vec3 specular_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) {
+void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) {
+
+#if defined(USE_LIGHT_SHADER_CODE)
+//light is written by the light shader
+
+
+LIGHT_SHADER_CODE
+
+
+#else
float dotNL = max(dot(N,L), 0.0 );
- float dotNV = max(dot(N,V), 0.0 );
+#if defined(DIFFUSE_HALF_LAMBERT)
+
+ float hl = dot(N,L) * 0.5 + 0.5;
+ diffuse += hl * light_color * diffuse_color;
+
+#elif defined(DIFFUSE_OREN_NAYAR)
+
+ {
+ float LdotV = dot(L, V);
+ float NdotL = dot(L, N);
+ float NdotV = dot(N, V);
+
+ float s = LdotV - NdotL * NdotV;
+ float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
+
+ float sigma2 = roughness * roughness;
+ vec3 A = 1.0 + sigma2 * (diffuse_color / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33));
+ float B = 0.45 * sigma2 / (sigma2 + 0.09);
+
+ diffuse += diffuse_color * max(0.0, NdotL) * (A + vec3(B) * s / t) / M_PI;
+ }
+
+#elif defined(DIFFUSE_BURLEY)
+
+ {
+ float NdotL = dot(L, N);
+ float NdotV = dot(N, V);
+ float VdotH = dot(N, normalize(L+V));
+ float energyBias = mix(roughness, 0.0, 0.5);
+ float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
+ float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness;
+ float f0 = 1.0;
+ float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0);
+ float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0);
+
+ diffuse+= light_color * diffuse_color * lightScatter * viewScatter * energyFactor;
+ }
+#else
+ //lambert
+ diffuse += dotNL * light_color * diffuse_color;
+#endif
+
+
+ float dotNV = max(dot(N,V), 0.0 );
#if defined(LIGHT_USE_RIM)
float rim_light = pow(1.0-dotNV,(1.0-roughness)*16.0);
diffuse += rim_light * rim * mix(vec3(1.0),diffuse_color,rim_tint) * light_color;
#endif
- diffuse += dotNL * light_color * diffuse_color;
if (roughness > 0.0) {
@@ -676,7 +724,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di
float speci = dotNL * D * F * vis;
- specular += speci * light_color /* specular_color*/ * specular_blob_intensity;
+ specular += speci * light_color * specular_blob_intensity;
#if defined(LIGHT_USE_CLEARCOAT)
float Dr = GTR1(dotNH, mix(.1,.001,clearcoat_gloss));
@@ -688,6 +736,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di
}
+#endif //defined(USE_LIGHT_SHADER_CODE)
}
@@ -735,6 +784,8 @@ in highp float dp_clip;
#endif
+
+
#if 0
//need to save texture depth for this
@@ -764,7 +815,7 @@ vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 po
}
#endif
-void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, vec3 specular, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) {
+void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) {
vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex;
float light_length = length( light_rel_vec );
@@ -815,11 +866,11 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino
light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
}
- light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+ light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
}
-void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, vec3 specular, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) {
+void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) {
vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex;
float light_length = length( light_rel_vec );
@@ -848,11 +899,11 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi
light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
}
- light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+ light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
}
-void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 tangent,float roughness,float anisotropy,vec3 ambient,vec3 skybox,vec2 brdf, inout highp vec4 reflection_accum,inout highp vec4 ambient_accum) {
+void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 tangent,float roughness,float anisotropy,vec3 ambient,vec3 skybox, inout highp vec4 reflection_accum,inout highp vec4 ambient_accum) {
vec3 ref_vec = normalize(reflect(vertex,normal));
vec3 local_pos = (reflections[idx].local_matrix * vec4(vertex,1.0)).xyz;
@@ -908,7 +959,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
splane.xy = clamp(splane.xy,clamp_rect.xy,clamp_rect.xy+clamp_rect.zw);
highp vec4 reflection;
- reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb * brdf.x + brdf.y;
+ reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb;
if (reflections[idx].params.z < 0.5) {
reflection.rgb = mix(skybox,reflection.rgb,blend);
@@ -969,7 +1020,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta
#ifdef USE_GI_PROBES
-uniform mediump sampler3D gi_probe1; //texunit:-11
+uniform mediump sampler3D gi_probe1; //texunit:-10
uniform highp mat4 gi_probe_xform1;
uniform highp vec3 gi_probe_bounds1;
uniform highp vec3 gi_probe_cell_size1;
@@ -977,7 +1028,7 @@ uniform highp float gi_probe_multiplier1;
uniform highp float gi_probe_bias1;
uniform bool gi_probe_blend_ambient1;
-uniform mediump sampler3D gi_probe2; //texunit:-10
+uniform mediump sampler3D gi_probe2; //texunit:-11
uniform highp mat4 gi_probe_xform2;
uniform highp vec3 gi_probe_bounds2;
uniform highp vec3 gi_probe_cell_size2;
@@ -1089,7 +1140,7 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s
}
-void gi_probes_compute(vec3 pos, vec3 normal, float roughness, vec3 specular, inout vec3 out_specular, inout vec3 out_ambient) {
+void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_specular, inout vec3 out_ambient) {
roughness = roughness * roughness;
@@ -1133,6 +1184,23 @@ void gi_probes_compute(vec3 pos, vec3 normal, float roughness, vec3 specular, in
#endif
+vec3 textureDualParabolod(sampler2D p_tex, vec3 p_vec,float p_lod) {
+
+ vec3 norm = normalize(p_vec);
+ float y_ofs=0.0;
+ if (norm.z>=0.0) {
+
+ norm.z+=1.0;
+ y_ofs+=0.5;
+ } else {
+ norm.z=1.0 - norm.z;
+ norm.y=-norm.y;
+ }
+
+ norm.xy/=norm.z;
+ norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25+y_ofs);
+ return textureLod(p_tex, norm.xy, p_lod).xyz;
+}
void main() {
@@ -1145,7 +1213,8 @@ void main() {
//lay out everything, whathever is unused is optimized away anyway
highp vec3 vertex = vertex_interp;
vec3 albedo = vec3(0.8,0.8,0.8);
- vec3 specular = vec3(0.2,0.2,0.2);
+ float metallic = 0.0;
+ float specular = 0.5;
vec3 emission = vec3(0.0,0.0,0.0);
float roughness = 1.0;
float rim = 0.0;
@@ -1260,11 +1329,7 @@ FRAGMENT_SHADER_CODE
vec3 eye_vec = -normalize( vertex_interp );
-#ifndef RENDER_DEPTH
- float ndotv = clamp(dot(normal,eye_vec),0.0,1.0);
- vec2 brdf = texture(brdf_texture, vec2(roughness, ndotv)).xy;
-#endif
#ifdef USE_RADIANCE_MAP
@@ -1274,28 +1339,15 @@ FRAGMENT_SHADER_CODE
{
-
- float lod = roughness * 5.0;
+#define RADIANCE_MAX_LOD 5.0
+ float lod = roughness * RADIANCE_MAX_LOD;
{ //read radiance from dual paraboloid
vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n);
ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz);
-
- vec3 norm = normalize(ref_vec);
- float y_ofs=0.0;
- if (norm.z>=0.0) {
-
- norm.z+=1.0;
- y_ofs+=0.5;
- } else {
- norm.z=1.0 - norm.z;
- norm.y=-norm.y;
- }
-
- norm.xy/=norm.z;
- norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25+y_ofs);
- specular_light = textureLod(radiance_map, norm.xy, lod).xyz * brdf.x + brdf.y;
+ vec3 radiance = textureDualParabolod(radiance_map,ref_vec,lod) * bg_energy;
+ specular_light = radiance;
}
//no longer a cubemap
@@ -1305,11 +1357,11 @@ FRAGMENT_SHADER_CODE
{
- /*vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz);
- vec3 env_ambient=textureLod(radiance_cube, ambient_dir, 5.0).xyz;
+ vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz);
+ vec3 env_ambient=textureDualParabolod(radiance_map,ambient_dir,RADIANCE_MAX_LOD) * bg_energy;
- ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution);*/
- ambient_light=vec3(0.0,0.0,0.0);
+ ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution);
+ //ambient_light=vec3(0.0,0.0,0.0);
}
}
@@ -1322,6 +1374,7 @@ FRAGMENT_SHADER_CODE
}
#endif
+ ambient_light*=ambient_energy;
#ifdef USE_LIGHT_DIRECTIONAL
@@ -1462,13 +1515,14 @@ FRAGMENT_SHADER_CODE
#endif //LIGHT_DIRECTIONAL_SHADOW
- light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,specular,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+ light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
#endif //#USE_LIGHT_DIRECTIONAL
#ifdef USE_GI_PROBES
- gi_probes_compute(vertex,normal,roughness,specular,specular_light,ambient_light);
+ gi_probes_compute(vertex,normal,roughness,specular_light,ambient_light);
+
#endif
@@ -1480,7 +1534,7 @@ FRAGMENT_SHADER_CODE
for(int i=0;i<reflection_count;i++) {
- reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,specular_light,brdf,reflection_accum,ambient_accum);
+ reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,specular_light,reflection_accum,ambient_accum);
}
if (reflection_accum.a>0.0) {
@@ -1491,11 +1545,11 @@ FRAGMENT_SHADER_CODE
}
for(int i=0;i<omni_light_count;i++) {
- light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+ light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
}
for(int i=0;i<spot_light_count;i++) {
- light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
+ light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
}
@@ -1505,14 +1559,7 @@ FRAGMENT_SHADER_CODE
-#if defined(USE_LIGHT_SHADER_CODE)
-//light is written by the light shader
-{
-LIGHT_SHADER_CODE
-
-}
-#endif
#ifdef RENDER_DEPTH
//nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
@@ -1525,10 +1572,29 @@ LIGHT_SHADER_CODE
ambient_light*=ao;
#endif
- //energy conservation
- diffuse_light=mix(diffuse_light,vec3(0.0),specular);
- ambient_light=mix(ambient_light,vec3(0.0),specular);
- specular_light *= max(vec3(0.04),specular);
+
+
+
+
+
+ //energu conservation
+ diffuse_light=mix(diffuse_light,vec3(0.0),metallic);
+ ambient_light=mix(ambient_light,vec3(0.0),metallic);
+ {
+ //brdf approximation (Lazarov 2013)
+ float ndotv = clamp(dot(normal,eye_vec),0.0,1.0);
+
+ //energy conservation
+ vec3 dielectric = vec3(0.034) * 0.5 * 2.0;
+ vec3 f0 = mix(dielectric, albedo, metallic);
+ 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 brdf = vec2( -1.04, 1.04 ) * a004 + r.zw;
+
+ specular_light *= min(1.0,50.0 * f0.g) * brdf.y + brdf.x * f0;
+ }
#ifdef USE_MULTIPLE_RENDER_TARGETS
@@ -1545,7 +1611,7 @@ LIGHT_SHADER_CODE
#endif //ENABLE_AO
diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale);
- specular_buffer=vec4(specular_light,max(specular.r,max(specular.g,specular.b)));
+ specular_buffer=vec4(specular_light,metallic);
normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness);
diff --git a/drivers/gles3/shaders/ssao_blur.glsl b/drivers/gles3/shaders/ssao_blur.glsl
index ff852487c0..ce4154f50c 100644
--- a/drivers/gles3/shaders/ssao_blur.glsl
+++ b/drivers/gles3/shaders/ssao_blur.glsl
@@ -24,7 +24,7 @@ layout(location = 0) out float visibility;
// Tunable Parameters:
/** Increase to make depth edges crisper. Decrease to reduce flicker. */
-#define EDGE_SHARPNESS (1.0)
+#define EDGE_SHARPNESS (4.0)
/** Step in 2-pixel intervals since we already blurred against neighbors in the
first AO pass. This constant can be increased while R decreases to improve
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp
index fe2372e3af..33d271248c 100644
--- a/drivers/png/image_loader_png.cpp
+++ b/drivers/png/image_loader_png.cpp
@@ -201,7 +201,7 @@ Error ImageLoaderPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Image> p_i
return OK;
}
-Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f) {
+Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) {
Error err = _load_image(f, _read_png_data, p_image);
f->close();
@@ -256,6 +256,7 @@ static Ref<Image> _load_mem_png(const uint8_t *p_png, int p_size) {
static Ref<Image> _lossless_unpack_png(const PoolVector<uint8_t> &p_data) {
int len = p_data.size();
+ ERR_FAIL_COND_V(len < 4, Ref<Image>());
PoolVector<uint8_t>::Read r = p_data.read();
ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Ref<Image>());
return _load_mem_png(&r[4], len - 4);
diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h
index f94b8bce6e..f0a525a9eb 100644
--- a/drivers/png/image_loader_png.h
+++ b/drivers/png/image_loader_png.h
@@ -43,7 +43,7 @@ class ImageLoaderPNG : public ImageFormatLoader {
public:
static Error _load_image(void *rf_up, png_rw_ptr p_func, Ref<Image> p_image);
- virtual Error load_image(Ref<Image> p_image, FileAccess *f);
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderPNG();
};
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 8fb307a77d..7fe483c834 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -253,7 +253,7 @@ void EditorHelpSearch::_confirmed() {
String mdata = ti->get_metadata(0);
emit_signal("go_to_help", mdata);
- editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpSearch beeen invoked on top of other editor window
+ EditorNode::get_singleton()->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpSearch beeen invoked on top of other editor window
// go to that
hide();
}
@@ -288,7 +288,6 @@ void EditorHelpSearch::_bind_methods() {
EditorHelpSearch::EditorHelpSearch() {
- editor = EditorNode::get_singleton();
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
@@ -363,7 +362,7 @@ void EditorHelpIndex::_tree_item_selected() {
return;
emit_signal("open_class", s->get_text(0));
-
+ EditorNode::get_singleton()->call("_editor_select", EditorNode::EDITOR_SCRIPT);
hide();
//_goto_desc(s->get_text(0));
@@ -371,12 +370,11 @@ void EditorHelpIndex::_tree_item_selected() {
void EditorHelpIndex::select_class(const String &p_class) {
- EditorNode *editor = EditorNode::get_singleton();
if (!tree_item_map.has(p_class))
return;
tree_item_map[p_class]->select(0);
class_list->ensure_cursor_is_visible();
- editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpIndex beeen invoked on top of other editor window
+ EditorNode::get_singleton()->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpIndex beeen invoked on top of other editor window
}
void EditorHelpIndex::popup() {
@@ -1281,7 +1279,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
void EditorHelp::_request_help(const String &p_string) {
Error err = _goto_desc(p_string);
if (err == OK) {
- editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
+ EditorNode::get_singleton()->call("_editor_select", EditorNode::EDITOR_SCRIPT);
}
//100 palabras
}
@@ -1691,8 +1689,6 @@ void EditorHelp::_bind_methods() {
EditorHelp::EditorHelp() {
- editor = EditorNode::get_singleton();
-
VBoxContainer *vbc = this;
EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true);
diff --git a/editor/editor_help.h b/editor/editor_help.h
index d6fc0e3bf2..46d83490f4 100644
--- a/editor/editor_help.h
+++ b/editor/editor_help.h
@@ -49,7 +49,6 @@ class EditorHelpSearch : public ConfirmationDialog {
GDCLASS(EditorHelpSearch, ConfirmationDialog)
- EditorNode *editor;
LineEdit *search_box;
Tree *search_options;
String base_type;
@@ -119,7 +118,6 @@ class EditorHelp : public VBoxContainer {
String edited_class;
- EditorNode *editor;
Map<String, int> method_line;
Map<String, int> signal_line;
Map<String, int> property_line;
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index f00ad97ee8..c1f422cce3 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -889,6 +889,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
}
editor_data.apply_changes_in_editors();
+ _save_default_environment();
_set_scene_metadata(p_file, idx);
@@ -950,7 +951,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
_dialog_display_file_error(p_file, err);
}
-};
+}
void EditorNode::_import_action(const String &p_action) {
#if 0
@@ -1113,6 +1114,7 @@ void EditorNode::_dialog_action(String p_file) {
if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
//_save_scene(p_file);
+ _save_default_environment();
_save_scene_with_preview(p_file);
}
@@ -1122,6 +1124,7 @@ void EditorNode::_dialog_action(String p_file) {
if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
//_save_scene(p_file);
+ _save_default_environment();
_save_scene_with_preview(p_file);
_call_build();
_run(true);
@@ -1375,6 +1378,17 @@ void EditorNode::_property_editor_back() {
_edit_current();
}
+void EditorNode::_save_default_environment() {
+
+ Ref<Environment> fallback = get_tree()->get_root()->get_world()->get_fallback_environment();
+
+ if (fallback.is_valid() && fallback->get_path().is_resource_file()) {
+ Map<RES, bool> processed;
+ _find_and_save_edited_subresources(fallback.ptr(), processed, 0);
+ save_resource_in_path(fallback, fallback->get_path());
+ }
+}
+
void EditorNode::_imported(Node *p_node) {
/*
@@ -1453,11 +1467,16 @@ void EditorNode::_edit_current() {
Node *current_node = current_obj->cast_to<Node>();
ERR_FAIL_COND(!current_node);
- ERR_FAIL_COND(!current_node->is_inside_tree());
+ // ERR_FAIL_COND(!current_node->is_inside_tree());
property_editor->edit(current_node);
- node_dock->set_node(current_node);
- scene_tree_dock->set_selected(current_node);
+ if (current_node->is_inside_tree()) {
+ node_dock->set_node(current_node);
+ scene_tree_dock->set_selected(current_node);
+ } else {
+ node_dock->set_node(NULL);
+ scene_tree_dock->set_selected(NULL);
+ }
object_menu->get_popup()->clear();
//top_pallete->set_current_tab(0);
@@ -1951,6 +1970,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
}
} // else: ignore new scenes
}
+
+ _save_default_environment();
} break;
case FILE_SAVE_BEFORE_RUN: {
if (!p_confirmed) {
@@ -2384,6 +2405,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case RUN_PLAY_SCENE: {
+
+ _save_default_environment();
_menu_option_confirm(RUN_STOP, true);
_call_build();
_run(true);
@@ -5237,6 +5260,7 @@ EditorNode::EditorNode() {
p->add_separator();
p->add_item(TTR("Project Settings"), RUN_SETTINGS);
p->add_separator();
+
#ifdef OSX_ENABLED
p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q);
#else
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 55b3aa94d3..bb5b57a454 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -593,6 +593,7 @@ private:
static int plugin_init_callback_count;
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
+ void _save_default_environment();
void _call_build();
static int build_callback_count;
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 2cefcdbc4a..907c7b045c 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -402,8 +402,8 @@ Error ColladaImport::_create_material(const String &p_target) {
Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
if (texture.is_valid()) {
- material->set_texture(SpatialMaterial::TEXTURE_SPECULAR, texture);
- material->set_specular(Color(1, 1, 1, 1));
+ material->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture);
+ material->set_specular(1.0);
//material->set_texture(SpatialMaterial::PARAM_SPECULAR,texture);
//material->set_parameter(SpatialMaterial::PARAM_SPECULAR,Color(1,1,1,1));
@@ -411,8 +411,9 @@ Error ColladaImport::_create_material(const String &p_target) {
missing_textures.push_back(texfile.get_file());
}
}
+
} else {
- material->set_metalness(effect.specular.color.get_v());
+ material->set_metallic(effect.specular.color.get_v());
}
// EMISSION
@@ -553,10 +554,10 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c
tangent = Vector3();
} else {
tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
- (t2 * z1 - t1 * z2) * r)
+ (t2 * z1 - t1 * z2) * r)
.normalized();
binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
- (s1 * z2 - s2 * z1) * r)
+ (s1 * z2 - s2 * z1) * r)
.normalized();
}
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index f27a01d119..7e27f6c618 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -177,6 +177,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/srgb", PROPERTY_HINT_ENUM, "Disable,Enable,Detect"), 2));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/fix_alpha_border"), p_preset != PRESET_3D ? true : false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/premult_alpha"), true));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/HDR_as_SRGB"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "stream"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "detect_3d"), p_preset == PRESET_DETECT));
@@ -276,7 +277,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
if (p_force_rgbe && image->get_format() >= Image::FORMAT_R8 && image->get_format() <= Image::FORMAT_RGBE9995) {
image->convert(Image::FORMAT_RGBE9995);
} else {
- image->compress(p_vram_compression);
+ image->compress(p_vram_compression, p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR);
}
format |= image->get_format();
@@ -327,10 +328,11 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
bool stream = p_options["stream"];
int size_limit = p_options["size_limit"];
bool force_rgbe = int(p_options["compress/hdr_mode"]) == 1;
+ bool hdr_as_srgb = p_options["process/HDR_as_SRGB"];
Ref<Image> image;
image.instance();
- Error err = ImageLoader::load_image(p_source_file, image);
+ Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb);
if (err != OK)
return err;
diff --git a/editor/plugins/color_ramp_editor_plugin.cpp b/editor/plugins/color_ramp_editor_plugin.cpp
index 63369e5475..e4172db415 100644
--- a/editor/plugins/color_ramp_editor_plugin.cpp
+++ b/editor/plugins/color_ramp_editor_plugin.cpp
@@ -46,10 +46,10 @@ ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) {
void ColorRampEditorPlugin::edit(Object *p_object) {
- ColorRamp *color_ramp = p_object->cast_to<ColorRamp>();
+ Gradient *color_ramp = p_object->cast_to<Gradient>();
if (!color_ramp)
return;
- color_ramp_ref = Ref<ColorRamp>(color_ramp);
+ color_ramp_ref = Ref<Gradient>(color_ramp);
ramp_editor->set_points(color_ramp_ref->get_points());
}
diff --git a/editor/plugins/color_ramp_editor_plugin.h b/editor/plugins/color_ramp_editor_plugin.h
index 73b15b85a1..35446062b5 100644
--- a/editor/plugins/color_ramp_editor_plugin.h
+++ b/editor/plugins/color_ramp_editor_plugin.h
@@ -39,7 +39,7 @@ class ColorRampEditorPlugin : public EditorPlugin {
GDCLASS(ColorRampEditorPlugin, EditorPlugin);
bool _2d;
- Ref<ColorRamp> color_ramp_ref;
+ Ref<Gradient> color_ramp_ref;
ColorRampEdit *ramp_editor;
EditorNode *editor;
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index c4595b477e..ff4b5e430e 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2493,17 +2493,11 @@ Dictionary SpatialEditor::get_state() const {
d["viewports"] = vpdata;
- d["default_light"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT));
- d["ambient_light_color"] = settings_ambient_color->get_pick_color();
-
- d["default_srgb"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB));
d["show_grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID));
d["show_origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN));
d["fov"] = get_fov();
d["znear"] = get_znear();
d["zfar"] = get_zfar();
- d["deflight_rot_x"] = settings_default_light_rot_x;
- d["deflight_rot_y"] = settings_default_light_rot_y;
return d;
}
@@ -2565,26 +2559,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
if (d.has("fov"))
settings_fov->set_value(float(d["fov"]));
- if (d.has("default_light")) {
- bool use = d["default_light"];
-
- bool existing = light_instance.is_valid();
- if (use != existing) {
- if (existing) {
- VisualServer::get_singleton()->free(light_instance);
- light_instance = RID();
- } else {
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
- }
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), light_instance.is_valid());
- }
- }
- if (d.has("ambient_light_color")) {
- settings_ambient_color->set_pick_color(d["ambient_light_color"]);
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]);
- }
-
if (d.has("default_srgb")) {
bool use = d["default_srgb"];
@@ -2607,13 +2581,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
VisualServer::get_singleton()->instance_set_visible(origin_instance, use);
}
}
-
- if (d.has("deflight_rot_x"))
- settings_default_light_rot_x = d["deflight_rot_x"];
- if (d.has("deflight_rot_y"))
- settings_default_light_rot_y = d["deflight_rot_y"];
-
- _update_default_light_angle();
}
void SpatialEditor::edit(Spatial *p_spatial) {
@@ -2750,38 +2717,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
xform_dialog->popup_centered(Size2(200, 200));
} break;
- case MENU_VIEW_USE_DEFAULT_LIGHT: {
-
- bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option));
-
- if (is_checked) {
- VisualServer::get_singleton()->free(light_instance);
- light_instance = RID();
- } else {
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
-
- _update_default_light_angle();
- }
-
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid());
-
- } break;
- case MENU_VIEW_USE_DEFAULT_SRGB: {
-
- bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option));
-
- if (is_checked) {
- //viewport_environment->set_enable_fx(Environment::FX_SRGB,false);
- } else {
- //viewport_environment->set_enable_fx(Environment::FX_SRGB,true);
- }
-
- is_checked = !is_checked;
-
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked);
-
- } break;
case MENU_VIEW_USE_1_VIEWPORT: {
for (int i = 1; i < 4; i++) {
@@ -2993,14 +2928,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
void SpatialEditor::_init_indicators() {
- //make sure that the camera indicator is not selectable
- light = VisualServer::get_singleton()->light_create(VisualServer::LIGHT_DIRECTIONAL);
- //VisualServer::get_singleton()->light_set_shadow( light, true );
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
-
- light_transform.rotate(Vector3(1, 0, 0), -Math_PI / 5.0);
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
-
//RID mat = VisualServer::get_singleton()->fixed_material_create();
///VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
//VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
@@ -3258,8 +3185,6 @@ void SpatialEditor::_finish_indicators() {
VisualServer::get_singleton()->free(grid_instance[i]);
VisualServer::get_singleton()->free(grid[i]);
}
- VisualServer::get_singleton()->free(light_instance);
- VisualServer::get_singleton()->free(light);
//VisualServer::get_singleton()->free(poly);
//VisualServer::get_singleton()->free(indicators_instance);
//VisualServer::get_singleton()->free(indicators);
@@ -3351,14 +3276,12 @@ void SpatialEditor::_notification(int p_what) {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
get_tree()->connect("node_removed", this, "_node_removed");
- VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(), viewport_environment->get_rid());
}
if (p_what == NOTIFICATION_ENTER_TREE) {
gizmos = memnew(SpatialEditorGizmos);
_init_indicators();
- _update_default_light_angle();
}
if (p_what == NOTIFICATION_EXIT_TREE) {
@@ -3481,8 +3404,6 @@ void SpatialEditor::_bind_methods() {
ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action);
ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data);
ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo);
- ClassDB::bind_method("_default_light_angle_input", &SpatialEditor::_default_light_angle_input);
- ClassDB::bind_method("_update_ambient_light_color", &SpatialEditor::_update_ambient_light_color);
ClassDB::bind_method("_toggle_maximize_view", &SpatialEditor::_toggle_maximize_view);
ADD_SIGNAL(MethodInfo("transform_key_request"));
@@ -3517,43 +3438,6 @@ void SpatialEditor::clear() {
}
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true);
-
- settings_default_light_rot_x = Math_PI * 0.3;
- settings_default_light_rot_y = Math_PI * 0.2;
-
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
- settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15));
- if (!light_instance.is_valid())
- _menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT);
-
- _update_default_light_angle();
-}
-
-void SpatialEditor::_update_ambient_light_color(const Color &p_color) {
-
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color());
-}
-
-void SpatialEditor::_update_default_light_angle() {
-
- Transform t;
- t.basis.rotate(Vector3(1, 0, 0), -settings_default_light_rot_x);
- t.basis.rotate(Vector3(0, 1, 0), -settings_default_light_rot_y);
- settings_dlight->set_transform(t);
- if (light_instance.is_valid()) {
- VS::get_singleton()->instance_set_transform(light_instance, t);
- }
-}
-
-void SpatialEditor::_default_light_angle_input(const Ref<InputEvent> &p_event) {
-
- Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && mm->get_button_mask() & (0x1 | 0x2 | 0x4)) {
-
- settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - mm->get_relative().x * 0.01, Math_PI * 2.0);
- settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - mm->get_relative().y * 0.01, Math_PI * 2.0);
- _update_default_light_angle();
- }
}
SpatialEditor::SpatialEditor(EditorNode *p_editor) {
@@ -3674,10 +3558,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p = view_menu->get_popup();
- p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_light", TTR("Use Default Light")), MENU_VIEW_USE_DEFAULT_LIGHT);
- p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_srgb", TTR("Use Default sRGB")), MENU_VIEW_USE_DEFAULT_SRGB);
- p->add_separator();
-
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT);
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS);
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT);
@@ -3696,7 +3576,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p->add_separator();
p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS);
- p->set_item_checked(p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true);
@@ -3755,36 +3634,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
settings_dialog->add_child(settings_vbc);
//settings_dialog->set_child_rect(settings_vbc);
- settings_light_base = memnew(ViewportContainer);
- settings_light_base->set_custom_minimum_size(Size2(128, 128));
- settings_light_base->connect("gui_input", this, "_default_light_angle_input");
- settings_vbc->add_margin_child(TTR("Default Light Normal:"), settings_light_base);
- settings_light_vp = memnew(Viewport);
- settings_light_vp->set_disable_input(true);
- settings_light_vp->set_use_own_world(true);
- settings_light_base->add_child(settings_light_vp);
-
- settings_dlight = memnew(DirectionalLight);
- settings_light_vp->add_child(settings_dlight);
- settings_sphere = memnew(ImmediateGeometry);
- settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES, Ref<Texture>());
- settings_sphere->set_color(Color(1, 1, 1));
- settings_sphere->add_sphere(32, 16, 1);
- settings_sphere->end();
- settings_light_vp->add_child(settings_sphere);
- settings_camera = memnew(Camera);
- settings_light_vp->add_child(settings_camera);
- settings_camera->set_translation(Vector3(0, 0, 2));
- settings_camera->set_orthogonal(2.1, 0.1, 5);
-
- settings_default_light_rot_x = Math_PI * 0.3;
- settings_default_light_rot_y = Math_PI * 0.2;
-
- settings_ambient_color = memnew(ColorPickerButton);
- settings_vbc->add_margin_child(TTR("Ambient Light Color:"), settings_ambient_color);
- settings_ambient_color->connect("color_changed", this, "_update_ambient_light_color");
- settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15));
-
settings_fov = memnew(SpinBox);
settings_fov->set_max(179);
settings_fov->set_min(1);
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 1f76d9bfb8..88245ad0dc 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -321,10 +321,6 @@ private:
VisualServer::ScenarioDebugMode scenario_debug;
- RID light;
- RID light_instance;
- Transform light_transform;
-
RID origin;
RID origin_instance;
RID grid[3];
@@ -383,8 +379,6 @@ private:
MENU_VIEW_USE_3_VIEWPORTS,
MENU_VIEW_USE_3_VIEWPORTS_ALT,
MENU_VIEW_USE_4_VIEWPORTS,
- MENU_VIEW_USE_DEFAULT_LIGHT,
- MENU_VIEW_USE_DEFAULT_SRGB,
MENU_VIEW_DISPLAY_NORMAL,
MENU_VIEW_DISPLAY_WIREFRAME,
MENU_VIEW_DISPLAY_OVERDRAW,
@@ -419,16 +413,6 @@ private:
SpinBox *settings_fov;
SpinBox *settings_znear;
SpinBox *settings_zfar;
- DirectionalLight *settings_dlight;
- ImmediateGeometry *settings_sphere;
- Camera *settings_camera;
- float settings_default_light_rot_x;
- float settings_default_light_rot_y;
-
- ViewportContainer *settings_light_base;
- Viewport *settings_light_vp;
- ColorPickerButton *settings_ambient_color;
- Ref<Image> settings_light_dir_image;
void _xform_dialog_action();
void _menu_item_pressed(int p_option);
@@ -462,10 +446,6 @@ private:
SpatialEditorGizmos *gizmos;
SpatialEditor();
- void _update_ambient_light_color(const Color &p_color);
- void _update_default_light_angle();
- void _default_light_angle_input(const Ref<InputEvent> &p_event);
-
bool is_any_freelook_active() const;
protected:
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 50b518afba..a4e8ef70ce 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -203,10 +203,23 @@ private:
f->store_line("\n");
f->store_line("name=\"" + project_name->get_text() + "\"");
f->store_line("icon=\"res://icon.png\"");
-
+ f->store_line("[rendering]");
+ f->store_line("viewport/default_environment=\"res://default_env.tres\"");
memdelete(f);
ResourceSaver::save(dir.plus_file("/icon.png"), get_icon("DefaultProjectIcon", "EditorIcons"));
+
+ f = FileAccess::open(dir.plus_file("/default_env.tres"), FileAccess::WRITE);
+ if (!f) {
+ error->set_text(TTR("Couldn't create project.godot in project path."));
+ } else {
+ f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]");
+ f->store_line("[sub_resource type=\"ProceduralSky\" id=1]");
+ f->store_line("[resource]");
+ f->store_line("background_mode = 2");
+ f->store_line("background_sky = SubResource( 1 )");
+ memdelete(f);
+ }
}
} else if (mode == MODE_INSTALL) {
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index 95a1672e67..d21be24dab 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -462,6 +462,59 @@ uint32_t ihash3(uint32_t a) {
MainLoop *test() {
+ {
+ float r = 1;
+ float g = 0.5;
+ float b = 0.1;
+
+ const float pow2to9 = 512.0f;
+ const float B = 15.0f;
+ //const float Emax = 31.0f;
+ const float N = 9.0f;
+
+ float sharedexp = 65408.000f; //(( pow2to9 - 1.0f)/ pow2to9)*powf( 2.0f, 31.0f - 15.0f);
+
+ float cRed = MAX(0.0f, MIN(sharedexp, r));
+ float cGreen = MAX(0.0f, MIN(sharedexp, g));
+ float cBlue = MAX(0.0f, MIN(sharedexp, b));
+
+ float cMax = MAX(cRed, MAX(cGreen, cBlue));
+
+ // expp = MAX(-B - 1, log2(maxc)) + 1 + B
+
+ float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B;
+
+ float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
+
+ float exps = expp + 1.0f;
+
+ if (0.0 <= sMax && sMax < pow2to9) {
+ exps = expp;
+ }
+
+ float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f);
+ float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f);
+ float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f);
+
+ print_line("R: " + rtos(sRed) + " G: " + rtos(sGreen) + " B: " + rtos(sBlue) + " EXP: " + rtos(exps));
+
+ uint32_t rgbe = (Math::fast_ftoi(sRed) & 0x1FF) | ((Math::fast_ftoi(sGreen) & 0x1FF) << 9) | ((Math::fast_ftoi(sBlue) & 0x1FF) << 18) | ((Math::fast_ftoi(exps) & 0x1F) << 27);
+
+ float rb = rgbe & 0x1ff;
+ float gb = (rgbe >> 9) & 0x1ff;
+ float bb = (rgbe >> 18) & 0x1ff;
+ float eb = (rgbe >> 27);
+ float mb = Math::pow(2, eb - 15.0 - 9.0);
+ ;
+ float rd = rb * mb;
+ float gd = gb * mb;
+ float bd = bb * mb;
+
+ print_line("RGBE: " + Color(rd, gd, bd));
+
+ return NULL;
+ }
+
print_line("Dvectors: " + itos(MemoryPool::allocs_used));
print_line("Mem used: " + itos(MemoryPool::total_memory));
print_line("MAx mem used: " + itos(MemoryPool::max_memory));
diff --git a/misc/dist/osx_template.app/Contents/Resources/icon.icns b/misc/dist/osx_template.app/Contents/Resources/icon.icns
index 375f61437d..be9254630c 100644
--- a/misc/dist/osx_template.app/Contents/Resources/icon.icns
+++ b/misc/dist/osx_template.app/Contents/Resources/icon.icns
Binary files differ
diff --git a/misc/dist/osx_tools.app/Contents/Resources/Godot.icns b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns
index 375f61437d..be9254630c 100644
--- a/misc/dist/osx_tools.app/Contents/Resources/Godot.icns
+++ b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png
index 6cff663eb5..6e307e5eb8 100644
--- a/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png
index 12ec232c87..cb2516d7a0 100644
--- a/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png
index ad059994ed..6e14223e87 100644
--- a/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png
index b1bf331365..0d4bd54da8 100644
--- a/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png b/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png
index 8d7a625c82..1501a09557 100644
--- a/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png
Binary files differ
diff --git a/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png b/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png
index b06f1ad50f..593568e980 100644
--- a/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png
+++ b/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png
Binary files differ
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp
index da895a6d69..71593ebfa9 100644
--- a/modules/dds/texture_loader_dds.cpp
+++ b/modules/dds/texture_loader_dds.cpp
@@ -76,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = {
{ "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 },
{ "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 },
{ "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 },
- { "ATI1", true, false, 4, 8, Image::FORMAT_LATC_L },
- { "ATI2", true, false, 4, 16, Image::FORMAT_LATC_LA },
{ "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 },
{ "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 },
{ "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 },
diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp
index bf2ef35972..8cf6d1b8ef 100644
--- a/modules/gdnative/godot/godot_array.cpp
+++ b/modules/gdnative/godot/godot_array.cpp
@@ -49,6 +49,12 @@ void GDAPI godot_array_new(godot_array *p_arr) {
memnew_placement(a, Array);
}
+void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src) {
+ Array *dest = (Array *)p_dest;
+ const Array *src = (const Array *)p_src;
+ memnew_placement(dest, Array(*src));
+}
+
void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) {
Array *a = (Array *)p_arr;
PoolVector<Color> *pca = (PoolVector<Color> *)p_pca;
diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h
index f7150950fc..5db0031b8c 100644
--- a/modules/gdnative/godot/godot_array.h
+++ b/modules/gdnative/godot/godot_array.h
@@ -49,6 +49,7 @@ typedef struct godot_array {
#include "../godot.h"
void GDAPI godot_array_new(godot_array *p_arr);
+void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src);
void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca);
void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a);
void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a);
diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp
index b98ee5b5c9..deec5f8ffb 100644
--- a/modules/gdnative/godot/godot_dictionary.cpp
+++ b/modules/gdnative/godot/godot_dictionary.cpp
@@ -44,6 +44,12 @@ void GDAPI godot_dictionary_new(godot_dictionary *r_dest) {
memnew_placement(dest, Dictionary);
}
+void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src) {
+ Dictionary *dest = (Dictionary *)r_dest;
+ const Dictionary *src = (const Dictionary *)r_src;
+ memnew_placement(dest, Dictionary(*src));
+}
+
void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) {
Dictionary *self = (Dictionary *)p_self;
self->~Dictionary();
diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h
index 42f7f872a1..a89bd4bba1 100644
--- a/modules/gdnative/godot/godot_dictionary.h
+++ b/modules/gdnative/godot/godot_dictionary.h
@@ -48,6 +48,7 @@ typedef struct godot_dictionary {
#include "godot_variant.h"
void GDAPI godot_dictionary_new(godot_dictionary *r_dest);
+void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src);
void GDAPI godot_dictionary_destroy(godot_dictionary *p_self);
godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self);
diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp
index 10d5d6d939..ff4586ebe7 100644
--- a/modules/gdnative/godot/godot_pool_arrays.cpp
+++ b/modules/gdnative/godot/godot_pool_arrays.cpp
@@ -49,6 +49,12 @@ void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) {
memnew_placement(pba, PoolVector<uint8_t>);
}
+void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src) {
+ PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)p_dest;
+ const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src;
+ memnew_placement(dest, PoolVector<uint8_t>(*src));
+}
+
void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) {
PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba;
Array *a = (Array *)p_a;
@@ -118,14 +124,20 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) {
// int
void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) {
- PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba;
- memnew_placement(pba, PoolVector<uint8_t>);
+ PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba;
+ memnew_placement(pba, PoolVector<godot_int>);
+}
+
+void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src) {
+ PoolVector<godot_int> *dest = (PoolVector<godot_int> *)p_dest;
+ const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src;
+ memnew_placement(dest, PoolVector<godot_int>(*src));
}
void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) {
- PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba;
+ PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba;
Array *a = (Array *)p_a;
- memnew_placement(pba, PoolVector<uint8_t>);
+ memnew_placement(pba, PoolVector<godot_int>);
pba->resize(a->size());
for (size_t i = 0; i < a->size(); i++) {
@@ -191,14 +203,20 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) {
// real
void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) {
- PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba;
- memnew_placement(pba, PoolVector<uint8_t>);
+ PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba;
+ memnew_placement(pba, PoolVector<godot_real>);
+}
+
+void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src) {
+ PoolVector<godot_real> *dest = (PoolVector<godot_real> *)p_dest;
+ const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src;
+ memnew_placement(dest, PoolVector<godot_real>(*src));
}
void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) {
- PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba;
+ PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba;
Array *a = (Array *)p_a;
- memnew_placement(pba, PoolVector<uint8_t>);
+ memnew_placement(pba, PoolVector<godot_real>);
pba->resize(a->size());
for (size_t i = 0; i < a->size(); i++) {
@@ -268,6 +286,12 @@ void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) {
memnew_placement(pba, PoolVector<String>);
}
+void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src) {
+ PoolVector<String> *dest = (PoolVector<String> *)p_dest;
+ const PoolVector<String> *src = (const PoolVector<String> *)p_src;
+ memnew_placement(dest, PoolVector<String>(*src));
+}
+
void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) {
PoolVector<String> *pba = (PoolVector<String> *)p_pba;
Array *a = (Array *)p_a;
@@ -349,6 +373,12 @@ void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) {
memnew_placement(pba, PoolVector<Vector2>);
}
+void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src) {
+ PoolVector<Vector2> *dest = (PoolVector<Vector2> *)p_dest;
+ const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src;
+ memnew_placement(dest, PoolVector<Vector2>(*src));
+}
+
void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) {
PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba;
Array *a = (Array *)p_a;
@@ -429,6 +459,12 @@ void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) {
memnew_placement(pba, PoolVector<Vector3>);
}
+void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src) {
+ PoolVector<Vector3> *dest = (PoolVector<Vector3> *)p_dest;
+ const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src;
+ memnew_placement(dest, PoolVector<Vector3>(*src));
+}
+
void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) {
PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba;
Array *a = (Array *)p_a;
@@ -509,6 +545,12 @@ void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) {
memnew_placement(pba, PoolVector<Color>);
}
+void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src) {
+ PoolVector<Color> *dest = (PoolVector<Color> *)p_dest;
+ const PoolVector<Color> *src = (const PoolVector<Color> *)p_src;
+ memnew_placement(dest, PoolVector<Color>(*src));
+}
+
void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) {
PoolVector<Color> *pba = (PoolVector<Color> *)p_pba;
Array *a = (Array *)p_a;
diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h
index 015be65c3e..8b0d0137fd 100644
--- a/modules/gdnative/godot/godot_pool_arrays.h
+++ b/modules/gdnative/godot/godot_pool_arrays.h
@@ -102,6 +102,7 @@ typedef struct godot_pool_color_array {
// byte
void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba);
+void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src);
void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a);
void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data);
@@ -128,6 +129,7 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba);
// int
void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia);
+void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src);
void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a);
void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data);
@@ -154,6 +156,7 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia);
// real
void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra);
+void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src);
void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a);
void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data);
@@ -180,6 +183,7 @@ void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra);
// string
void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa);
+void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src);
void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a);
void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data);
@@ -206,6 +210,7 @@ void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa);
// vector2
void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a);
+void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src);
void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a);
void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data);
@@ -232,6 +237,7 @@ void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a);
// vector3
void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a);
+void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src);
void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a);
void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data);
@@ -258,6 +264,7 @@ void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a);
// color
void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca);
+void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src);
void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a);
void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data);
diff --git a/modules/hdr/SCsub b/modules/hdr/SCsub
new file mode 100644
index 0000000000..c960e8126b
--- /dev/null
+++ b/modules/hdr/SCsub
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+
+Import('env')
+Import('env_modules')
+
+env_hdr = env_modules.Clone()
+
+# Godot's own source files
+env_hdr.add_source_files(env.modules_sources, "*.cpp")
diff --git a/modules/hdr/config.py b/modules/hdr/config.py
new file mode 100644
index 0000000000..fb920482f5
--- /dev/null
+++ b/modules/hdr/config.py
@@ -0,0 +1,7 @@
+
+def can_build(platform):
+ return True
+
+
+def configure(env):
+ pass
diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp
new file mode 100644
index 0000000000..85819104cf
--- /dev/null
+++ b/modules/hdr/image_loader_hdr.cpp
@@ -0,0 +1,161 @@
+/*************************************************************************/
+/* image_loader_jpegd.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "image_loader_hdr.h"
+
+#include "os/os.h"
+#include "print_string.h"
+
+#include "thirdparty/tinyexr/tinyexr.h"
+
+Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) {
+
+ String header = f->get_token();
+
+ print_line("HEADER: " + header);
+ ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED);
+
+ while (true) {
+ String format = f->get_token();
+ ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED);
+ if (format.begins_with("FORMAT=") && format != "FORMAT=32-bit_rle_rgbe") {
+ ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for .hdr files.");
+ return ERR_FILE_UNRECOGNIZED;
+ }
+ if (format == "FORMAT=32-bit_rle_rgbe")
+ break;
+ }
+
+ String token = f->get_token();
+
+ ERR_FAIL_COND_V(token != "-Y", ERR_FILE_CORRUPT);
+
+ int height = f->get_token().to_int();
+
+ token = f->get_token();
+
+ ERR_FAIL_COND_V(token != "+X", ERR_FILE_CORRUPT);
+
+ int width = f->get_line().to_int();
+
+ print_line("HDR w: " + itos(width) + " h:" + itos(height));
+
+ PoolVector<uint8_t> imgdata;
+
+ imgdata.resize(height * width * sizeof(uint32_t));
+
+ {
+
+ PoolVector<uint8_t>::Write w = imgdata.write();
+
+ uint8_t *ptr = (uint8_t *)w.ptr();
+
+ if (width < 8 || width >= 32768) {
+ // Read flat data
+
+ f->get_buffer(ptr, width * height * 4);
+ } else {
+ // Read RLE-encoded data
+
+ for (int j = 0; j < height; ++j) {
+ int c1 = f->get_8();
+ int c2 = f->get_8();
+ int len = f->get_8();
+ if (c1 != 2 || c2 != 2 || (len & 0x80)) {
+ // not run-length encoded, so we have to actually use THIS data as a decoded
+ // pixel (note this can't be a valid pixel--one of RGB must be >= 128)
+
+ ptr[(j * width) * 4 + 0] = uint8_t(c1);
+ ptr[(j * width) * 4 + 1] = uint8_t(c2);
+ ptr[(j * width) * 4 + 2] = uint8_t(len);
+ ptr[(j * width) * 4 + 3] = f->get_8();
+
+ f->get_buffer(&ptr[(j * width + 1) * 4], (width - 1) * 4);
+ continue;
+ }
+ len <<= 8;
+ len |= f->get_8();
+
+ print_line("line: " + itos(len));
+ if (len != width) {
+ ERR_EXPLAIN("invalid decoded scanline length, corrupt HDR");
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
+ }
+
+ for (int k = 0; k < 4; ++k) {
+ int i = 0;
+ while (i < width) {
+ int count = f->get_8();
+ if (count > 128) {
+ // Run
+ int value = f->get_8();
+ count -= 128;
+ for (int z = 0; z < count; ++z)
+ ptr[(j * width + i++) * 4 + k] = uint8_t(value);
+ } else {
+ // Dump
+ for (int z = 0; z < count; ++z)
+ ptr[(j * width + i++) * 4 + k] = f->get_8();
+ }
+ }
+ }
+ }
+ }
+
+ //convert
+ for (int i = 0; i < width * height; i++) {
+
+ float exp = pow(2, ptr[3] - 128);
+
+ Color c(
+ ptr[0] * exp / 255.0,
+ ptr[1] * exp / 255.0,
+ ptr[2] * exp / 255.0);
+
+ if (p_force_linear) {
+ c = c.to_linear();
+ }
+
+ *(uint32_t *)ptr = c.to_rgbe9995();
+ ptr += 4;
+ }
+ }
+
+ p_image->create(width, height, false, Image::FORMAT_RGBE9995, imgdata);
+
+ return OK;
+}
+
+void ImageLoaderHDR::get_recognized_extensions(List<String> *p_extensions) const {
+
+ p_extensions->push_back("hdr");
+}
+
+ImageLoaderHDR::ImageLoaderHDR() {
+}
diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h
new file mode 100644
index 0000000000..9bc1fadd13
--- /dev/null
+++ b/modules/hdr/image_loader_hdr.h
@@ -0,0 +1,46 @@
+/*************************************************************************/
+/* image_loader_jpegd.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef IMAGE_LOADER_TINYEXR_H
+#define IMAGE_LOADER_TINYEXR_H
+
+#include "io/image_loader.h"
+
+/**
+ @author Juan Linietsky <reduzio@gmail.com>
+*/
+class ImageLoaderHDR : public ImageFormatLoader {
+
+public:
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ ImageLoaderHDR();
+};
+
+#endif
diff --git a/modules/hdr/register_types.cpp b/modules/hdr/register_types.cpp
new file mode 100644
index 0000000000..e4f7c14aa7
--- /dev/null
+++ b/modules/hdr/register_types.cpp
@@ -0,0 +1,45 @@
+/*************************************************************************/
+/* register_types.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "register_types.h"
+
+#include "image_loader_hdr.h"
+
+static ImageLoaderHDR *image_loader_hdr = NULL;
+
+void register_hdr_types() {
+
+ image_loader_hdr = memnew(ImageLoaderHDR);
+ ImageLoader::add_image_format_loader(image_loader_hdr);
+}
+
+void unregister_hdr_types() {
+
+ memdelete(image_loader_hdr);
+}
diff --git a/modules/hdr/register_types.h b/modules/hdr/register_types.h
new file mode 100644
index 0000000000..3d901ea003
--- /dev/null
+++ b/modules/hdr/register_types.h
@@ -0,0 +1,31 @@
+/*************************************************************************/
+/* register_types.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+void register_hdr_types();
+void unregister_hdr_types();
diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp
index 0741dd198a..8c73b69f1b 100644
--- a/modules/jpg/image_loader_jpegd.cpp
+++ b/modules/jpg/image_loader_jpegd.cpp
@@ -89,7 +89,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
return OK;
}
-Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f) {
+Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) {
PoolVector<uint8_t> src_image;
int src_image_len = f->get_len();
diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h
index 57d7a2bb1c..aa073b493d 100644
--- a/modules/jpg/image_loader_jpegd.h
+++ b/modules/jpg/image_loader_jpegd.h
@@ -38,7 +38,7 @@
class ImageLoaderJPG : public ImageFormatLoader {
public:
- virtual Error load_image(Ref<Image> p_image, FileAccess *f);
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderJPG();
};
diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp
index 2427dac8a7..e927f1ceaa 100644
--- a/modules/squish/image_compress_squish.cpp
+++ b/modules/squish/image_compress_squish.cpp
@@ -59,9 +59,9 @@ void image_decompress_squish(Image *p_image) {
squish_flags = squish::kDxt3;
} else if (p_image->get_format() == Image::FORMAT_DXT5) {
squish_flags = squish::kDxt5;
- } else if (p_image->get_format() == Image::FORMAT_LATC_L || p_image->get_format() == Image::FORMAT_RGTC_R) {
+ } else if (p_image->get_format() == Image::FORMAT_RGTC_R) {
squish_flags = squish::kBc4;
- } else if (p_image->get_format() == Image::FORMAT_LATC_LA || p_image->get_format() == Image::FORMAT_RGTC_RG) {
+ } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) {
squish_flags = squish::kBc5;
} else {
ERR_FAIL_COND(true);
@@ -79,7 +79,7 @@ void image_decompress_squish(Image *p_image) {
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
}
-void image_compress_squish(Image *p_image) {
+void image_compress_squish(Image *p_image, bool p_srgb) {
if (p_image->get_format() >= Image::FORMAT_DXT1)
return; //do not compress, already compressed
@@ -96,16 +96,21 @@ void image_compress_squish(Image *p_image) {
p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert
+ if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) {
+ //R and RG do not support SRGB
+ dc = Image::DETECTED_RGB;
+ }
+
switch (dc) {
case Image::DETECTED_L: {
- target_format = Image::FORMAT_LATC_L;
- squish_comp |= squish::kBc4;
+ target_format = Image::FORMAT_DXT1;
+ squish_comp |= squish::kDxt1;
} break;
case Image::DETECTED_LA: {
- target_format = Image::FORMAT_LATC_LA;
- squish_comp |= squish::kBc5;
+ target_format = Image::FORMAT_DXT5;
+ squish_comp |= squish::kDxt5;
} break;
case Image::DETECTED_R: {
@@ -148,8 +153,8 @@ void image_compress_squish(Image *p_image) {
int bh = h % 4 != 0 ? h + (4 - h % 4) : h;
int src_ofs = p_image->get_mipmap_offset(i);
- squish::CompressImage(&rb[src_ofs], bw, bh, &wb[dst_ofs], squish_comp);
- dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift;
+ squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp);
+ dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift;
w >>= 1;
h >>= 1;
}
diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h
index 519e3537ef..8d859b8e0b 100644
--- a/modules/squish/image_compress_squish.h
+++ b/modules/squish/image_compress_squish.h
@@ -32,7 +32,7 @@
#include "image.h"
-void image_compress_squish(Image *p_image);
+void image_compress_squish(Image *p_image, bool p_srgb);
void image_decompress_squish(Image *p_image);
#endif // IMAGE_COMPRESS_SQUISH_H
diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp
index fbf5dea15e..4eb91da10b 100644
--- a/modules/tinyexr/image_loader_tinyexr.cpp
+++ b/modules/tinyexr/image_loader_tinyexr.cpp
@@ -34,7 +34,7 @@
#include "thirdparty/tinyexr/tinyexr.h"
-Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f) {
+Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) {
PoolVector<uint8_t> src_image;
int src_image_len = f->get_len();
@@ -133,9 +133,17 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f) {
// Assume `out_rgba` have enough memory allocated.
for (int i = 0; i < exr_image.width * exr_image.height; i++) {
- *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxR][i]);
- *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxG][i]);
- *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxB][i]);
+ Color color(
+ reinterpret_cast<float **>(exr_image.images)[idxR][i],
+ reinterpret_cast<float **>(exr_image.images)[idxG][i],
+ reinterpret_cast<float **>(exr_image.images)[idxB][i]);
+
+ if (p_force_linear)
+ color = color.to_linear();
+
+ *iw++ = Math::make_half_float(color.r);
+ *iw++ = Math::make_half_float(color.g);
+ *iw++ = Math::make_half_float(color.b);
if (idxA > 0) {
*iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxA][i]);
diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h
index 328ac2a385..a52894b12b 100644
--- a/modules/tinyexr/image_loader_tinyexr.h
+++ b/modules/tinyexr/image_loader_tinyexr.h
@@ -38,7 +38,7 @@
class ImageLoaderTinyEXR : public ImageFormatLoader {
public:
- virtual Error load_image(Ref<Image> p_image, FileAccess *f);
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderTinyEXR();
};
diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp
index 7313cb6c7c..87c2e811b3 100644
--- a/modules/webp/image_loader_webp.cpp
+++ b/modules/webp/image_loader_webp.cpp
@@ -115,7 +115,7 @@ static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) {
return img;
}
-Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f) {
+Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) {
uint32_t size = f->get_len();
PoolVector<uint8_t> src_image;
diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h
index ba817e0ecd..1ac2196a71 100644
--- a/modules/webp/image_loader_webp.h
+++ b/modules/webp/image_loader_webp.h
@@ -38,7 +38,7 @@
class ImageLoaderWEBP : public ImageFormatLoader {
public:
- virtual Error load_image(Ref<Image> p_image, FileAccess *f);
+ virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
ImageLoaderWEBP();
};
diff --git a/platform/windows/godot.ico b/platform/windows/godot.ico
index 3e52f2e52f..fd5c28944f 100644
--- a/platform/windows/godot.ico
+++ b/platform/windows/godot.ico
Binary files differ
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 8534185389..2a912a7ba2 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -336,7 +336,9 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
cursor_theme = XcursorGetTheme(x11_display);
if (!cursor_theme) {
- WARN_PRINT("Could not find cursor theme");
+ if (is_stdout_verbose()) {
+ print_line("XcursorGetTheme could not get cursor theme");
+ }
cursor_theme = "default";
}
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index c782968ea0..80969d11b3 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -99,7 +99,7 @@ Color Line2D::get_default_color() const {
return _default_color;
}
-void Line2D::set_gradient(const Ref<ColorRamp> &gradient) {
+void Line2D::set_gradient(const Ref<Gradient> &gradient) {
// Cleanup previous connection if any
if (_gradient.is_valid()) {
@@ -116,7 +116,7 @@ void Line2D::set_gradient(const Ref<ColorRamp> &gradient) {
update();
}
-Ref<ColorRamp> Line2D::get_gradient() const {
+Ref<Gradient> Line2D::get_gradient() const {
return _gradient;
}
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index fee1cad942..e8ca5e6e7c 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -57,8 +57,8 @@ public:
void set_default_color(Color color);
Color get_default_color() const;
- void set_gradient(const Ref<ColorRamp> &gradient);
- Ref<ColorRamp> get_gradient() const;
+ void set_gradient(const Ref<Gradient> &gradient);
+ Ref<Gradient> get_gradient() const;
void set_texture(const Ref<Texture> &texture);
Ref<Texture> get_texture() const;
@@ -97,7 +97,7 @@ private:
LineCapMode _end_cap_mode;
float _width;
Color _default_color;
- Ref<ColorRamp> _gradient;
+ Ref<Gradient> _gradient;
Ref<Texture> _texture;
LineTextureMode _texture_mode;
float _sharp_limit;
diff --git a/scene/2d/line_builder.h b/scene/2d/line_builder.h
index eed9cac0aa..0e1a2aaf50 100644
--- a/scene/2d/line_builder.h
+++ b/scene/2d/line_builder.h
@@ -62,7 +62,7 @@ public:
LineCapMode end_cap_mode;
float width;
Color default_color;
- ColorRamp *gradient;
+ Gradient *gradient;
LineTextureMode texture_mode;
float sharp_limit;
int round_precision;
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index b91d9b835c..951861256e 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -774,12 +774,12 @@ Color Particles2D::get_color() const {
return default_color;
}
-void Particles2D::set_color_ramp(const Ref<ColorRamp> &p_color_ramp) {
+void Particles2D::set_color_ramp(const Ref<Gradient> &p_color_ramp) {
color_ramp = p_color_ramp;
}
-Ref<ColorRamp> Particles2D::get_color_ramp() const {
+Ref<Gradient> Particles2D::get_color_ramp() const {
return color_ramp;
}
@@ -810,7 +810,7 @@ void Particles2D::set_color_phases(int p_phases) {
//Create color ramp if we have 2 or more phases.
//Otherwise first phase phase will be assigned to default color.
if (p_phases > 1 && color_ramp.is_null()) {
- color_ramp = Ref<ColorRamp>(memnew(ColorRamp()));
+ color_ramp = Ref<Gradient>(memnew(Gradient()));
}
if (color_ramp.is_valid()) {
color_ramp->get_points().resize(p_phases);
diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h
index 4b87a26195..5769fdd251 100644
--- a/scene/2d/particles_2d.h
+++ b/scene/2d/particles_2d.h
@@ -169,7 +169,7 @@ private:
//If no color ramp is set then default color is used. Created as simple alternative to color_ramp.
Color default_color;
- Ref<ColorRamp> color_ramp;
+ Ref<Gradient> color_ramp;
void _process_particles(float p_delta);
friend class ParticleAttractor2D;
@@ -241,8 +241,8 @@ public:
void set_color(const Color &p_color);
Color get_color() const;
- void set_color_ramp(const Ref<ColorRamp> &p_texture);
- Ref<ColorRamp> get_color_ramp() const;
+ void set_color_ramp(const Ref<Gradient> &p_texture);
+ Ref<Gradient> get_color_ramp() const;
void set_emissor_offset(const Point2 &p_offset);
Point2 get_emissor_offset() const;
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index 96311236ef..2acbed3b4e 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -885,7 +885,7 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo
Vector<Color> ret;
- if (p_image.is_null()) {
+ if (p_image.is_null() || p_image->empty()) {
ret.resize(bake_texture_size * bake_texture_size);
for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
@@ -894,9 +894,11 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo
return ret;
}
+ p_image = p_image->duplicate();
if (p_image->is_compressed()) {
print_line("DECOMPRESSING!!!!");
+
p_image->decompress();
}
p_image->convert(Image::FORMAT_RGBA8);
@@ -907,10 +909,11 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo
for (int i = 0; i < bake_texture_size * bake_texture_size; i++) {
Color c;
- c.r = r[i * 4 + 0] / 255.0;
- c.g = r[i * 4 + 1] / 255.0;
- c.b = r[i * 4 + 2] / 255.0;
+ c.r = (r[i * 4 + 0] / 255.0) * p_color.r;
+ c.g = (r[i * 4 + 1] / 255.0) * p_color.g;
+ c.b = (r[i * 4 + 2] / 255.0) * p_color.b;
c.a = r[i * 4 + 3] / 255.0;
+
ret[i] = c;
}
@@ -1277,6 +1280,7 @@ void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<Multi
xform.basis.scale(p_aabb.size * 0.5);
p_multimesh->set_instance_transform(idx, xform);
Color col = Color(p_baker->bake_cells[p_idx].albedo[0], p_baker->bake_cells[p_idx].albedo[1], p_baker->bake_cells[p_idx].albedo[2]);
+ //Color col = Color(p_baker->bake_cells[p_idx].emission[0], p_baker->bake_cells[p_idx].emission[1], p_baker->bake_cells[p_idx].emission[2]);
p_multimesh->set_instance_color(idx, col);
idx++;
@@ -1464,7 +1468,7 @@ GIProbe::GIProbe() {
subdiv = SUBDIV_128;
dynamic_range = 4;
energy = 1.0;
- bias = 0.4;
+ bias = 1.8;
propagation = 1.0;
extents = Vector3(10, 10, 10);
color_scan_cell_width = 4;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index c4ea42d461..543b64bd15 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -202,6 +202,7 @@ void AnimationPlayer::_notification(int p_what) {
if (!get_tree()->is_editor_hint() && animation_set.has(autoplay)) {
play(autoplay);
set_autoplay(""); //this line is the fix for autoplay issues with animatio
+ _animation_process(0);
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp
index 9270b97e02..8c47f8559a 100644
--- a/scene/gui/color_ramp_edit.cpp
+++ b/scene/gui/color_ramp_edit.cpp
@@ -114,7 +114,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (grabbed != -1) {
int total_w = get_size().width - get_size().height - 3;
- ColorRamp::Point newPoint = points[grabbed];
+ Gradient::Point newPoint = points[grabbed];
newPoint.offset = CLAMP(x / float(total_w), 0, 1);
points.push_back(newPoint);
@@ -152,11 +152,11 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
//insert
- ColorRamp::Point newPoint;
+ Gradient::Point newPoint;
newPoint.offset = CLAMP(x / float(total_w), 0, 1);
- ColorRamp::Point prev;
- ColorRamp::Point next;
+ Gradient::Point prev;
+ Gradient::Point next;
int pos = -1;
for (int i = 0; i < points.size(); i++) {
@@ -293,7 +293,7 @@ void ColorRampEdit::_notification(int p_what) {
_draw_checker(0, 0, total_w, h);
//Draw color ramp
- ColorRamp::Point prev;
+ Gradient::Point prev;
prev.offset = 0;
if (points.size() == 0)
prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
@@ -302,7 +302,7 @@ void ColorRampEdit::_notification(int p_what) {
for (int i = -1; i < points.size(); i++) {
- ColorRamp::Point next;
+ Gradient::Point next;
//If there is no next point
if (i + 1 == points.size()) {
if (points.size() == 0)
@@ -410,7 +410,7 @@ void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
ERR_FAIL_COND(p_offsets.size() != p_colors.size());
points.clear();
for (int i = 0; i < p_offsets.size(); i++) {
- ColorRamp::Point p;
+ Gradient::Point p;
p.offset = p_offsets[i];
p.color = p_colors[i];
points.push_back(p);
@@ -434,14 +434,14 @@ Vector<Color> ColorRampEdit::get_colors() const {
return ret;
}
-void ColorRampEdit::set_points(Vector<ColorRamp::Point> &p_points) {
+void ColorRampEdit::set_points(Vector<Gradient::Point> &p_points) {
if (points.size() != p_points.size())
grabbed = -1;
points.clear();
points = p_points;
}
-Vector<ColorRamp::Point> &ColorRampEdit::get_points() {
+Vector<Gradient::Point> &ColorRampEdit::get_points() {
return points;
}
diff --git a/scene/gui/color_ramp_edit.h b/scene/gui/color_ramp_edit.h
index ede8954040..0fe447c43a 100644
--- a/scene/gui/color_ramp_edit.h
+++ b/scene/gui/color_ramp_edit.h
@@ -48,7 +48,7 @@ class ColorRampEdit : public Control {
bool grabbing;
int grabbed;
- Vector<ColorRamp::Point> points;
+ Vector<Gradient::Point> points;
void _draw_checker(int x, int y, int w, int h);
void _color_changed(const Color &p_color);
@@ -64,8 +64,8 @@ public:
void set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors);
Vector<float> get_offsets() const;
Vector<Color> get_colors() const;
- void set_points(Vector<ColorRamp::Point> &p_points);
- Vector<ColorRamp::Point> &get_points();
+ void set_points(Vector<Gradient::Point> &p_points);
+ Vector<Gradient::Point> &get_points();
virtual Size2 get_minimum_size() const;
ColorRampEdit();
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 1263dc91be..83fa20bee5 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1352,7 +1352,7 @@ void Control::_change_notify_margins() {
_change_notify("margin_top");
_change_notify("margin_right");
_change_notify("margin_bottom");
- _change_notify("rect_pos");
+ _change_notify("rect_position");
_change_notify("rect_size");
}
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index b55a925f55..96a3519840 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -37,6 +37,7 @@
#include "print_string.h"
#include <stdio.h>
//#include "servers/spatial_sound_2d_server.h"
+
#include "io/marshalls.h"
#include "io/resource_loader.h"
#include "scene/resources/material.h"
@@ -609,6 +610,30 @@ bool SceneTree::idle(float p_time) {
_call_idle_callbacks();
+#ifdef TOOLS_ENABLED
+
+ if (is_editor_hint()) {
+ //simple hack to reload fallback environment if it changed from editor
+ String env_path = GlobalConfig::get_singleton()->get("rendering/viewport/default_environment");
+ env_path = env_path.strip_edges(); //user may have added a space or two
+ String cpath;
+ Ref<Environment> fallback = get_root()->get_world()->get_fallback_environment();
+ if (fallback.is_valid()) {
+ cpath = fallback->get_path();
+ }
+ if (cpath != env_path) {
+
+ if (env_path != String()) {
+ fallback = ResourceLoader::load(env_path);
+ } else {
+ fallback.unref();
+ }
+ get_root()->get_world()->set_fallback_environment(fallback);
+ }
+ }
+
+#endif
+
return _quit;
}
@@ -2301,7 +2326,9 @@ SceneTree::SceneTree() {
root = memnew(Viewport);
root->set_name("root");
- root->set_world(Ref<World>(memnew(World)));
+ if (!root->get_world().is_valid())
+ root->set_world(Ref<World>(memnew(World)));
+
//root->set_world_2d( Ref<World2D>( memnew( World2D )));
root->set_as_audio_listener(true);
root->set_as_audio_listener_2d(true);
@@ -2317,6 +2344,37 @@ SceneTree::SceneTree() {
VS::get_singleton()->scenario_set_reflection_atlas_size(root->get_world()->get_scenario(), ref_atlas_size, ref_atlas_subdiv);
+ { //load default fallback environment
+ //get possible extensions
+ List<String> exts;
+ ResourceLoader::get_recognized_extensions_for_type("Environment", &exts);
+ String ext_hint;
+ for (List<String>::Element *E = exts.front(); E; E = E->next()) {
+ if (ext_hint != String())
+ ext_hint += ",";
+ ext_hint += "*." + E->get();
+ }
+ //get path
+ String env_path = GLOBAL_DEF("rendering/viewport/default_environment", "");
+ //setup property
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/viewport/default_environment", PropertyInfo(Variant::STRING, "rendering/viewport/default_environment", PROPERTY_HINT_FILE, ext_hint));
+ env_path = env_path.strip_edges();
+ if (env_path != String()) {
+ Ref<Environment> env = ResourceLoader::load(env_path);
+ if (env.is_valid()) {
+ root->get_world()->set_fallback_environment(env);
+ } else {
+ if (is_editor_hint()) {
+ //file was erased, clear the field.
+ GlobalConfig::get_singleton()->set("rendering/viewport/default_environment", "");
+ } else {
+ //file was erased, notify user.
+ ERR_PRINTS(RTR("Default Environment as specified in Project Setings (Rendering -> Viewport -> Default Environment) could not be loaded."));
+ }
+ }
+ }
+ }
+
stretch_mode = STRETCH_MODE_DISABLED;
stretch_aspect = STRETCH_ASPECT_IGNORE;
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 4c359f73ab..0a3f64eacd 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -563,6 +563,7 @@ void register_scene_types() {
ClassDB::register_virtual_class<Texture>();
ClassDB::register_virtual_class<Sky>();
ClassDB::register_class<PanoramaSky>();
+ ClassDB::register_class<ProceduralSky>();
ClassDB::register_class<StreamTexture>();
ClassDB::register_class<ImageTexture>();
ClassDB::register_class<AtlasTexture>();
@@ -584,7 +585,7 @@ void register_scene_types() {
ClassDB::register_class<PolygonPathFinder>();
ClassDB::register_class<BitMap>();
- ClassDB::register_class<ColorRamp>();
+ ClassDB::register_class<Gradient>();
OS::get_singleton()->yield(); //may take time to init
diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp
index 3c58a76998..3cf8845189 100644
--- a/scene/resources/color_ramp.cpp
+++ b/scene/resources/color_ramp.cpp
@@ -36,7 +36,7 @@
#define COLOR_RAMP_SET_OFFSETS "set_offsets"
#define COLOR_RAMP_SET_COLORS "set_colors"
-ColorRamp::ColorRamp() {
+Gradient::Gradient() {
//Set initial color ramp transition from black to white
points.resize(2);
points[0].color = Color(0, 0, 0, 1);
@@ -46,35 +46,35 @@ ColorRamp::ColorRamp() {
is_sorted = true;
}
-ColorRamp::~ColorRamp() {
+Gradient::~Gradient() {
}
-void ColorRamp::_bind_methods() {
+void Gradient::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_point", "offset", "color"), &ColorRamp::add_point);
- ClassDB::bind_method(D_METHOD("remove_point", "offset", "color"), &ColorRamp::remove_point);
+ ClassDB::bind_method(D_METHOD("add_point", "offset", "color"), &Gradient::add_point);
+ ClassDB::bind_method(D_METHOD("remove_point", "offset", "color"), &Gradient::remove_point);
- ClassDB::bind_method(D_METHOD("set_offset", "point", "offset"), &ColorRamp::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset", "point"), &ColorRamp::get_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "point", "offset"), &Gradient::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset", "point"), &Gradient::get_offset);
- ClassDB::bind_method(D_METHOD("set_color", "point", "color"), &ColorRamp::set_color);
- ClassDB::bind_method(D_METHOD("get_color", "point"), &ColorRamp::get_color);
+ ClassDB::bind_method(D_METHOD("set_color", "point", "color"), &Gradient::set_color);
+ ClassDB::bind_method(D_METHOD("get_color", "point"), &Gradient::get_color);
- ClassDB::bind_method(D_METHOD("interpolate", "offset"), &ColorRamp::get_color_at_offset);
+ ClassDB::bind_method(D_METHOD("interpolate", "offset"), &Gradient::get_color_at_offset);
- ClassDB::bind_method(D_METHOD("get_point_count"), &ColorRamp::get_points_count);
+ ClassDB::bind_method(D_METHOD("get_point_count"), &Gradient::get_points_count);
- ClassDB::bind_method(D_METHOD(COLOR_RAMP_SET_OFFSETS, "offsets"), &ColorRamp::set_offsets);
- ClassDB::bind_method(D_METHOD(COLOR_RAMP_GET_OFFSETS), &ColorRamp::get_offsets);
+ ClassDB::bind_method(D_METHOD(COLOR_RAMP_SET_OFFSETS, "offsets"), &Gradient::set_offsets);
+ ClassDB::bind_method(D_METHOD(COLOR_RAMP_GET_OFFSETS), &Gradient::get_offsets);
- ClassDB::bind_method(D_METHOD(COLOR_RAMP_SET_COLORS, "colors"), &ColorRamp::set_colors);
- ClassDB::bind_method(D_METHOD(COLOR_RAMP_GET_COLORS), &ColorRamp::get_colors);
+ ClassDB::bind_method(D_METHOD(COLOR_RAMP_SET_COLORS, "colors"), &Gradient::set_colors);
+ ClassDB::bind_method(D_METHOD(COLOR_RAMP_GET_COLORS), &Gradient::get_colors);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "offsets"), COLOR_RAMP_SET_OFFSETS, COLOR_RAMP_GET_OFFSETS);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "colors"), COLOR_RAMP_SET_COLORS, COLOR_RAMP_GET_COLORS);
}
-Vector<float> ColorRamp::get_offsets() const {
+Vector<float> Gradient::get_offsets() const {
Vector<float> offsets;
offsets.resize(points.size());
for (int i = 0; i < points.size(); i++) {
@@ -83,7 +83,7 @@ Vector<float> ColorRamp::get_offsets() const {
return offsets;
}
-Vector<Color> ColorRamp::get_colors() const {
+Vector<Color> Gradient::get_colors() const {
Vector<Color> colors;
colors.resize(points.size());
for (int i = 0; i < points.size(); i++) {
@@ -92,7 +92,7 @@ Vector<Color> ColorRamp::get_colors() const {
return colors;
}
-void ColorRamp::set_offsets(const Vector<float> &p_offsets) {
+void Gradient::set_offsets(const Vector<float> &p_offsets) {
points.resize(p_offsets.size());
for (int i = 0; i < points.size(); i++) {
points[i].offset = p_offsets[i];
@@ -101,7 +101,7 @@ void ColorRamp::set_offsets(const Vector<float> &p_offsets) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-void ColorRamp::set_colors(const Vector<Color> &p_colors) {
+void Gradient::set_colors(const Vector<Color> &p_colors) {
if (points.size() < p_colors.size())
is_sorted = false;
points.resize(p_colors.size());
@@ -111,11 +111,11 @@ void ColorRamp::set_colors(const Vector<Color> &p_colors) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-Vector<ColorRamp::Point> &ColorRamp::get_points() {
+Vector<Gradient::Point> &Gradient::get_points() {
return points;
}
-void ColorRamp::add_point(float p_offset, const Color &p_color) {
+void Gradient::add_point(float p_offset, const Color &p_color) {
Point p;
p.offset = p_offset;
@@ -126,7 +126,7 @@ void ColorRamp::add_point(float p_offset, const Color &p_color) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-void ColorRamp::remove_point(int p_index) {
+void Gradient::remove_point(int p_index) {
ERR_FAIL_INDEX(p_index, points.size());
ERR_FAIL_COND(points.size() <= 2);
@@ -134,13 +134,13 @@ void ColorRamp::remove_point(int p_index) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-void ColorRamp::set_points(Vector<ColorRamp::Point> &p_points) {
+void Gradient::set_points(Vector<Gradient::Point> &p_points) {
points = p_points;
is_sorted = false;
emit_signal(CoreStringNames::get_singleton()->changed);
}
-void ColorRamp::set_offset(int pos, const float offset) {
+void Gradient::set_offset(int pos, const float offset) {
if (points.size() <= pos)
points.resize(pos + 1);
points[pos].offset = offset;
@@ -148,13 +148,13 @@ void ColorRamp::set_offset(int pos, const float offset) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-float ColorRamp::get_offset(int pos) const {
+float Gradient::get_offset(int pos) const {
if (points.size() > pos)
return points[pos].offset;
return 0; //TODO: Maybe throw some error instead?
}
-void ColorRamp::set_color(int pos, const Color &color) {
+void Gradient::set_color(int pos, const Color &color) {
if (points.size() <= pos) {
points.resize(pos + 1);
is_sorted = false;
@@ -163,12 +163,12 @@ void ColorRamp::set_color(int pos, const Color &color) {
emit_signal(CoreStringNames::get_singleton()->changed);
}
-Color ColorRamp::get_color(int pos) const {
+Color Gradient::get_color(int pos) const {
if (points.size() > pos)
return points[pos].color;
return Color(0, 0, 0, 1); //TODO: Maybe throw some error instead?
}
-int ColorRamp::get_points_count() const {
+int Gradient::get_points_count() const {
return points.size();
}
diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h
index e231e9fc52..d7ec20b324 100644
--- a/scene/resources/color_ramp.h
+++ b/scene/resources/color_ramp.h
@@ -32,9 +32,9 @@
#include "resource.h"
-class ColorRamp : public Resource {
- GDCLASS(ColorRamp, Resource);
- OBJ_SAVE_TYPE(ColorRamp);
+class Gradient : public Resource {
+ GDCLASS(Gradient, Resource);
+ OBJ_SAVE_TYPE(Gradient);
public:
struct Point {
@@ -54,8 +54,8 @@ protected:
static void _bind_methods();
public:
- ColorRamp();
- virtual ~ColorRamp();
+ Gradient();
+ virtual ~Gradient();
void add_point(float p_offset, const Color &p_color);
void remove_point(int p_index);
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 39943b99db..66f913f347 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -266,19 +266,19 @@ Ref<Texture> Environment::get_adjustment_color_correction() const {
void Environment::_validate_property(PropertyInfo &property) const {
- if (property.name == "background/sky" || property.name == "background/sky_scale" || property.name == "ambient_light/sky_contribution") {
+ if (property.name == "background_sky" || property.name == "background_sky_scale" || property.name == "ambient_light/sky_contribution") {
if (bg_mode != BG_SKY) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
- if (property.name == "background/color") {
+ if (property.name == "background_color") {
if (bg_mode != BG_COLOR) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
- if (property.name == "background/canvas_max_layer") {
+ if (property.name == "background_canvas_max_layer") {
if (bg_mode != BG_CANVAS) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
@@ -695,6 +695,41 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_light_energy", "get_ambient_light_energy");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_sky_contribution", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ambient_light_sky_contribution", "get_ambient_light_sky_contribution");
+ ClassDB::bind_method(D_METHOD("set_tonemapper", "mode"), &Environment::set_tonemapper);
+ ClassDB::bind_method(D_METHOD("get_tonemapper"), &Environment::get_tonemapper);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_exposure", "exposure"), &Environment::set_tonemap_exposure);
+ ClassDB::bind_method(D_METHOD("get_tonemap_exposure"), &Environment::get_tonemap_exposure);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_white", "white"), &Environment::set_tonemap_white);
+ ClassDB::bind_method(D_METHOD("get_tonemap_white"), &Environment::get_tonemap_white);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure", "auto_exposure"), &Environment::set_tonemap_auto_exposure);
+ ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure"), &Environment::get_tonemap_auto_exposure);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_max", "exposure_max"), &Environment::set_tonemap_auto_exposure_max);
+ ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_max"), &Environment::get_tonemap_auto_exposure_max);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_min", "exposure_min"), &Environment::set_tonemap_auto_exposure_min);
+ ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_min"), &Environment::get_tonemap_auto_exposure_min);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_speed", "exposure_speed"), &Environment::set_tonemap_auto_exposure_speed);
+ ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_speed"), &Environment::get_tonemap_auto_exposure_speed);
+
+ ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_grey", "exposure_grey"), &Environment::set_tonemap_auto_exposure_grey);
+ ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_grey"), &Environment::get_tonemap_auto_exposure_grey);
+
+ ADD_GROUP("Tonemap", "tonemap_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reindhart,Filmic,Aces"), "set_tonemapper", "get_tonemapper");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_exposure", "get_tonemap_exposure");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_white", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_white", "get_tonemap_white");
+ ADD_GROUP("Auto Exposure", "auto_exposure_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_exposure_enabled"), "set_tonemap_auto_exposure", "get_tonemap_auto_exposure");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_exposure_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_tonemap_auto_exposure_grey", "get_tonemap_auto_exposure_grey");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_exposure_min_luma", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_auto_exposure_min", "get_tonemap_auto_exposure_min");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_exposure_max_luma", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_auto_exposure_max", "get_tonemap_auto_exposure_max");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_exposure_speed", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_tonemap_auto_exposure_speed", "get_tonemap_auto_exposure_speed");
+
ClassDB::bind_method(D_METHOD("set_ssr_enabled", "enabled"), &Environment::set_ssr_enabled);
ClassDB::bind_method(D_METHOD("is_ssr_enabled"), &Environment::is_ssr_enabled);
@@ -852,41 +887,6 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_scale", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_scale", "get_glow_hdr_bleed_scale");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_bicubic_upscale"), "set_glow_bicubic_upscale", "is_glow_bicubic_upscale_enabled");
- ClassDB::bind_method(D_METHOD("set_tonemapper", "mode"), &Environment::set_tonemapper);
- ClassDB::bind_method(D_METHOD("get_tonemapper"), &Environment::get_tonemapper);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_exposure", "exposure"), &Environment::set_tonemap_exposure);
- ClassDB::bind_method(D_METHOD("get_tonemap_exposure"), &Environment::get_tonemap_exposure);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_white", "white"), &Environment::set_tonemap_white);
- ClassDB::bind_method(D_METHOD("get_tonemap_white"), &Environment::get_tonemap_white);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure", "auto_exposure"), &Environment::set_tonemap_auto_exposure);
- ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure"), &Environment::get_tonemap_auto_exposure);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_max", "exposure_max"), &Environment::set_tonemap_auto_exposure_max);
- ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_max"), &Environment::get_tonemap_auto_exposure_max);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_min", "exposure_min"), &Environment::set_tonemap_auto_exposure_min);
- ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_min"), &Environment::get_tonemap_auto_exposure_min);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_speed", "exposure_speed"), &Environment::set_tonemap_auto_exposure_speed);
- ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_speed"), &Environment::get_tonemap_auto_exposure_speed);
-
- ClassDB::bind_method(D_METHOD("set_tonemap_auto_exposure_grey", "exposure_grey"), &Environment::set_tonemap_auto_exposure_grey);
- ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_grey"), &Environment::get_tonemap_auto_exposure_grey);
-
- ADD_GROUP("Tonemap", "tonemap_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reindhart,Filmic,Aces"), "set_tonemapper", "get_tonemapper");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_exposure", "get_tonemap_exposure");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_white", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_white", "get_tonemap_white");
- ADD_GROUP("Auto Exposure", "auto_exposure_");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_expoure_enabled"), "set_tonemap_auto_exposure", "get_tonemap_auto_exposure");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_expoure_scale", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_tonemap_auto_exposure_grey", "get_tonemap_auto_exposure_grey");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_expoure_min_luma", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_auto_exposure_min", "get_tonemap_auto_exposure_min");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_expoure_max_luma", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_auto_exposure_max", "get_tonemap_auto_exposure_max");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "auto_expoure_speed", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_tonemap_auto_exposure_speed", "get_tonemap_auto_exposure_speed");
-
ClassDB::bind_method(D_METHOD("set_adjustment_enable", "enabled"), &Environment::set_adjustment_enable);
ClassDB::bind_method(D_METHOD("is_adjustment_enabled"), &Environment::is_adjustment_enabled);
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 48299d566c..026b243b21 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -181,7 +181,7 @@ void SpatialMaterial::init_shaders() {
shader_names->albedo = "albedo";
shader_names->specular = "specular";
shader_names->roughness = "roughness";
- shader_names->metalness = "metalness";
+ shader_names->metallic = "metallic";
shader_names->emission = "emission";
shader_names->emission_energy = "emission_energy";
shader_names->normal_scale = "normal_scale";
@@ -205,7 +205,8 @@ void SpatialMaterial::init_shaders() {
shader_names->particles_anim_loop = "particles_anim_loop";
shader_names->texture_names[TEXTURE_ALBEDO] = "texture_albedo";
- shader_names->texture_names[TEXTURE_SPECULAR] = "texture_specular";
+ shader_names->texture_names[TEXTURE_METALLIC] = "texture_metallic";
+ shader_names->texture_names[TEXTURE_ROUGHNESS] = "texture_roughness";
shader_names->texture_names[TEXTURE_EMISSION] = "texture_emission";
shader_names->texture_names[TEXTURE_NORMAL] = "texture_normal";
shader_names->texture_names[TEXTURE_RIM] = "texture_rim";
@@ -215,7 +216,6 @@ void SpatialMaterial::init_shaders() {
shader_names->texture_names[TEXTURE_HEIGHT] = "texture_height";
shader_names->texture_names[TEXTURE_SUBSURFACE_SCATTERING] = "texture_subsurface_scattering";
shader_names->texture_names[TEXTURE_REFRACTION] = "texture_refraction";
- shader_names->texture_names[TEXTURE_REFRACTION_ROUGHNESS] = "texture_refraction_roughness";
shader_names->texture_names[TEXTURE_DETAIL_MASK] = "texture_detail_mask";
shader_names->texture_names[TEXTURE_DETAIL_ALBEDO] = "texture_detail_albedo";
shader_names->texture_names[TEXTURE_DETAIL_NORMAL] = "texture_detail_normal";
@@ -278,6 +278,12 @@ void SpatialMaterial::_update_shader() {
case CULL_FRONT: code += ",cull_front"; break;
case CULL_DISABLED: code += ",cull_disabled"; break;
}
+ switch (diffuse_mode) {
+ case DIFFUSE_LAMBERT: code += ",diffuse_lambert"; break;
+ case DIFFUSE_HALF_LAMBERT: code += ",diffuse_half_lambert"; break;
+ case DIFFUSE_OREN_NAYAR: code += ",diffuse_oren_nayar"; break;
+ case DIFFUSE_BURLEY: code += ",diffuse_burley"; break;
+ }
if (flags[FLAG_UNSHADED]) {
code += ",unshaded";
@@ -290,15 +296,13 @@ void SpatialMaterial::_update_shader() {
code += "uniform vec4 albedo : hint_color;\n";
code += "uniform sampler2D texture_albedo : hint_albedo;\n";
- if (specular_mode == SPECULAR_MODE_SPECULAR) {
- code += "uniform vec4 specular : hint_color;\n";
- } else {
- code += "uniform float metalness;\n";
- }
+ code += "uniform float specular;\n";
+ code += "uniform float metallic;\n";
code += "uniform float roughness : hint_range(0,1);\n";
code += "uniform float point_size : hint_range(0,128);\n";
- code += "uniform sampler2D texture_specular : hint_white;\n";
+ code += "uniform sampler2D texture_metallic : hint_white;\n";
+ code += "uniform sampler2D texture_roughness : hint_white;\n";
code += "uniform vec2 uv1_scale;\n";
code += "uniform vec2 uv1_offset;\n";
code += "uniform vec2 uv2_scale;\n";
@@ -502,16 +506,11 @@ void SpatialMaterial::_update_shader() {
code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n";
}
- if (specular_mode == SPECULAR_MODE_SPECULAR) {
-
- code += "\tvec4 specular_tex = texture(texture_specular,UV);\n";
- code += "\tSPECULAR = specular.rgb * specular_tex.rgb;\n";
- code += "\tROUGHNESS = specular_tex.a * roughness;\n";
- } else {
- code += "\tvec4 specular_tex = texture(texture_specular,UV);\n";
- code += "\tSPECULAR = vec3(ALBEDO.rgb * metalness * specular_tex.r);\n";
- code += "\tROUGHNESS = specular_tex.a * roughness;\n";
- }
+ code += "\tfloat metallic_tex = texture(texture_metallic,UV).r;\n";
+ code += "\tMETALLIC = metallic_tex * metallic;\n";
+ code += "\tfloat roughness_tex = texture(texture_roughness,UV).r;\n";
+ code += "\tROUGHNESS = roughness_tex * roughness;\n";
+ code += "\tSPECULAR = specular;\n";
code += "}\n";
@@ -579,23 +578,13 @@ Color SpatialMaterial::get_albedo() const {
return albedo;
}
-void SpatialMaterial::set_specular_mode(SpecularMode p_mode) {
- specular_mode = p_mode;
- _change_notify();
- _queue_shader_change();
-}
-
-SpatialMaterial::SpecularMode SpatialMaterial::get_specular_mode() const {
-
- return specular_mode;
-}
-
-void SpatialMaterial::set_specular(const Color &p_specular) {
+void SpatialMaterial::set_specular(float p_specular) {
specular = p_specular;
VS::get_singleton()->material_set_param(_get_material(), shader_names->specular, p_specular);
}
-Color SpatialMaterial::get_specular() const {
+
+float SpatialMaterial::get_specular() const {
return specular;
}
@@ -611,15 +600,15 @@ float SpatialMaterial::get_roughness() const {
return roughness;
}
-void SpatialMaterial::set_metalness(float p_metalness) {
+void SpatialMaterial::set_metallic(float p_metallic) {
- metalness = p_metalness;
- VS::get_singleton()->material_set_param(_get_material(), shader_names->metalness, p_metalness);
+ metallic = p_metallic;
+ VS::get_singleton()->material_set_param(_get_material(), shader_names->metallic, p_metallic);
}
-float SpatialMaterial::get_metalness() const {
+float SpatialMaterial::get_metallic() const {
- return metalness;
+ return metallic;
}
void SpatialMaterial::set_emission(const Color &p_emission) {
@@ -888,13 +877,6 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const {
_validate_feature("refraction", FEATURE_REFRACTION, property);
_validate_feature("detail", FEATURE_DETAIL, property);
- if (property.name == "specular/color" && specular_mode == SPECULAR_MODE_METALLIC) {
- property.usage = 0;
- }
- if (property.name == "specular/metalness" && specular_mode == SPECULAR_MODE_SPECULAR) {
- property.usage = 0;
- }
-
if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) {
property.usage = 0;
}
@@ -1014,14 +996,11 @@ void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo);
ClassDB::bind_method(D_METHOD("get_albedo"), &SpatialMaterial::get_albedo);
- ClassDB::bind_method(D_METHOD("set_specular_mode", "specular_mode"), &SpatialMaterial::set_specular_mode);
- ClassDB::bind_method(D_METHOD("get_specular_mode"), &SpatialMaterial::get_specular_mode);
-
ClassDB::bind_method(D_METHOD("set_specular", "specular"), &SpatialMaterial::set_specular);
ClassDB::bind_method(D_METHOD("get_specular"), &SpatialMaterial::get_specular);
- ClassDB::bind_method(D_METHOD("set_metalness", "metalness"), &SpatialMaterial::set_metalness);
- ClassDB::bind_method(D_METHOD("get_metalness"), &SpatialMaterial::get_metalness);
+ ClassDB::bind_method(D_METHOD("set_metallic", "metallic"), &SpatialMaterial::set_metallic);
+ ClassDB::bind_method(D_METHOD("get_metallic"), &SpatialMaterial::get_metallic);
ClassDB::bind_method(D_METHOD("set_roughness", "roughness"), &SpatialMaterial::set_roughness);
ClassDB::bind_method(D_METHOD("get_roughness"), &SpatialMaterial::get_roughness);
@@ -1146,12 +1125,14 @@ void SpatialMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "albedo_color"), "set_albedo", "get_albedo");
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "albedo_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ALBEDO);
- ADD_GROUP("Specular", "specular_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "specular_mode", PROPERTY_HINT_ENUM, "Metallic,Specular"), "set_specular_mode", "get_specular_mode");
- ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular", "get_specular");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "specular_metalness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_metalness", "get_metalness");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "specular_roughness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_roughness", "get_roughness");
- ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "specular_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_SPECULAR);
+ ADD_GROUP("Metallic", "metallic_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "metallic_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_metallic", "get_metallic");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "metallic_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_specular", "get_specular");
+ ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "metallic_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_METALLIC);
+
+ ADD_GROUP("Roughness", "roughness_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "roughness_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_roughness", "get_roughness");
+ ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "roughness_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ROUGHNESS);
ADD_GROUP("Emission", "emission_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "emission_enabled"), "set_feature", "get_feature", FEATURE_EMISSION);
@@ -1218,7 +1199,8 @@ void SpatialMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_offset"), "set_uv2_offset", "get_uv2_offset");
BIND_CONSTANT(TEXTURE_ALBEDO);
- BIND_CONSTANT(TEXTURE_SPECULAR);
+ BIND_CONSTANT(TEXTURE_METALLIC);
+ BIND_CONSTANT(TEXTURE_ROUGHNESS);
BIND_CONSTANT(TEXTURE_EMISSION);
BIND_CONSTANT(TEXTURE_NORMAL);
BIND_CONSTANT(TEXTURE_RIM);
@@ -1228,7 +1210,6 @@ void SpatialMaterial::_bind_methods() {
BIND_CONSTANT(TEXTURE_HEIGHT);
BIND_CONSTANT(TEXTURE_SUBSURFACE_SCATTERING);
BIND_CONSTANT(TEXTURE_REFRACTION);
- BIND_CONSTANT(TEXTURE_REFRACTION_ROUGHNESS);
BIND_CONSTANT(TEXTURE_DETAIL_MASK);
BIND_CONSTANT(TEXTURE_DETAIL_ALBEDO);
BIND_CONSTANT(TEXTURE_DETAIL_NORMAL);
@@ -1273,13 +1254,10 @@ void SpatialMaterial::_bind_methods() {
BIND_CONSTANT(FLAG_MAX);
BIND_CONSTANT(DIFFUSE_LAMBERT);
- BIND_CONSTANT(DIFFUSE_LAMBERT_WRAP);
+ BIND_CONSTANT(DIFFUSE_HALF_LAMBERT);
BIND_CONSTANT(DIFFUSE_OREN_NAYAR);
BIND_CONSTANT(DIFFUSE_BURLEY);
- BIND_CONSTANT(SPECULAR_MODE_METALLIC);
- BIND_CONSTANT(SPECULAR_MODE_SPECULAR);
-
BIND_CONSTANT(BILLBOARD_DISABLED);
BIND_CONSTANT(BILLBOARD_ENABLED);
BIND_CONSTANT(BILLBOARD_FIXED_Y);
@@ -1290,11 +1268,10 @@ SpatialMaterial::SpatialMaterial()
: element(this) {
//initialize to right values
- specular_mode = SPECULAR_MODE_METALLIC;
set_albedo(Color(0.7, 0.7, 0.7, 1.0));
- set_specular(Color(0.1, 0.1, 0.1));
+ set_specular(0.5);
set_roughness(0.0);
- set_metalness(0.1);
+ set_metallic(0.1);
set_emission(Color(0, 0, 0));
set_emission_energy(1.0);
set_normal_scale(1);
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 408815d756..f4d93da017 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -89,7 +89,8 @@ class SpatialMaterial : public Material {
public:
enum TextureParam {
TEXTURE_ALBEDO,
- TEXTURE_SPECULAR,
+ TEXTURE_METALLIC,
+ TEXTURE_ROUGHNESS,
TEXTURE_EMISSION,
TEXTURE_NORMAL,
TEXTURE_RIM,
@@ -99,7 +100,6 @@ public:
TEXTURE_HEIGHT,
TEXTURE_SUBSURFACE_SCATTERING,
TEXTURE_REFRACTION,
- TEXTURE_REFRACTION_ROUGHNESS,
TEXTURE_DETAIL_MASK,
TEXTURE_DETAIL_ALBEDO,
TEXTURE_DETAIL_NORMAL,
@@ -160,16 +160,11 @@ public:
enum DiffuseMode {
DIFFUSE_LAMBERT,
- DIFFUSE_LAMBERT_WRAP,
+ DIFFUSE_HALF_LAMBERT,
DIFFUSE_OREN_NAYAR,
DIFFUSE_BURLEY,
};
- enum SpecularMode {
- SPECULAR_MODE_METALLIC,
- SPECULAR_MODE_SPECULAR,
- };
-
enum BillboardMode {
BILLBOARD_DISABLED,
BILLBOARD_ENABLED,
@@ -230,7 +225,6 @@ private:
}
mk.detail_blend_mode = detail_blend_mode;
mk.diffuse_mode = diffuse_mode;
- mk.specular_mode = specular_mode;
mk.billboard_mode = billboard_mode;
return mk;
@@ -239,7 +233,7 @@ private:
struct ShaderNames {
StringName albedo;
StringName specular;
- StringName metalness;
+ StringName metallic;
StringName roughness;
StringName emission;
StringName emission_energy;
@@ -275,8 +269,8 @@ private:
_FORCE_INLINE_ bool _is_shader_dirty() const;
Color albedo;
- Color specular;
- float metalness;
+ float specular;
+ float metallic;
float roughness;
Color emission;
float emission_energy;
@@ -310,7 +304,6 @@ private:
CullMode cull_mode;
bool flags[FLAG_MAX];
DiffuseMode diffuse_mode;
- SpecularMode specular_mode;
BillboardMode billboard_mode;
bool features[FEATURE_MAX];
@@ -327,14 +320,11 @@ public:
void set_albedo(const Color &p_albedo);
Color get_albedo() const;
- void set_specular_mode(SpecularMode p_mode);
- SpecularMode get_specular_mode() const;
-
- void set_specular(const Color &p_specular);
- Color get_specular() const;
+ void set_specular(float p_specular);
+ float get_specular() const;
- void set_metalness(float p_metalness);
- float get_metalness() const;
+ void set_metallic(float p_metallic);
+ float get_metallic() const;
void set_roughness(float p_roughness);
float get_roughness() const;
@@ -447,7 +437,6 @@ VARIANT_ENUM_CAST(SpatialMaterial::DepthDrawMode)
VARIANT_ENUM_CAST(SpatialMaterial::CullMode)
VARIANT_ENUM_CAST(SpatialMaterial::Flags)
VARIANT_ENUM_CAST(SpatialMaterial::DiffuseMode)
-VARIANT_ENUM_CAST(SpatialMaterial::SpecularMode)
VARIANT_ENUM_CAST(SpatialMaterial::BillboardMode)
//////////////////////
diff --git a/scene/resources/sky_box.cpp b/scene/resources/sky_box.cpp
index 59ade4a729..61aaaf8fb4 100644
--- a/scene/resources/sky_box.cpp
+++ b/scene/resources/sky_box.cpp
@@ -112,3 +112,394 @@ PanoramaSky::~PanoramaSky() {
VS::get_singleton()->free(sky);
}
+//////////////////////////////////
+
+void ProceduralSky::_radiance_changed() {
+
+ if (update_queued)
+ return; //do nothing yet
+
+ static const int size[RADIANCE_SIZE_MAX] = {
+ 256, 512, 1024, 2048
+ };
+ VS::get_singleton()->sky_set_texture(sky, texture, size[get_radiance_size()]);
+}
+
+void ProceduralSky::_update_sky() {
+
+ update_queued = false;
+
+ PoolVector<uint8_t> imgdata;
+
+ static const int size[TEXTURE_SIZE_MAX] = {
+ 1024, 2048, 4096
+ };
+
+ int w = size[texture_size];
+ int h = w / 2;
+
+ imgdata.resize(w * h * 4); //RGBE
+
+ {
+ PoolVector<uint8_t>::Write dataw = imgdata.write();
+
+ uint32_t *ptr = (uint32_t *)dataw.ptr();
+
+ Color sky_top_linear = sky_top_color.to_linear();
+ Color sky_horizon_linear = sky_horizon_color.to_linear();
+
+ Color ground_bottom_linear = ground_bottom_color.to_linear();
+ Color ground_horizon_linear = ground_horizon_color.to_linear();
+
+ //Color sun_linear = sun_color.to_linear();
+
+ Vector3 sun(0, 0, -1);
+
+ sun = Basis(Vector3(1, 0, 0), Math::deg2rad(sun_latitude)).xform(sun);
+ sun = Basis(Vector3(0, 1, 0), Math::deg2rad(sun_longitude)).xform(sun);
+
+ sun.normalize();
+
+ for (int i = 0; i < w; i++) {
+
+ float u = float(i) / (w - 1);
+ float phi = u * 2.0 * Math_PI;
+
+ for (int j = 0; j < h; j++) {
+
+ float v = float(j) / (h - 1);
+ float theta = v * Math_PI;
+
+ Vector3 normal(
+ Math::sin(phi) * Math::sin(theta) * -1.0,
+ Math::cos(theta),
+ Math::cos(phi) * Math::sin(theta) * -1.0);
+
+ normal.normalize();
+
+ float v_angle = Math::acos(normal.y);
+
+ Color color;
+
+ if (normal.y < 0) {
+ //ground
+
+ float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5);
+ color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve));
+ } else {
+ float c = v_angle / (Math_PI * 0.5);
+ color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve));
+
+ float sun_angle = Math::rad2deg(Math::acos(sun.dot(normal)));
+
+ if (sun_angle < sun_angle_min) {
+ color = color.blend(sun_color);
+ } else if (sun_angle < sun_angle_max) {
+
+ float c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);
+ c2 = Math::ease(c2, sun_curve);
+
+ color = color.blend(sun_color).linear_interpolate(color, c2);
+ }
+ }
+
+ ptr[j * w + i] = color.to_rgbe9995();
+ }
+ }
+ }
+
+ Ref<Image> image;
+ image.instance();
+ image->create(w, h, false, Image::FORMAT_RGBE9995, imgdata);
+
+ VS::get_singleton()->texture_allocate(texture, w, h, Image::FORMAT_RGBE9995, VS::TEXTURE_FLAG_FILTER | VS::TEXTURE_FLAG_REPEAT);
+ VS::get_singleton()->texture_set_data(texture, image);
+ _radiance_changed();
+}
+
+void ProceduralSky::set_sky_top_color(const Color &p_sky_top) {
+
+ sky_top_color = p_sky_top;
+ _queue_update();
+}
+
+Color ProceduralSky::get_sky_top_color() const {
+
+ return sky_top_color;
+}
+
+void ProceduralSky::set_sky_horizon_color(const Color &p_sky_horizon) {
+
+ sky_horizon_color = p_sky_horizon;
+ _queue_update();
+}
+Color ProceduralSky::get_sky_horizon_color() const {
+
+ return sky_horizon_color;
+}
+
+void ProceduralSky::set_sky_curve(float p_curve) {
+
+ sky_curve = p_curve;
+ _queue_update();
+}
+float ProceduralSky::get_sky_curve() const {
+
+ return sky_curve;
+}
+
+void ProceduralSky::set_sky_energy(float p_energy) {
+
+ sky_energy = p_energy;
+ _queue_update();
+}
+float ProceduralSky::get_sky_energy() const {
+
+ return sky_energy;
+}
+
+void ProceduralSky::set_ground_bottom_color(const Color &p_ground_bottom) {
+
+ ground_bottom_color = p_ground_bottom;
+ _queue_update();
+}
+Color ProceduralSky::get_ground_bottom_color() const {
+
+ return ground_bottom_color;
+}
+
+void ProceduralSky::set_ground_horizon_color(const Color &p_ground_horizon) {
+
+ ground_horizon_color = p_ground_horizon;
+ _queue_update();
+}
+Color ProceduralSky::get_ground_horizon_color() const {
+
+ return ground_horizon_color;
+}
+
+void ProceduralSky::set_ground_curve(float p_curve) {
+
+ ground_curve = p_curve;
+ _queue_update();
+}
+float ProceduralSky::get_ground_curve() const {
+
+ return ground_curve;
+}
+
+void ProceduralSky::set_ground_energy(float p_energy) {
+
+ ground_energy = p_energy;
+ _queue_update();
+}
+float ProceduralSky::get_ground_energy() const {
+
+ return ground_energy;
+}
+
+void ProceduralSky::set_sun_color(const Color &p_sun) {
+
+ sun_color = p_sun;
+ _queue_update();
+}
+Color ProceduralSky::get_sun_color() const {
+
+ return sun_color;
+}
+
+void ProceduralSky::set_sun_latitude(float p_angle) {
+
+ sun_latitude = p_angle;
+ _queue_update();
+}
+float ProceduralSky::get_sun_latitude() const {
+
+ return sun_latitude;
+}
+
+void ProceduralSky::set_sun_longitude(float p_angle) {
+
+ sun_longitude = p_angle;
+ _queue_update();
+}
+float ProceduralSky::get_sun_longitude() const {
+
+ return sun_longitude;
+}
+
+void ProceduralSky::set_sun_angle_min(float p_angle) {
+
+ sun_angle_min = p_angle;
+ _queue_update();
+}
+float ProceduralSky::get_sun_angle_min() const {
+
+ return sun_angle_min;
+}
+
+void ProceduralSky::set_sun_angle_max(float p_angle) {
+
+ sun_angle_max = p_angle;
+ _queue_update();
+}
+float ProceduralSky::get_sun_angle_max() const {
+
+ return sun_angle_max;
+}
+
+void ProceduralSky::set_sun_curve(float p_curve) {
+
+ sun_curve = p_curve;
+ _queue_update();
+}
+float ProceduralSky::get_sun_curve() const {
+
+ return sun_curve;
+}
+
+void ProceduralSky::set_sun_energy(float p_energy) {
+
+ sun_energy = p_energy;
+ _queue_update();
+}
+float ProceduralSky::get_sun_energy() const {
+
+ return sun_energy;
+}
+
+void ProceduralSky::set_texture_size(TextureSize p_size) {
+ ERR_FAIL_INDEX(p_size, TEXTURE_SIZE_MAX);
+
+ texture_size = p_size;
+ _queue_update();
+}
+ProceduralSky::TextureSize ProceduralSky::get_texture_size() const {
+ return texture_size;
+}
+
+RID ProceduralSky::get_rid() const {
+ return sky;
+}
+
+void ProceduralSky::_queue_update() {
+
+ if (update_queued)
+ return;
+
+ update_queued = true;
+ call_deferred("_update_sky");
+}
+
+void ProceduralSky::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("_update_sky"), &ProceduralSky::_update_sky);
+
+ ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSky::set_sky_top_color);
+ ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSky::get_sky_top_color);
+
+ ClassDB::bind_method(D_METHOD("set_sky_horizon_color", "color"), &ProceduralSky::set_sky_horizon_color);
+ ClassDB::bind_method(D_METHOD("get_sky_horizon_color"), &ProceduralSky::get_sky_horizon_color);
+
+ ClassDB::bind_method(D_METHOD("set_sky_curve", "curve"), &ProceduralSky::set_sky_curve);
+ ClassDB::bind_method(D_METHOD("get_sky_curve"), &ProceduralSky::get_sky_curve);
+
+ ClassDB::bind_method(D_METHOD("set_sky_energy", "energy"), &ProceduralSky::set_sky_energy);
+ ClassDB::bind_method(D_METHOD("get_sky_energy"), &ProceduralSky::get_sky_energy);
+
+ ClassDB::bind_method(D_METHOD("set_ground_bottom_color", "color"), &ProceduralSky::set_ground_bottom_color);
+ ClassDB::bind_method(D_METHOD("get_ground_bottom_color"), &ProceduralSky::get_ground_bottom_color);
+
+ ClassDB::bind_method(D_METHOD("set_ground_horizon_color", "color"), &ProceduralSky::set_ground_horizon_color);
+ ClassDB::bind_method(D_METHOD("get_ground_horizon_color"), &ProceduralSky::get_ground_horizon_color);
+
+ ClassDB::bind_method(D_METHOD("set_ground_curve", "curve"), &ProceduralSky::set_ground_curve);
+ ClassDB::bind_method(D_METHOD("get_ground_curve"), &ProceduralSky::get_ground_curve);
+
+ ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSky::set_ground_energy);
+ ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSky::get_ground_energy);
+
+ ClassDB::bind_method(D_METHOD("set_sun_color", "color"), &ProceduralSky::set_sun_color);
+ ClassDB::bind_method(D_METHOD("get_sun_color"), &ProceduralSky::get_sun_color);
+
+ ClassDB::bind_method(D_METHOD("set_sun_latitude", "degrees"), &ProceduralSky::set_sun_latitude);
+ ClassDB::bind_method(D_METHOD("get_sun_latitude"), &ProceduralSky::get_sun_latitude);
+
+ ClassDB::bind_method(D_METHOD("set_sun_longitude", "degrees"), &ProceduralSky::set_sun_longitude);
+ ClassDB::bind_method(D_METHOD("get_sun_longitude"), &ProceduralSky::get_sun_longitude);
+
+ ClassDB::bind_method(D_METHOD("set_sun_angle_min", "degrees"), &ProceduralSky::set_sun_angle_min);
+ ClassDB::bind_method(D_METHOD("get_sun_angle_min"), &ProceduralSky::get_sun_angle_min);
+
+ ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSky::set_sun_angle_max);
+ ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSky::get_sun_angle_max);
+
+ ClassDB::bind_method(D_METHOD("set_sun_curve", "curve"), &ProceduralSky::set_sun_curve);
+ ClassDB::bind_method(D_METHOD("get_sun_curve"), &ProceduralSky::get_sun_curve);
+
+ ClassDB::bind_method(D_METHOD("set_sun_energy", "energy"), &ProceduralSky::set_sun_energy);
+ ClassDB::bind_method(D_METHOD("get_sun_energy"), &ProceduralSky::get_sun_energy);
+
+ ClassDB::bind_method(D_METHOD("set_texture_size", "size"), &ProceduralSky::set_texture_size);
+ ClassDB::bind_method(D_METHOD("get_texture_size"), &ProceduralSky::get_texture_size);
+
+ ADD_GROUP("Sky", "sky_");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_top_color"), "set_sky_top_color", "get_sky_top_color");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_horizon_color"), "set_sky_horizon_color", "get_sky_horizon_color");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_curve", PROPERTY_HINT_EXP_EASING), "set_sky_curve", "get_sky_curve");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sky_energy", "get_sky_energy");
+
+ ADD_GROUP("Ground", "ground_");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_bottom_color"), "set_ground_bottom_color", "get_ground_bottom_color");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_horizon_color"), "set_ground_horizon_color", "get_ground_horizon_color");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_curve", PROPERTY_HINT_EXP_EASING), "set_ground_curve", "get_ground_curve");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy");
+
+ ADD_GROUP("Sun", "sun_");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sun_color"), "set_sun_color", "get_sun_color");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_latitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_latitude", "get_sun_latitude");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_longitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_longitude", "get_sun_longitude");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_min", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_min", "get_sun_angle_min");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sun_energy", "get_sun_energy");
+
+ ADD_GROUP("Texture", "texture_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "1024,2048,4096"), "set_texture_size", "get_texture_size");
+}
+
+ProceduralSky::ProceduralSky() {
+
+ sky = VS::get_singleton()->sky_create();
+ texture = VS::get_singleton()->texture_create();
+
+ update_queued = false;
+
+ sky_top_color = Color::hex(0x4d67e8ff);
+ sky_horizon_color = Color::hex(0x8ed2e8ff);
+ sky_curve = 0.25;
+ sky_energy = 1;
+
+ ground_bottom_color = Color::hex(0x322719ff);
+ ground_horizon_color = Color::hex(0x543610ff);
+ ground_curve = 0.25;
+ ground_energy = 1;
+
+ sun_color = Color(1, 1, 1);
+ sun_latitude = 35;
+ sun_longitude = 0;
+ sun_angle_min = 1;
+ sun_angle_max = 100;
+ sun_curve = 0.05;
+ sun_energy = 16;
+
+ texture_size = TEXTURE_SIZE_1024;
+
+ _queue_update();
+}
+
+ProceduralSky::~ProceduralSky() {
+
+ VS::get_singleton()->free(sky);
+ VS::get_singleton()->free(texture);
+}
diff --git a/scene/resources/sky_box.h b/scene/resources/sky_box.h
index afbfb3019e..7b707af3a6 100644
--- a/scene/resources/sky_box.h
+++ b/scene/resources/sky_box.h
@@ -62,17 +62,6 @@ VARIANT_ENUM_CAST(Sky::RadianceSize)
class PanoramaSky : public Sky {
GDCLASS(PanoramaSky, Sky);
-public:
- enum ImagePath {
- IMAGE_PATH_NEGATIVE_X,
- IMAGE_PATH_POSITIVE_X,
- IMAGE_PATH_NEGATIVE_Y,
- IMAGE_PATH_POSITIVE_Y,
- IMAGE_PATH_NEGATIVE_Z,
- IMAGE_PATH_POSITIVE_Z,
- IMAGE_PATH_MAX
- };
-
private:
RID sky;
Ref<Texture> panorama;
@@ -91,6 +80,105 @@ public:
~PanoramaSky();
};
-VARIANT_ENUM_CAST(PanoramaSky::ImagePath)
+class ProceduralSky : public Sky {
+ GDCLASS(ProceduralSky, Sky);
+
+public:
+ enum TextureSize {
+ TEXTURE_SIZE_1024,
+ TEXTURE_SIZE_2048,
+ TEXTURE_SIZE_4096,
+ TEXTURE_SIZE_MAX
+ };
+
+private:
+ Color sky_top_color;
+ Color sky_horizon_color;
+ float sky_curve;
+ float sky_energy;
+
+ Color ground_bottom_color;
+ Color ground_horizon_color;
+ float ground_curve;
+ float ground_energy;
+
+ Color sun_color;
+ float sun_latitude;
+ float sun_longitude;
+ float sun_angle_min;
+ float sun_angle_max;
+ float sun_curve;
+ float sun_energy;
+
+ TextureSize texture_size;
+
+ RID sky;
+ RID texture;
+
+ bool update_queued;
+
+protected:
+ static void _bind_methods();
+ virtual void _radiance_changed();
+
+ void _update_sky();
+ void _queue_update();
+
+public:
+ void set_sky_top_color(const Color &p_sky_top);
+ Color get_sky_top_color() const;
+
+ void set_sky_horizon_color(const Color &p_sky_horizon);
+ Color get_sky_horizon_color() const;
+
+ void set_sky_curve(float p_curve);
+ float get_sky_curve() const;
+
+ void set_sky_energy(float p_energy);
+ float get_sky_energy() const;
+
+ void set_ground_bottom_color(const Color &p_ground_bottom);
+ Color get_ground_bottom_color() const;
+
+ void set_ground_horizon_color(const Color &p_ground_horizon);
+ Color get_ground_horizon_color() const;
+
+ void set_ground_curve(float p_curve);
+ float get_ground_curve() const;
+
+ void set_ground_energy(float p_energy);
+ float get_ground_energy() const;
+
+ void set_sun_color(const Color &p_sun);
+ Color get_sun_color() const;
+
+ void set_sun_latitude(float p_angle);
+ float get_sun_latitude() const;
+
+ void set_sun_longitude(float p_angle);
+ float get_sun_longitude() const;
+
+ void set_sun_angle_min(float p_angle);
+ float get_sun_angle_min() const;
+
+ void set_sun_angle_max(float p_angle);
+ float get_sun_angle_max() const;
+
+ void set_sun_curve(float p_curve);
+ float get_sun_curve() const;
+
+ void set_sun_energy(float p_energy);
+ float get_sun_energy() const;
+
+ void set_texture_size(TextureSize p_size);
+ TextureSize get_texture_size() const;
+
+ virtual RID get_rid() const;
+
+ ProceduralSky();
+ ~ProceduralSky();
+};
+
+VARIANT_ENUM_CAST(ProceduralSky::TextureSize)
#endif // Sky_H
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index bc8deb501e..68a11b821d 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -494,9 +494,9 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla
img = Image::lossy_unpacker(pv);
}
- if (img.is_null()) {
+ if (img.is_null() || img->empty()) {
memdelete(f);
- ERR_FAIL_COND_V(img->empty(), ERR_FILE_CORRUPT);
+ ERR_FAIL_COND_V(img.is_null() || img->empty(), ERR_FILE_CORRUPT);
}
total_size += img->get_data().size();
diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp
index eab7cf6098..24551e9135 100644
--- a/scene/resources/world.cpp
+++ b/scene/resources/world.cpp
@@ -280,6 +280,20 @@ Ref<Environment> World::get_environment() const {
return environment;
}
+void World::set_fallback_environment(const Ref<Environment> &p_environment) {
+
+ fallback_environment = p_environment;
+ if (fallback_environment.is_valid())
+ VS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid());
+ else
+ VS::get_singleton()->scenario_set_fallback_environment(scenario, RID());
+}
+
+Ref<Environment> World::get_fallback_environment() const {
+
+ return fallback_environment;
+}
+
PhysicsDirectSpaceState *World::get_direct_space_state() {
return PhysicsServer::get_singleton()->space_get_direct_state(space);
@@ -291,8 +305,11 @@ void World::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_scenario"), &World::get_scenario);
ClassDB::bind_method(D_METHOD("set_environment", "env:Environment"), &World::set_environment);
ClassDB::bind_method(D_METHOD("get_environment:Environment"), &World::get_environment);
+ ClassDB::bind_method(D_METHOD("set_fallback_environment", "env:Environment"), &World::set_fallback_environment);
+ ClassDB::bind_method(D_METHOD("get_fallback_environment:Environment"), &World::get_fallback_environment);
ClassDB::bind_method(D_METHOD("get_direct_space_state:PhysicsDirectSpaceState"), &World::get_direct_space_state);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment");
}
World::World() {
diff --git a/scene/resources/world.h b/scene/resources/world.h
index f2c85f31f6..96857a577a 100644
--- a/scene/resources/world.h
+++ b/scene/resources/world.h
@@ -48,6 +48,7 @@ private:
RID scenario;
SpatialIndexer *indexer;
Ref<Environment> environment;
+ Ref<Environment> fallback_environment;
protected:
static void _bind_methods();
@@ -68,9 +69,13 @@ protected:
public:
RID get_space() const;
RID get_scenario() const;
+
void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const;
+ void set_fallback_environment(const Ref<Environment> &p_environment);
+ Ref<Environment> get_fallback_environment() const;
+
PhysicsDirectSpaceState *get_direct_space_state();
World();
diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp
index b565ee8f9d..f7ea158646 100644
--- a/servers/visual/rasterizer.cpp
+++ b/servers/visual/rasterizer.cpp
@@ -38,11 +38,11 @@ Rasterizer *Rasterizer::create() {
return _create_func();
}
-RasterizerStorage *RasterizerStorage::base_signleton = NULL;
+RasterizerStorage *RasterizerStorage::base_singleton = NULL;
RasterizerStorage::RasterizerStorage() {
- base_signleton = this;
+ base_singleton = this;
}
#if 0
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index c51dcd1a3b..4b274acd9e 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -493,7 +493,7 @@ public:
virtual void update_dirty_resources() = 0;
- static RasterizerStorage *base_signleton;
+ static RasterizerStorage *base_singleton;
RasterizerStorage();
virtual ~RasterizerStorage() {}
};
@@ -806,7 +806,7 @@ public:
case Item::Command::TYPE_MESH: {
const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c);
- Rect3 aabb = RasterizerStorage::base_signleton->mesh_get_aabb(mesh->mesh, mesh->skeleton);
+ Rect3 aabb = RasterizerStorage::base_singleton->mesh_get_aabb(mesh->mesh, mesh->skeleton);
r = Rect2(aabb.pos.x, aabb.pos.y, aabb.size.x, aabb.size.y);
@@ -814,7 +814,7 @@ public:
case Item::Command::TYPE_MULTIMESH: {
const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c);
- Rect3 aabb = RasterizerStorage::base_signleton->multimesh_get_aabb(multimesh->multimesh);
+ Rect3 aabb = RasterizerStorage::base_singleton->multimesh_get_aabb(multimesh->multimesh);
r = Rect2(aabb.pos.x, aabb.pos.y, aabb.size.x, aabb.size.y);
diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp
index 8d72ee3f34..1caee3fd25 100644
--- a/servers/visual/shader_types.cpp
+++ b/servers/visual/shader_types.cpp
@@ -91,7 +91,8 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMAL"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALBEDO"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALPHA"] = ShaderLanguage::TYPE_FLOAT;
- shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECULAR"] = ShaderLanguage::TYPE_VEC3;
+ shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["METALLIC"] = ShaderLanguage::TYPE_FLOAT;
+ shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECULAR"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ROUGHNESS"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["RIM"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["RIM_TINT"] = ShaderLanguage::TYPE_FLOAT;
@@ -130,6 +131,11 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].modes.insert("unshaded");
shader_modes[VS::SHADER_SPATIAL].modes.insert("ontop");
+ shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_lambert");
+ shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_half_lambert");
+ shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_oren_nayar");
+ shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_burley");
+
shader_modes[VS::SHADER_SPATIAL].modes.insert("skip_default_transform");
/************ CANVAS ITEM **************************/
@@ -165,8 +171,6 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["COLOR"] = ShaderLanguage::TYPE_VEC4;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["TEXTURE_PIXEL_SIZE"] = ShaderLanguage::TYPE_VEC2;
- shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["VAR1"] = ShaderLanguage::TYPE_VEC4;
- shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["VAR2"] = ShaderLanguage::TYPE_VEC4;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["LIGHT_VEC"] = ShaderLanguage::TYPE_VEC2;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["LIGHT_HEIGHT"] = ShaderLanguage::TYPE_FLOAT;
diff --git a/signal_renames.txt b/signal_renames.txt
deleted file mode 100644
index 859985cb11..0000000000
--- a/signal_renames.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-area_enter = area_entered
-area_exit = area_exited
-
-area_enter_shape = area_shape_entered
-area_exit_shape = area_shape_exited
-
-body_enter = body_entered
-body_exit = body_exited
-
-body_enter_shape = body_shape_entered
-body_exit_shape = body_shape_exited
-
-mouse_enter = mouse_entered
-mouse_exit = mouse_exited
-focus_enter = focus_entered
-focus_exit = focus_exited
-
-modal_close = modal_closed
-
-enter_tree = tree_entered
-exit_tree = tree_exited \ No newline at end of file
diff --git a/thirdparty/README.md b/thirdparty/README.md
index be870008eb..756b31b995 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -272,7 +272,7 @@ Files extracted from the upstream source:
## opus
- Upstream: https://opus-codec.org
-- Version: 1.1.4 (opus) and 0.8 (opusfile)
+- Version: 1.1.5 (opus) and 0.8 (opusfile)
- License: BSD-3-Clause
Files extracted from upstream source:
diff --git a/thirdparty/opus/celt/arch.h b/thirdparty/opus/celt/arch.h
index 9f74ddd267..8ceab5fe10 100644
--- a/thirdparty/opus/celt/arch.h
+++ b/thirdparty/opus/celt/arch.h
@@ -78,6 +78,15 @@ static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line)
#define UADD32(a,b) ((a)+(b))
#define USUB32(a,b) ((a)-(b))
+/* Set this if opus_int64 is a native type of the CPU. */
+/* Assume that all LP64 architectures have fast 64-bit types; also x86_64
+ (which can be ILP32 for x32) and Win64 (which is LLP64). */
+#if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
+#define OPUS_FAST_INT64 1
+#else
+#define OPUS_FAST_INT64 0
+#endif
+
#define PRINT_MIPS(file)
#ifdef FIXED_POINT
@@ -118,7 +127,9 @@ static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
#include "fixed_generic.h"
-#ifdef OPUS_ARM_INLINE_EDSP
+#ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
+#include "arm/fixed_arm64.h"
+#elif OPUS_ARM_INLINE_EDSP
#include "arm/fixed_armv5e.h"
#elif defined (OPUS_ARM_INLINE_ASM)
#include "arm/fixed_armv4.h"
diff --git a/thirdparty/opus/celt/arm/arm_celt_map.c b/thirdparty/opus/celt/arm/arm_celt_map.c
index ee6c244786..4d4d069a86 100644
--- a/thirdparty/opus/celt/arm/arm_celt_map.c
+++ b/thirdparty/opus/celt/arm/arm_celt_map.c
@@ -36,6 +36,9 @@
#if defined(OPUS_HAVE_RTCD)
# if defined(FIXED_POINT)
+# if ((defined(OPUS_ARM_MAY_HAVE_NEON) && !defined(OPUS_ARM_PRESUME_NEON)) || \
+ (defined(OPUS_ARM_MAY_HAVE_MEDIA) && !defined(OPUS_ARM_PRESUME_MEDIA)) || \
+ (defined(OPUS_ARM_MAY_HAVE_EDSP) && !defined(OPUS_ARM_PRESUME_EDSP)))
opus_val32 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
const opus_val16 *, opus_val32 *, int , int) = {
celt_pitch_xcorr_c, /* ARMv4 */
@@ -43,8 +46,10 @@ opus_val32 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
MAY_HAVE_MEDIA(celt_pitch_xcorr), /* Media */
MAY_HAVE_NEON(celt_pitch_xcorr) /* NEON */
};
+
+# endif
# else /* !FIXED_POINT */
-# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)
void (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
const opus_val16 *, opus_val32 *, int, int) = {
celt_pitch_xcorr_c, /* ARMv4 */
@@ -55,6 +60,23 @@ void (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
# endif
# endif /* FIXED_POINT */
+#if defined(FIXED_POINT) && defined(OPUS_HAVE_RTCD) && \
+ defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)
+
+void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])(
+ const opus_val16 *x,
+ const opus_val16 *y,
+ opus_val32 sum[4],
+ int len
+) = {
+ xcorr_kernel_c, /* ARMv4 */
+ xcorr_kernel_c, /* EDSP */
+ xcorr_kernel_c, /* Media */
+ xcorr_kernel_neon_fixed, /* Neon */
+};
+
+#endif
+
# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
# if defined(HAVE_ARM_NE10)
# if defined(CUSTOM_MODES)
diff --git a/thirdparty/opus/celt/arm/armcpu.c b/thirdparty/opus/celt/arm/armcpu.c
index 5e5d10c344..694a63b78e 100644
--- a/thirdparty/opus/celt/arm/armcpu.c
+++ b/thirdparty/opus/celt/arm/armcpu.c
@@ -37,11 +37,12 @@
#include "cpu_support.h"
#include "os_support.h"
#include "opus_types.h"
+#include "arch.h"
-#define OPUS_CPU_ARM_V4 (1)
-#define OPUS_CPU_ARM_EDSP (1<<1)
-#define OPUS_CPU_ARM_MEDIA (1<<2)
-#define OPUS_CPU_ARM_NEON (1<<3)
+#define OPUS_CPU_ARM_V4_FLAG (1<<OPUS_ARCH_ARM_V4)
+#define OPUS_CPU_ARM_EDSP_FLAG (1<<OPUS_ARCH_ARM_EDSP)
+#define OPUS_CPU_ARM_MEDIA_FLAG (1<<OPUS_ARCH_ARM_MEDIA)
+#define OPUS_CPU_ARM_NEON_FLAG (1<<OPUS_ARCH_ARM_NEON)
#if defined(_MSC_VER)
/*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
@@ -55,20 +56,22 @@ static OPUS_INLINE opus_uint32 opus_cpu_capabilities(void){
/* MSVC has no OPUS_INLINE __asm support for ARM, but it does let you __emit
* instructions via their assembled hex code.
* All of these instructions should be essentially nops. */
-# if defined(OPUS_ARM_MAY_HAVE_EDSP)
+# if defined(OPUS_ARM_MAY_HAVE_EDSP) || defined(OPUS_ARM_MAY_HAVE_MEDIA) \
+ || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
__try{
/*PLD [r13]*/
__emit(0xF5DDF000);
- flags|=OPUS_CPU_ARM_EDSP;
+ flags|=OPUS_CPU_ARM_EDSP_FLAG;
}
__except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
/*Ignore exception.*/
}
-# if defined(OPUS_ARM_MAY_HAVE_MEDIA)
+# if defined(OPUS_ARM_MAY_HAVE_MEDIA) \
+ || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
__try{
/*SHADD8 r3,r3,r3*/
__emit(0xE6333F93);
- flags|=OPUS_CPU_ARM_MEDIA;
+ flags|=OPUS_CPU_ARM_MEDIA_FLAG;
}
__except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
/*Ignore exception.*/
@@ -77,7 +80,7 @@ static OPUS_INLINE opus_uint32 opus_cpu_capabilities(void){
__try{
/*VORR q0,q0,q0*/
__emit(0xF2200150);
- flags|=OPUS_CPU_ARM_NEON;
+ flags|=OPUS_CPU_ARM_NEON_FLAG;
}
__except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){
/*Ignore exception.*/
@@ -107,26 +110,26 @@ opus_uint32 opus_cpu_capabilities(void)
while(fgets(buf, 512, cpuinfo) != NULL)
{
-# if defined(OPUS_ARM_MAY_HAVE_EDSP) || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
+# if defined(OPUS_ARM_MAY_HAVE_EDSP) || defined(OPUS_ARM_MAY_HAVE_MEDIA) \
+ || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
/* Search for edsp and neon flag */
if(memcmp(buf, "Features", 8) == 0)
{
char *p;
-# if defined(OPUS_ARM_MAY_HAVE_EDSP)
p = strstr(buf, " edsp");
if(p != NULL && (p[5] == ' ' || p[5] == '\n'))
- flags |= OPUS_CPU_ARM_EDSP;
-# endif
+ flags |= OPUS_CPU_ARM_EDSP_FLAG;
# if defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
p = strstr(buf, " neon");
if(p != NULL && (p[5] == ' ' || p[5] == '\n'))
- flags |= OPUS_CPU_ARM_NEON;
+ flags |= OPUS_CPU_ARM_NEON_FLAG;
# endif
}
# endif
-# if defined(OPUS_ARM_MAY_HAVE_MEDIA)
+# if defined(OPUS_ARM_MAY_HAVE_MEDIA) \
+ || defined(OPUS_ARM_MAY_HAVE_NEON) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
/* Search for media capabilities (>= ARMv6) */
if(memcmp(buf, "CPU architecture:", 17) == 0)
{
@@ -134,7 +137,7 @@ opus_uint32 opus_cpu_capabilities(void)
version = atoi(buf+17);
if(version >= 6)
- flags |= OPUS_CPU_ARM_MEDIA;
+ flags |= OPUS_CPU_ARM_MEDIA_FLAG;
}
# endif
}
@@ -156,18 +159,26 @@ int opus_select_arch(void)
opus_uint32 flags = opus_cpu_capabilities();
int arch = 0;
- if(!(flags & OPUS_CPU_ARM_EDSP))
+ if(!(flags & OPUS_CPU_ARM_EDSP_FLAG)) {
+ /* Asserts ensure arch values are sequential */
+ celt_assert(arch == OPUS_ARCH_ARM_V4);
return arch;
+ }
arch++;
- if(!(flags & OPUS_CPU_ARM_MEDIA))
+ if(!(flags & OPUS_CPU_ARM_MEDIA_FLAG)) {
+ celt_assert(arch == OPUS_ARCH_ARM_EDSP);
return arch;
+ }
arch++;
- if(!(flags & OPUS_CPU_ARM_NEON))
+ if(!(flags & OPUS_CPU_ARM_NEON_FLAG)) {
+ celt_assert(arch == OPUS_ARCH_ARM_MEDIA);
return arch;
+ }
arch++;
+ celt_assert(arch == OPUS_ARCH_ARM_NEON);
return arch;
}
diff --git a/thirdparty/opus/celt/arm/armcpu.h b/thirdparty/opus/celt/arm/armcpu.h
index ac5744606e..820262ff5f 100644
--- a/thirdparty/opus/celt/arm/armcpu.h
+++ b/thirdparty/opus/celt/arm/armcpu.h
@@ -66,6 +66,12 @@
# if defined(OPUS_HAVE_RTCD)
int opus_select_arch(void);
+
+#define OPUS_ARCH_ARM_V4 (0)
+#define OPUS_ARCH_ARM_EDSP (1)
+#define OPUS_ARCH_ARM_MEDIA (2)
+#define OPUS_ARCH_ARM_NEON (3)
+
# endif
#endif
diff --git a/thirdparty/opus/celt/arm/celt_neon_intr.c b/thirdparty/opus/celt/arm/celt_neon_intr.c
index 47dce15ba5..47bbe3dc22 100644
--- a/thirdparty/opus/celt/arm/celt_neon_intr.c
+++ b/thirdparty/opus/celt/arm/celt_neon_intr.c
@@ -37,7 +37,66 @@
#include <arm_neon.h>
#include "../pitch.h"
-#if !defined(FIXED_POINT)
+#if defined(FIXED_POINT)
+void xcorr_kernel_neon_fixed(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
+{
+ int j;
+ int32x4_t a = vld1q_s32(sum);
+ /* Load y[0...3] */
+ /* This requires len>0 to always be valid (which we assert in the C code). */
+ int16x4_t y0 = vld1_s16(y);
+ y += 4;
+
+ for (j = 0; j + 8 <= len; j += 8)
+ {
+ /* Load x[0...7] */
+ int16x8_t xx = vld1q_s16(x);
+ int16x4_t x0 = vget_low_s16(xx);
+ int16x4_t x4 = vget_high_s16(xx);
+ /* Load y[4...11] */
+ int16x8_t yy = vld1q_s16(y);
+ int16x4_t y4 = vget_low_s16(yy);
+ int16x4_t y8 = vget_high_s16(yy);
+ int32x4_t a0 = vmlal_lane_s16(a, y0, x0, 0);
+ int32x4_t a1 = vmlal_lane_s16(a0, y4, x4, 0);
+
+ int16x4_t y1 = vext_s16(y0, y4, 1);
+ int16x4_t y5 = vext_s16(y4, y8, 1);
+ int32x4_t a2 = vmlal_lane_s16(a1, y1, x0, 1);
+ int32x4_t a3 = vmlal_lane_s16(a2, y5, x4, 1);
+
+ int16x4_t y2 = vext_s16(y0, y4, 2);
+ int16x4_t y6 = vext_s16(y4, y8, 2);
+ int32x4_t a4 = vmlal_lane_s16(a3, y2, x0, 2);
+ int32x4_t a5 = vmlal_lane_s16(a4, y6, x4, 2);
+
+ int16x4_t y3 = vext_s16(y0, y4, 3);
+ int16x4_t y7 = vext_s16(y4, y8, 3);
+ int32x4_t a6 = vmlal_lane_s16(a5, y3, x0, 3);
+ int32x4_t a7 = vmlal_lane_s16(a6, y7, x4, 3);
+
+ y0 = y8;
+ a = a7;
+ x += 8;
+ y += 8;
+ }
+
+ for (; j < len; j++)
+ {
+ int16x4_t x0 = vld1_dup_s16(x); /* load next x */
+ int32x4_t a0 = vmlal_s16(a, y0, x0);
+
+ int16x4_t y4 = vld1_dup_s16(y); /* load next y */
+ y0 = vext_s16(y0, y4, 1);
+ a = a0;
+ x++;
+ y++;
+ }
+
+ vst1q_s32(sum, a);
+}
+
+#else
/*
* Function: xcorr_kernel_neon_float
* ---------------------------------
diff --git a/thirdparty/opus/celt/arm/pitch_arm.h b/thirdparty/opus/celt/arm/pitch_arm.h
index 8626ed75b9..14331169ee 100644
--- a/thirdparty/opus/celt/arm/pitch_arm.h
+++ b/thirdparty/opus/celt/arm/pitch_arm.h
@@ -46,10 +46,53 @@ opus_val32 celt_pitch_xcorr_edsp(const opus_val16 *_x, const opus_val16 *_y,
opus_val32 *xcorr, int len, int max_pitch);
# endif
-# if !defined(OPUS_HAVE_RTCD)
+# if defined(OPUS_HAVE_RTCD) && \
+ ((defined(OPUS_ARM_MAY_HAVE_NEON) && !defined(OPUS_ARM_PRESUME_NEON)) || \
+ (defined(OPUS_ARM_MAY_HAVE_MEDIA) && !defined(OPUS_ARM_PRESUME_MEDIA)) || \
+ (defined(OPUS_ARM_MAY_HAVE_EDSP) && !defined(OPUS_ARM_PRESUME_EDSP)))
+extern opus_val32
+(*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
+ const opus_val16 *, opus_val32 *, int, int);
+# define OVERRIDE_PITCH_XCORR (1)
+# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
+ ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \
+ xcorr, len, max_pitch))
+
+# elif defined(OPUS_ARM_PRESUME_EDSP) || \
+ defined(OPUS_ARM_PRESUME_MEDIA) || \
+ defined(OPUS_ARM_PRESUME_NEON)
# define OVERRIDE_PITCH_XCORR (1)
# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
((void)(arch),PRESUME_NEON(celt_pitch_xcorr)(_x, _y, xcorr, len, max_pitch))
+
+# endif
+
+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
+void xcorr_kernel_neon_fixed(
+ const opus_val16 *x,
+ const opus_val16 *y,
+ opus_val32 sum[4],
+ int len);
+# endif
+
+# if defined(OPUS_HAVE_RTCD) && \
+ (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR))
+
+extern void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])(
+ const opus_val16 *x,
+ const opus_val16 *y,
+ opus_val32 sum[4],
+ int len);
+
+# define OVERRIDE_XCORR_KERNEL (1)
+# define xcorr_kernel(x, y, sum, len, arch) \
+ ((*XCORR_KERNEL_IMPL[(arch) & OPUS_ARCHMASK])(x, y, sum, len))
+
+# elif defined(OPUS_ARM_PRESUME_NEON_INTR)
+# define OVERRIDE_XCORR_KERNEL (1)
+# define xcorr_kernel(x, y, sum, len, arch) \
+ ((void)arch, xcorr_kernel_neon_fixed(x, y, sum, len))
+
# endif
#else /* Start !FIXED_POINT */
@@ -57,12 +100,27 @@ opus_val32 celt_pitch_xcorr_edsp(const opus_val16 *_x, const opus_val16 *_y,
#if defined(OPUS_ARM_MAY_HAVE_NEON_INTR)
void celt_pitch_xcorr_float_neon(const opus_val16 *_x, const opus_val16 *_y,
opus_val32 *xcorr, int len, int max_pitch);
-#if !defined(OPUS_HAVE_RTCD) || defined(OPUS_ARM_PRESUME_NEON_INTR)
-#define OVERRIDE_PITCH_XCORR (1)
+#endif
+
+# if defined(OPUS_HAVE_RTCD) && \
+ (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR))
+extern void
+(*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
+ const opus_val16 *, opus_val32 *, int, int);
+
+# define OVERRIDE_PITCH_XCORR (1)
+# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
+ ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \
+ xcorr, len, max_pitch))
+
+# elif defined(OPUS_ARM_PRESUME_NEON_INTR)
+
+# define OVERRIDE_PITCH_XCORR (1)
# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
((void)(arch),celt_pitch_xcorr_float_neon(_x, _y, xcorr, len, max_pitch))
-#endif
-#endif
+
+# endif
#endif /* end !FIXED_POINT */
+
#endif
diff --git a/thirdparty/opus/celt/bands.c b/thirdparty/opus/celt/bands.c
index 25f229e267..87eaa6c031 100644
--- a/thirdparty/opus/celt/bands.c
+++ b/thirdparty/opus/celt/bands.c
@@ -414,7 +414,7 @@ static void stereo_merge(celt_norm * OPUS_RESTRICT X, celt_norm * OPUS_RESTRICT
/* Compensating for the mid normalization */
xp = MULT16_32_Q15(mid, xp);
/* mid and side are in Q15, not Q14 like X and Y */
- mid2 = SHR32(mid, 1);
+ mid2 = SHR16(mid, 1);
El = MULT16_16(mid2, mid2) + side - 2*xp;
Er = MULT16_16(mid2, mid2) + side + 2*xp;
if (Er < QCONST32(6e-4f, 28) || El < QCONST32(6e-4f, 28))
@@ -714,7 +714,7 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx,
if (qn!=1)
{
if (encode)
- itheta = (itheta*qn+8192)>>14;
+ itheta = (itheta*(opus_int32)qn+8192)>>14;
/* Entropy coding of the angle. We use a uniform pdf for the
time split, a step for stereo, and a triangular one for the rest. */
diff --git a/thirdparty/opus/celt/celt.h b/thirdparty/opus/celt/celt.h
index a423b95046..d1f7eb690d 100644
--- a/thirdparty/opus/celt/celt.h
+++ b/thirdparty/opus/celt/celt.h
@@ -209,7 +209,7 @@ void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
#endif
#ifndef OVERRIDE_COMB_FILTER_CONST
-# define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
+# define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
((void)(arch),comb_filter_const_c(y, x, T, N, g10, g11, g12))
#endif
diff --git a/thirdparty/opus/celt/celt_decoder.c b/thirdparty/opus/celt/celt_decoder.c
index b688f2a4e3..b978bb34d1 100644
--- a/thirdparty/opus/celt/celt_decoder.c
+++ b/thirdparty/opus/celt/celt_decoder.c
@@ -82,6 +82,7 @@ struct OpusCustomDecoder {
int error;
int last_pitch_index;
int loss_count;
+ int skip_plc;
int postfilter_period;
int postfilter_period_old;
opus_val16 postfilter_gain;
@@ -164,8 +165,6 @@ OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_init(CELTDecoder *st, const CELTMod
st->signalling = 1;
st->arch = opus_select_arch();
- st->loss_count = 0;
-
opus_custom_decoder_ctl(st, OPUS_RESET_STATE);
return OPUS_OK;
@@ -447,7 +446,7 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM)
loss_count = st->loss_count;
start = st->start;
- noise_based = loss_count >= 5 || start != 0;
+ noise_based = loss_count >= 5 || start != 0 || st->skip_plc;
if (noise_based)
{
/* Noise-based PLC/CNG */
@@ -832,6 +831,10 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
return frame_size/st->downsample;
}
+ /* Check if there are at least two packets received consecutively before
+ * turning on the pitch-based PLC */
+ st->skip_plc = st->loss_count != 0;
+
if (dec == NULL)
{
ec_dec_init(&_dec,(unsigned char*)data,len);
@@ -1198,6 +1201,7 @@ int opus_custom_decoder_ctl(CELTDecoder * OPUS_RESTRICT st, int request, ...)
((char*)&st->DECODER_RESET_START - (char*)st));
for (i=0;i<2*st->mode->nbEBands;i++)
oldLogE[i]=oldLogE2[i]=-QCONST16(28.f,DB_SHIFT);
+ st->skip_plc = 1;
}
break;
case OPUS_GET_PITCH_REQUEST:
diff --git a/thirdparty/opus/celt/celt_encoder.c b/thirdparty/opus/celt/celt_encoder.c
index 41fbfd49c8..3ee7a4d3f7 100644
--- a/thirdparty/opus/celt/celt_encoder.c
+++ b/thirdparty/opus/celt/celt_encoder.c
@@ -1175,10 +1175,10 @@ static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem,
if (N>COMBFILTER_MAXPERIOD)
{
- OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD, pre[c]+N, COMBFILTER_MAXPERIOD);
+ OPUS_COPY(prefilter_mem+c*COMBFILTER_MAXPERIOD, pre[c]+N, COMBFILTER_MAXPERIOD);
} else {
OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD, prefilter_mem+c*COMBFILTER_MAXPERIOD+N, COMBFILTER_MAXPERIOD-N);
- OPUS_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD+COMBFILTER_MAXPERIOD-N, pre[c]+COMBFILTER_MAXPERIOD, N);
+ OPUS_COPY(prefilter_mem+c*COMBFILTER_MAXPERIOD+COMBFILTER_MAXPERIOD-N, pre[c]+COMBFILTER_MAXPERIOD, N);
}
} while (++c<CC);
@@ -1281,12 +1281,15 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32
if ((!has_surround_mask||lfe) && (constrained_vbr || bitrate<64000))
{
- opus_val16 rate_factor;
+ opus_val16 rate_factor = Q15ONE;
+ if (bitrate < 64000)
+ {
#ifdef FIXED_POINT
- rate_factor = MAX16(0,(bitrate-32000));
+ rate_factor = MAX16(0,(bitrate-32000));
#else
- rate_factor = MAX16(0,(1.f/32768)*(bitrate-32000));
+ rate_factor = MAX16(0,(1.f/32768)*(bitrate-32000));
#endif
+ }
if (constrained_vbr)
rate_factor = MIN16(rate_factor, QCONST16(0.67f, 15));
target = base_target + (opus_int32)MULT16_32_Q15(rate_factor, target-base_target);
diff --git a/thirdparty/opus/celt/celt_lpc.c b/thirdparty/opus/celt/celt_lpc.c
index f02145af0d..b410a21c5f 100644
--- a/thirdparty/opus/celt/celt_lpc.c
+++ b/thirdparty/opus/celt/celt_lpc.c
@@ -49,8 +49,7 @@ int p
float *lpc = _lpc;
#endif
- for (i = 0; i < p; i++)
- lpc[i] = 0;
+ OPUS_CLEAR(lpc, p);
if (ac[0] != 0)
{
for (i = 0; i < p; i++) {
diff --git a/thirdparty/opus/celt/cwrs.c b/thirdparty/opus/celt/cwrs.c
index 2fa9f89cd6..9722f0ac86 100644
--- a/thirdparty/opus/celt/cwrs.c
+++ b/thirdparty/opus/celt/cwrs.c
@@ -74,7 +74,7 @@ int log2_frac(opus_uint32 val, int frac)
/*Although derived separately, the pulse vector coding scheme is equivalent to
a Pyramid Vector Quantizer \cite{Fis86}.
Some additional notes about an early version appear at
- http://people.xiph.org/~tterribe/notes/cwrs.html, but the codebook ordering
+ https://people.xiph.org/~tterribe/notes/cwrs.html, but the codebook ordering
and the definitions of some terms have evolved since that was written.
The conversion from a pulse vector to an integer index (encoding) and back
diff --git a/thirdparty/opus/celt/fixed_generic.h b/thirdparty/opus/celt/fixed_generic.h
index ac67d37ce8..1cfd6d6989 100644
--- a/thirdparty/opus/celt/fixed_generic.h
+++ b/thirdparty/opus/celt/fixed_generic.h
@@ -37,16 +37,32 @@
#define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(b))
/** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */
+#if OPUS_FAST_INT64
+#define MULT16_32_Q16(a,b) ((opus_val32)SHR((opus_int64)((opus_val16)(a))*(b),16))
+#else
#define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR((b),16)), SHR(MULT16_16SU((a),((b)&0x0000ffff)),16))
+#endif
/** 16x32 multiplication, followed by a 16-bit shift right (round-to-nearest). Results fits in 32 bits */
+#if OPUS_FAST_INT64
+#define MULT16_32_P16(a,b) ((opus_val32)PSHR((opus_int64)((opus_val16)(a))*(b),16))
+#else
#define MULT16_32_P16(a,b) ADD32(MULT16_16((a),SHR((b),16)), PSHR(MULT16_16SU((a),((b)&0x0000ffff)),16))
+#endif
/** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */
+#if OPUS_FAST_INT64
+#define MULT16_32_Q15(a,b) ((opus_val32)SHR((opus_int64)((opus_val16)(a))*(b),15))
+#else
#define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15))
+#endif
/** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */
+#if OPUS_FAST_INT64
+#define MULT32_32_Q31(a,b) ((opus_val32)SHR((opus_int64)(a)*(opus_int64)(b),31))
+#else
#define MULT32_32_Q31(a,b) ADD32(ADD32(SHL(MULT16_16(SHR((a),16),SHR((b),16)),1), SHR(MULT16_16SU(SHR((a),16),((b)&0x0000ffff)),15)), SHR(MULT16_16SU(SHR((b),16),((a)&0x0000ffff)),15))
+#endif
/** Compile-time conversion of float constant to 16-bit value */
#define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits))))
diff --git a/thirdparty/opus/celt/kiss_fft.c b/thirdparty/opus/celt/kiss_fft.c
index 4ed37d2bb7..1f8fd05321 100644
--- a/thirdparty/opus/celt/kiss_fft.c
+++ b/thirdparty/opus/celt/kiss_fft.c
@@ -191,7 +191,7 @@ static void kf_bfly3(
kiss_fft_cpx * Fout_beg = Fout;
#ifdef FIXED_POINT
- epi3.r = -16384;
+ /*epi3.r = -16384;*/ /* Unused */
epi3.i = -28378;
#else
epi3 = st->twiddles[fstride*m];
diff --git a/thirdparty/opus/celt/mathops.c b/thirdparty/opus/celt/mathops.c
index 3f8c5dcc0e..21a01f52e4 100644
--- a/thirdparty/opus/celt/mathops.c
+++ b/thirdparty/opus/celt/mathops.c
@@ -164,7 +164,7 @@ opus_val16 celt_cos_norm(opus_val32 x)
{
return _celt_cos_pi_2(EXTRACT16(x));
} else {
- return NEG32(_celt_cos_pi_2(EXTRACT16(65536-x)));
+ return NEG16(_celt_cos_pi_2(EXTRACT16(65536-x)));
}
} else {
if (x&0x0000ffff)
diff --git a/thirdparty/opus/celt/pitch.c b/thirdparty/opus/celt/pitch.c
index 1d89cb0342..bf46e7d562 100644
--- a/thirdparty/opus/celt/pitch.c
+++ b/thirdparty/opus/celt/pitch.c
@@ -412,6 +412,41 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR
RESTORE_STACK;
}
+#ifdef FIXED_POINT
+static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy)
+{
+ opus_val32 x2y2;
+ int sx, sy, shift;
+ opus_val32 g;
+ opus_val16 den;
+ if (xy == 0 || xx == 0 || yy == 0)
+ return 0;
+ sx = celt_ilog2(xx)-14;
+ sy = celt_ilog2(yy)-14;
+ shift = sx + sy;
+ x2y2 = MULT16_16_Q14(VSHR32(xx, sx), VSHR32(yy, sy));
+ if (shift & 1) {
+ if (x2y2 < 32768)
+ {
+ x2y2 <<= 1;
+ shift--;
+ } else {
+ x2y2 >>= 1;
+ shift++;
+ }
+ }
+ den = celt_rsqrt_norm(x2y2);
+ g = MULT16_32_Q15(den, xy);
+ g = VSHR32(g, (shift>>1)-1);
+ return EXTRACT16(MIN32(g, Q15ONE));
+}
+#else
+static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy)
+{
+ return xy/celt_sqrt(1+xx*yy);
+}
+#endif
+
static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3, 2};
opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
int N, int *T0_, int prev_period, opus_val16 prev_gain, int arch)
@@ -450,18 +485,7 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
yy = yy_lookup[T0];
best_xy = xy;
best_yy = yy;
-#ifdef FIXED_POINT
- {
- opus_val32 x2y2;
- int sh, t;
- x2y2 = 1+HALF32(MULT32_32_Q31(xx,yy));
- sh = celt_ilog2(x2y2)>>1;
- t = VSHR32(x2y2, 2*(sh-7));
- g = g0 = VSHR32(MULT16_32_Q15(celt_rsqrt_norm(t), xy),sh+1);
- }
-#else
- g = g0 = xy/celt_sqrt(1+xx*yy);
-#endif
+ g = g0 = compute_pitch_gain(xy, xx, yy);
/* Look for any pitch at T/k */
for (k=2;k<=15;k++)
{
@@ -484,24 +508,13 @@ opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
T1b = celt_udiv(2*second_check[k]*T0+k, 2*k);
}
dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2, arch);
- xy += xy2;
- yy = yy_lookup[T1] + yy_lookup[T1b];
-#ifdef FIXED_POINT
- {
- opus_val32 x2y2;
- int sh, t;
- x2y2 = 1+MULT32_32_Q31(xx,yy);
- sh = celt_ilog2(x2y2)>>1;
- t = VSHR32(x2y2, 2*(sh-7));
- g1 = VSHR32(MULT16_32_Q15(celt_rsqrt_norm(t), xy),sh+1);
- }
-#else
- g1 = xy/celt_sqrt(1+2.f*xx*1.f*yy);
-#endif
+ xy = HALF32(xy + xy2);
+ yy = HALF32(yy_lookup[T1] + yy_lookup[T1b]);
+ g1 = compute_pitch_gain(xy, xx, yy);
if (abs(T1-prev_period)<=1)
cont = prev_gain;
else if (abs(T1-prev_period)<=2 && 5*k*k < T0)
- cont = HALF32(prev_gain);
+ cont = HALF16(prev_gain);
else
cont = 0;
thresh = MAX16(QCONST16(.3f,15), MULT16_16_Q15(QCONST16(.7f,15),g0)-cont);
diff --git a/thirdparty/opus/celt/pitch.h b/thirdparty/opus/celt/pitch.h
index 65a77a6ecc..d3503532a0 100644
--- a/thirdparty/opus/celt/pitch.h
+++ b/thirdparty/opus/celt/pitch.h
@@ -187,25 +187,6 @@ celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
opus_val32 *xcorr, int len, int max_pitch);
#if !defined(OVERRIDE_PITCH_XCORR)
-/*Is run-time CPU detection enabled on this platform?*/
-# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_ASM) \
- || (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) \
- && !defined(OPUS_ARM_PRESUME_NEON_INTR)))
-extern
-# if defined(FIXED_POINT)
-opus_val32
-# else
-void
-# endif
-(*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
- const opus_val16 *, opus_val32 *, int, int);
-
-# define OVERRIDE_PITCH_XCORR
-# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
- ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \
- xcorr, len, max_pitch))
-# else
-
#ifdef FIXED_POINT
opus_val32
#else
@@ -214,7 +195,6 @@ void
celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
opus_val32 *xcorr, int len, int max_pitch, int arch);
-# endif
#endif
#endif
diff --git a/thirdparty/opus/celt/rate.c b/thirdparty/opus/celt/rate.c
index b28d8feccd..7dfa5be8a6 100644
--- a/thirdparty/opus/celt/rate.c
+++ b/thirdparty/opus/celt/rate.c
@@ -296,7 +296,7 @@ static OPUS_INLINE int interp_bits2pulses(const CELTMode *m, int start, int end,
done = 0;
for (j=end;j-->start;)
{
- int tmp = bits1[j] + (lo*bits2[j]>>ALLOC_STEPS);
+ int tmp = bits1[j] + ((opus_int32)lo*bits2[j]>>ALLOC_STEPS);
if (tmp < thresh[j] && !done)
{
if (tmp >= alloc_floor)
diff --git a/thirdparty/opus/celt/vq.c b/thirdparty/opus/celt/vq.c
index f358396065..d29f38fd8e 100644
--- a/thirdparty/opus/celt/vq.c
+++ b/thirdparty/opus/celt/vq.c
@@ -271,7 +271,7 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc
best_id = 0;
/* The squared magnitude term gets added anyway, so we might as well
add it outside the loop */
- yy = ADD32(yy, 1);
+ yy = ADD16(yy, 1);
j=0;
do {
opus_val16 Rxy, Ryy;
diff --git a/thirdparty/opus/celt/x86/pitch_sse.h b/thirdparty/opus/celt/x86/pitch_sse.h
index d4cbeb8b9c..e5f87ab51a 100644
--- a/thirdparty/opus/celt/x86/pitch_sse.h
+++ b/thirdparty/opus/celt/x86/pitch_sse.h
@@ -102,21 +102,21 @@ opus_val32 celt_inner_prod_sse(
#if defined(OPUS_X86_PRESUME_SSE4_1) && defined(FIXED_POINT)
#define OVERRIDE_CELT_INNER_PROD
#define celt_inner_prod(x, y, N, arch) \
- ((void)arch, celt_inner_prod_sse4_1(x, y, N))
+ ((void)arch, celt_inner_prod_sse4_1(x, y, N))
#elif defined(OPUS_X86_PRESUME_SSE2) && defined(FIXED_POINT) && !defined(OPUS_X86_MAY_HAVE_SSE4_1)
#define OVERRIDE_CELT_INNER_PROD
#define celt_inner_prod(x, y, N, arch) \
- ((void)arch, celt_inner_prod_sse2(x, y, N))
+ ((void)arch, celt_inner_prod_sse2(x, y, N))
#elif defined(OPUS_X86_PRESUME_SSE) && !defined(FIXED_POINT)
#define OVERRIDE_CELT_INNER_PROD
#define celt_inner_prod(x, y, N, arch) \
- ((void)arch, celt_inner_prod_sse(x, y, N))
+ ((void)arch, celt_inner_prod_sse(x, y, N))
#elif ((defined(OPUS_X86_MAY_HAVE_SSE4_1) || defined(OPUS_X86_MAY_HAVE_SSE2)) && defined(FIXED_POINT)) || \
- (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT))
+ (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT))
extern opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
const opus_val16 *x,
@@ -138,19 +138,19 @@ extern opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
#undef comb_filter_const
void dual_inner_prod_sse(const opus_val16 *x,
- const opus_val16 *y01,
- const opus_val16 *y02,
- int N,
- opus_val32 *xy1,
- opus_val32 *xy2);
+ const opus_val16 *y01,
+ const opus_val16 *y02,
+ int N,
+ opus_val32 *xy1,
+ opus_val32 *xy2);
void comb_filter_const_sse(opus_val32 *y,
- opus_val32 *x,
- int T,
- int N,
- opus_val16 g10,
- opus_val16 g11,
- opus_val16 g12);
+ opus_val32 *x,
+ int T,
+ int N,
+ opus_val16 g10,
+ opus_val16 g11,
+ opus_val16 g12);
#if defined(OPUS_X86_PRESUME_SSE)
@@ -169,7 +169,7 @@ extern void (*const DUAL_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
opus_val32 *xy1,
opus_val32 *xy2);
-#define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
+#define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
((*DUAL_INNER_PROD_IMPL[(arch) & OPUS_ARCHMASK])(x, y01, y02, N, xy1, xy2))
extern void (*const COMB_FILTER_CONST_IMPL[OPUS_ARCHMASK + 1])(
@@ -181,7 +181,7 @@ extern void (*const COMB_FILTER_CONST_IMPL[OPUS_ARCHMASK + 1])(
opus_val16 g11,
opus_val16 g12);
-#define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
+#define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
((*COMB_FILTER_CONST_IMPL[(arch) & OPUS_ARCHMASK])(y, x, T, N, g10, g11, g12))
#define NON_STATIC_COMB_FILTER_CONST_C
diff --git a/thirdparty/opus/celt/x86/x86_celt_map.c b/thirdparty/opus/celt/x86/x86_celt_map.c
index 8e5e449275..47ba41b9ee 100644
--- a/thirdparty/opus/celt/x86/x86_celt_map.c
+++ b/thirdparty/opus/celt/x86/x86_celt_map.c
@@ -72,7 +72,7 @@ void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])(
#endif
#if (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \
- (!defined(OPUS_X86_MAY_HAVE_SSE_4_1) && defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2))
+ (!defined(OPUS_X86_MAY_HAVE_SSE_4_1) && defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2))
opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
const opus_val16 *x,
diff --git a/thirdparty/opus/celt/x86/x86cpu.c b/thirdparty/opus/celt/x86/x86cpu.c
index 555a576b8a..080eb25e41 100644
--- a/thirdparty/opus/celt/x86/x86cpu.c
+++ b/thirdparty/opus/celt/x86/x86cpu.c
@@ -46,7 +46,7 @@
#include <intrin.h>
static _inline void cpuid(unsigned int CPUInfo[4], unsigned int InfoType)
{
- __cpuid((int*)CPUInfo, InfoType);
+ __cpuid((int*)CPUInfo, InfoType);
}
#else
diff --git a/thirdparty/opus/opus_multistream_encoder.c b/thirdparty/opus/opus_multistream_encoder.c
index e722e31ab8..1698223a16 100644
--- a/thirdparty/opus/opus_multistream_encoder.c
+++ b/thirdparty/opus/opus_multistream_encoder.c
@@ -277,7 +277,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b
sum = celt_inner_prod(in, in, frame_size+overlap, 0);
/* This should filter out both NaNs and ridiculous signals that could
cause NaNs further down. */
- if (!(sum < 1e9f) || celt_isnan(sum))
+ if (!(sum < 1e18f) || celt_isnan(sum))
{
OPUS_CLEAR(in, frame_size+overlap);
preemph_mem[c] = 0;
diff --git a/thirdparty/opus/silk/CNG.c b/thirdparty/opus/silk/CNG.c
index 61787c2302..8443ad63bb 100644
--- a/thirdparty/opus/silk/CNG.c
+++ b/thirdparty/opus/silk/CNG.c
@@ -34,9 +34,8 @@ POSSIBILITY OF SUCH DAMAGE.
/* Generates excitation for CNG LPC synthesis */
static OPUS_INLINE void silk_CNG_exc(
- opus_int32 exc_Q10[], /* O CNG excitation signal Q10 */
+ opus_int32 exc_Q14[], /* O CNG excitation signal Q10 */
opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */
- opus_int32 Gain_Q16, /* I Gain to apply */
opus_int length, /* I Length */
opus_int32 *rand_seed /* I/O Seed to random index generator */
)
@@ -55,7 +54,7 @@ static OPUS_INLINE void silk_CNG_exc(
idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask );
silk_assert( idx >= 0 );
silk_assert( idx <= CNG_BUF_MASK_MAX );
- exc_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
+ exc_Q14[ i ] = exc_buf_Q14[ idx ];
}
*rand_seed = seed;
}
@@ -85,7 +84,7 @@ void silk_CNG(
)
{
opus_int i, subfr;
- opus_int32 sum_Q6, max_Gain_Q16, gain_Q16;
+ opus_int32 LPC_pred_Q10, max_Gain_Q16, gain_Q16, gain_Q10;
opus_int16 A_Q12[ MAX_LPC_ORDER ];
silk_CNG_struct *psCNG = &psDec->sCNG;
SAVE_STACK;
@@ -124,8 +123,8 @@ void silk_CNG(
/* Add CNG when packet is lost or during DTX */
if( psDec->lossCnt ) {
- VARDECL( opus_int32, CNG_sig_Q10 );
- ALLOC( CNG_sig_Q10, length + MAX_LPC_ORDER, opus_int32 );
+ VARDECL( opus_int32, CNG_sig_Q14 );
+ ALLOC( CNG_sig_Q14, length + MAX_LPC_ORDER, opus_int32 );
/* Generate CNG excitation */
gain_Q16 = silk_SMULWW( psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_Q16[1] );
@@ -138,42 +137,46 @@ void silk_CNG(
gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 );
}
- silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, gain_Q16, length, &psCNG->rand_seed );
+ gain_Q10 = silk_RSHIFT( gain_Q16, 6 );
+
+ silk_CNG_exc( CNG_sig_Q14 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, length, &psCNG->rand_seed );
/* Convert CNG NLSF to filter representation */
silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
/* Generate CNG signal, by synthesis filtering */
- silk_memcpy( CNG_sig_Q10, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof( opus_int32 ) );
+ silk_memcpy( CNG_sig_Q14, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof( opus_int32 ) );
for( i = 0; i < length; i++ ) {
silk_assert( psDec->LPC_order == 10 || psDec->LPC_order == 16 );
/* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
- sum_Q6 = silk_RSHIFT( psDec->LPC_order, 1 );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] );
+ LPC_pred_Q10 = silk_RSHIFT( psDec->LPC_order, 1 );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 1 ], A_Q12[ 0 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 2 ], A_Q12[ 1 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 3 ], A_Q12[ 2 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 4 ], A_Q12[ 3 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 5 ], A_Q12[ 4 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 6 ], A_Q12[ 5 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 7 ], A_Q12[ 6 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 8 ], A_Q12[ 7 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 9 ], A_Q12[ 8 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 10 ], A_Q12[ 9 ] );
if( psDec->LPC_order == 16 ) {
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 11 ], A_Q12[ 10 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 12 ], A_Q12[ 11 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 13 ], A_Q12[ 12 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 14 ], A_Q12[ 13 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 15 ], A_Q12[ 14 ] );
- sum_Q6 = silk_SMLAWB( sum_Q6, CNG_sig_Q10[ MAX_LPC_ORDER + i - 16 ], A_Q12[ 15 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 11 ], A_Q12[ 10 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 12 ], A_Q12[ 11 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 13 ], A_Q12[ 12 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 14 ], A_Q12[ 13 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 15 ], A_Q12[ 14 ] );
+ LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, CNG_sig_Q14[ MAX_LPC_ORDER + i - 16 ], A_Q12[ 15 ] );
}
/* Update states */
- CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX_LPC_ORDER + i ], sum_Q6, 4 );
-
- frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( CNG_sig_Q10[ MAX_LPC_ORDER + i ], 10 ) );
+ CNG_sig_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q14[ MAX_LPC_ORDER + i ], LPC_pred_Q10, 4 );
+
+ /* Scale with Gain and add to input signal */
+ frame[ i ] = (opus_int16)silk_ADD_SAT16( frame[ i ], silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( CNG_sig_Q14[ MAX_LPC_ORDER + i ], gain_Q10 ), 8 ) ) );
+
}
- silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
+ silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q14[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
} else {
silk_memset( psCNG->CNG_synth_state, 0, psDec->LPC_order * sizeof( opus_int32 ) );
}
diff --git a/thirdparty/opus/silk/NLSF_del_dec_quant.c b/thirdparty/opus/silk/NLSF_del_dec_quant.c
index c3b9efccfa..de88fee060 100644
--- a/thirdparty/opus/silk/NLSF_del_dec_quant.c
+++ b/thirdparty/opus/silk/NLSF_del_dec_quant.c
@@ -46,8 +46,9 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns
)
{
opus_int i, j, nStates, ind_tmp, ind_min_max, ind_max_min, in_Q10, res_Q10;
- opus_int pred_Q10, diff_Q10, out0_Q10, out1_Q10, rate0_Q5, rate1_Q5;
- opus_int32 RD_tmp_Q25, min_Q25, min_max_Q25, max_min_Q25, pred_coef_Q16;
+ opus_int pred_Q10, diff_Q10, rate0_Q5, rate1_Q5;
+ opus_int16 out0_Q10, out1_Q10;
+ opus_int32 RD_tmp_Q25, min_Q25, min_max_Q25, max_min_Q25;
opus_int ind_sort[ NLSF_QUANT_DEL_DEC_STATES ];
opus_int8 ind[ NLSF_QUANT_DEL_DEC_STATES ][ MAX_LPC_ORDER ];
opus_int16 prev_out_Q10[ 2 * NLSF_QUANT_DEL_DEC_STATES ];
@@ -74,8 +75,8 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns
out0_Q10 = silk_ADD16( out0_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
out1_Q10 = silk_ADD16( out1_Q10, SILK_FIX_CONST( NLSF_QUANT_LEVEL_ADJ, 10 ) );
}
- out0_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_SMULWB( (opus_int32)out0_Q10, quant_step_size_Q16 );
- out1_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_SMULWB( (opus_int32)out1_Q10, quant_step_size_Q16 );
+ out0_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT( silk_SMULBB( out0_Q10, quant_step_size_Q16 ), 16 );
+ out1_Q10_table[ i + NLSF_QUANT_MAX_AMPLITUDE_EXT ] = silk_RSHIFT( silk_SMULBB( out1_Q10, quant_step_size_Q16 ), 16 );
}
silk_assert( (NLSF_QUANT_DEL_DEC_STATES & (NLSF_QUANT_DEL_DEC_STATES-1)) == 0 ); /* must be power of two */
@@ -85,12 +86,11 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns
prev_out_Q10[ 0 ] = 0;
for( i = order - 1; ; i-- ) {
rates_Q5 = &ec_rates_Q5[ ec_ix[ i ] ];
- pred_coef_Q16 = silk_LSHIFT( (opus_int32)pred_coef_Q8[ i ], 8 );
in_Q10 = x_Q10[ i ];
for( j = 0; j < nStates; j++ ) {
- pred_Q10 = silk_SMULWB( pred_coef_Q16, prev_out_Q10[ j ] );
+ pred_Q10 = silk_RSHIFT( silk_SMULBB( (opus_int16)pred_coef_Q8[ i ], prev_out_Q10[ j ] ), 8 );
res_Q10 = silk_SUB16( in_Q10, pred_Q10 );
- ind_tmp = silk_SMULWB( (opus_int32)inv_quant_step_size_Q6, res_Q10 );
+ ind_tmp = silk_RSHIFT( silk_SMULBB( inv_quant_step_size_Q6, res_Q10 ), 16 );
ind_tmp = silk_LIMIT( ind_tmp, -NLSF_QUANT_MAX_AMPLITUDE_EXT, NLSF_QUANT_MAX_AMPLITUDE_EXT-1 );
ind[ j ][ i ] = (opus_int8)ind_tmp;
diff --git a/thirdparty/opus/silk/NLSF_encode.c b/thirdparty/opus/silk/NLSF_encode.c
index 03a036fda2..f03c3f1c35 100644
--- a/thirdparty/opus/silk/NLSF_encode.c
+++ b/thirdparty/opus/silk/NLSF_encode.c
@@ -46,7 +46,7 @@ opus_int32 silk_NLSF_encode( /* O Returns
)
{
opus_int i, s, ind1, bestIndex, prob_Q8, bits_q7;
- opus_int32 W_tmp_Q9;
+ opus_int32 W_tmp_Q9, ret;
VARDECL( opus_int32, err_Q26 );
VARDECL( opus_int32, RD_Q25 );
VARDECL( opus_int, tempIndices1 );
@@ -131,6 +131,7 @@ opus_int32 silk_NLSF_encode( /* O Returns
/* Decode */
silk_NLSF_decode( pNLSF_Q15, NLSFIndices, psNLSF_CB );
+ ret = RD_Q25[ 0 ];
RESTORE_STACK;
- return RD_Q25[ 0 ];
+ return ret;
}
diff --git a/thirdparty/opus/silk/NSQ.c b/thirdparty/opus/silk/NSQ.c
index a065884070..43e3fee7e0 100644
--- a/thirdparty/opus/silk/NSQ.c
+++ b/thirdparty/opus/silk/NSQ.c
@@ -31,6 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "main.h"
#include "stack_alloc.h"
+#include "NSQ.h"
+
static OPUS_INLINE void silk_nsq_scale_states(
const silk_encoder_state *psEncC, /* I Encoder State */
@@ -66,7 +68,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer(
opus_int offset_Q10, /* I */
opus_int length, /* I Input length */
opus_int shapingLPCOrder, /* I Noise shaping AR filter order */
- opus_int predictLPCOrder /* I Prediction filter order */
+ opus_int predictLPCOrder, /* I Prediction filter order */
+ int arch /* I Architecture */
);
#endif
@@ -155,7 +158,7 @@ void silk_NSQ_c
silk_noise_shape_quantizer( NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, A_Q12, B_Q14,
AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10,
- offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder );
+ offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncC->arch );
x_Q3 += psEncC->subfr_length;
pulses += psEncC->subfr_length;
@@ -198,15 +201,19 @@ void silk_noise_shape_quantizer(
opus_int offset_Q10, /* I */
opus_int length, /* I Input length */
opus_int shapingLPCOrder, /* I Noise shaping AR filter order */
- opus_int predictLPCOrder /* I Prediction filter order */
+ opus_int predictLPCOrder, /* I Prediction filter order */
+ int arch /* I Architecture */
)
{
- opus_int i, j;
+ opus_int i;
opus_int32 LTP_pred_Q13, LPC_pred_Q10, n_AR_Q12, n_LTP_Q13;
opus_int32 n_LF_Q12, r_Q10, rr_Q10, q1_Q0, q1_Q10, q2_Q10, rd1_Q20, rd2_Q20;
opus_int32 exc_Q14, LPC_exc_Q14, xq_Q14, Gain_Q10;
opus_int32 tmp1, tmp2, sLF_AR_shp_Q14;
opus_int32 *psLPC_Q14, *shp_lag_ptr, *pred_lag_ptr;
+#ifdef silk_short_prediction_create_arch_coef
+ opus_int32 a_Q12_arch[MAX_LPC_ORDER];
+#endif
shp_lag_ptr = &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
pred_lag_ptr = &sLTP_Q15[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
@@ -215,32 +222,16 @@ void silk_noise_shape_quantizer(
/* Set up short term AR state */
psLPC_Q14 = &NSQ->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 ];
+#ifdef silk_short_prediction_create_arch_coef
+ silk_short_prediction_create_arch_coef(a_Q12_arch, a_Q12, predictLPCOrder);
+#endif
+
for( i = 0; i < length; i++ ) {
/* Generate dither */
NSQ->rand_seed = silk_RAND( NSQ->rand_seed );
/* Short-term prediction */
- silk_assert( predictLPCOrder == 10 || predictLPCOrder == 16 );
- /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
- LPC_pred_Q10 = silk_RSHIFT( predictLPCOrder, 1 );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ 0 ], a_Q12[ 0 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
- if( predictLPCOrder == 16 ) {
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -10 ], a_Q12[ 10 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -11 ], a_Q12[ 11 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -12 ], a_Q12[ 12 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -13 ], a_Q12[ 13 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -14 ], a_Q12[ 14 ] );
- LPC_pred_Q10 = silk_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -15 ], a_Q12[ 15 ] );
- }
+ LPC_pred_Q10 = silk_noise_shape_quantizer_short_prediction(psLPC_Q14, a_Q12, a_Q12_arch, predictLPCOrder, arch);
/* Long-term prediction */
if( signalType == TYPE_VOICED ) {
@@ -259,23 +250,8 @@ void silk_noise_shape_quantizer(
/* Noise shape feedback */
silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
- tmp2 = psLPC_Q14[ 0 ];
- tmp1 = NSQ->sAR2_Q14[ 0 ];
- NSQ->sAR2_Q14[ 0 ] = tmp2;
- n_AR_Q12 = silk_RSHIFT( shapingLPCOrder, 1 );
- n_AR_Q12 = silk_SMLAWB( n_AR_Q12, tmp2, AR_shp_Q13[ 0 ] );
- for( j = 2; j < shapingLPCOrder; j += 2 ) {
- tmp2 = NSQ->sAR2_Q14[ j - 1 ];
- NSQ->sAR2_Q14[ j - 1 ] = tmp1;
- n_AR_Q12 = silk_SMLAWB( n_AR_Q12, tmp1, AR_shp_Q13[ j - 1 ] );
- tmp1 = NSQ->sAR2_Q14[ j + 0 ];
- NSQ->sAR2_Q14[ j + 0 ] = tmp2;
- n_AR_Q12 = silk_SMLAWB( n_AR_Q12, tmp2, AR_shp_Q13[ j ] );
- }
- NSQ->sAR2_Q14[ shapingLPCOrder - 1 ] = tmp1;
- n_AR_Q12 = silk_SMLAWB( n_AR_Q12, tmp1, AR_shp_Q13[ shapingLPCOrder - 1 ] );
+ n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(psLPC_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch);
- n_AR_Q12 = silk_LSHIFT32( n_AR_Q12, 1 ); /* Q11 -> Q12 */
n_AR_Q12 = silk_SMLAWB( n_AR_Q12, NSQ->sLF_AR_shp_Q14, Tilt_Q14 );
n_LF_Q12 = silk_SMULWB( NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - 1 ], LF_shp_Q14 );
diff --git a/thirdparty/opus/silk/NSQ_del_dec.c b/thirdparty/opus/silk/NSQ_del_dec.c
index aff560c221..ab6feeac98 100644
--- a/thirdparty/opus/silk/NSQ_del_dec.c
+++ b/thirdparty/opus/silk/NSQ_del_dec.c
@@ -31,6 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "main.h"
#include "stack_alloc.h"
+#include "NSQ.h"
+
typedef struct {
opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ];
@@ -106,7 +108,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
opus_int warping_Q16, /* I */
opus_int nStatesDelayedDecision, /* I Number of states in decision tree */
opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */
- opus_int decisionDelay /* I */
+ opus_int decisionDelay, /* I */
+ int arch /* I */
);
void silk_NSQ_del_dec_c(
@@ -260,7 +263,7 @@ void silk_NSQ_del_dec_c(
silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15,
delayedGain_Q10, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ],
Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder,
- psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay );
+ psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay, psEncC->arch );
x_Q3 += psEncC->subfr_length;
pulses += psEncC->subfr_length;
@@ -333,7 +336,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
opus_int warping_Q16, /* I */
opus_int nStatesDelayedDecision, /* I Number of states in decision tree */
opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */
- opus_int decisionDelay /* I */
+ opus_int decisionDelay, /* I */
+ int arch /* I */
)
{
opus_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
@@ -343,6 +347,10 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
opus_int32 q1_Q0, q1_Q10, q2_Q10, exc_Q14, LPC_exc_Q14, xq_Q14, Gain_Q10;
opus_int32 tmp1, tmp2, sLF_AR_shp_Q14;
opus_int32 *pred_lag_ptr, *shp_lag_ptr, *psLPC_Q14;
+#ifdef silk_short_prediction_create_arch_coef
+ opus_int32 a_Q12_arch[MAX_LPC_ORDER];
+#endif
+
VARDECL( NSQ_sample_pair, psSampleState );
NSQ_del_dec_struct *psDD;
NSQ_sample_struct *psSS;
@@ -355,6 +363,10 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
pred_lag_ptr = &sLTP_Q15[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
Gain_Q10 = silk_RSHIFT( Gain_Q16, 6 );
+#ifdef silk_short_prediction_create_arch_coef
+ silk_short_prediction_create_arch_coef(a_Q12_arch, a_Q12, predictLPCOrder);
+#endif
+
for( i = 0; i < length; i++ ) {
/* Perform common calculations used in all states */
@@ -398,27 +410,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
/* Pointer used in short term prediction and shaping */
psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];
/* Short-term prediction */
- silk_assert( predictLPCOrder == 10 || predictLPCOrder == 16 );
- /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */
- LPC_pred_Q14 = silk_RSHIFT( predictLPCOrder, 1 );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ 0 ], a_Q12[ 0 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -1 ], a_Q12[ 1 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -2 ], a_Q12[ 2 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -3 ], a_Q12[ 3 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -4 ], a_Q12[ 4 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -5 ], a_Q12[ 5 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -6 ], a_Q12[ 6 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -7 ], a_Q12[ 7 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -8 ], a_Q12[ 8 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -9 ], a_Q12[ 9 ] );
- if( predictLPCOrder == 16 ) {
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -10 ], a_Q12[ 10 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -11 ], a_Q12[ 11 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -12 ], a_Q12[ 12 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -13 ], a_Q12[ 13 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -14 ], a_Q12[ 14 ] );
- LPC_pred_Q14 = silk_SMLAWB( LPC_pred_Q14, psLPC_Q14[ -15 ], a_Q12[ 15 ] );
- }
+ LPC_pred_Q14 = silk_noise_shape_quantizer_short_prediction(psLPC_Q14, a_Q12, a_Q12_arch, predictLPCOrder, arch);
LPC_pred_Q14 = silk_LSHIFT( LPC_pred_Q14, 4 ); /* Q10 -> Q14 */
/* Noise shape feedback */
diff --git a/thirdparty/opus/silk/PLC.c b/thirdparty/opus/silk/PLC.c
index 34a94bc313..fb6ea887b7 100644
--- a/thirdparty/opus/silk/PLC.c
+++ b/thirdparty/opus/silk/PLC.c
@@ -365,7 +365,8 @@ static OPUS_INLINE void silk_PLC_conceal(
}
/* Add prediction to LPC excitation */
- sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], LPC_pred_Q10, 4 );
+ sLPC_Q14_ptr[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ],
+ silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ));
/* Scale with Gain */
frame[ i ] = (opus_int16)silk_SAT16( silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14_ptr[ MAX_LPC_ORDER + i ], prevGain_Q10[ 1 ] ), 8 ) ) );
diff --git a/thirdparty/opus/silk/decode_core.c b/thirdparty/opus/silk/decode_core.c
index b88991e349..e569c0e72b 100644
--- a/thirdparty/opus/silk/decode_core.c
+++ b/thirdparty/opus/silk/decode_core.c
@@ -219,7 +219,7 @@ void silk_decode_core(
}
/* Add prediction to LPC excitation */
- sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT32( pres_Q14[ i ], LPC_pred_Q10, 4 );
+ sLPC_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( pres_Q14[ i ], silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ) );
/* Scale with gain */
pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) );
diff --git a/thirdparty/opus/silk/fixed/burg_modified_FIX.c b/thirdparty/opus/silk/fixed/burg_modified_FIX.c
index 4878553b65..17d0e0993c 100644
--- a/thirdparty/opus/silk/fixed/burg_modified_FIX.c
+++ b/thirdparty/opus/silk/fixed/burg_modified_FIX.c
@@ -150,8 +150,11 @@ void silk_burg_modified_c(
C_first_row[ k ] = silk_MLA( C_first_row[ k ], x1, x_ptr[ n - k - 1 ] ); /* Q( -rshifts ) */
C_last_row[ k ] = silk_MLA( C_last_row[ k ], x2, x_ptr[ subfr_length - n + k ] ); /* Q( -rshifts ) */
Atmp1 = silk_RSHIFT_ROUND( Af_QA[ k ], QA - 17 ); /* Q17 */
- tmp1 = silk_MLA( tmp1, x_ptr[ n - k - 1 ], Atmp1 ); /* Q17 */
- tmp2 = silk_MLA( tmp2, x_ptr[ subfr_length - n + k ], Atmp1 ); /* Q17 */
+ /* We sometimes have get overflows in the multiplications (even beyond +/- 2^32),
+ but they cancel each other and the real result seems to always fit in a 32-bit
+ signed integer. This was determined experimentally, not theoretically (unfortunately). */
+ tmp1 = silk_MLA_ovflw( tmp1, x_ptr[ n - k - 1 ], Atmp1 ); /* Q17 */
+ tmp2 = silk_MLA_ovflw( tmp2, x_ptr[ subfr_length - n + k ], Atmp1 ); /* Q17 */
}
tmp1 = -tmp1; /* Q17 */
tmp2 = -tmp2; /* Q17 */
@@ -200,12 +203,14 @@ void silk_burg_modified_c(
/* Max prediction gain exceeded; set reflection coefficient such that max prediction gain is exactly hit */
tmp2 = ( (opus_int32)1 << 30 ) - silk_DIV32_varQ( minInvGain_Q30, invGain_Q30, 30 ); /* Q30 */
rc_Q31 = silk_SQRT_APPROX( tmp2 ); /* Q15 */
- /* Newton-Raphson iteration */
- rc_Q31 = silk_RSHIFT32( rc_Q31 + silk_DIV32( tmp2, rc_Q31 ), 1 ); /* Q15 */
- rc_Q31 = silk_LSHIFT32( rc_Q31, 16 ); /* Q31 */
- if( num < 0 ) {
- /* Ensure adjusted reflection coefficients has the original sign */
- rc_Q31 = -rc_Q31;
+ if( rc_Q31 > 0 ) {
+ /* Newton-Raphson iteration */
+ rc_Q31 = silk_RSHIFT32( rc_Q31 + silk_DIV32( tmp2, rc_Q31 ), 1 ); /* Q15 */
+ rc_Q31 = silk_LSHIFT32( rc_Q31, 16 ); /* Q31 */
+ if( num < 0 ) {
+ /* Ensure adjusted reflection coefficients has the original sign */
+ rc_Q31 = -rc_Q31;
+ }
}
invGain_Q30 = minInvGain_Q30;
reached_max_gain = 1;
diff --git a/thirdparty/opus/silk/fixed/x86/burg_modified_FIX_sse.c b/thirdparty/opus/silk/fixed/x86/burg_modified_FIX_sse.c
index 3756095fbe..3c3583c5fc 100644
--- a/thirdparty/opus/silk/fixed/x86/burg_modified_FIX_sse.c
+++ b/thirdparty/opus/silk/fixed/x86/burg_modified_FIX_sse.c
@@ -300,12 +300,14 @@ void silk_burg_modified_sse4_1(
/* Max prediction gain exceeded; set reflection coefficient such that max prediction gain is exactly hit */
tmp2 = ( (opus_int32)1 << 30 ) - silk_DIV32_varQ( minInvGain_Q30, invGain_Q30, 30 ); /* Q30 */
rc_Q31 = silk_SQRT_APPROX( tmp2 ); /* Q15 */
- /* Newton-Raphson iteration */
- rc_Q31 = silk_RSHIFT32( rc_Q31 + silk_DIV32( tmp2, rc_Q31 ), 1 ); /* Q15 */
- rc_Q31 = silk_LSHIFT32( rc_Q31, 16 ); /* Q31 */
- if( num < 0 ) {
- /* Ensure adjusted reflection coefficients has the original sign */
- rc_Q31 = -rc_Q31;
+ if( rc_Q31 > 0 ) {
+ /* Newton-Raphson iteration */
+ rc_Q31 = silk_RSHIFT32( rc_Q31 + silk_DIV32( tmp2, rc_Q31 ), 1 ); /* Q15 */
+ rc_Q31 = silk_LSHIFT32( rc_Q31, 16 ); /* Q31 */
+ if( num < 0 ) {
+ /* Ensure adjusted reflection coefficients has the original sign */
+ rc_Q31 = -rc_Q31;
+ }
}
invGain_Q30 = minInvGain_Q30;
reached_max_gain = 1;
diff --git a/thirdparty/opus/silk/macros.h b/thirdparty/opus/silk/macros.h
index bc30303466..d3ca347520 100644
--- a/thirdparty/opus/silk/macros.h
+++ b/thirdparty/opus/silk/macros.h
@@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "opus_types.h"
#include "opus_defines.h"
+#include "arch.h"
#if OPUS_GNUC_PREREQ(3, 0)
#define opus_likely(x) (__builtin_expect(!!(x), 1))
@@ -43,31 +44,32 @@ POSSIBILITY OF SUCH DAMAGE.
#define opus_unlikely(x) (!!(x))
#endif
-/* Set this if opus_int64 is a native type of the CPU. */
-#define OPUS_FAST_INT64 (defined(__x86_64__) || defined(__LP64__) || defined(_WIN64))
-
/* This is an OPUS_INLINE header file for general platform. */
/* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
#if OPUS_FAST_INT64
-#define silk_SMULWB(a32, b32) (((a32) * (opus_int64)((opus_int16)(b32))) >> 16)
+#define silk_SMULWB(a32, b32) ((opus_int32)(((a32) * (opus_int64)((opus_int16)(b32))) >> 16))
#else
#define silk_SMULWB(a32, b32) ((((a32) >> 16) * (opus_int32)((opus_int16)(b32))) + ((((a32) & 0x0000FFFF) * (opus_int32)((opus_int16)(b32))) >> 16))
#endif
/* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
#if OPUS_FAST_INT64
-#define silk_SMLAWB(a32, b32, c32) ((a32) + (((b32) * (opus_int64)((opus_int16)(c32))) >> 16))
+#define silk_SMLAWB(a32, b32, c32) ((opus_int32)((a32) + (((b32) * (opus_int64)((opus_int16)(c32))) >> 16)))
#else
#define silk_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)))
#endif
/* (a32 * (b32 >> 16)) >> 16 */
+#if OPUS_FAST_INT64
+#define silk_SMULWT(a32, b32) ((opus_int32)(((a32) * (opus_int64)((b32) >> 16)) >> 16))
+#else
#define silk_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
+#endif
/* a32 + (b32 * (c32 >> 16)) >> 16 */
#if OPUS_FAST_INT64
-#define silk_SMLAWT(a32, b32, c32) ((a32) + (((b32) * ((opus_int64)(c32) >> 16)) >> 16))
+#define silk_SMLAWT(a32, b32, c32) ((opus_int32)((a32) + (((b32) * ((opus_int64)(c32) >> 16)) >> 16)))
#else
#define silk_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
#endif
@@ -89,14 +91,14 @@ POSSIBILITY OF SUCH DAMAGE.
/* (a32 * b32) >> 16 */
#if OPUS_FAST_INT64
-#define silk_SMULWW(a32, b32) (((opus_int64)(a32) * (b32)) >> 16)
+#define silk_SMULWW(a32, b32) ((opus_int32)(((opus_int64)(a32) * (b32)) >> 16))
#else
#define silk_SMULWW(a32, b32) silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16))
#endif
/* a32 + ((b32 * c32) >> 16) */
#if OPUS_FAST_INT64
-#define silk_SMLAWW(a32, b32, c32) ((a32) + (((opus_int64)(b32) * (c32)) >> 16))
+#define silk_SMLAWW(a32, b32, c32) ((opus_int32)((a32) + (((opus_int64)(b32) * (c32)) >> 16)))
#else
#define silk_SMLAWW(a32, b32, c32) silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16))
#endif
@@ -149,5 +151,9 @@ static OPUS_INLINE opus_int32 silk_CLZ32(opus_int32 in32)
#include "arm/macros_armv5e.h"
#endif
+#ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
+#include "arm/macros_arm64.h"
+#endif
+
#endif /* SILK_MACROS_H */
diff --git a/thirdparty/opus/silk/mips/NSQ_del_dec_mipsr1.h b/thirdparty/opus/silk/mips/NSQ_del_dec_mipsr1.h
index f6afd923e8..ad1cfe2a9b 100644
--- a/thirdparty/opus/silk/mips/NSQ_del_dec_mipsr1.h
+++ b/thirdparty/opus/silk/mips/NSQ_del_dec_mipsr1.h
@@ -62,7 +62,8 @@ static inline void silk_noise_shape_quantizer_del_dec(
opus_int warping_Q16, /* I */
opus_int nStatesDelayedDecision, /* I Number of states in decision tree */
opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */
- opus_int decisionDelay /* I */
+ opus_int decisionDelay, /* I */
+ int arch /* I */
)
{
opus_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
@@ -82,6 +83,9 @@ static inline void silk_noise_shape_quantizer_del_dec(
opus_int32 cur, prev, next;
+ /*Unused.*/
+ (void)arch;
+
//Intialize b_Q14 variables
b_Q14_0 = b_Q14[ 0 ];
b_Q14_1 = b_Q14[ 1 ];
diff --git a/thirdparty/opus/silk/process_NLSFs.c b/thirdparty/opus/silk/process_NLSFs.c
index c27cf03046..0ab71f0163 100644
--- a/thirdparty/opus/silk/process_NLSFs.c
+++ b/thirdparty/opus/silk/process_NLSFs.c
@@ -41,7 +41,7 @@ void silk_process_NLSFs(
{
opus_int i, doInterpolate;
opus_int NLSF_mu_Q20;
- opus_int32 i_sqr_Q15;
+ opus_int16 i_sqr_Q15;
opus_int16 pNLSF0_temp_Q15[ MAX_LPC_ORDER ];
opus_int16 pNLSFW_QW[ MAX_LPC_ORDER ];
opus_int16 pNLSFW0_temp_QW[ MAX_LPC_ORDER ];
@@ -79,7 +79,8 @@ void silk_process_NLSFs(
/* Update NLSF weights with contribution from first half */
i_sqr_Q15 = silk_LSHIFT( silk_SMULBB( psEncC->indices.NLSFInterpCoef_Q2, psEncC->indices.NLSFInterpCoef_Q2 ), 11 );
for( i = 0; i < psEncC->predictLPCOrder; i++ ) {
- pNLSFW_QW[ i ] = silk_SMLAWB( silk_RSHIFT( pNLSFW_QW[ i ], 1 ), (opus_int32)pNLSFW0_temp_QW[ i ], i_sqr_Q15 );
+ pNLSFW_QW[ i ] = silk_ADD16( silk_RSHIFT( pNLSFW_QW[ i ], 1 ), silk_RSHIFT(
+ silk_SMULBB( pNLSFW0_temp_QW[ i ], i_sqr_Q15 ), 16) );
silk_assert( pNLSFW_QW[ i ] >= 1 );
}
}
@@ -100,6 +101,7 @@ void silk_process_NLSFs(
} else {
/* Copy LPC coefficients for first half from second half */
+ silk_assert( psEncC->predictLPCOrder <= MAX_LPC_ORDER );
silk_memcpy( PredCoef_Q12[ 0 ], PredCoef_Q12[ 1 ], psEncC->predictLPCOrder * sizeof( opus_int16 ) );
}
}
diff --git a/thirdparty/opus/silk/sort.c b/thirdparty/opus/silk/sort.c
index 8670dbdd02..7187c9efb1 100644
--- a/thirdparty/opus/silk/sort.c
+++ b/thirdparty/opus/silk/sort.c
@@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
/* Best case: O(n) for an already sorted array */
/* Worst case: O(n^2) for an inversely sorted array */
/* */
-/* Shell short: http://en.wikipedia.org/wiki/Shell_sort */
+/* Shell short: https://en.wikipedia.org/wiki/Shell_sort */
#include "SigProc_FIX.h"
diff --git a/thirdparty/opus/silk/stereo_LR_to_MS.c b/thirdparty/opus/silk/stereo_LR_to_MS.c
index 42906e6f67..dda0298de2 100644
--- a/thirdparty/opus/silk/stereo_LR_to_MS.c
+++ b/thirdparty/opus/silk/stereo_LR_to_MS.c
@@ -77,7 +77,7 @@ void silk_stereo_LR_to_MS(
ALLOC( LP_mid, frame_length, opus_int16 );
ALLOC( HP_mid, frame_length, opus_int16 );
for( n = 0; n < frame_length; n++ ) {
- sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[ n + 1 ], 1 ), 2 );
+ sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 2 );
LP_mid[ n ] = sum;
HP_mid[ n ] = mid[ n + 1 ] - sum;
}
@@ -86,7 +86,7 @@ void silk_stereo_LR_to_MS(
ALLOC( LP_side, frame_length, opus_int16 );
ALLOC( HP_side, frame_length, opus_int16 );
for( n = 0; n < frame_length; n++ ) {
- sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( side[ n ] + side[ n + 2 ], side[ n + 1 ], 1 ), 2 );
+ sum = silk_RSHIFT_ROUND( silk_ADD_LSHIFT( side[ n ] + (opus_int32)side[ n + 2 ], side[ n + 1 ], 1 ), 2 );
LP_side[ n ] = sum;
HP_side[ n ] = side[ n + 1 ] - sum;
}
@@ -207,7 +207,7 @@ void silk_stereo_LR_to_MS(
pred0_Q13 += delta0_Q13;
pred1_Q13 += delta1_Q13;
w_Q24 += deltaw_Q24;
- sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */
+ sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */
sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 ); /* Q8 */
sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */
x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) );
@@ -217,7 +217,7 @@ void silk_stereo_LR_to_MS(
pred1_Q13 = -pred_Q13[ 1 ];
w_Q24 = silk_LSHIFT( width_Q14, 10 );
for( n = STEREO_INTERP_LEN_MS * fs_kHz; n < frame_length; n++ ) {
- sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */
+ sum = silk_LSHIFT( silk_ADD_LSHIFT( mid[ n ] + (opus_int32)mid[ n + 2 ], mid[ n + 1 ], 1 ), 9 ); /* Q11 */
sum = silk_SMLAWB( silk_SMULWB( w_Q24, side[ n + 1 ] ), sum, pred0_Q13 ); /* Q8 */
sum = silk_SMLAWB( sum, silk_LSHIFT( (opus_int32)mid[ n + 1 ], 11 ), pred1_Q13 ); /* Q8 */
x2[ n - 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sum, 8 ) );
diff --git a/thirdparty/opus/silk/x86/NSQ_sse.c b/thirdparty/opus/silk/x86/NSQ_sse.c
index 72f34fd6fc..bb3c5f1955 100644
--- a/thirdparty/opus/silk/x86/NSQ_sse.c
+++ b/thirdparty/opus/silk/x86/NSQ_sse.c
@@ -221,7 +221,7 @@ void silk_NSQ_sse4_1(
{
silk_noise_shape_quantizer( NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, A_Q12, B_Q14,
AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10,
- offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder );
+ offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncC->arch );
}
x_Q3 += psEncC->subfr_length;
diff --git a/thirdparty/opus/silk/x86/main_sse.h b/thirdparty/opus/silk/x86/main_sse.h
index afd5ec26e1..d8d61310ed 100644
--- a/thirdparty/opus/silk/x86/main_sse.h
+++ b/thirdparty/opus/silk/x86/main_sse.h
@@ -207,7 +207,8 @@ void silk_noise_shape_quantizer(
opus_int offset_Q10, /* I */
opus_int length, /* I Input length */
opus_int shapingLPCOrder, /* I Noise shaping AR filter order */
- opus_int predictLPCOrder /* I Prediction filter order */
+ opus_int predictLPCOrder, /* I Prediction filter order */
+ int arch /* I Architecture */
);
/**************************/