Jan
4
2012

Fake 2D Realtime Raycast Shadows (for unity free version)

Testing another way of doing realtime 2D shadows, by casting rays from the player position, then create “light” polygon to the area where we can see.
More info later, need to test few things (using setpixels & shader? or using different shader for better light effect with polygon plane)

Webplayer:
http://unitycoder.com/upload/demos/mShadowRayScan1/ (added 10.1.2012)

Download source:
mRayCastShadowTest.unityPackage

More test images:
Rays with 1 bounce (so we get light behind the corners also..red color is bounced light ray, using 512 rays for this image, using Debug.DrawLine)


8 Comments + Add Comment

  • Added webplayer demo v1.0

  • -Interesting method, how is performance/# of rays?
    (this would be very useful for me if the ray# can be high. i want to draw a cone of sight with this but for the edges of obstacles in great distances the gap between rays would be to high i guess…)
    -is it possible to create this as a cutoutpolygon for a already placed shadowpolygon?

  • Added source download (had forgotten to upload it)
    So you can test it.. (I’ve only tested on this small scene)

  • Actually, theres no need to triangulate it every frame, for example
    if you use this kind of mesh (every triangle connects to the middle always)
    http://unitycoder.com/blog/2012/01/06/noob-triangulator-js/

    Then all you need to do is,
    – Do scan
    – Modify vertices

    (saves creating: “uv maps”, “triangulation” etc.. from the Update loop)

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.