Search Unity

Creating Flat Lighting?

Discussion in 'Global Illumination' started by Denisowator, Mar 22, 2017.

  1. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    So in most 2D games, I see light affecting sprites to a point. Basically it will never get so bright, where the sprite is just a white shape, no matter how close it is to the light source.

    Think of it this way. When you make a sprite, it has neutral lighting, meaning you can perfectly see it as if it was lit up exactly the same from every possible direction. But if you were to put it into Unity, and add a Light object into the scene, and a diffuse map/shader to the sprite. The closer the Light object is to that sprite, the brighter the sprite will become, without a limit. And the same goes for when the Light object is far away, the sprite basically becomes completely black.

    I'll explain this another way. Imagine yourself standing in the middle of the woods, at midnight. If you've been standing long enough, then your eyes adjusted, and if you look at your hands, they're not pitch black (unless you have an extremely dark complexion). Same with if you were facing away from the sun in the middle of a desert, on the sunniest day of the year. If you held up your hands, they wouldn't be bright like white hot metal, but exactly what they look like every other sunny day, maybe with just a little bit of color change due to the intense light.

    What I want, is for light to affect the color and brightness of sprites, but only to a certain extent, and equally across the whole sprite. For example, if I have a scene happening during a sunset, I want the characters to be lit up and slightly orange, however I don't want them to be lit up brighter than what their original brightness looks like (their neutral lighting).

    I have never done or researched this, so I don't know if its a use of shaders, or whatever.

    Here's an example of what I don't want to happen, since I can't replicate it as I'm not at home right now. The person in that question isn't facing the same problem, but if you look at the image they included, you'll see that the light affects the scene in 3D space, even though the scene and game is 2D. The light is causing a gradient on the surface, and the player character is lit up like a Christmas tree on fire, as if they had replaced all their blood with glow-stick fluid. This is what I want to avoid, and what I currently happening to my sprites.

    The person used the same method for lighting as me, ie. using a diffuse on the sprite, and the Unity light object. And the closer the light source is to the sprites, the brighter they get.

    One thing I tried doing, is making the light source absolutely gigantic (like 10000x the size of the player) and making it be really far away (like the sun irl). It sort of works, in that a pretty big area is lit up almost perfectly and evenly, but the 3D lighting thing still remains an issue in this case. Especially since I will want to create parallaxing later on, therefore I will have to move some objects closer to the light than others, which will result in exactly what the person in that question has done (which is what caused their issue).

    Any and all answers are welcome, whether it's links, advice, pointers, explanations, etc.

    Thanks for reading. :)
     
    Last edited: Mar 23, 2017
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    You could maybe write a new sprite shader with a custom lighting function that just clamps the intensity.