Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Pixel art spotlight?

Discussion in '2D' started by Tom01098, Nov 28, 2015.

  1. Tom01098

    Tom01098

    Joined:
    Jun 8, 2015
    Posts:
    42
    Hey ;)

    So, I've been planning on working on my own dungeon crawler/escape/survival game for a little while now. One of the features is that the dungeon is pitch black, and the only light originates from the players torch (or spell later in the game). Sort of like the torch in this image:



    I want to preserve the pixelated style that the game will be, and I can think of one solution.

    My method is to create an animated sprite that is close to the camera. The outside is black, and the inside has a circle that is semi-transparent. Because of this, the only light the player can see is around the hero.

    This will create problems with immobile objects, so one thing I need to ask is: Is there a way to make good pixel-y light sources?

    Thanks
     
  2. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    My solution is to make the light "halo" as a sprite that is parented to the torch in front of or behind the flame. Then add a trigger collide to the halo. When the player (or any sprite with physics) is colliding with the trigger, lerp it's sprite color by it's distance to the torch to simulate a lit visual.

    This can be quite processor intensive if you have a large amount of sprites, or impractical if they don't already have physics/collides on them, but it's the best I could come up with. Unity really needs a good 2D lighting and shadow solution...
     
  3. Tom01098

    Tom01098

    Joined:
    Jun 8, 2015
    Posts:
    42
    Yeah, unfortunately I'm thinking there may be many sprites, so I may just have to stick with my original idea
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    Can you do it with shaders?
     
  5. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    565
    I am a shader-noob but this is what i found out about this topic so far

    In general you have those limitations:

    -if your world consists out of many tiles, using a lightning affected Sprite-Renderer-Material will break your batching and double your drawcalls (i get like 700 for ~50x50 tiles for a medium light) - that makes any game unsuitable for mobile

    -if you use many semitransparent halo sprites as overlay your Fill-Rate will suffer, making your game unsuitable for mobile if you overdo it

    -Bionicle_fanatic solution will highlight the transitions of your tiles, i believe it is the same thing that Legend of loot uses (and legend of loot lags a bit on my s4mini):
    http://www.androidrundown.com/wp-content/uploads/2013/07/HeroesOfLootPreview-03.png


    best thing would be to combine tiles of one type or drawing order (floor, walls) into a mesh that can accept lights. being only one object the mesh will only be one drawcall (but don't make it too large, i am not sure but this may caus other issues i guess), but referencing the tiles into a mesh from a Spritesheet is some coding work...
    maybe that will help:

    http://forum.unity3d.com/threads/2d-efficiency-with-sprites-and-game-objects.240750/

    http://gamedev.stackexchange.com/qu...durally-generated-level-in-2d-tile-based-maps


    but in short: Lightning and sprites are a headache if you want to go mobile.

    you can also check out this approach for desktop:
     
    Tom01098 likes this.
  6. Tom01098

    Tom01098

    Joined:
    Jun 8, 2015
    Posts:
    42
    Thank you Marrt!
     
  7. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    681
    Hey Tom01098! I am making a similar game. The best way (for me) to do this is using a light cookie. Here is the one I made:
    Light Cookie.png

    Feel free to use it. You can make your own easily
    Here is the result:
    Capture23.PNG
     
    Tom01098 and tedthebug like this.
  8. Tom01098

    Tom01098

    Joined:
    Jun 8, 2015
    Posts:
    42
    Thank you calmcarrots, your game looks great by the way!
     
    calmcarrots likes this.
  9. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    565
    @calmcarrots Which technique do you use to achieve that effect?
     
  10. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    681
    Thanks! Good luck! Also, if you want more of the pixel-y effect, lower the resolution of the texture that I linked!

    Hi, download the file that I linked in my previous post. Import it to Unity and make sure you make the settings like this:
    Capture12131232123.PNG

    Next, place a Spot-light in the scene and make it faces downwards towards the player. After that, make sure your light settings are like mine:
    Capture2112.PNG

    The important part is that you put the texture into the "Light Cookie" slot otherwise it won't work. You can read about light cookies and how to make them here:

    http://docs.unity3d.com/Manual/HOWTO-LightCookie.html

    They are super simple to make.

    Also, if you want more of the pixel-y effect, lower the resolution of the texture that I linked!
     
    Tom01098 and Marrt like this.
  11. Bionicle_fanatic

    Bionicle_fanatic

    Joined:
    Jun 8, 2013
    Posts:
    368
    Wow... That is a whole lot simpler... I'm kinda shocked that I didn't think of that O_O [:p] Good job, and thanks [:)]
     
  12. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    565
    @calmcarrots Finally got to try the cookie light, but i wonder, doesn't this break batching for you?

    upload_2015-12-13_18-19-58.png
     
  13. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    681
    That's weird. Try changing the importance to Auto maybe?
     
  14. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    565
    Maybe it is the composition of your scene, my scene consist out of multiple tiles - each with a SpriteRenderer. So every Tile creates 2 drawcalls because of the broken batching.

    If your scene is only one groundplane then you'll have 2 drawcalls for each plane and that may not add up to much.
     
unityunity