Efficient way to apply two textures to the same mesh?

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.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Efficient way to apply two textures to the same mesh?

Post by Bobble68 »

Ok so the title doesn't properly explain what I mean.

So my game has a repeating stone texture, which is overlayed on it self at a bigger scale so that it's easier to see it when it's zoomed out, as well as giving it a distinct style.
rock.png
rock.png (310.37 KiB) Viewed 4980 times
However, as people were saying they were getting performance issues, I'm now using meshes instead of canvases to draw the rocks, and I'm unsure if there's an efficient way to achieve the same effect.
rock.png
rock.png (144.75 KiB) Viewed 4980 times
The best I can think of is drawing the mesh twice with the UVs changed, but I have a feeling there might be a better way.
Dragon
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Efficient way to apply two textures to the same mesh?

Post by UnixRoot »

I haven't done it before, but it's possible to use 2 different UV values with custom vertex attributes that you send to a shader.
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Efficient way to apply two textures to the same mesh?

Post by darkfrei »

I think that you need to make two meshes with alpha transparency and draw the both of them.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Efficient way to apply two textures to the same mesh?

Post by UnixRoot »

He's using the same texture, just different UV's. So it should be possible with only one mesh and a shader.
User avatar
slime
Solid Snayke
Posts: 3161
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Efficient way to apply two textures to the same mesh?

Post by slime »

Even if you had multiple textures, you don't need multiple meshes for that because you can sample from multiple textures within the same shader.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Efficient way to apply two textures to the same mesh?

Post by Bobble68 »

slime wrote: Sun Jun 18, 2023 4:49 pm Even if you had multiple textures, you don't need multiple meshes for that because you can sample from multiple textures within the same shader.
You can give transparency as a vertex attribute right?
Dragon
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Efficient way to apply two textures to the same mesh?

Post by UnixRoot »

Each vertex already has RGBA vertex color attributes that you can use.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Efficient way to apply two textures to the same mesh?

Post by Bobble68 »

UnixRoot wrote: Sun Jun 18, 2023 6:27 pm Each vertex already has RGBA vertex color attributes that you can use.
So how would I do this using UVs?
Dragon
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Efficient way to apply two textures to the same mesh?

Post by UnixRoot »

You mean 2 different UV sets for multi texturing? I've never done it myself but I would search the web for GLSL shaders from others who have done multi texturing like light mapping or AO before and adapt it to Love2D.

Custom vertex attributes and how to use them, is explained in the Wiki.

But I think you don't even need a second pair of UV values, because you could probably just multiply the original UV coordinates with a scaling factor and mix the two resulting images together, inside of the shader.

You can find formulas to mix / blend images, similar to Photoshop blending modes, online.

Like I said, I've never done it before, so everything I said is just theoretical knowledge. But it sounds right :D
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Efficient way to apply two textures to the same mesh?

Post by Bobble68 »

UnixRoot wrote: Mon Jun 19, 2023 6:57 am You mean 2 different UV sets for multi texturing? I've never done it myself but I would search the web for GLSL shaders from others who have done multi texturing like light mapping or AO before and adapt it to Love2D.

Custom vertex attributes and how to use them, is explained in the Wiki.

But I think you don't even need a second pair of UV values, because you could probably just multiply the original UV coordinates with a scaling factor and mix the two resulting images together, inside of the shader.

You can find formulas to mix / blend images, similar to Photoshop blending modes, online.

Like I said, I've never done it before, so everything I said is just theoretical knowledge. But it sounds right :D
Oh right, shaders 😅, I just tried that and it worked super easily with my limited shader knowledge. I have no clue why I find it so hard to think of them to solve problems.
Dragon
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests