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.
Alpha of one texture applied to another?
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Alpha of one texture applied to another?
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.
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 True 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.
Re: Alpha of one texture applied to another?
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;
Re: Alpha of one texture applied to another?
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.
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.
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Alpha of one texture applied to another?
Both works, to be honest; I do think it's more for Support & Dev, but at least it wasn't Games or Libraries.
Me and my stuff True 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.
Who is online
Users browsing this forum: Google [Bot] and 8 guests