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
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.
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
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.
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
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...
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.
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
This problem has to do with vertex lighting vs pixel lighting. I had the same problem and was told that the problem lay therein. Pixel lightning seems to solve the problem but it's cost heavy and had artifacts in the shadows, but this was in unity3D 2.5. http://forum.unity3d.com/viewtopic.php?t=32874&postdays=0&postorder=asc&start=15 Hope this helps!
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
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
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.
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).
Lights still go through standard shader in 5. Edit: I did find that changing some quality settings prevented this from happening.
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.
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.
I turned on shadows on the spotlight and it stopped going through walls even though the range was large
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 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. Soft shadow And this is what it SHOULD look like, with no light influence. ( I simulated with turning off the light that affects it). 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.