Add 'to mask' button for color id tool

This commit is contained in:
luboslenco
2023-01-05 15:34:08 +01:00
parent c140073a97
commit 5bf3e5192f
3 changed files with 55 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
// Turn picked color id into mask
#version 330
uniform sampler2D texpaint_colorid; // 1x1 picked color
uniform sampler2D texcolorid;
in vec2 texCoord;
out vec4 FragColor;
void main() {
vec3 colorid_c1 = texelFetch(texpaint_colorid, ivec2(0, 0), 0).rgb;
vec3 colorid_c2 = textureLod(texcolorid, texCoord, 0).rgb;
if (colorid_c1 != colorid_c2) discard;
FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
+13
View File
@@ -35,6 +35,7 @@ class Layers {
public static var pipeInvert8: PipelineState;
public static var pipeApplyMask: PipelineState;
public static var pipeMergeMask: PipelineState;
public static var pipeColorIdToMask: PipelineState;
public static var tex0: TextureUnit;
public static var tex1: TextureUnit;
public static var texmask: TextureUnit;
@@ -45,6 +46,8 @@ class Layers {
public static var texaMask: TextureUnit;
public static var tex0MergeMask: TextureUnit;
public static var texaMergeMask: TextureUnit;
public static var texColorId: TextureUnit;
public static var texpaintColorId: TextureUnit;
public static var opacMergeMask: ConstantLocation;
public static var blendingMergeMask: ConstantLocation;
public static var tempImage: Image = null;
@@ -240,6 +243,16 @@ class Layers {
texaMergeMask = pipeMergeMask.getTextureUnit("texa");
opacMergeMask = pipeMergeMask.getConstantLocation("opac");
blendingMergeMask = pipeMergeMask.getConstantLocation("blending");
pipeColorIdToMask = new PipelineState();
pipeColorIdToMask.vertexShader = kha.Shaders.getVertex("layer_merge.vert");
pipeColorIdToMask.fragmentShader = kha.Shaders.getFragment("mask_colorid.frag");
var vs = new VertexStructure();
vs.add("pos", VertexData.Float2);
pipeColorIdToMask.inputLayout = [vs];
pipeColorIdToMask.compile();
texpaintColorId = pipeColorIdToMask.getTextureUnit("texpaint_colorid");
texColorId = pipeColorIdToMask.getTextureUnit("texcolorid");
}
public static function makePipeCopyRGB() {
+27
View File
@@ -45,10 +45,12 @@ class UIHeader {
if (Context.colorIdPicked) {
ui.image(RenderPath.active.renderTargets.get("texpaint_colorid").image, 0xffffffff, 64);
}
ui.enabled = Context.colorIdPicked;
if (ui.button(tr("Clear"))) {
Context.colorIdPicked = false;
UIToolbar.inst.toolbarHandle.redraws = 1;
}
ui.enabled = true;
ui.text(tr("Color ID Map"));
if (Project.assetNames.length > 0) {
var cid = ui.combo(Context.colorIdHandle, App.enumTexts("TEX_IMAGE"), tr("Color ID"));
@@ -58,6 +60,7 @@ class UIHeader {
UIToolbar.inst.toolbarHandle.redraws = 1;
}
ui.image(Project.getImage(Project.assets[cid]));
if (ui.isHovered) ui.tooltipImage(Project.getImage(Project.assets[cid]), 256);
}
if (ui.button(tr("Import"))) {
UIFiles.show(Path.textureFormats.join(","), false, true, function(path: String) {
@@ -74,6 +77,30 @@ class UIHeader {
UIStatus.inst.statusHandle.redraws = 2;
});
}
ui.enabled = Context.colorIdPicked;
if (ui.button(tr("To Mask"))) {
if (Context.layer.isMask()) Context.setLayer(Context.layer.parent);
var m = Layers.newMask(false, Context.layer);
function _next() {
if (Layers.pipeMerge == null) Layers.makePipe();
if (iron.data.ConstData.screenAlignedVB == null) iron.data.ConstData.createScreenAlignedData();
m.texpaint.g4.begin();
m.texpaint.g4.setPipeline(Layers.pipeColorIdToMask);
m.texpaint.g4.setTexture(Layers.texpaintColorId, RenderPath.active.renderTargets.get("texpaint_colorid").image);
m.texpaint.g4.setTexture(Layers.texColorId, Project.getImage(Project.assets[Context.colorIdHandle.position]));
m.texpaint.g4.setVertexBuffer(iron.data.ConstData.screenAlignedVB);
m.texpaint.g4.setIndexBuffer(iron.data.ConstData.screenAlignedIB);
m.texpaint.g4.drawIndexedVertices();
m.texpaint.g4.end();
Context.colorIdPicked = false;
UIToolbar.inst.toolbarHandle.redraws = 1;
UIHeader.inst.headerHandle.redraws = 1;
Context.layerPreviewDirty = true;
}
App.notifyOnNextFrame(_next);
History.newWhiteMask();
}
ui.enabled = true;
}
else if (Context.tool == ToolPicker) {
var baseRPicked = Math.round(Context.pickedColor.base.R * 10) / 10;