Oct
12
2014

2D Visibility / Shadow

2d_visibility_shadow_casting_unity_1

Started converting this 2D visibility/light script ( http://ncase.me/sight-and-light/ ) to unity, finally some progress!
btw. lines are drawn using GLDebug from : http://www.unity3d-france.com/unity/phpBB3/viewtopic.php?f=24&t=5409

Unity forum thread: http://forum.unity3d.com/threads/2d-visibility-shadow-free.275698/

TODO:
– Quad segments are currently crossed..
– Fix mesh generation *Temporary fix:  insert extra boxes outside the view..
– Source cleaning up
– Publish to github
– Optimize
– Some documentation
– Try raster version (bresenham + floodfill)
– Support for moving objects
– Sprite support (but unity indie has quad sprite mesh, no tight mesh generation..needs extra script to generate helper points for sprite image edges..?)
– Better system for finding edge segments
– …

Stats:
– 20 obstacles (~80 vertices) : ~45-50ms per frame (in editor, with slow’ish pc)

Webplayer:
http://unitycoder.com/upload/demos/2DVisibility/v1/ (v1, still broken)
http://unitycoder.com/upload/demos/2DVisibility/v2/ (v2, almost done)


Source:

https://github.com/unitycoder/2DShadow (Please help improving the code!)

Previous attempt:
Shadow casting 2D : http://unitycoder.com/blog/2014/02/10/shadow-casting-2d/ (using pseudo angles, unfinished

Image#2: Few problems fixed, mesh still broken..somehow cannot make the light vertices go in to “correct” world space(?)

2d_visibility_shadow_casting_unity_2

Image#3: Mesh fixed, but still starts “stretching” when mouse moves away from center..

2d_visibility_shadow_casting_unity_3

Image#4: Good enough..(added hidden boxes outside the view, to avoid broken mesh *hidden box idea from denamond)

2d_visibility_shadow_casting_unity_4

Image#5: Current profiler view, gets quite slow with many objects..need to start optimizing

2d_visibility_shadow_casting_unity_profiler_1(click image to view)

Image#6: Testing visibility with Martt’s dual camera depth mask system (see the 2nd sphere is partly hidden)

2d_visibility_shadow_casting_unity_camera_mask_5


18 Comments + Add Comment

Leave a comment

@unitycoder_com

Subscribe to Blog via Email

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