- Home /
2D Lighting With Unity Free
I am currently working on making a 2D game where I want to "simulate" lighting effects that are capable of having multiple light sources in a scene. Now, I'm not looking to create real-time 2D lighting as it doesn't need to be that advanced. What I would like to do is create what appears to be lighting effects using shaders.
I'm wondering if its possible to overlay the screen with a black texture and then place images of a certain color on the screen that alter the alpha of the black overlay based on the use of color in that image. This way, I could not only place multiple lights but also I would be able to alter the black overlay to simulate different areas being darker than others.
I have basically no experience with shaders in Unity, so if this is a silly question then I apologize :D Also, I am using the free edition of Unity for all of this if that affects the answer.
Answer by PuppyPunch · Oct 08, 2012 at 05:51 PM
If you use a texture targa of a white dot on a black background with an alpha channel the following shader will give you a spotlight effect. Unfortunately, I'm not able to get it to gradient the transparency. However if you change the blend to the one I have commented out, it will go from transparent to black in a gradient, this means that lights cannot overlap though.
If you or anyone knows how to make this go from cutting transparency to just being opaque (i.e. showing the black texture behind it) that'd be awesome.
Shader "bitmask"
{
Properties
{
_Mask ("Culling Mask", 2D) = "white" {}
}
SubShader
{
Tags {"Queue" = "Geometry"}
//Blend SrcAlpha OneMinusSrcAlpha
Blend One One
Pass {
AlphaTest LEqual 0.9
SetTexture [_Mask] { combine texture }
}
}
}
Answer by reveriejake · Jun 02, 2013 at 08:19 AM
2D Volumetric Lights on the Asset Store.
And I sell it for only $15. It should be exactly what you need. You can check the light as "Static" to make it non-dynamic.
Your answer
Follow this Question
Related Questions
2D ligting, light cone 2 Answers
2D Sptite Shader Character in 3D World 0 Answers
Multiple lights disable additive intensity for Sprites-Diffuse? 0 Answers
URP Lit 2D Sprite Shader Texture 0 Answers
Limit Amount of Light Applied to Sprite 0 Answers