Search Unity

Terraria / Starbound Style Lighting (Round 2)

Discussion in 'Shaders' started by BlueSin, Jul 21, 2015.

  1. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Well, I had made a similar post before about how to do lighting for my game Chronos that is similar to Terraria & Starbound. That post can be found here: http://forum.unity3d.com/threads/starbound-terraria-style-lighting.325086/#post-2108542. Since then I have been quite busy with other stuff so progress is slow, but I have indeed made progress...albeit I am stuck again.

    Here is the new results of the lighting I have (vertex lit):




    The first image shows "sun" lighting...I am not entirely sure how to do it though so until I figure that out I am simply traversing the map data on the X, starting with a light value of 1 at the top of the map, that diminishes by 0.1f for every solid block I hit going downward.

    The second image shows what will eventually be a "torch" style kind of light, however there are obvious issues with this one too, (diamond shape) for example.

    The big problem with both of these images are the hard edges on the shadows, particularly visible in the first image. When compared to where I would eventually want to get with a picture of Starbound:



    These edges are much softer than my hard and sudden edges. I know next to nothing about lighting, and nothing about shaders. But I am willing to learn so long as I can get some help going in the right direction. Particularly I want to solve the hard edges, and if I can also get solutions for the diamond shaped torch light issue and how to actually create "sunlight" that would be even better! Much thanks in advance!
     
  2. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
  3. ADoby

    ADoby

    Joined:
    Dec 10, 2012
    Posts:
    21
    You could use some sort of noise map to regulate some of those edges
    and make the light feel more natural.
     
  4. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
  5. chris-z562

    chris-z562

    Joined:
    Jul 11, 2012
    Posts:
    41
    The diamond shape is caused by using manhattan distance instead of real distance (which is more expensive to compute).

    The hard edges are there because you linearly change the intensity of the shadow.
     
  6. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Your post gave me an idea. So when I am building my mesh, I iterate over each tile. Obviously each tile has 4 vertices (1 for each corner) to which I can apply color for that vertex. With that having been said, couldn't I apply manhattan distance to nearest open air block for each vertex and set vertex color based on that? And for each block I have to travel through, light would diminish by say 0.1f or some other value? Thus ensuring I do not have to search too far for air, because once I get to 0 on the lighting I can move on to the next vertex, right?

    Hopefully I am stating that correctly, I can already visualize my procedural mesh generator exploding from searching for nearest air block 4 times per tile in a 100x100 tile mesh. Call me dumb but I am having some trouble visualizing alternative methods to illuminating my world. And on second thought, the method I just described would likely result in the same look (but with significantly more overhead).

    As far as the torch light is concerned, I got my solution to that from: http://www.java-gaming.org/index.php?topic=26363.0 on the last post. But I got lost once he started applying "PreRendereredLight". So close, yet so far away.
     
    Last edited: Jul 27, 2015