Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity build a dark scene with no lights except torch

I want to create a dark scene. The player just got a torch in his hands so this is the only light in the scene.

So the rest of the area should have no lights in it. Maybe it's a cave or a dark forest?

In Pokemon you had this effect in dungeons

enter image description here

Here is a rough sketch how I imagine it

enter image description here

So when I want to set the directional light of the scene to complete black color, you can still see good enough.

How can I archieve these effects of having a dark world?

I don't want to use a texture around the player or something like that. Maybe you can still see through darkness but really really badly.

like image 423
Question3r Avatar asked Sep 05 '25 05:09

Question3r


2 Answers

Use this scene as an example of how to do that:

https://github.com/Galandil74/Unity-Spotlights-Example

Basically, as Lestat already said, you set the overall brightness by changing RenderSettings.ambientLight, then to create the torch effect, you use a directional light game object with a texture cookie in order to illuminate only a portion/shape of the screen.

Remember that to get full illumination through the cookie texture, the light must have its intensity propriety set to 1 - RenderSettings.ambientLight.grayScale (if it's a directional light).

I prefer to use directional light because you can then control the effect via the alpha channel of the cookie texture.

And if you're using sprites (for background, etc.), if you want them to be affected by the ambient light, remember to use the Sprites/Diffuse material.

like image 91
Galandil Avatar answered Sep 07 '25 19:09

Galandil


I know I am 6 years late to this thread, but I figured I'd comment anyway for future finders like me!

I found this as I was searching for similar but in 3D and solved it by

  • creating an empty GameObject with a light component,
  • changing the light to spot and angled it down, and
  • changing the range to however big I wanted it to be.

Then I deleted the directional light and changed the general lighting settings in the environment tab to:

Environment Lighting > Intensity Multiplier -> 0

Environment Reflections > Source -> Custom

Then I attached the GameObject to the player as a child and it worked perfectly!

If you want it to be slightly lighter gradually out you can duplicate it, make the range bigger and intensity down.

I find this to be a way easier way than scripting the directional light, hope it helps someone!

like image 43
linnea kleibrant Avatar answered Sep 07 '25 21:09

linnea kleibrant