Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

light passes through walls

Discussion in 'Scripting' started by mythicwave, Aug 9, 2010.

  1. mythicwave

    mythicwave

    Joined:
    Jul 13, 2008
    Posts:
    144
    I have a rotating spotlight whose beam hits a wall. But when it hits the wall, the light passes through to the other side. The material used for the wall uses a wood texture and is opaque. How do I get the light to stop passing through the wall? Is this a texture or material setting? A light setting?

    Thanks,

    Brian
     
    Krim85 likes this.
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    Make the light range shorter.

    There is nothing preventing light from passing through, what makes it vanish is having dynamic shadows that compensate for it.
     
    sindern likes this.
  3. mythicwave

    mythicwave

    Joined:
    Jul 13, 2008
    Posts:
    144
    I can't make the light range shorter. The spotlight is actually surrounded by four walls, all different distances away. If I make it shorter it wouldn't hit one or more of the walls at all.

    I'm not sure what you mean by dynamic shadows. What are they and how do I set them up?

    Why can't I simply get the light to model real world conditions, where light would never pass through an opaque surface?

    -- Brian
     
  4. Chris Sinclair

    Chris Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    If you're using Unity Pro, you can simply alter the shadow properties on your spotlight: http://unity3d.com/support/documentation/Components/class-Light.html

    The reason why it doesn't simply model real world conditions is because the graphics rendering industry doesn't work that way. Real-time rendering utilizes a lot of tricks, optimizations, and compromises to achieve a decent output at very very fast speeds (at bare minimum 30+ frames per second). To this end, real-time shadow casting is actually complicated texture tom-foolery otherwise you'd need full-fledged raytrace rendering engines (which run way way too slow to be considered "real-time").

    EDIT: In Unity3 (or Unity2 as well?) I believe you can mark objects such that they aren't affected by some lights (or vice versa), but someone else would have to expand on that as I haven't done that yet.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,157
    You can simulate that with realtime shadows in Unity Pro, but computer graphics aren't at all like the real world. There are no actual light rays cast; the lighting for every vertex or pixel (depending on the type of light) is calculated without regard to any other objects in the scene. There's nothing simple about shadows I'm afraid.

    --Eric
     
  6. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    427
    you could set the wall object to a layer which the light does not affect, thereby still allowing the light to have a large range. It's a fudge, but there is no real way to do it without raytracing which is too slow for realtime...
     
  7. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    516
    Could you put a script on the light that dynamically adjusts the light's range using a raycast for instance? Based on the raycast hit distance, you can adjust the light's range based on the wall that is being hit.
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    yeah though you would make the range longer depending on the lights direction to take into account the fact that with anything but "horizontal", either bottom or top of the light cone will reach further than the middle point
     
  9. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,157
    No, that's not it at all. You can use real-time shadows with pixel lighting, but that's an additional option, not something inherent in vertex vs. pixel lighting, and only works if you have Unity Pro. (And even with real-time shadows, light still "passes through" walls, which you can see if you have the shadow strength less than 100%.)

    --Eric
     
  11. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Just posting what aNTeNNa trEE said:

     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,157
    Right, that's just saying that realtime shadows are not available with vertex lights. Pixel lighting by itself doesn't change the fact that lighting is computed on surfaces without regard to other objects; shadows are like a texture that's overlaid on top of things. i.e., light doesn't really "pass through" walls, it's just that walls are irrelevant to how lighting is computed. Light in realtime CG doesn't actually travel from a source in the form of rays that can be blocked.

    --Eric
     
  13. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    23
    So - I was having this same issue and FINALLY figured it out. The issue I was having is that under Player Settings I needed to place a check-mark in Dynamic Batching.
     
  14. Captain-Awesome

    Captain-Awesome

    Joined:
    Jul 29, 2014
    Posts:
    28
    In Unity 5 you just turn on shadows at your light object, and use the standard shader on any materials that are misbehaving (like your floor or wall).
     
  15. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    132
    Lights still go through standard shader in 5.

    Edit: I did find that changing some quality settings prevented this from happening.
     
    Last edited: Oct 22, 2017
    DavidSof likes this.
  16. Koala_Squad

    Koala_Squad

    Joined:
    Aug 30, 2017
    Posts:
    9
    For those people seeing this post now, here's what you need to do. Go into quality settings and switch the Shadows option to either hard or hard and soft shadows. This allows unity to cast the shadows from the objects and makes sure that the object can block light. Then, increase the shadow distance to a level you find suitable, so the shadow doesn't just disappear until it's out of sight or far away.
     
  17. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    387
    Except that

    Except that really still doesn't solve the issue, at least with Spotlights.
    Light side:

    Shadow side:


    That spotlight is on the other side of the wall, and while hard/soft shadows does mitigate it, it doesn't resolve it completely. If any part of the cone is on the other side of the wall, it will light that area. I have an idea to try using a cookie to darken half the cone, I hope that takes it the other 30% of the way.
     
  18. kami1339

    kami1339

    Joined:
    Oct 3, 2018
    Posts:
    6
    No!
    This will work with any objects & lights! only in light active soft shadows.
     

    Attached Files:

    • bad.png
      bad.png
      File size:
      540.5 KB
      Views:
      530
  19. hnm938

    hnm938

    Joined:
    Nov 3, 2017
    Posts:
    2
    I turned on shadows on the spotlight and it stopped going through walls even though the range was large
     
  20. vbs

    vbs

    Joined:
    Sep 8, 2014
    Posts:
    24
    The problem still persists in Unity 2019.2. Here are some example screenshots. Even with shadows on, there is a noticeable lighting of shadowed areas... I wonder if it has something to do with the material specular/reflectivity properties?


    No Shadow

    2019-08-04 12_31_15-.png
    Hard shadow

    While better, the light is still visible on parts and meshes that it should not be at all. I've played with texture packing and there are no overlapping UV's.

    2019-08-04 12_31_29-.png
    Soft shadow

    2019-08-04 12_31_49-Settings.png

    And this is what it SHOULD look like, with no light influence. ( I simulated with turning off the light that affects it). 2019-08-04 12_48_07-Settings.png

    SOLUTION:

    Just posting this because I did a facepalm... I had to turn the shadow "strength" to full (1) where as before they were less that 1. And that got rid of the extra lighting issues.
     
    Last edited: Aug 4, 2019