Commit graph

31 commits

Author SHA1 Message Date
N8n5h 5509096158 fix volumetric lights not working with shadow map atlas enabled
Added missing code so the shader refers to the correct variable when
using shadow map atlasing.
2021-08-06 18:34:39 -03:00
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
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 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
Moritz Brückner 1505f94b2b Fix spaces/tabs 2020-10-21 16:18:30 +02:00
Moritz Brückner 93f0bcba78 Fix volumetric light for different lamp combinations 2020-10-21 15:30:11 +02:00
luboslenco 9802016556 Cleanup 2019-05-19 15:23:56 +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 7b7260d647 Update volumetric 2019-01-28 11:28:21 +01:00
luboslenco 93cc102bf5 Faster 2018-12-06 15:23:08 +01:00
luboslenco fe9fa0eea9 Apply reflection plane 2018-10-03 13:59:34 +02:00
luboslenco d5682233da Add Khamake Threads option for faster builds 2018-08-30 15:42:25 +02:00
luboslenco d2a96abcde Rename Lamp to Light to keep in sync with Blender2.8 2018-08-28 15:10:28 +02:00
Lubos Lenco 9e8181edbc Simplify shader include 2018-01-29 23:52:42 +01:00
Lubos Lenco 1110cdb5d6 Fix volumetrics for cubemap 2018-01-28 14:57:49 +01:00
Lubos Lenco 1c56653849 Improve volumetrics filtering 2018-01-28 14:03:56 +01:00
Lubos Lenco 989b91720b Reduce volumetrics mem usage 2018-01-28 13:53:06 +01:00
Lubos Lenco cea57c33ea Shader fixes 2018-01-07 20:01:43 +01:00
Lubos Lenco 67f5bf0c6a Forward renderer effects 2018-01-06 00:33:33 +01:00
Lubos Lenco 42b4185187 Reduce shader count 2017-12-20 15:37:58 +01:00
Lubos Lenco 91cb952fd8 Shader cleanup 2017-12-13 14:44:21 +01:00
Lubos Lenco a1532d5bec Simplify shader passes 2017-12-13 14:21:42 +01:00
Lubos Lenco 321de4bbdd Volumetric quad pass 2017-07-08 14:12:18 +02:00
Lubos Lenco 81b8b0bc3a Fix volumetric light 2017-05-22 15:55:34 +02:00
Lubos Lenco f4898a130c Begin true material builder 2016-12-13 01:09:17 +01:00
Lubos Lenco e50f60454e Shaders ready. 2016-10-23 15:32:26 +02:00
Lubos Lenco 9edb0b0fa9 Shaders overhaul. 2016-10-17 17:39:40 +02:00
Lubos Lenco 73e67e3c1e Refactor shader params. 2016-10-17 12:02:41 +02:00
Lubos Lenco fd6ec03f41 Reuse shader code. 2016-10-17 02:29:37 +02:00
Lubos Lenco 1dc2dcf6f8 Reusing shader code. 2016-10-17 00:02:51 +02:00