Decals methods?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
azathoth
Prole
Posts: 5
Joined: Fri May 03, 2013 12:27 am

Decals methods?

Post 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 ..
Attachments
ex.jpg
ex.jpg (6.28 KiB) Viewed 2626 times
User avatar
slime
Solid Snayke
Posts: 3161
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Decals methods?

Post 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.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Decals methods?

Post 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.
User avatar
azathoth
Prole
Posts: 5
Joined: Fri May 03, 2013 12:27 am

Re: Decals methods?

Post 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.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Decals methods?

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests