P
pawpads
Guest
I'm currently trying to improve my project's implementation of shadow projections. Currently, the lighting system is very rudimentary, and works as follows:
1. Render a surface and populate it using all light-creating objects' lighting sprites
2. Calculate the projection of all shadow-casting objects according to their bounding box
3. Subtract the shadows from the lighting surface
4. Add the lighting surface to the rest of the application surface
I'm attempting to create a system that allows for more precise shadows to be calculated, but I'm getting pretty stuck along the way. At this point, I'm only worried about getting a working system created, and don't want to bother with optimization until I know it works (I'm fairly new to GMS in general).
My proposal is that a shadow-casting object's projection can be defined by doing the following (given a light-source and a square, for single demonstration):
- First, project a huge scaled-up version of the object in the direction the shadow should be cast.
(e.g. (light_xy - object_xy) * projection_size). By making the projection arbitrarily large (or at least larger than whatever will be displayed on screen at any time), it will basically serve as a mask.
- Draw a rectangle from each side of the object to its respective side at the projection. That's two triangles for every vertex. This should consistently create a solid shadow regardless of angle or shape.
However, since I need to be able to access more vertices in order to define more precise shadows than simple squares -- for example, the shadow defined by a sprite's precise collision mask -- the built-in bounding box vertices are no longer sufficient to create these projections. I've skimmed through the manual for any mention of accessing a ds_list of vertices for a sprite or its collision mask, but didn't come across anything.
My question, hence, is follows: Is there any way to access sprite/mask data as a collection of points? I don't think I could use a shader to enumerate a sprite per-pixel by alpha and pass that back to GMS, could I? I'm not sure what the best way to do this is -- and I definitely don't want to have to define a dataset manually for every single sprite instance in my game, since this is supposed to be fully dynamic.
If anyone has suggestions, please let me know. Apologies if I've missed something that would answer this easily -- I'm still learning where to look.
1. Render a surface and populate it using all light-creating objects' lighting sprites
2. Calculate the projection of all shadow-casting objects according to their bounding box
3. Subtract the shadows from the lighting surface
4. Add the lighting surface to the rest of the application surface
I'm attempting to create a system that allows for more precise shadows to be calculated, but I'm getting pretty stuck along the way. At this point, I'm only worried about getting a working system created, and don't want to bother with optimization until I know it works (I'm fairly new to GMS in general).
My proposal is that a shadow-casting object's projection can be defined by doing the following (given a light-source and a square, for single demonstration):
- First, project a huge scaled-up version of the object in the direction the shadow should be cast.
(e.g. (light_xy - object_xy) * projection_size). By making the projection arbitrarily large (or at least larger than whatever will be displayed on screen at any time), it will basically serve as a mask.
- Draw a rectangle from each side of the object to its respective side at the projection. That's two triangles for every vertex. This should consistently create a solid shadow regardless of angle or shape.
However, since I need to be able to access more vertices in order to define more precise shadows than simple squares -- for example, the shadow defined by a sprite's precise collision mask -- the built-in bounding box vertices are no longer sufficient to create these projections. I've skimmed through the manual for any mention of accessing a ds_list of vertices for a sprite or its collision mask, but didn't come across anything.
My question, hence, is follows: Is there any way to access sprite/mask data as a collection of points? I don't think I could use a shader to enumerate a sprite per-pixel by alpha and pass that back to GMS, could I? I'm not sure what the best way to do this is -- and I definitely don't want to have to define a dataset manually for every single sprite instance in my game, since this is supposed to be fully dynamic.
If anyone has suggestions, please let me know. Apologies if I've missed something that would answer this easily -- I'm still learning where to look.