Skip to content

Latest commit

 

History

History
77 lines (50 loc) · 4.07 KB

README.md

File metadata and controls

77 lines (50 loc) · 4.07 KB

GiLight2D

Dev by NullTale - author's games, materials, graphics
Itch Twitter Discord Asset Store Forum

Unity Urp Render Feature for 2D Global Illumination.
GiLight can be used both for conventional lighting and to create stylized visual effects ✨

  • Tested with Unity 2021, 2022 Web

WebGl TechArt Sandbox
https://nulltale.itch.io/light-room

Dontations for project support and RenderGraph compatibility
https://boosty.to/nulltale/single-payment/donation/641586/target?share=target_link

Gif

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.

Gif

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).

image

Now the texture can be used from the shader.

UrpRenderer is configured so that it doesn't draw Gi objects by mask.
Texture Exposed checkbox must be unchecked.

image
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.

Rays

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.

Pipeline

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.