x


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.

more ▼

asked May 05 '10 at 12:20 AM

Waz gravatar image

Waz
6.5k 22 33 71

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

alt text

more ▼

answered May 05 '10 at 01:40 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

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).

May 05 '10 at 06:33 AM Waz

Come to think of it, the always-face-the-camera would also make the lighting terrible. Okay, I think that pretty well covers it!

May 05 '10 at 06:36 AM Waz

@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. ;)

May 05 '10 at 08:03 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 05 '10 at 12:32 AM

qJake gravatar image

qJake
11.6k 43 78 161

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x425
x272
x171
x108

asked: May 05 '10 at 12:20 AM

Seen: 1962 times

Last Updated: May 05 '10 at 12:20 AM