Awesome
GiLight2D
Dev by NullTale - author's games, materials, graphics <br>
Unity Urp Render Feature for 2D Global Illumination.<br> GiLight can be used both for conventional lighting and to create stylized visual effects ✨
- Tested with Unity 2021, 2022 Web
WebGl TechArt Sandbox <br> • https://nulltale.itch.io/light-room <br>
Dontations for project support and RenderGraph compatibility <br> • https://boosty.to/nulltale/single-payment/donation/641586/target?share=target_link
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.<br> Implemented quite enough options, tested with Unity 2022.<br>
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).<br>
If the scene is empty this should already be enough to see the effect.
<img src="https://user-images.githubusercontent.com/1497430/213907330-64d37b07-2833-4f8e-8b62-88455c05d604.png"><br> <sup>Three sprites on an empty scene.</sup>
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.<br>
UrpRenderer is configured so that it doesn't draw Gi objects by mask.<br> Texture
Exposed
checkbox must be unchecked.
<br> <sup>The sprite of the square uses the Gi texture from the screen coordinates.</sup>
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.<Br> In the end a lighting texture should be calculated which can then be used.<Br> 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.