Git Product home page Git Product logo

gilight2d's Introduction

GiLight2D

Unity Urp Render Feature for 2D Global Illumination.

Demo

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 2021 and 2022 versions.

Some of the options

  • fixed resolution for pixel art.
  • render to texture to use it later in the shader or in the camera to apply built-in post effects.
  • padding the screen borders to display objects outside the camera.
  • different noise settings and resolution.
  • etc.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.