Skip to content

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

Notifications You must be signed in to change notification settings

Tim-W-James/Pixel-Perfect-Lighting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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 Combines the Unity 2D Pixel Perfect Camera with this 2D shadows technique and other post processing effects.

Features

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

Built With

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 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 for more details.

I have used this method which implements this 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.

Contact

Email: tim.jameswork9800@gmail.com

Project Link: https://github.com/Tim-W-James/Pixel-Perfect-Lighting

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published