GMS 2 Accessing Sprite / Mask As Vertices

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.
 

SoVes

Member
I'm also curious for a good dynamic solution. only approach I came with was to draw a light source to a black surface and then draw the objects with black on top and then loop the surface and scale it each time, but it doesn't run too fast.
 
P

pawpads

Guest
I'm also curious for a good dynamic solution. only approach I came with was to draw a light source to a black surface and then draw the objects with black on top and then loop the surface and scale it each time, but it doesn't run too fast.
I've considered this approach, and while it would definitely work, the resolution of the shadows would be dependent on how small the scaling factor was per cycle. Definitely not the most optimal... but I might write this in the mean time for our demo to keep me occupied.
 

SoVes

Member
I've considered this approach, and while it would definitely work, the resolution of the shadows would be dependent on how small the scaling factor was per cycle. Definitely not the most optimal... but I might write this in the mean time for our demo to keep me occupied.
yeah, The best solution might be like a inner outline shader and then save pixels as points if they are corners.
 
P

pawpads

Guest
is it even possible to save pixel information from within a shader to outside it, in gms?
 

SoVes

Member
I think you can use surfaces to output. Performance doesn't really matter here since you need to only calculate the points only once.
 

SoVes

Member
or you could have manually placed pixels in the image editor and you could use those so you don't need a shader, but if you'd do this it would be better just to have like a custom editor that let's you place dots so you don't need to process anything at the start of the game. Anyways processing everything outside the game and just importing the data would be the best way.
 
Top