Page 1 of 1

Decals methods?

Posted: Mon May 06, 2013 9:23 pm
by azathoth
I'm having some difficulty trying to think of a way to do decals on objects that are rendered as polygonal shapes.. Just keeping a table of extra images to be rendered with the object doesn't seem right, the decals would go past the object shape.

Basically I want the decal to be somehow cut to whatever shape the object has, see the attached image.

Sorry if there's an obvious answer.I suspect there is, and a canvas would be involved, but I can't figure it out ..

Re: Decals methods?

Posted: Mon May 06, 2013 10:27 pm
by slime
One way would go something like this:

Code: Select all

drawPolygon()
love.graphics.setStencil(drawPolygon)
drawDecal()
love.graphics.setStencil()
It might not be very efficient if you have many polygons with decals, though.

Re: Decals methods?

Posted: Wed May 08, 2013 10:58 am
by T-Bone
slime wrote:One way would go something like this:

Code: Select all

drawPolygon()
love.graphics.setStencil(drawPolygon)
drawDecal()
love.graphics.setStencil()
It might not be very efficient if you have many polygons with decals, though.
Yes, a stencil makes sense here. If you run inte performance issues, only render with the stencil once by rendering it to a canvas first, and then only draw the canvas to the screen. This will only work if these "decals" don't change every frame.

Re: Decals methods?

Posted: Wed May 08, 2013 5:59 pm
by azathoth
Thanks, these made a lot of sense. I ended up with using one canvas per object, to which I render the splatter textures with the object's draw method itself as a stencil. As this happens only on collisions and shouldn't happen on many objects at once, it's not causing any problems performance-wise so far.
Maybe so many canvases is a bit of an overkill? They're not very large as a rule, though.

Re: Decals methods?

Posted: Wed May 08, 2013 7:27 pm
by T-Bone
You can have quite a lot of canvases before you run into issues, even on integrated graphics. Especially if they're small.