Search Unity

Directional light and caves

Discussion in 'Editor & General Support' started by Kryber, Mar 1, 2014.

  1. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    Hi. How can I darken my cave without using the shadows? Im using a directional light. Thanks in advance.

    $Immagine.png
     
  2. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Setting the ambient light amount to zero in Render Settings should help.
     
  3. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    Doesn't work... I setted Ambient Light to Black (0, 0, 0, 0)
     
    Last edited: Mar 1, 2014
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    If you don't have shadows, then you basically can't.

    You could try lightmapping, or using point/spot lights instead of directional.
     
  5. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    It's a voxel terrain... I cant :/
     
  6. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Try changing the directional light to a spotlight or point light instead. Then you can set the range of the light to darken the cave by attenuation.
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    You could implement your own shadowing, perhaps. It being voxel-based makes things much simpler.
     
  8. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    Any advice on how to start to develop it? :(
     
    Last edited: Mar 2, 2014
  9. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    A good first step would be to try to figure out when the player is in an enclosed space. The easiest approximation of that would be to randomly fire rays towards the sky as the player moves around. If enough of those rays hit something, then it's a good guess that the player is inside. When the player is inside, ramp the intensity of the sun light down.
     
  10. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    Could I implement the Physics.SphereCast, or you think it's better to use Physics.Raycast?

    Thank you for the reply :)
     
  11. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Raycast is likely to be a lot cheaper, esp since you'll want to fire multiple rays per frame.
     
  12. Kryber

    Kryber

    Joined:
    Apr 14, 2013
    Posts:
    92
    mmm... I like this approach to the problem. I created a script in wich foreach frame it create 256 ray. Based, then, the number of rays that strike a block of voxels world, it increases or decreases the brightness. It make also particular effect like dark luminosity near big mountains.
     
  13. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Glad you like it! It's inspired by Monte Carlo Integration.