Alpha of one texture applied to another?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

Alpha of one texture applied to another?

Post by Madrayken »

Hi folks,
Long time Love2d user here.
I'm making an old-school RPG and I'm using two textures to show the world 'map' screen (not the main display).
1) Texture 1 stores data such as the values of various tiles in the 'r' channel, and flags tiles you've seen in the 'g' channel.
2) Texture 2 stores a 'pretty' map using all the rgb values as normal.
Now, I want Texture 2 to be drawn using the 'g' channel of Texture 1 as alpha, so I can draw it over parchment or something, with only the bits you've seen being visible.

What's the most sensible way to combine 2 textures like this? Draw to a canvas, and then draw in some 'black=alpha' mode? Can I send 2 textures to my shader and combine them in there? Any ideas much appreciated.
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Alpha of one texture applied to another?

Post by zorg »

Hi!

First, apologies that this might sound too simplistic or wrong, but i haven't done any practical work with too many shaders yet.

You do mean like a minimap, i take it? That basically reveals square tiles as you move, and looks like a parchment?

You can definitely send two or more textures to a shader and have them be available for you to utilize.

This might be one way you could do it:
- Have your two textures be in the state you want them to be.
- Set your shader.
- Send those two textures to your shader.
- Draw the image of the parchment, which will use the active shader

And the shader would basically modify the parchment image, darken and a bit desaturated, possibly (up to you what kind of effect you want), based on the second texture's rgb channels and the first one's g channel utilized as an alpha channel (you could use a vec4 variable and combine those values before modifying the actual parchment image with said variable.)

Something like that may work, i think.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Alpha of one texture applied to another?

Post by pgimeno »

A shader is what I'd use. Something like:

Code: Select all

extern Image image1; // the G channel should be alpha
extern Image image2; // the alpha of this image is ignored
...
    return vec4(Texel(image2, texturepos).rgb, Texel(image1, texturepos).g) * colour;
User avatar
Madrayken
Party member
Posts: 126
Joined: Sun May 04, 2014 4:21 pm
Location: Oakland CA
Contact:

Re: Alpha of one texture applied to another?

Post by Madrayken »

Thanks for both the replies, folks. You both got the idea perfectly. I didn't realise you could send two textures to a shader! I've sent plenty of other variables as externs in the past, but for some reason I thought doing that with textures was a nono. As ever, lovely to find out that I've still tons to learn. :-)

P.S. Was General the right place for this, or should I have sent it to Support and Development? Apologies if I got the wrong one.
Discord: https://discord.gg/tYfHgXc
Bandcamp: https://madrayken.bandcamp.com/
Twitter: @Fluttermind
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Alpha of one texture applied to another?

Post by zorg »

Both works, to be honest; I do think it's more for Support & Dev, but at least it wasn't Games or Libraries. :P
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 92 guests