GiLight2D
Unity Urp Render Feature for 2D Global Illumination.
GiLight can be used both for conventional lighting and to create stylized visual effects ✨
WebGl https://nulltale.itch.io/light-room
What is it?
In practice, this is an approach to lighting with rays, in which glow and shadows are created naturally, and the number of light sources is not limited.
Implemented quite enough options, tested with Unity 2022.
Some of the options
- fixed resolution for pixel art.
- control via post process volume.
- render texture output.
- padding the screen borders to display objects outside the camera.
- different noise settings and resolution.
- etc.
Volume control
Various lighting configurations can be mixed to create certain kinds of scene effects.
Installation and use
Install via PackageManager https://github.com/NullTale/GiLight2D.git
Add GiLight2DFeature
to the Urp Renderer (urp must be configured).
If the scene is empty this should already be enough to see the effect.
Three sprites on an empty scene.
Then configure the object mask and the output texture, which can then be used in the shader (the name must match).
Now the texture can be used from the shader.
UrpRenderer is configured so that it doesn't draw Gi objects by mask.
TextureExposed
checkbox must be unchecked.
The sprite of the square uses the Gi texture from the screen coordinates.
How it works?
The general idea is that from each pixel rays are released in all directions, from the sum of the rays that hit the light source is the final color of the pixel.
In the end a lighting texture should be calculated which can then be used.
With this approach glow and shadow are formed naturally.
In order to effectively calculate the rays a sdf map is created, in fact it is a distance map to the nearest light source, it is used to get the offset distance of the ray when searching for the light source. So the whole rendering process consists of three steps: rendering objects into buffer, creating a distance map using jfa algorithm, applying gi shader. Ray bounces are counted by calculating the illumination for the pixels on the border of the objects.
Almost all the calculations are performed in a fragment shader, from which the number of objects does not affect performance, but strongly depends on the resolution.