Advertisement

Outlining A Group Of Layered Sprites

Started by November 09, 2024 07:21 PM
1 comment, last by Brian Sandberg 2 months ago

Currently, I've got a GLSL shader which can outline individual sprites by finding the edges of the sprite texture, however I've found this to be insufficient in the case where I have two or more sprites that are layered on top of each other to form a single sprite, because each individual layer is being outlined, while what I want is for the whole thing to be outlined as if it were a single sprite. For example, imagine a character sprite with a separate hat sprite rendered on top, I don't want all the hat's edges to be outlined because the bottom outline will overlap the player head.

An idea I had for a solution is, for each sprite that is to be outlined, instead of rendering each sprite layer to the screen individually, I will create a frame buffer object to use as an offscreen texture where I will render each of the sprite layers. Then, I will render that offscreen texture to the screen instead and outline it.

Does this idea make sense, or is it the wrong approach? If I'm understanding correctly, I could potentially be creating a lot of frame buffer objects, as each outlined sprite would need its own surface, and I believe I would also have to create a VBO and IBO to go with each of them too, is my understanding correct here? Furthermore, outlines will likely be turning on and off throughout the game, so I am wonder if I should just have an ever growing list of FBOs, or should I create and delete them only as they are needed? Another scenario I just realized is the overall sprite size could change (imagine the previous example with that hat, you might swap a small hat for a very tall hat), so in this case I think I would have to delete the offscreen surface and recreate it using the new size.

If your outline is supposed to be an outline and not something on top of the sprites, you could do it in two passes; one where you draw the outline-only of each sprite in the group, and then one where you draw the sprites themselves which would hide the overlapping parts of the sprites.

This topic is closed to new replies.

Advertisement