Commit graph

342 commits

Author SHA1 Message Date
Bastiaan Olij
73722f3c65 Convert output of GLES2 to linear color space if keep_3d_linear is enabled 2021-08-23 15:59:56 +10:00
Hugo Locurcio
663af7ff03
Fix tonemap exposure not being taken into account by sharpening
The same fix as FXAA was applied to the CAS filter.
2021-08-18 16:44:41 +02:00
clayjohn
8ac85e6a9e Normalize the results of octahedral decompression 2021-08-16 22:17:38 -07:00
Rémi Verschelde
51dd4d0c6c
Merge pull request #49509 from Chaosus/shader_time_3.x 2021-08-16 19:42:55 +02:00
clayjohn
81dc6a7688 Define normal_attrib when not using octahedral compression in GLES3 2021-08-15 22:27:46 -07:00
Rémi Verschelde
9e3e7b03e4
Merge pull request #51376 from The-O-King/vertex_buffer_alignment
Align Vertex Buffer to 4 Bytes
2021-08-12 07:13:45 +02:00
Rémi Verschelde
7c6bdea33c
Merge pull request #47416 from Calinou/add-contrast-adaptive-sharpening-3.x
Add support for contrast-adaptive sharpening in 3D (GLES3 only)
2021-08-10 10:08:24 +02:00
Rémi Verschelde
5116855637
Merge pull request #51439 from Calinou/tonemap-clamp-negative-colors-3.x
Clamp negative colors regardless of the tonemapper to avoid artifacts
2021-08-10 09:56:18 +02:00
Rémi Verschelde
dad5d09d1b
Merge pull request #51416 from clayjohn/GLES-horizon-occlusion
[3.x] Add horizon specular occlusion
2021-08-10 09:55:46 +02:00
Rémi Verschelde
6518a61bd4
Merge pull request #51410 from clayjohn/GLES-blinn-phong 2021-08-10 09:52:28 +02:00
clayjohn
f92a600d5c Make blinn and phong specular use full pbr 2021-08-09 20:45:14 -07:00
Hugo Locurcio
313527b3fa
Clamp negative colors regardless of the tonemapper to avoid artifacts
Color artifacts could be visible when using negative lights with the
Filmic and ACES tonemapping operators, as these did not clamp negative
colors.
2021-08-09 17:16:27 +02:00
clayjohn
1065f8dc86 Add horizon specular occlusion 2021-08-08 19:29:02 -07:00
Yuri Roubinsky
0f817e127d [3.x] Fix a default shader specular render mode to (SCHLICK_GGX) 2021-08-08 19:26:00 +03:00
Omar El Sheikh
f0de7ec2b6 Align Vertex Buffer to 4 Bytes
With the octahedral compression, we had attributes of a size of 2 bytes
which potentially caused performance regressions on iOS/Mac

Now add padding to the normal/tangent buffer

For octahedral, normal will always be oct32 encoded
UNLESS tangent exists and is also compressed
then both will be oct16 encoded and packed into a vec4<GL_BYTE>
attribute
2021-08-07 15:42:03 -04:00
Bastiaan Olij
cc1f7f2edc Revert "Combined the DOF far and DOF near passes"
This reverts commit 39658b4e07.
2021-08-05 23:22:31 +10:00
Omar El Sheikh
d274284069 Octahedral Normal/Tangent Compression
Implement Octahedral Compression for normal/tangent vectors
*Oct32 for uncompressed vectors
*Oct16 for compressed vectors

Reduces vertex size for each attribute by
*Uncompressed: 12 bytes, vec4<float32> -> vec2<unorm16>
*Compressed: 2 bytes, vec4<unorm8> -> vec2<unorm8>

Binormal sign is encoded in the y coordinate of the encoded tangent

Added conversion functions to go from octahedral mapping to cartesian
for normal and tangent vectors

sprite_3d and soft_body meshes write to their vertex buffer memory
directly and need to convert their normals and tangents to the new oct
format before writing

Created a new mesh flag to specify whether a mesh is using octahedral
compression or not
Updated documentation to discuss new flag/defaults

Created shader flags to specify whether octahedral or cartesian vectors
are being used

Updated importers to use octahedral representation as the default format
for importing meshes

Updated ShaderGLES2 to support 64 bit version codes as we hit the limit
of the 32-bit integer that was previously used as a bitset to store
enabled/disabled flags
2021-07-30 10:29:09 -04:00
Bastiaan Olij
39658b4e07 Combined the DOF far and DOF near passes 2021-07-22 13:45:57 +10:00
Hugo Locurcio
a9c0c5484f
Add support for contrast-adaptive sharpening in 3D (GLES3 only)
This is an older, easier to implement variant of CAS as a pure
fragment shader. It doesn't support upscaling, but we won't make
use of it (at least for now).

The sharpening intensity can be adjusted on a per-Viewport basis.
For the root viewport, it can be adjusted in the Project Settings.

Since `textureLodOffset()` isn't available in GLES2, there is no
way to support contrast-adaptive sharpening in GLES2.
2021-06-21 15:37:31 +02:00
Yuri Roubinsky
2d7c9f1ef1 [3.x] Makes shader 'TIME' available in custom functions by default 2021-06-11 15:23:24 +03:00
Bastiaan Olij
8f8c9c2f57 Add VIEW_INDEX variable in shader so we know which eye/view we're rendering for 2021-05-05 16:22:03 +10:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
Rémi Verschelde
3d15f04668
Style: clang-format: Disable AllowShortIfStatementsOnASingleLine 2021-05-04 14:45:15 +02:00
Rémi Verschelde
3f246ebeed
Merge pull request #46932 from JFonS/fix_lm_capture_env
[3.2] Batch of lightmapper fixes and minor improvements
2021-03-12 12:30:36 +01:00
JFonS
e2c28675ef Batch of lightmapper fixes and minor improvements
- Fix objects with no material being considered as fully transparent by the lightmapper.
- Added "environment_min_light" property: gives artistic control over the shadow color.
- Fixed "Custom Color" environment mode, it was ignored before.
- Added "interior" property to BakedLightmapData: controls whether dynamic capture objects receive environment light or not.
- Automatically update dynamic capture objects when the capture data changes (also works for "energy" which used to require object movement to trigger the update).
- Added "use_in_baked_light" property to GridMap: controls whether the GridMap will be included in BakedLightmap bakes.
- Set "flush zero" and "denormal zero" mode for SSE2 instructions in the Embree raycaster. According to Embree docs it should give a performance improvement.
2021-03-12 12:00:53 +01:00
Rémi Verschelde
a550260404
Merge pull request #46865 from lawnjelly/ninepatch_shader_option
Support ninepatch mode in GLES3 shader
2021-03-12 10:05:44 +01:00
lawnjelly
5ed0fd067d Batching - use FINAL_MODULATE_ALIAS in shaders
As part of the improvements to batch more cases, batching can store final_modulate as an attribute in the vertex format rather than sending as a uniform. This allows draw calls with different final_modulate to be batched together.

However custom shader code was reading from only the final_modulate uniform, and not the attribute when it was in use. This was leading to visual errors.

This is tricky to solve, because we cannot use the same name for the attribute in the vertex and fragment shaders, because one is an attribute and one a varying, whereas a uniform is accessible anywhere. To get around this, a macro is used which can translate to the most appropriate variable depending on whether uniform or attribute or varying is required.
2021-03-11 17:07:19 +00:00
lawnjelly
e70d7294e2 Support ninepatch mode in GLES3 shader
Although batching supported both ninepatch modes (fixed and scaling) when using ninepatch stretch mode, the ninepatch tiling modes (in GLES3) could only run through the shader.

The shader only supported one of the ninepatch modes. This PR uses the hack method of #if defined in the shader to prevent the use of a conditional. The define is set at startup according to the project setting.
2021-03-10 11:05:59 +00:00
clayjohn
c29ade28af Multiply vertex lit DirectionalLights by albedo in GLES3 2021-02-18 20:56:45 -08:00
JFonS
b1ca82c43a CPU lightmapper fixes.
- Fix Embree runtime when using MinGW (patch by @RandomShaper).
- Fix baking of lightmaps on GridMaps.
- Fix some GLSL errors.
- Fix overflow in the number of shader variants (GLES2).
2021-01-15 12:32:54 +01:00
JFonS
112b416056 Implement new CPU lightmapper
Completely re-write the lightmap generation code:
- Follow the general lightmapper code structure from 4.0.
- Use proper path tracing to compute the global illumination.
- Use atlassing to merge all lightmaps into a single texture (done by @RandomShaper)
- Use OpenImageDenoiser to improve the generated lightmaps.
- Take into account alpha transparency in material textures.
- Allow baking environment lighting.
- Add bicubic lightmap filtering.

There is some minor compatibility breakage in some properties and methods
in BakedLightmap, but lightmaps generated in previous engine versions
should work fine out of the box.

The scene importer has been changed to generate `.unwrap_cache` files
next to the imported scene files. These files *SHOULD* be added to any
version control system as they guarantee there won't be differences when
re-importing the scene from other OSes or engine versions.

This work started as a Google Summer of Code project; Was later funded by IMVU for a good amount of progress;
Was then finished and polished by me on my free time.

Co-authored-by: Pedro J. Estébanez <pedrojrulez@gmail.com>
2021-01-14 18:05:56 +01:00
clayjohn
6cefadc233 Properly apply auto exposure with FXAA in GLES3 2020-12-26 15:23:08 -08:00
lawnjelly
e13040b373 Fix bug in normal map decompression
Not clamping the range here leads to dithering artifacts.
2020-12-11 10:34:53 +00:00
lawnjelly
e88b4f330e Poly colors fixes
This adds support for custom shaders for polys, and properly handles modulate in the case of large FVF and modulate FVF.

It also fixes poly vertex colors not being sent to OpenGL.
2020-11-13 13:23:28 +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
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
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
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
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
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
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
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
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
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
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