Commit graph

21 commits

Author SHA1 Message Date
N8n5h ead7dc9d32 Moved biasLWVP matrix uniform reference to a new one for sun
This was done because the original "_biasLightWorldViewProjectionMatrix"
relies on renderpath.light, which is problematic when rendering the
deferred light pass and there is a sun and other lights of different
type on the scene. Which would result on the wrong light being picked up
for the calculation of the uniform value.
2021-03-29 10:55:58 -03:00
Lubos Lenco 7d78e01bb4
Merge pull request #2128 from N8n5h/light-fix-2
Fix shadows not working when there are lights present with cast_shadow=false
2021-03-16 08:28:19 +01:00
N8n5h 7463de6140 Add cast_shadow to lightArray data
This was done to undo the hardcoded nature of "receiveShadows", which
doesn't play nice when you have multiple lights of the same type and
one or several have cast_shadow set to false.

By simply "passing" the cast_shadow parameter within the lightArray it
was possible to detect lights that don't cast shadows before actually
wasting gpu cycles to render shadows with garbage data.

Support for deferred desktop and mobile, and forward was added.
2021-03-14 23:20:57 -03:00
N8n5h efcef7dd25 Fix shadow rendering for deferred and forward mobile 2021-03-14 22:04:47 -03:00
N8n5h 1c3e24a8fd Add support for shadow map atlasing
With this it is now possible to enable atlasing of shadow maps, which solves the existing limitation of 4 lights in a scene. This is done by
grouping the rendering of shadow maps, that currently are drawn into their own images for each light, into one or several big textures. This was
done because the openGL and webGL version Armory targets do not support dynamic indexing of shadowMapSamplers, meaning that the index that
access an array of shadow maps has to be know by the compiler before hand so it can be unrolled into if/else branching. By instead simply
using a big shadow map texture and moving the dynamic part to other types of array that are allowed dynamic indexing like vec4 and mat4, this
limitation was solved.

The premise was simple enough for the shader part, but for the Haxe part, managing and solving where lights shadow maps should go in a shadow map
can be tricky. So to keep track and solve this, ShadowMapAtlas and ShadowMapTile were created. These classes have the minimally required logic
to solve the basic features needed for this problem: defining some kind of abstraction to prevent overlapping of shadowmaps, finding available
space, assigning such space efficiently, locking and freeing this space, etc. This functionality it is used by drawShadowMapAtlas(), which is a
modified version of drawShadowMap().

Shadow map atlases are represented with perfectly balanced 4-ary trees, where each tree of the previous definition represents a "tile" or slice
that results from dividing a square that represents the image into 4 slices or sub-images. The root of this "tile" it's a reference to the
tile-slice, and this tile is divided in 4 slices, and the process is repeated depth-times. If depth is 1, slices are kept at just the initial
4 tiles of max size, which is the default size of the shadow map. #arm_shadowmap_atlas_lod allows controlling if code to support more depth
levels is added or not when compiling.

the tiles that populate atlases tile trees are simply a data structure that contains a reference to the light they are linked to, inner
subtiles in case LOD is enabled, coordinates to where this tile starts in the atlas that go from 0 to Shadow Map Size, and a reference to a
linked tile for LOD. This simple definition allows tiles having a theoretically small memory footprint, but in turn this simplicity might make
some functionality that might be responsibility of tiles (for example knowing if they are overlapping) a responsibility of the ones that
utilizes tiles instead. This decision may complicate maintenance so it is to be revised in future iterations of this feature.
2021-02-04 17:53:59 -03:00
N8n5h b05f719392 Solve artifact for deferred mobile too 2020-12-27 16:45:27 -03:00
Moritz Brückner 3654d34997 Update more shaders for receive shadow option 2020-07-13 23:28:43 +02:00
Lubos Lenco c970c5db6c Pass irradiance uniform as argument 2020-05-10 19:43:02 +02:00
luboslenco b0cd02d68e Allow multiple color attachment formats 2020-05-10 10:46:12 +02:00
Lubos Lenco df6346c1d1 Color attachment format 2020-05-06 21:30:59 +02:00
unknown 8e2f037d9b Fix packing inline 2019-07-14 16:45:34 +02:00
luboslenco f82be5bc64 Improve packing 2019-07-07 22:02:07 +02:00
luboslenco aa5c4f7e73 Link to embedded data 2019-04-26 11:12:09 +02:00
luboslenco c29e8fdbd0 Shadows cleanup 2019-03-23 10:56:30 +01:00
luboslenco 9c9fd0881e Uniform fixes 2018-12-15 19:03:11 +01:00
luboslenco 7dcb443060 Use shadow samplers, remove arm_dev 2018-12-15 15:07:30 +01:00
luboslenco 914030e7f4 Shadowmap arrays 2018-12-11 23:05:18 +01:00
luboslenco d8f78638bd Begin shadow index 2018-12-10 23:29:04 +01:00
luboslenco bd03fd0465 Forward clusters 2018-12-10 18:18:32 +01:00
luboslenco 6176a26e22 Improved light sampling 2018-12-10 17:25:29 +01:00
luboslenco 00d7bba7c8 Deferred modes 2018-12-10 09:46:46 +01:00