- Home /
Lighting and shadows for LineRenderer
Is it possible for a LineRenderer to cast or receive shadows or lighting? In my testing they are always dark with any lit shader (like Diffuse), and never cast shadows (in Pro).
The docs for LineRenderer say that Particles shaders are recommended, which suggests that shadows and lighting are not possible.
If not, how expensive would it be to construct an "equivalent" mesh every frame (eg. pentagonal cross section) compared to a LineRenderer? If it's only 5 times as expensive, that's probably bearable in my use-case.
Answer by Eric5h5 · May 05, 2010 at 01:40 AM
You can use shadows with line renderers by using a shader that supports shadows. If the shader you want to use doesn't, then you can make a custom shader that properly incorporates shadow code. However, the "always face camera" thing that a line renderer does makes its shadow weird and glitchy. It would be better to construct a mesh yourself that doesn't have that behavior.
Here's a pic of a line renderer casting a shadow...it looks OK here, but gets weird when the camera moves or zooms. It does have lighting, but it's not really useful since the light has to be pointing in unexpected directions to have any effect.
Other objects to which I apply Diffuse have shadows, but not LineRenderer. Indeed, the LineRenderer appears not to even get light from lights (it looks just ambient lit).
Come to think of it, the always-face-the-camera would also make the lighting terrible. Okay, I think that pretty well covers it!
@Warwick Allison: I edited my answer to add a pic. Line renderers definitely cast shadows and have lighting if you use a diffuse shader, but it's kind of bizarre shadows and lighting so it's not very useful. Rather a moot point but anyway. ;)
Answer by qJake · May 05, 2010 at 12:32 AM
Line renderers are not expensive to create. It's quite literally 2 triangles per segment. If you can't get the desired effect using the existing LineRenderer component, it may be best to create your own.
The only thing that may be tricky to handle is, the faces of the LineRenderer segments always "face" the camera. I'm not sure if that's going to be a problem for you or not, but I thought I'd mention it.
If you create your own, each segment would act basically like a plane, to which you could apply whatever material you like onto it. I'm pretty sure the planes would cast shadows, as well, though I'm not 100% sure as I only use Unity's free version.