Page 1 of 2
Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 11:05 am
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 (310.37 KiB) Viewed 5102 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 (144.75 KiB) Viewed 5102 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.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 12:55 pm
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.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 3:50 pm
by darkfrei
I think that you need to make two meshes with alpha transparency and draw the both of them.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 3:58 pm
by UnixRoot
He's using the same texture, just different UV's. So it should be possible with only one mesh and a shader.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 4:49 pm
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.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 6:21 pm
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?
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 6:27 pm
by UnixRoot
Each vertex already has RGBA vertex color attributes that you can use.
Re: Efficient way to apply two textures to the same mesh?
Posted: Sun Jun 18, 2023 7:55 pm
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?
Re: Efficient way to apply two textures to the same mesh?
Posted: Mon Jun 19, 2023 6:57 am
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
Re: Efficient way to apply two textures to the same mesh?
Posted: Mon Jun 19, 2023 9:56 am
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
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.