Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tim-w-james/pixel-perfect-lighting

Implements several post-processing effects in Unity for 2D pixel perfect rendering with lighting and dynamic shadows.
https://github.com/tim-w-james/pixel-perfect-lighting

game-development unity3d

Last synced: 2 months ago
JSON representation

Implements several post-processing effects in Unity for 2D pixel perfect rendering with lighting and dynamic shadows.

Awesome Lists containing this project

README

        



Pixel Perfect Lighting


Implements several post-processing effects in Unity for 2D pixel perfect rendering with lighting and dynamic shadows.

Table of Contents



  1. About The Project



  2. Usage

  3. Contact

## About The Project
[![Product Name Screen Shot][product-screenshot]](https://github.com/Tim-W-James/Pixel-Perfect-Lighting)
Combines the Unity [2D Pixel Perfect Camera](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) with [this 2D shadows technique](https://medium.com/@tidyui/fast-beautiful-2d-lighting-in-unity-47b76b10447c) and other [post processing effects](https://docs.google.com/document/d/1brkjiMgB8urmjMZFrbpasWn8Yp-qtIZmtJwBFIAfaxo/view?usp=sharing#heading=h.5v5whdw1py9q).

### Features

* 2D Pixel Perfect Rendering
* Sprite lighting
* Dynamic shadows
* Post-processing effects such as bloom

### Built With

* [Unity3D 2018.4.14f1](https://unity.com/)
* C#
* Visual Studio Code

## Usage

Clone the repo and use with Unity 2018.4.14f1. Repo contains a demo scene to showcase the rendering.

### 2D Pixel Perfect Rendering
The main camera has a [2D Pixel Perfect Camera](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) component. Adjust pixels per unit and reference resolution to match those of your pixel art.

### 2D Shadows
**Note**: this method of drawing shadows is no longer necessary for Unity 2019 and beyond. See Unity [documentation](https://docs.unity3d.com/Packages/[email protected]/manual/2DShadows.html) for more details.

I have used [this](https://medium.com/@tidyui/fast-beautiful-2d-lighting-in-unity-47b76b10447c) method which implements [this](https://github.com/prime31/SpriteLightKit) script to blend cameras together.

Since we can’t render shadows in 2D, we need to create a copy of our scene with anything we want to cast shadows having 3D geometry. These objects are then given the 'Shadowcaster' layer. Using Unity 3D primitives such as cubes is the easiest way to approximate simple shadows, and these objects can be attached as children of their respective sprites. Use greater Z scales for geometry or adjust the Z position of lights to adjust the ‘height’ of lights/objects.

_Example Scene without Shadows_:


img

_Geometry of Scene_:


img

**Note**: the fox and eagle are not currently drawing shadows.

This is achieved with the use of two cameras. Our main camera renders all sprites and UI as usual, however our second camera, the 'ShadowCamera', only renders shadows.

_Main camera_:


img

_Shadow Camera_:


img

Then these cameras are blended together to give the effect of shadows:


img

Belding is done by outputting the shadow camera to a texture, and then blending this texture with the main camera. This also allows sprites to be partially shadowed.

The shadow camera is not pixel perfect. We cannot both upscale render textures and output the camera to a texture because this is not supported by the package. Instead, we use soft shadows, which is what most other pixel art games do. The difference between pixel perfect shadows and soft shadows is very subtle and only really visible during motion. A blend of pixel art and high resolution effects can look pleasing regardless. Additional post processing effects can be applied with the

Further details can be found [here](https://docs.google.com/document/d/1brkjiMgB8urmjMZFrbpasWn8Yp-qtIZmtJwBFIAfaxo/view?usp=sharing#heading=h.91d5o2vw6ai4).

## Contact

Email: [[email protected]](mailto:[email protected] "[email protected]")

Project Link: [https://github.com/Tim-W-James/Pixel-Perfect-Lighting](https://github.com/Tim-W-James/Pixel-Perfect-Lighting)

[release-shield]: https://img.shields.io/github/v/release/Tim-W-James/Pixel-Perfect-Lighting.svg?include_prereleases&style=for-the-badge
[release-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/releases
[last-commit-shield]: https://img.shields.io/github/last-commit/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[last-commit-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/commits/main
[contributors-shield]: https://img.shields.io/github/contributors/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[contributors-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/graphs/contributors
[contributors-shield]: https://img.shields.io/github/contributors/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[contributors-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[forks-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/network/members
[stars-shield]: https://img.shields.io/github/stars/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[stars-url]: https://github.com/Tim-W-James/repPixel-Perfect-Lightingo_name/stargazers
[issues-shield]: https://img.shields.io/github/issues/Tim-W-James/Pixel-Perfect-Lighting.svg?style=for-the-badge
[issues-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/issues
[license-shield]: https://img.shields.io/github/license/Tim-W-James/Pixel-Perfect-Lighting?style=for-the-badge
[license-url]: https://github.com/Tim-W-James/Pixel-Perfect-Lighting/blob/main/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/timothy-william-james/
[product-screenshot]: images/screenshot.png