What kind of techniques are used to make characters fit in an environment?
I’m using sprites for everything (game is 2D).
I believe normally lights would be used but I can’t use lights in my game.
The game is continuous (metroidvania) so the characters’ brightness must change based on their environment.
A single direction light would probably be the easiest way. How come you can’t use lights?
I suppose another way would be to have a single ‘scene lighting’ script in every scene and all sprites have another ‘ambient light’ script that references this ‘scene lighting’ for a color that they then use to set their sprite renderer’s tint. But again, a single directional light wold be a lot easier, get the same effect, and provide more options for nuance.
I’ve had a few runs with lit shaders for sprites and while they’re doing a good job they’re always limited to a maximum number of lights (8 max). When it gets over that treshold it won’t display correctly anymore.
Is it a good idea to put a light-receiving shader on all my sprites anyway?
How do you make a directional light not affect everything in the scene? With the shaders I tested, directional light just added light to everything in all scenes the same amount. Since my game is continuous (there’s no loading between scenes) 1 directional light will affect every scene. So if I unload a scene, that light will disappear and it’s gonna drastically change the lighting.
For the ambient light script, touching the sprite renderer tint gives a rather poor result and it’s only capable of going darker so I don’t believe that’s a solution.
So there are a few ways of dealing with this. The easiest is simply to use layers. You can set all of your 'character ’ sprites to a layer just for globally lit sprites and then in the directional light settings you can set the layer mask that it will affect only these sprites. Another way is to use one shader for scenery that isn’t affected by directional lights and one for characters that are.
As far as shaders go, directional lights are the easiest to support and in the case of sprites are often done using vertex shaders which means, in theory (depending n the shader) you can have support for an unlimited number of directional lights.
While on the topic - you did set your render mode to linear color space, yes? If you haven’t and your not planning to support older mobile hardware you’ll want to do that now. Trying to light sprites in gamma space can be a real pain and if you try to switch to linear later you’ll have to go back and readjust everything.
Thanks for tip, I didn’t do that, I’ll switch to linear now.
Directional lights seem like an easy solution but something bothers me with them.
Since they are affecting everything in the layer no matter the distance to the light, what do I do when I just arrived in a new scenery (different mood, brightness, colors)?
Disabling the previous directional light will drastically change lighting, should I just slowly turn the previous directional light off and slowly fade in the new directional light in. I guess that should work.
Lights are a good way, especially for variations in the scene.
Instead of using a directional light you should tweak ambient lighting, but I have to admit that I never worked with sprites yet so does it even work?
Instead of switching the light you can adjust the color of the light.
You could also simply adjust the color of the sprite, but then the source must be brighter or you might need a custom shader which multiplies color by 2 for instance.
Yes it works with materials that use light but it will affect everything (my environment included).
I at least need one type of light that only affects the characters so I can make them fit the environment (w/ directional light & layers). I’ll keep the same dir light and modify it based on the player’s position.
Thanks for the suggestions.

