Mar
27
2012

Shadow Casting + Convex Hull = More Fake Shadows

Combine Simple Shadow Casting & Monotone Chain Convex Hull and you have…more fake shadows for unity indie!!1

Works fine for a box..should try the teapot next.

Details:
– Calculate vectors from the light, through every vertex in target object,Β  lengthen the vector until reach ground (y=0)
– You get list of points in the ground, convex hull them to get shadow outline
– Create shadow mesh from the convex hull points

Ideas:
– Try multiple lights? Multiple objects?
– Soft shadows? (shader)
– ShadowMesh could have trigger collider, to check if object enters shadow?
– Use ShadowMesh as a mask for something else..(?)
– Only cast shadows for objects in view? (or objects within _ – range from light?)
Webplayer:
http://unitycoder.com/upload/demos/ShadowCastingConvexHull2/

Download source:
shadowhull1.unityPackage

Image#2: Deep profiler report (array sorting seems to take most of the time..)


12 Comments + Add Comment

  • looks promising, always a pleasure to check your blog πŸ˜€

  • Interesting. Does this technique allow projection on uneven surfaces? That’d be very good to achieve.

    • No it wouldnt work, as it just creates a flat (shadow) plane. Maybe with some modifications, but not sure how..

  • this is really kul!

  • This is what I need for a 2D project of mine. So basically, this, except simpler.

    Do you think you could help me out with my forum thread when you have spare time? Casting mesh shadows is driving me up the wall, I just can’t figure it out. I’ve been trying for hours and I’m about two seconds away from total insanity.

    http://forum.unity3d.com/threads/132728-Need-help-from-someone-who-understands-mesh-generation-%28Advanced%29.

  • It is possible to obtain code for this? I would like to experiment or improve this. I just see code latter everywhere πŸ™‚ Can you zip and email it please? I would be pleased.

    • ..even a very small donation is enough for a special “Source-to-Your-Email”-service : )

      I’ll post it there later also..just would need to clean it up a bit, add comments etc.. but havent had the time yet..

  • Hey there, really nice work, could you possibly share the code for this? I would be very grateful!! πŸ™‚ (trying to build something similar for a university game prototype…)

    • yes, i’ll add it within few days (remind me if i forgot : )

      • cool thx a lot! πŸ™‚

        • added source, but something is broken (tested on 4.3), shadow is not visible..(?)

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.