Best approach for shadows on avatar

Hello all,

We are at the stage of adding an avatar into our game and would like to utilize the same lighting setup as our terrain (which is using a lightmap). Is there any way to have this lightmap affect the avatar (or any other object for that matter) for dynamic shadowing? I imagine real time shadows are expensive and would not accomplish the effect we are looking for. I’m not sure what the best technique would be for the numerous trees that we have that would block the light and shade the player when appropriate.

If anyone has experience or recommendations on how to approach this, it would be much appreciated.

Thanks,
Matt

Here’s one way to go about it. This creates a projection matrix the size of the terrain and maps the terrain’s lightmap onto objects with the “LightmappedObjectUV” script attached and using the “SimpleLightmapped” shader. Play the example scene and move some of the smaller objects around to see it in action.

This isn’t the greatest solution, but might give enough sense of lighting/shading for your needs.

HTH,
EThan

87231–3388–$lightfromterrain_162.zip (519 KB)

Ethan -

That is really actually quite cool. I suppose it would actually be possible to use the same lightmap → pixel transition with distance to switch that too?

Thanks Ethan,

Looks good in the sample, we just want a general sense of light and shadow, so something like this should work!

Matt

Great thing
thank you for sharing.

Yeah, this could be done, but the transition wouldn’t really work since this method projects the lightmap topdown so the shadows aren’t that accurate, it just gives a sense of light and dark. The real trick might be to project the matrix from the angle of the Directional Light. Not sure though.

Anyway, there are a lot of limitations with this example, but it works nicely for objects that are close to the terrain surface and are relatively flat. There’s also a lot of overhead with this example that needs to be taken into account. If you want to “light” static objects with this method you certainly don’t need to update the projection every frame. I’d love to see someone improve upon this. It could be rolled into a default Unity shader possibly. I’m pretty sure terrain detail meshes are shaded on this same principle.

Ethan

This is great!
Now you probably noticed projected shadows do not modulate grass brightness, Would this shader+script
be a basis to fix that ?