• Stars
    star
    227
  • Rank 175,900 (Top 4 %)
  • Language
    C#
  • Created over 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Blended lighting system for Unity that works with standard Sprites

SpriteLightKit

SpriteLightKit brings back the old two buffered blend trick to get pseudo lighting with just sprites. It handles the setup process of getting that second buffer blended with your normal scene.

how it works

The same scene with two different ambient light setups:

low ambient light brighter ambient light

Setup

  • create an empty GameObject as a child of your main camera and add the SpriteLightKit component
  • add the SpriteLightKitImageEffect component to your main camera and drag the SpriteLightKitBlendImageEffect.shader into the inspector in the shader property
  • set the Light Layer in the SpriteLightKit component, which is the layer you want to place your sprite lights on
  • remove the Light Layer from your main camera's culling mask so that it does not render the sprite lights
  • create some sprites using the SpriteLightMaterial and make sure they are on the Light Layer you chose in the previous step

You can set the ambient lighting by changing the background color of the camera on the SpriteLightKit GameObject. Each of your lights can use the normal sprite tint color to change how it affects the underlying scene. The SpriteLightKitImageEffect has a toggle for 1x or 2x multiplicative blending (bool use2xMultiplicationBlending). 2x is useful for a scene where the sprite lights can lighten or darken a scene. Use colors darker than the ambient color to darken the scene and lighter colors to lighten it.

Lights look best when they are white and falloff to 0 alpha. That lets you use the tint color to color the lights and the tint color.alpha to set the intensity of the lights. Get creative with your light shapes and experiment! If you need to occlude lights (if you have walls where light shouldn't pass for example) you can just use any black sprite and place it so that it blocks the light however you want it to.

Advanced Emissive Features

SpriteLightKit has some extra, more advanced features baked in as well along with some shaders/materials to help you utilize them. The following emissive features are for use on your normal GameObjects that are not on the Light Layer. The emissive materials will write to the stencil buffer which will then be read by the SpriteLightKitImageEffect and lights will not be rendered for those pixels. This basically makes the masked pixels always display as if lights do not affect them. Materials are provided that let you use a Sprite or a Mesh as the emissive mask.

Since the emissive materials main purpose is to write to the stencil buffer you can stick your geometry that uses them behind all other geometry. This gives you some flexibility when using the SpriteLightEmissiveSpriteMaterial. If it is behind your other Sprites/geometry then it will work like a mask. If it is in front of your other Sprites/geometry it will work like a mask and it will also be displayed.

  • SpriteLightEmissiveSpriteMaterial lets you use a Sprite as an emissive mask. Set the Alpha Cutoff of the Material to control which pixels will be discarded.
  • SpriteLightEmissiveMeshMaterial lets you use a Mesh as an emissive mask.

Advanced Shadow Features

SpriteLightKit can also cast simple offset shadows. The current implementation uses a brute force approach to find affected lights but a b-tree or other spatial search will be added to speed things up. The shadow shader is ready to handle approximated planar shadows (via skew and scale in addition to the offset) but it hasn't yet been implemented due to some decisions that need to be made about how to best handle things.

Implementing shadows requires the following steps:

  • stick the SpriteLightKitLightManager on a GameObject in your scene
  • add the SpriteLightKitShadow component to any objects that should project shadows
  • make sure the objects that should cast shadows have the SpriteLightShadowedMaterial on them

Credit

The sweet little town sketch is from the amazing work of @pixelatedcrown. Follow on Twitter and Tumblr to see more awesome art!

License

Attribution-NonCommercial-ShareAlike 3.0 Unported with simple explanation with the attribution clause waived. You are free to use SpriteLightKit in any and all games that you make. You cannot sell SpriteLightKit directly or as part of a larger game asset.

More Repositories

1

Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
C#
1,799
star
2

CharacterController2D

C#
1,032
star
3

TouchKit

Gestures and input handling made sane for Unity
C#
896
star
4

GoKit

Lightweight tween library for Unity
C#
583
star
5

RecyclerKit

Object pool manager for Unity
C#
363
star
6

TransitionKit

Modular, extensible transitions in scene and between scenes
C#
300
star
7

StateKit

Dead simple, lightweight "states as objects" system
C#
220
star
8

ZestKit

Tween library for Unity. The best of GoKit and GoKitLite combined in an easy to use API
C#
156
star
9

Nez-Samples

Samples and demos of various Nez features
C#
148
star
10

zig-ecs

Zig
144
star
11

P31UnityAddOns

Mostly defunct. Features were added and components broken out in the *Kit repositories.
C#
142
star
12

zig-upaya

Zig-based framework for creating game tools and helper apps
Zig
124
star
13

MessageKit

Decoupled message sending system meant as a replacement for SendMessage and its variants.
C#
122
star
14

zig-gamekit

Companion repo for zig-renderkit for making 2D games
Zig
103
star
15

CameraKit2D

Framework for creating 2D camera systems
C#
95
star
16

zig-renderkit

Zig
54
star
17

zig-flecs

C
51
star
18

GoKitLite

A super duper lightweight tweening library for Unity
C#
51
star
19

SoundKit

C#
45
star
20

Unity-Ripgrep-Search-Tool

C#
42
star
21

P31TaskManager

General purpose task manager that provides a lot more control and power than a standard coroutine
C#
35
star
22

via

V 2D game library
V
29
star
23

UnityCgShaderTutorials

Source code for the Unity Cg Shaders tutorial series on YouTube: http://www.youtube.com/playlist?list=PLb8LPjN5zpx1tauZfNE1cMIIPy15UlJNZ
C#
27
star
24

V-C-Wrapper-Generator

Helper for generating Odin and V wrapper code from C source
C#
19
star
25

Simple-ECS-Sharp

C#
18
star
26

ecs-lua

A simple, hybrid ECS
Lua
17
star
27

zig-miniaudio

Zig
17
star
28

SpriteKit

DEFUNCT: Unity now has 2D tools built in. This is now not maintained.
C#
15
star
29

PaletteKit

Helpful editor classes for importing and displaying color palettes
JavaScript
12
star
30

LearningUnits

C#
10
star
31

Odin-Sublime-Text-Plugin

Python
9
star
32

ImGuiGL-Renderer

C#
9
star
33

zig-vulkan

C++
5
star
34

egui_curve_tool

Rust
4
star
35

zig-aya

Zig
4
star
36

App-Engine-Task-Manager

Python
3
star
37

Odin-Libs

C
3
star
38

v-temp-modules

V
3
star
39

zig-fmod

Zig
2
star
40

Hugo-Helper

macOS app for managing a Hugo website
C#
2
star
41

prime31.github.io

HTML
2
star
42

fips-flecs

fipsified version of the Flecs ECS
CMake
1
star