Keeping shadows for clipped pixels?

I’m working on a surface shader that modifies the vertices, and because of this I need to use the “addshadow” directive to get nice looking lighting for these modified verts.

In this shader I’m also clipping certain pixels. Because of the addshadow directive, this creates holes in the shadows for these clipped pixels. However, I wanted to keep the shadows for them. :confused:

Without the addshadow directive the shadows behave as I want them to, but the lighting on the actual object looks very bad. When using addshadows, I get nice lighting but instead get holes.

Any way around this issue? That is - updating the lighting for moved vertices while still casting shadows for clipped pixels.

What I’m trying to achieve is the casting of shadows for a character’s head, when the head is clipped (due to first person perspective).

I would dislike to add another draw call.

You can do this by writing your own shadowcaster pass and including it with the surface shader and not using addshadow. See the vertex fragment examples in the manual for a basic shadow caster shader.

There’s not a lot of documentation on mixing surface shaders and vertex fragment shaders together, even Unity employees were a little surprised it works, but they totally do.

1 Like