Add mask invert operator

This commit is contained in:
luboslenco
2020-07-08 12:21:41 +02:00
parent 482214b8e2
commit 26094a7a5a
4 changed files with 45 additions and 1 deletions
+13
View File
@@ -30,6 +30,7 @@ class Layers {
public static var pipeCopy8: PipelineState;
public static var pipeCopy128: PipelineState;
public static var pipeCopyBGRA: PipelineState;
public static var pipeInvert8: PipelineState;
public static var pipeMask: PipelineState;
public static var tex0: TextureUnit;
public static var tex1: TextureUnit;
@@ -186,6 +187,18 @@ class Layers {
pipeCopy128 = pipeCopy;
#end
pipeInvert8 = new PipelineState();
pipeInvert8.vertexShader = Reflect.field(kha.Shaders, "layer_view_vert");
pipeInvert8.fragmentShader = Reflect.field(kha.Shaders, "layer_invert_frag");
var vs = new VertexStructure();
vs.add("pos", VertexData.Float3);
vs.add("tex", VertexData.Float2);
vs.add("col", VertexData.Float4);
pipeInvert8.inputLayout = [vs];
pipeCopy8.colorAttachmentCount = 1;
pipeCopy8.colorAttachments[0] = TextureFormat.L8;
pipeInvert8.compile();
pipeMask = new PipelineState();
pipeMask.vertexShader = Reflect.field(kha.Shaders, "layer_merge_vert");
pipeMask.fragmentShader = Reflect.field(kha.Shaders, "mask_merge_frag");
+14
View File
@@ -210,6 +210,20 @@ class LayerSlot {
Context.ddirty = 3;
}
public function invertMask() {
if (Layers.pipeInvert8 == null) Layers.makePipe();
var inverted = Image.createRenderTarget(texpaint_mask.width, texpaint_mask.height, TextureFormat.L8);
inverted.g2.begin(false);
inverted.g2.pipeline = Layers.pipeInvert8;
inverted.g2.drawImage(texpaint_mask, 0, 0);
inverted.g2.pipeline = null;
inverted.g2.end();
texpaint_mask.unload();
texpaint_mask = RenderPath.active.renderTargets.get("texpaint_mask" + id).image = inverted;
Context.layerPreviewDirty = true;
Context.ddirty = 3;
}
public function deleteMask() {
if (texpaint_mask == null) return;
+10 -1
View File
@@ -227,6 +227,15 @@ class TabLayers {
}
iron.App.notifyOnRender(clear);
}
if (ui.button(tr("Invert"), Left)) {
function invert(g: kha.graphics4.Graphics) {
g.end();
l.invertMask();
g.begin();
iron.App.removeRender(invert);
}
iron.App.notifyOnRender(invert);
}
if (ui.button(tr("Apply"), Left)) {
function makeApply(g: kha.graphics4.Graphics) {
g.end();
@@ -239,7 +248,7 @@ class TabLayers {
}
iron.App.notifyOnRender(makeApply);
}
}, 5);
}, 6);
}
if (state == State.Started) {
Context.setLayer(l, true);