Commit graph

2358 commits

Author SHA1 Message Date
clayjohn
756a37bcae Properly reset texture flags when generating radiance 2020-11-01 09:06:44 -08:00
lawnjelly
5c8f497a24 Add project settings to manually specify API usage
As a result of the GLES specifications being vague about best practice for how buffers should be used dynamically, different GPUs / platforms appear to have different preferences.

Mac in particular seems to have a number of problems in this area, and none of the rendering team uses Macs. So far we have relied on guesswork to choose the best usage, but in an attempt to pin this down, this PR begins to introduce manual selection of options for users to test their configurations.
2020-10-31 18:33:55 +00:00
Rémi Verschelde
c43b2ab603
Merge pull request #42942 from Calinou/add-viewport-debanding-3.2
Add a debanding property to Viewport for GLES3
2020-10-30 11:47:57 +01:00
Ev1lbl0w
126d08e33d
Fix wrong exit code being returned
(cherry picked from commit 0d3a168a53)
2020-10-28 14:05:41 +01:00
Rémi Verschelde
efdc5f0f89
Merge pull request #43054 from lawnjelly/ewok_fix_largefvf
Fix transforms in custom shaders using large FVF
2020-10-28 09:49:36 +01:00
lawnjelly
586285639a Fix lines used in item with custom shader
Lines are batched using the simplest fvf 'BatchVertex', however when used in an item with a custom shader material, it may attempt to translate to large_fvf without the required extra channels. To prevent this a special case in flushing is made to deal with lines.
2020-10-26 17:45:44 +00:00
lawnjelly
f4cb88e232 Fix transforms in custom shaders using large FVF
In small batches using hardware transform, vertices would be drawn in incorrect positions due to the item transform being applied twice - once in the transform uniform, and once from the transform passed as a vertex attribute.

This PR alters the shader to ignore uniform transforms when using large FVF.
2020-10-25 12:57:42 +00:00
clayjohn
505d469e50 Remove extra exposure multiply in FXAA 2020-10-24 13:11:27 -07:00
lawnjelly
debda7f411 Reverting changes to legacy polys and generic prims
Due to my less than eagle-like view over these functions I had assumed they were passing in a single buffer input for the changes to make buffer uploading more efficient. They aren't, which is less than ideal.

So these particular changes should be reverted. When I have some more time I'll see whether the API for these calls can be changed, because as is the multiple glSubBufferData calls could be causing stalls on some hardware.
2020-10-22 10:01:25 +01:00
Hugo Locurcio
2dbc329704
Add a debanding property to Viewport for GLES3
It can be enabled in the Project Settings
(`rendering/quality/filters/use_debanding`). It's disabled
by default as it has a small performance impact and can make
PNG screenshots much larger (due to how dithering works).

As a result, it should be enabled only when banding is noticeable enough.

Since debanding requires a HDR viewport to work, it's only supported
in the GLES3 backend.
2020-10-20 19:07:15 +02:00
Hugo Locurcio
af45c97652
Add fast approximate antialiasing (FXAA) to Viewport
This backports FXAA from the `master` branch.

Co-authored-by: Clay John <claynjohn@gmail.com>
2020-10-20 14:54:52 +02:00
lawnjelly
a63d8aa634 Resync RasterizerDummy to Rasterizer 2020-10-20 11:59:13 +01:00
Rémi Verschelde
f442dc062a
Merge pull request #42056 from Yetizone/negative_lights_behavior
tonemap.glsl: Ensure color parameter of tonemap_reinhard() is positive
2020-10-19 22:40:24 +02:00
Juan Linietsky
388ebfb498
Merge pull request #41629 from JFonS/disable_baked_lights
Disable lights for objects with baked lighting
2020-10-19 14:12:50 -03:00
Rémi Verschelde
123942f61f
Merge pull request #42119 from lawnjelly/ewok3
Unified GLES3 / GLES2 Batching
2020-10-19 15:01:10 +02:00
Rémi Verschelde
4a92d2111b
Merge pull request #38954 from puchik/ssr-far-clip
Check if screen space reflection has passed far clip
2020-10-18 20:48:44 +02:00
Juan Linietsky
8ca98dd1a0
Merge pull request #41892 from puchik/ssr-edge-fade
Fade screen-space reflection towards inner margin
2020-10-18 14:50:20 -03:00
lawnjelly
74c460fb67 Reduce glBufferSubData calls in legacy renderer
This is part of effort to make more efficient use of the API for devices with poor drivers. This eliminates multiple calls to glBufferSubData per update.
2020-10-18 11:27:08 +01:00
lawnjelly
c2290dbedd Unified GLES2 / GLES3 Batching
Batching is mostly separated into a common template which can be used with multiple backends (GLES2 and GLES3 here). Only necessary specifics are in the backend files.

Batching is extended to cover more primitives.
2020-10-16 10:34:47 +01:00
lawnjelly
42bca1a4a9 Fix buffer orphaning on desktop
Vertex / Index Buffer orphaning was previously turned off on desktop, which was causing performance problems on some platforms, especially Mac.
2020-10-12 10:32:35 +01:00
JFonS
fcb00ca048 Disable lights for objects with baked lighting
Don't apply lighting to objects when they have a lightmap texture and
the light is set to BAKE_ALL. This prevents applying the same direct
light twice on the same object and makes setting up scenes with mixed
lighting much easier.
2020-10-11 20:41:40 +02:00
PouleyKetchoupp
f9544716f4 Option for software skinning in MeshInstance
Option in MeshInstance to enable software skinning, in order to test
against the current USE_SKELETON_SOFTWARE path which causes problems
with bad performance.

Co-authored-by: lawnjelly <lawnjelly@gmail.com>
2020-10-08 16:14:55 +02:00
Rémi Verschelde
2882284795
Merge pull request #42538 from clayjohn/GLES2-light-texture
Use separate texture unit for light_texture
2020-10-03 23:33:57 +02:00
clayjohn
081d016e60 Use separate texture unit for light_texture 2020-10-03 12:15:58 -07:00
xix xeaon
975637c60b
Fix mod op (%) implementation in GLES2 2020-10-02 11:43:19 +02:00
clayjohn
ea1b8d8435 Fix glow on devices with only 8 texture slots 2020-09-30 22:28:20 -07:00
Haoyu Qiu
7840a550b5
Hides special folders in FileDialog for macOS
(cherry picked from commit 1998f78679)
2020-09-29 13:57:58 +02:00
Bartłomiej T. Listwon
858bdbacfd
Add all headers to VS Project
(cherry picked from commit 317c2b194d)
2020-09-29 13:57:56 +02:00
Rémi Verschelde
422c279fcb
Merge pull request #41323 from lawnjelly/kessel_lightangles
GLES2 2D fix normal mapping - batching and nvidia workaround
2020-09-28 18:45:43 +02:00
Rémi Verschelde
cd05197fb3
Merge pull request #41254 from lawnjelly/gles3_nvidia_normalrotation
GLES3 fix normal map flipping with nvidia workaround
2020-09-28 10:40:22 +02:00
Vasiliy Makarov
f388ea00bf iOS: Fix multiple issues with PVRTC import, disable ETC1
Fixes: #28683, #28621, #28596 and maybe others

For iOS we enable pvrtc feature by default for both GLES2/GLES3
Etc1 for iOS doesn't have any sense, so it disabled.
Fixed checks in export editor.
Fixed pvrtc ability detection in GLES2 driver.
Fixed pvrtc encoding procedure.
2020-09-23 11:13:50 +02:00
Rémi Verschelde
c8859f0463
Fix typos with codespell
Using codespell 1.17.1.

Method:
```
$ cat > ../godot-word-whitelist.txt << EOF
ang
curvelinear
dof
doubleclick
fave
findn
leapyear
lod
merchantibility
nd
numer
ois
ony
que
seeked
synching
te
uint
unselect
webp
EOF

$ codespell -w -q 3 -I ../godot-word-whitelist.txt --skip="./thirdparty,*.po"
$ git diff // undo unwanted changes
```
2020-09-18 14:09:51 +02:00
Rémi Verschelde
b73a9109ab
NetBSD: Implement OS_Unix::get_executable_path()
Same implementation as OpenBSD seems to work fine.

(cherry picked from commit 01185acecb)
2020-09-18 11:55:58 +02:00
Rémi Verschelde
cb78a5d7ae
Linux/BSD: Fix support for NetBSD
Add __NetBSD__ to `platform_config.h` so that it can find `alloca`
and use the proper `pthread_setname_np` format.

Rename RANDOM_MAX to avoid conflict with NetBSD stdlib.

Fixes #42145.

(cherry picked from commit 5f4d64f4f3)
2020-09-18 10:29:52 +02:00
Yetizone
e6a860deb6 tonemap.glsl: Ensure color parameter of tonemap_reinhard() is positive
Color values can become negative in the case of negative lights which
leads to undesired behaviour.
2020-09-15 15:46:30 +03:00
Arman
cf7bb2c51f Fade screen-space reflection towards inner margin
- Fade reflection towards inner margin and clip it at screen edges instead of external margin.
- Round edges of the fade margin if both are being cut off to prevent sharp corners.
2020-09-08 15:29:36 -07:00
Marcel Admiraal
5f1dd48496
Replace calls to gmtime with gmtime_r and localtime with localtime_r.
(cherry picked from commit 4b3aec50c0)
2020-09-08 08:55:26 +02:00
Fredia Huya-Kouadio
0af5cded1e Fix the update logic for user-added custom defines.
The previous logic was causing the (unintentional) removal of custom defines automatically added by the engine.
2020-09-06 21:31:09 -07:00
Marcel Admiraal
c6cccdf0c6 Ensure header guards enclose entire header.
(cherry picked from commit f6ad1954f7)
2020-09-04 08:48:35 +02:00
Adam Brown
a16bedd2d9 dummy_rasterizer now returns lightmap type
Previously VS::INSTANCE_NONE was returned for Lightmap data, this caused `visual_server_scene.cpp` to assert in `instance_set_use_lightmap()`

Now `dummy_rasterizer.h` returns `VS::INSTANCE_LIGHTMAP_CAPTURE` for lightmap capture data thus satisfying `visual_server_scene`
2020-09-02 11:50:36 -07:00
lawnjelly
674327b78f GLES3 fix normal map flipping with nvidia workaround
When not using TEXTURE_RECT path, flips have to sent via another method to the shader, to ensure that normal maps are correctly adjusted for direction. This PR adds an extra vertex attribute, LIGHT_ANGLE.

For nvidia workarounds, where the shader still has access to the final transform and extra matrix, the LIGHT_ANGLE can be 0 (no adjustment), 180 degrees for a horizontal flip, and negative indicates a vertical flip.

For batching path, the LIGHT_ANGLE can be used to directly specify the light angle for normal mapping, even when the final transform and extra matrix have been baked into vertex positions, so the same shader can be used for both.
2020-08-23 07:54:58 +01:00
lawnjelly
ecd39094ed GLES2 2D fix normal mapping - batching and nvidia workaround
Normal mapping previously took no account of rotation or flips in any path except the TEXTURE_RECT (uniform draw) method. This passed flips to the shader in uniforms.

In order to pass flips and rotations to the shader in batching and nvidia workaround, a per vertex attribute is required rather than a uniform. This introduces LIGHT_ANGLE which encodes both the rotation of a quad (vertex) and the horizontal and vertical flip.

In order to optionally store light angles in batching, we switch to using a 'unit' sized array which can be reused for different FVF types, as there is no need for a separate array for each FVF, as it is a waste of memory.
2020-08-18 17:49:24 +01:00
lawnjelly
2961d905bb GLES2 batching - Fix redundant transform synchronization in batches
In rare circumstances an item would issue multiple transform commands before a (non rect) draw command. The command syncronization would incorrectly start from first transform, instead of the current transform in these circumstances, which could have the result of missing drawing some commands from the end of the batch.

This had been shown in the wild occuring in debug collision polys. It was a benign error (sometimes visual elements would be lost), but did not cause any serious problems.

This PR fixes this synchronization error.
2020-08-18 08:37:07 +01:00
bruvzg
b0aabf2c03 [macOS] Fix crash on failed fork.
(cherry picked from commit d6e3a8a137)
2020-08-14 00:32:04 +02:00
lawnjelly
e126b941be Removes some superfluous FORCE_INLINES
Compiler is usually in the best position to decide whether to inline functions. Great care must be taken using FORCE_INLINE because it can have unforeseen consequences with recursion, loops and bloat to the executable.

Here some FORCE_INLINES are removed in order to allow the compiler to make best choice and remove a compilation warning where unable to inline during a recursive function.

Fixes #41226
2020-08-13 17:58:47 +01:00
Holger Dammertz
efe6b50f17 Added option to enable high precision float in GLES2
An additional project setting under rendering/gles2/compatibility with the name
enable_high_float.Android is introduced that enables #define USE_HIGHP_PRECISION
in GLES2 shader on Android when it is supported by the shader compiler.
This fixes #33633 and #32813 and also https://github.com/GodotVR/godot_oculus_mobile/issues/60
and https://github.com/GodotVR/godot_oculus_mobile/issues/68 on devices that
support the highp (high precision) modifier.
2020-07-30 05:40:15 +02:00
Nathan Franke
b9e1db7e03
Revert "Fix Directory Open Check"
This reverts commit 3f898f5207.
2020-07-28 13:54:13 -04:00
Rémi Verschelde
b40f3f9740 Style: Sync other changes from new fix_style.sh and clang_format.sh 2020-07-24 10:39:18 +02:00
clayjohn
2534e28918 Fix OpenGL error when generating radiance 2020-07-21 10:40:49 -07:00
clayjohn
e5cc4d4f87 Allow nearest neighbor lookup when using mipmaps 2020-07-19 14:44:42 -07:00
lawnjelly
2f983c82c8 GLES2 Batching - Fix FORCE_REPEAT not being set properly on npot hardware
On platforms that don't report support for GL_REPEAT for non power of two textures, the FORCE_REPEAT conditional is used instead. However for rect batches, the conditional was being set AFTER binding the shader, which meant it wasn't being activated.

This PR simply shifts setting the conditional to before the shader bind.
2020-07-15 09:28:16 +01:00
Johan Rastén
4c2d0d38fd Handle 16 bit PNG files in sRGB format
(cherry picked from commit e7e632cbed)
2020-07-10 08:51:21 +02:00
PouleyKetchoupp
5854bf4696 Fixed mesh data access errors in GLES2
1. Removed errors in mesh_surface_get_array as it's supported now
2. More accurate errors in mesh_surface_get_blend_shapes

(cherry picked from commit e19a3df98f)
2020-07-10 08:51:21 +02:00
Nathan Franke
3f898f5207 Fix Directory Open Check
(cherry picked from commit 09aeb7706b)
2020-07-08 09:01:57 +02:00
azagaya
d539627be2 Fixed white image in margins when using same image in scene 2020-07-06 15:54:45 -03:00
Rémi Verschelde
22863363a7
Merge pull request #37475 from azagaya/3.2
Fixed images in black margins
2020-07-03 13:09:22 +02:00
clayjohn
95f93b5f0f force depth prepass when using alpha prepass 2020-06-26 15:16:20 -07:00
Wavesonics
23d44223e6 Fix memory leaks in RasterizerStorageDummy::free
Lightmap capture data is now freed as well
free() now also properly returns true or false based on if something was actually freed.
2020-06-25 12:22:00 -07:00
lawnjelly
491059ca82 GLES2 Batching - Fix texture wrapping state bug.
For textures that were imported as wrapping, the legacy renderer relied on GL repeat state being set as a once off during load, and didn't alter the GL wrapping state at runtime.

Batching was setting wrapping according to the CANVAS_RECT_TILE flag on rects, however this reset GL wrapping to clamp after use, which was conflicting with later drawcalls that relied on the default wrapping being preserved.

In this PR we only set the wrapping in GL if the texture has not been imported with wrapping. This duplicates the logic in the legacy renderer and solves the state bug.
2020-06-23 08:34:17 +01:00
lawnjelly
a4bd66f854 GLES2 Batching - prevent baking on VERTEX use in a shader
Using the operator += in a shader is classified as an 'assign', and so is classified as a write rather than a read. This means that we need to prevent vertex baking on either a write or read (i.e. on usage), rather than just on reads.
2020-06-19 09:42:04 +01:00
Rémi Verschelde
e50e834197
Merge pull request #39559 from RandomShaper/fix_half_float_textures_3.2
Fix wrong internal format for half-float textures
2020-06-15 19:36:49 +02:00
Pedro J. Estébanez
c15e5af60e Fix wrong internal format for half-float textures 2020-06-15 13:03:13 +02:00
lawnjelly
94d127ccc3 GLES2 Batching - Fix try_join_item logic for lights
The old logic was incorrect, the first item with lights would prevent joining the next item in case it didn't have lights. Now the check is deferred so that items without lights check to see if the previous item had lights, and if so they prevent a join.
2020-06-14 08:22:41 +01:00
Rémi Verschelde
3fb9c776ff
Merge pull request #39437 from akien-mga/3.2-cherrypicks
Cherry-picks for the 3.2 branch (future 3.2.2) - 8th batch
2020-06-10 17:33:50 +02:00
Rémi Verschelde
3c7e03510c
Merge pull request #39256 from lawnjelly/tilemap_pixel2
GLES2 batching - Add UV precision adjustment for tilemaps
2020-06-10 15:52:00 +02:00
Rémi Verschelde
7bf9787921 SCons: Format buildsystem files with psf/black
Configured for a max line length of 120 characters.

psf/black is very opinionated and purposely doesn't leave much room for
configuration. The output is mostly OK so that should be fine for us,
but some things worth noting:

- Manually wrapped strings will be reflowed, so by using a line length
  of 120 for the sake of preserving readability for our long command
  calls, it also means that some manually wrapped strings are back on
  the same line and should be manually merged again.

- Code generators using string concatenation extensively look awful,
  since black puts each operand on a single line. We need to refactor
  these generators to use more pythonic string formatting, for which
  many options are available (`%`, `format` or f-strings).

- CI checks and a pre-commit hook will be added to ensure that future
  buildsystem changes are well-formatted.

(cherry picked from commit cd4e46ee65)
2020-06-10 15:30:52 +02:00
Wilson E. Alvarez
782173f0dc
Fixed mismatched disable half float property string 2020-06-09 23:02:28 -04:00
lawnjelly
275183ef15 GLES2 batching - Add UV precision adjustment for tilemaps
Scaling tilemaps can cause border artifacts around the edges of tiles. This has been traced to precision issues in the GPU. This PR adds an adjustment to allow a minor contraction of the UVs of rects in order to compensate for the incorrect classification of texels across the UV border.
2020-06-07 16:29:40 +01:00
Rémi Verschelde
6e1af78df4
Merge pull request #39068 from lawnjelly/kessel_settings_rename
Rename batching project settings in preparation for GLES3
2020-06-07 14:25:50 +02:00
Pedro J. Estébanez
1ff7b0a0a9 Add shader time scaling
Shaders' `TIME` will be affected by the new shader time scale, that is set via the also new `VisualServer::set_time_scale()`.
2020-06-06 23:59:48 +02:00
Nathan Franke
219717fc21 fix(Directory): remove erasing print
Fixes #39106

(cherry picked from commit e48fb01d59)
2020-06-04 12:09:39 +02:00
Arman
48ffd3d157 Check if screen space reflection has passed far clip
Before "accepting" the reflection, check if it's within our view (prevent tracing environment and creating artifacts).
2020-06-04 00:52:16 -07:00
azagaya
3305783bac Fixed images in black margins 2020-06-03 18:33:33 -03:00
Yuri Roubinsky
371d48aea1 [3.2] Fix shader's length() function parsing in expressions 2020-06-03 19:43:47 +03:00
lawnjelly
c7d18dec70 Rename batching project settings in preparation for GLES3
As it now seems like we will soon have GLES3 batching working using the same intermediate layer as GLES2, it makes more sense to reuse the same batching settings for both renderers rather than duplicate project settings for GLES2 and GLES3.
2020-05-26 18:15:35 +01:00
CJ DiMaggio
ad3d643bc2 Delete DummyMesh when RasterizerStorageDummy is freed
(cherry picked from commit 66a294d459)
2020-05-25 16:32:48 +02:00
lawnjelly
b95add2bfd GLES2 Batching - Builtins prevent baking in unshaded shaders
Builtins that should prevent baking colors and vertex positions were incorrectly only active in shaders that were not unshaded. This was a terminology misunderstanding - unshaded materials can still use shaders so should have the same test to prevent baking.
2020-05-23 11:35:33 +01:00
Andrii Doroshenko (Xrayez)
a3cad44f44 Add Image.save_png_to_buffer method
Backported from da0457fa29.

This commit additionally exposes the method to scripting (4.0).
2020-05-20 15:38:20 +03:00
Rémi Verschelde
e6a3499bef Fix Visual Studio C4334 warning 2020-05-19 10:19:52 +02:00
Fabio Alessandrelli
92031098bf Move mixrate and latency definition to AudioServer
Each driver used to define the (same) project settings value, but the
setting names are not driver specific. Ovverriding is still possible via
platform tags.

(cherry picked from commit 90c7102b51)
2020-05-18 16:40:33 +02:00
lawnjelly
8005175ea5 GLES2 polyline drawn as GL_LINE_STRIP to match GLES3
The behaviour of TYPE_POLYLINE appeared incorrect in GLES2, and inconsistent with GLES3 and the docs, which state that draw_polyline 'Draws interconnected line segments'. Also when drawing with triangles GLES2 draws interconnected segments.

This PR simply changes the primitive from GL_LINES to GL_LINE_STRIP as in GLES3.
2020-05-14 10:38:12 +01:00
Author Lawnjelly
94ed206bfc GLES2 Batching - Prevent baking colors with COLOR writes
Writing to COLOR in a custom shader can result in incorrect results if colors are baked (vertex color and modulate). This PR prevents baking with COLOR output, except under the special circumstances that final modulate is (1, 1, 1, 1), in which case the result will be correct. This should still allow color baking in many scenarios with custom shaders.
2020-05-12 14:04:53 +01:00
lawnjelly
57c70d8e9c GLES2 Batching - Prevent VERTEX baking within items in custom shaders
In addition to prevent item joins when VERTEX reads are present in a custom shader, it is also necessary to prevent baking extra matrices (extra transforms) WITHIN items, because these can also report incorrect results.
2020-05-11 17:18:57 +01:00
lawnjelly
d096ce1644 GLES2 Batching - Fix custom shaders reading VERTEX
In situations where custom canvas shaders read VERTEX values, they could read incorrect global positions rather than local positions where batching had baked item transforms. This PR prevents joining items that read VERTEX built in in shaders, and thus prevents this situation arising (as unjoined items will not bake transforms).
2020-05-11 15:54:15 +01:00
Technohacker
9584f24be5
Use DWMEnableBlurBehindWindow instead of WS_EX_LAYERED
Affects per-pixel transparency

The current method renders to the screen by copying the GLES output to a
DIB for transparency using the CPU instead of rendering directly to the
window via the GPU. This is slower and also forces the window to be borderless
as WS_EX_LAYERED affects the non-client region as well.

This change uses DWMEnableBlurBehindWindow which allows using the standard
glClearColor() background alpha and is also performed through the GPU,
eliminating CPU bottlenecks
2020-05-10 21:05:37 +05:30
Rémi Verschelde
d038a7e42d
Merge pull request #38517 from lawnjelly/gles3_nvidia_workaround
Add Nvidia Workaround for GLES3
2020-05-08 10:52:31 +02:00
lawnjelly
dcb19ed735 Add Nvidia Workaround for GLES3
Ported GLES2 workaround code to GLES3.
2020-05-07 14:54:14 +01:00
Avril
5e320816f6 fix mistyped setting path 2020-05-07 15:48:43 +02:00
lawnjelly
17bb7af425 GLES3 - add counts for 2d drawcall and 2d items to performance monitor
This had already been implemented for GLES2 but not GLES3.
2020-05-07 11:31:43 +01:00
lawnjelly
bda20edb76 GLES2 Batching - fix item reordering bug
There was a bug in the initial logic for item reordering, whereby it would check for overlaps between the mover (item being moved back) and sandwiched items, but there was no check for overlaps between the movee (item moved forward) and the sandwich items. This extra check is now done.

Also a minor addition to the diagnose frame info (godot texture ID).
2020-05-06 12:55:18 +01:00
Rémi Verschelde
ef715f37d5
Merge pull request #35091 from Faless/dtls/enet
[3.2] DTLS support + optional ENet encryption
2020-05-05 13:40:59 +02:00
Rémi Verschelde
d20485039c
Merge pull request #38453 from lawnjelly/ios_halffloat_hacky
GLES2 disable half-float project setting
2020-05-04 16:29:27 +02:00
Rémi Verschelde
41b836cb3d
Merge pull request #38450 from lawnjelly/shaper_modulate
GLES2 batching - prevent color baking with MODULATE or COLOR
2020-05-04 15:13:35 +02:00
lawnjelly
30a3f16e34 GLES2 disable half-float project setting
It seems that particles (and some other features) do not work correctly on iOS in GLES2 because either many of the devices do not support half float compression, or the GL constant used to reference it from Godot is incorrect.

This PR adds a project setting in rendering/gles2/ to disable half-float compression on iOS.
2020-05-04 13:11:23 +01:00
lawnjelly
b08ad9ef64 GLES2 batching - prevent color baking with MODULATE or COLOR
Adding the ability to access MODULATE in the shader breaks when final_modulate is baked into vertex colors (this is a technique used to batch together different colored items). This PR prevents baking vertex colors when MODULATE is detected in the shader.

It also prevents baking when COLOR is read in canvas shaders, which could currently produce the wrong result in the shader if colors were baked. It does not prevent baking if COLOR is only written, which happens in most shaders, and will operate correctly without baking.
2020-05-04 11:19:55 +01:00
Pedro J. Estébanez
d8be5a9986 Add MODULATE builtin to canvas item shaders 2020-05-04 00:10:24 +02:00
Rémi Verschelde
01a085d05f
Merge pull request #38320 from lawnjelly/kessel_pr_light_join
GLES2 2D batching - item reordering, light joining and light modulate fix
2020-05-01 15:03:03 +02:00
lawnjelly
451c3fc0fb GLES2 2D batching - item reordering, light joining and light modulate fix
Although 2D draws in painters order with strict ordering, in certain circumstances items can be reordered to increase batching / decrease state changes, without affecting the end result. This can be determined by an overlap test.

In situation with item:
A-B-A
providing the third item does not overlap the second, they can be reordered:
A-A-B

Items already contain an AABB which can be used for this overlap test.

1)
To utilise this, I have implemented item reordering (only for single rects for now), with the lookahead adjustable in project settings. This can increase performance in situations where items may not be grouped in the scene tree by texture. It can also be switched off (by setting lookahead to 0).

2)
This same trick can be used to help join items that are lit. Lit items previously would prevent joining completely, thus missing out on performance gains other than multi-command items such as tilemaps.

In this PR, lights are assigned as bits in a bitfield (up to 64, the optimization is disabled above this), and on each try_item (for joining), the bitfield for lights and shadows is constructed and compared with the previous items. If these match the 2 items can potentially be joined. However, this can only be done without changing the rendered result if an overlap test is successful.

This overlap test can be adjusted to join items up to a specific number of item references, selectable in project settings, or turned off.

3)
The legacy uniform single rect drawing routine seems to have been identified as the source of flicker, particularly on nvidia. However, it can also be up to 2x as fast. Because of the speed the batching contains a fallback where it can use the legacy single rect method, but I have now added a project setting to make this switchable. In most cases with batching it should not be necessary (as single rects are drawn less frequently) and thus the flickering can be totally avoided.

4)
This PR also fixes a color modulate bug when drawing light passes, in certain situations (particularly custom _draw routines with multiple rects).

5)
This PR also fixes #38291, a bug in the legacy renderer where light passes could draw rects in wrong position.
2020-05-01 07:47:33 +01:00
Pedro J. Estébanez
7cc0f181c9 Improve shader time roll over
- Resurrect it for GL ES 2
- Apply roll over with `fmod()` instead of resetting it to 0
- Expose the setting from the `VisualServer`, since it does not belong in any specific rasterizer
2020-04-29 22:33:03 +02:00
Rémi Verschelde
f2150d1766
Merge pull request #37462 from Chaosus/shader_fix_const_order
[3.2] Fix shader constant sorting
2020-04-29 09:41:49 +02:00
Fredia Huya-Kouadio
7c559afe29 Restrict GL_TEXTURE_EXTERNAL_OES to Android platform 2020-04-27 10:18:31 -07:00
Hugo Locurcio
708184c402 Add more extensions to the dummy texture loader
This should make headless exporting work in projects using textures
in any format.

Error messages should no longer appear when running a project
that used image formats that were previously not present in the list.

(cherry picked from commit 3007c7e2a3)
2020-04-27 10:09:17 +02:00
Rémi Verschelde
0233b7e51f
Merge pull request #38251 from clayjohn/GLES2-shader-defines
Avoid duplicating shader defines in GLES2
2020-04-27 08:47:46 +02:00
clayjohn
782fd5fab6 Avoid duplicating shader defines in GLES2 2020-04-26 23:28:24 -07:00
lawnjelly
a75c1ed1df GLES2 Batching fix canvas texscreen (SCREEN_TEXTURE)
When reading SCREEN_TEXTURE in a shader, this previously only worked succesfully for the first read of the screen, because state.canvas_texscreen_used was never getting reset. This PR resets state.canvas_texscreen_used at the beginning of each joined item, so that further screen reads can happen.
2020-04-25 13:40:43 +01:00
lawnjelly
b954a8c099 Fix batching z_indices with z ranged lights
Joining items across z_indices can interfere with light culling for lights which only affect certain z ranges. This PR disables joining across z_indices when lights are present, except specifically for lights with both z_min set to the global minimum (-4096) and z_max set to the global maximum (4096).

In addition, the z_index is now stored on the joined_item for accurate light culling. The z_index is also displayed in frame diagnostics.
2020-04-23 11:58:06 +01:00
Rémi Verschelde
3b44f34166
Merge pull request #38114 from lawnjelly/kessel_rulerfix
Fix batch translate to colored synchronization error
2020-04-22 21:42:00 +02:00
lawnjelly
54cd6d3077 Fix batch translate to colored synchronization error
In rare circumstances default batches were being joined incorrectly, causing visual regressions. This logic has been fixed.

In addition slightly more output information has been added to frame diagnosis mode.
2020-04-22 18:52:42 +01:00
Rémi Verschelde
ade57c4bf0
Merge pull request #38099 from clayjohn/GLES2-skeleton-rebind
Rebind material when skeleton changes in GLES2
2020-04-22 08:23:43 +02:00
clayjohn
6f322af3fb Rebind material when skeleton changes in GLES2 2020-04-21 17:46:40 -07:00
clayjohn
7fc2cba47d Use proper depth buffer format for rgba shadows
(cherry picked from commit 123dd390e4)
2020-04-21 14:15:49 +02:00
lawnjelly
a9ae0fac86 Fixes incorrectly joining batch items from earlier z_index layers
Batching across z_index layers was not preserving the batch_break flag, which determines whether to not join the previous item. This is fixed by storing the flag in RenderItemState and preserving it across canvas_render_items calls.
2020-04-19 19:32:14 +01:00
Rémi Verschelde
008e0748c1
Merge pull request #37349 from lawnjelly/kessel32_1
GLES2 2d Batch rendering (across items)
2020-04-17 12:55:33 +02:00
lawnjelly
72adefa5cf Add frame diagnostics for GLES2 Batch renderer
Added project setting to enable / disable print frame diagnostics every 10 seconds. This prints out a list of batches and info, which is useful to optimize games and identify performance problems.
2020-04-17 08:54:33 +01:00
lawnjelly
b6d652367b Items and draw calls added to IDE Monitor in '2d' section
This adds 2 new values (items and draw calls) to the performance monitor in a '2d' section, rather than reusing the 3d values in the 'raster' section.

This makes it far easier to optimize games to minimize drawcalls.
2020-04-16 11:52:22 +01:00
lawnjelly
a4cd274ca7 Batching with Extra Matrix commands
Defers sending 'transform' commands within a RasterizerCanvas::Item until they are needed for default batches. Instead locally caches the extra matrix and applies it using software transform, preventing unnecessary batch breaks.

The logic is relatively complex, and the whole 'extra matrix' of the legacy renderer in addition to the final_transform is not ideal. However this is required to accelerate some user drawing techniques, and later the lines in the IDE.
2020-04-15 12:48:36 +01:00
lawnjelly
93af8e7d1b Batching across z_indices
Extra functions canvas_render_items_begin and canvas_render_items_end are added to RasterizerCanvas, with noop stubs for non-GLES2 renderers. This enables batching to be spready over multiple z_indices, and multiple calls to canvas_render_items.

It does this by only performing item joining within canvas_render_items, and deferring rendering until canvas_render_items_end().
2020-04-12 13:52:25 +01:00
Rémi Verschelde
4dadec331e
Merge pull request #37815 from clayjohn/reset-sky-flags
Reset texture flags after radiance map generation
2020-04-12 11:35:07 +02:00
clayjohn
193b0bf1e3 Reset texture flags after radiance map generation 2020-04-11 16:10:34 -07:00
lawnjelly
1fb6181ba6 Revert to default Rect drawing code for single rects
Determined that a large reason for the decrease in performance in unbatchable scenes was due to the new routine being analogous to the 'nvidia workaround' code, that is about half the speed. So this simply uses the old routine in the case of single unbatchable rects. Hopefully we will be able to remove the old path at a later stage.
2020-04-11 17:40:30 +01:00
clayjohn
4d32652851 Avoid material rebind when using skeleton 2020-04-07 10:35:58 -07:00
lawnjelly
e7bec77ef3 Bake final_modulate uniform into vertex colors
Where the final_modulate color varies between render_items this can prevent batching. This PR solves this by baking final_modulate into the vertex colors, and setting the uniform 'final_modulate' to white, and allowing the joining of items that have different final_modulate values. The previous batching system can then cope with vertex color changes as normal.
2020-04-06 12:49:47 +01:00
lawnjelly
45b0b8bff8 GLES2 2d Batch rendering (across items)
2d rendering is currently bottlenecked by drawing primitives one at a time, limiting OpenGL efficiency. This PR batches primitives and renders in fewer drawcalls, resulting in significant performance improvements. This also speeds up text rendering.

This PR batches across canvas items as well as within items.

The code dynamically chooses between a vertex format with and without color, depending on the input data for a frame, in order to optimize throughput and maximize batch size. It also adds an option to use glScissor to reduce fillrate in light passes.
2020-04-04 17:13:58 +01:00
Pedro J. Estébanez
21703aefee Fix res:// trimmed to s:// on Windows 2020-04-01 10:22:05 +02:00
Yuri Roubinsky
ee93c85ef1 Fix shader constant sorting 2020-03-31 14:32:33 +03:00
Rajat Goswami
19e71f94d8 Adding missing include guards to header files identified by LGTM.
This addresses the issue godotengine/godot#37143

(cherry picked from commit 2ecf928ae3)
2020-03-25 11:38:54 +01:00
Rémi Verschelde
cc70b2fa0a
Merge pull request #36342 from m4gr3d/external_texture_support_for_godot_3_2
Add support for opengl external textures
2020-03-17 16:29:14 +01:00
Rémi Verschelde
c01e840f03
Merge pull request #36639 from RandomShaper/imvu/improve_drives_ux_3.2
Improve UX of drive letters (3.2)
2020-03-17 16:27:33 +01:00
Pedro J. Estébanez
6105dfdac9 Improve UX of drive letters
Namely, move the drive dropdown to just the left of the path text box and don't include the former
in the latter.

This improves the UX on Windows.

In the UNIX case, since its concept of drives is (ab)used to provide shortcuts to useful paths, its
dropdown is kept at the original location.
2020-03-17 14:48:54 +01:00
fhuya
30d738eda7 Add support for opengl external textures as defined by https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt 2020-03-05 13:09:49 -08:00
Mateo Dev .59
d6c94fd527 os: execute parse the command output from utf8
(cherry picked from commit 8a88637705)
2020-03-04 12:40:15 +01:00
Fabio Alessandrelli
6b9240aa84 Add peek option to NetSocket recv_from. 2020-02-25 11:26:34 +01:00
Twarit
6d78636163 Remove unused driver/dummy/audio_driver_dummy.h
(cherry picked from commit 04882a481b)
2020-02-20 08:00:34 +01:00
Fabio Alessandrelli
ec4abf421a Disable NetSocket reuse address on Windows.
It actually means reuse port -.- ...

(cherry picked from commits cae0d8853d
and 19ef28a614)
2020-02-20 07:57:50 +01:00
Yuri Roubinsky
786b1cc7ff Fix shader crash if using multiple underscores in identifier names
(cherry picked from commit 15358b808b)
2020-02-06 13:02:07 +01:00
clayjohn
eb5cb5d016 Add project setting for max irradiance size 2020-01-25 13:27:13 -08:00
Eric Rybicki
3d4a2a09f6 Fix Softbody always spawns from world center [gles2]
Fixes #35373
2020-01-24 09:25:05 +01:00
clayjohn
3631a3cc9e Fix recently introduced crash in viewport size 2020-01-23 08:11:01 -08:00
Hugo Locurcio
90a1f8d8a7
Make OS.execute() blocking by default if not specified
This makes `OS.execute()` calls quicker to set up when calling programs
in a blocking fashion.
2020-01-23 01:26:32 +01:00
Rémi Verschelde
a8460bffd2
Merge pull request #35414 from Ovnuniarchos/AlsaMidiBadPitchBend
ALSA MIDI: Pitch bend and System Common messages
2020-01-22 22:12:57 +01:00
Rémi Verschelde
37897dba80
Merge pull request #35406 from lawnjelly/ortho-shadow
Replace CameraMatrix::get_viewport_size with get_viewport_half_extents, shadow culling with ortho camera and other affected issues
2020-01-22 22:02:09 +01:00
Ovnuniarchos
9c48eb1c59 ALSA MIDI driver:
Pith bend message now has correct size (was 2 bytes instead of 3).
	Recognized (but not implemented) 0xF? messages. SysEx messages will be reocognized as such, but their contents will be ignored.
2020-01-22 21:41:48 +01:00
lawnjelly
eaf8e5ce52 Change CameraMatrix::get_viewport_size to get_viewport_half_extents
Fixes #26637.
Fixes #19900.

The viewport_size returned by get_viewport_size was previously incorrect, being half the correct value. The function is renamed to get_viewport_half_extents, and now returns a Vector2.

Code which called this function has also been modified accordingly.

This PR also fixes shadow culling when using ortho cameras, because the correct input for CameraMatrix::set_orthogonal should be the full HEIGHT from get_viewport_half_extents, and not half the width.

It also fixes state.ubo_data.viewport_size in rasterizer_scene_gles3.cpp to be the width and the height of the viewport in pixels as stated in the documentation, rather than the current value which is half the viewport extents in worldspace, presumed to be a bug.
2020-01-22 18:22:00 +00:00
Rémi Verschelde
00284a75e8 GLES3: Fix invalid value for GL_TEXTURE_MAG_FILTER parameter
`GL_LINEAR_MIPMAP_LINEAR` can be used for `GL_TEXTURE_MIN_FILTER`,
but not for `GL_TEXTURE_MAG_FILTER`.

Cf. https://www.khronos.org/opengl/wiki/GLAPI/glTexParameter

Fixes #35436.
2020-01-22 15:18:56 +01:00
Rémi Verschelde
4faaf6089a Remove unused #if 0'ed code 2020-01-21 21:41:54 +01:00
Rémi Verschelde
837adb30fd Revert "Exposes capture methods to AudioServer + documentation" #30468
Reverts the following commits:

- c81ec6f26d:
  "Exposes capture methods to AudioServer, variable renames for
  consistency, added documentation."
- 47c558b98a:
  "Expose audio callbacks as signals."
- dabaa11b3c:
  "Fix to make sure the capture buffers are deallocated at shutdown.
  Silences warnings."

Some documentation improvements were kept for pre-existing methods.

See rationale for reverting these changes in #30468.
2020-01-20 13:18:01 +01:00
Rémi Verschelde
90a224c6eb
Merge pull request #35310 from akien-mga/gles3-irradiance-small-optimization
GLES3: Slight optimization to irradiance compute
2020-01-19 18:55:51 +01:00
Rémi Verschelde
4d052e51a2
Merge pull request #35302 from clayjohn/GLES3-env-map
Reduce complexity of irradiance map generation
2020-01-19 12:39:36 +01:00
Rémi Verschelde
dc4db4ab45 GLES3: Slight optimization to irradiance compute
All the calculations leading up to `mipLevel` are only relevant for
Panorama mode. Similarly, the `source_resolution` uniform is only
needed for that mode.
2020-01-19 11:03:11 +01:00
Rémi Verschelde
43caf83c09
Merge pull request #35284 from Ovnuniarchos/MidiNoReopen
Alsa MIDI input thread gets properly reinitialized on open_midi_input.
2020-01-19 09:34:38 +01:00