Thanks a lot, I got it!
Here's some of my incomplete badly written and unoptimized code in case anyone else needs it:
class ImageObject extends Entity {
public var framebuffers:Array<Framebuffer>;
public var image:Image;
var textureID:TextureUnit;
var maskID:TextureUnit;
public var mask:Image;
public function new(image:Image,x:Float, y:Float, width:Int, height: Int){
super(x, y, width, height);
textureID = Project.pipeline.getTextureUnit("tex");
this.image = image;
maskID = Project.pipeline.getTextureUnit("mask");
mask = Assets.images.armopacity;
}
public function update(){
}
public function render(graphics:Graphics,frames:Array<Framebuffer>){
var g4 = frames[0].g4;
var g2 = graphics;
g4.begin();
graphics.pipeline = Project.pipeline;
g4.setTexture(textureID, image);
g4.setTexture(maskID, mask);
g4.end();
g2.begin(true, Color.Green);
graphics.drawScaledImage(image,x - width / 2, y,width * 1.1, height * 1.1);
g2.end();
}
}
I don't even know if I did the rendering correctly, I've only done trial and error until it worked.
Shader:
#version 450
uniform sampler2D tex;
uniform sampler2D mask;
in vec2 texCoord;
in vec4 color;
out vec4 FragColor;
void main() {
vec4 texcolor = texture(tex, texCoord) * color;
vec4 maskcolor = texture(mask, texCoord) * color;
texcolor.rgb *= color.a;
maskcolor.rgb *= color.a;
if(maskcolor.rgb == vec3(0.0,0.0,0.0))
{
discard;
}
FragColor = texcolor;
}
The shader gets the alpha channel black pixels and delete them (I don't need alpha blending though).
And here's the final result.

But there's a line on the top of the image. I've checked the opacity image and it does have all the black pixels actually black, rgb(0,0,0) and the white pixels are fully white, so the line isn't caused by the image. Also, both diffuse and opacity are the same size. And nope, it isn't also caused by "graphics.drawScaledImage" width and height, no matter the in-code image size the line still appear.

But I think I'll solve this out, some day. Anyways, thanks a lot for the help!