Commit graph

773 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
Rémi Verschelde
e6a3499bef Fix Visual Studio C4334 warning 2020-05-19 10:19:52 +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
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
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