EXAMPLE SOURCE CODE



 Mapping Light / Shadows using Ray Intersection

By: Kevin Picone Added: March 21st, 2015

Category: All


     This demo shows the core logic behind drawing radial lights in top down 2D game. The light source is made up of a group triangle fragments drawn in a circular pattern. So we just step around the edge of the circle and draw triangles from the center to the edges. This gives us an N sided polygon that represents our light in the scene, the more sides the accurate the circle will be mapped.

     To make it act more light natural light, we need something to handle the occlusion/shadows. In PlayBasic we can use the ray intersection support found in the world commands. That means we define the "hard" parts of the world and by hard I mean zones where light is not allowed to go/pas through, by outlining them with lines. So when we draw our light, we run ray intersections along the triangle edges against the hard / occlusion world, if there's a collision we grab the intersection point which will clip our light map triangles for us.

     This demo generates the occlusion world randomly, it's basically a cut'n'paste from the Projects/Worlds/RayIntersectWorld demo.

Get Mapping Light / Shadows using Ray Intersection from forums






Release Type: The source code & tutorials found on this site are released as license ware for PlayBasic Users. No Person or Company may redistribute any file (tutorial / source code or media files) from this site, without explicit written permission.


 

 
     
 
       

(c) Copyright 2002 / 2024 Kevin Picone , UnderwareDesign.com  - Privacy Policy   Site: V0.99a [Alpha]