Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for shadow map atlasing #2102

Merged
merged 2 commits into from Feb 14, 2021
Merged

Commits on Feb 4, 2021

  1. 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.
    N8n5h committed Feb 4, 2021
    Configuration menu
    Copy the full SHA
    1c3e24a View commit details
    Browse the repository at this point in the history

Commits on Feb 11, 2021

  1. Added support for direct3d-like texture coords uv for shadow atlases

    See http://thedev-log.blogspot.com/2012/07/texture-coordinates-tutorial-opengl-and.html,
    the "opengl coordinates" where inverted for proper support of direct3d texture coordinate system.
    N8n5h committed Feb 11, 2021
    Configuration menu
    Copy the full SHA
    c64b475 View commit details
    Browse the repository at this point in the history