Decal mask cleanup

This commit is contained in:
luboslenco
2020-03-10 14:09:26 +01:00
parent 3b90cfcd5a
commit bb9a2182a7
6 changed files with 6 additions and 50 deletions
+1 -4
View File
@@ -104,10 +104,7 @@ class Context {
var current = @:privateAccess kha.graphics4.Graphics2.current;
if (current != null) current.end();
if (tool == ToolDecal) {
RenderUtil.makeDecalMaskPreview();
}
else if (tool == ToolText) {
if (tool == ToolText) {
RenderUtil.makeTextPreview();
}
+1 -5
View File
@@ -76,11 +76,7 @@ class MakeMeshPreview {
var decal = UITrait.inst.decalPreview;
if (decal) {
if (Context.tool == ToolDecal) {
frag.add_uniform('sampler2D texdecalmask', '_texdecalmask');
frag.write('opacity *= textureLod(texdecalmask, texCoord, 0.0).r;');
}
else if (Context.tool == ToolText) {
if (Context.tool == ToolText) {
frag.add_uniform('sampler2D textexttool', '_textexttool');
frag.write('opacity *= textureLod(textexttool, texCoord, 0.0).r;');
}
+4 -4
View File
@@ -212,16 +212,16 @@ class MakePaint {
if (subs != "0") MaterialBuilder.subsUsed = true;
}
if (Context.tool == ToolDecal) {
frag.add_uniform('sampler2D texdecalmask', '_texdecalmask');
frag.write('opacity *= textureLod(texdecalmask, texCoord, 0.0).r;');
if (UITrait.inst.brushMaskImage != null && Context.tool == ToolDecal) {
frag.add_uniform('sampler2D texbrushmask', '_texbrushmask');
frag.write('opacity *= textureLod(texbrushmask, texCoord, 0.0).r;');
}
else if (Context.tool == ToolText) {
frag.add_uniform('sampler2D textexttool', '_textexttool');
frag.write('opacity *= textureLod(textexttool, texCoord, 0.0).r;');
}
if (UITrait.inst.brushMaskImage != null && Context.tool == ToolBrush) {
if (UITrait.inst.brushMaskImage != null && (Context.tool == ToolBrush || Context.tool == ToolEraser)) {
frag.add_uniform('sampler2D texbrushmask', '_texbrushmask');
frag.write('vec2 binp_mask = inp.xy * 2.0 - 1.0;');
frag.write('binp_mask.x *= aspectRatio;');
-3
View File
@@ -302,9 +302,6 @@ class Uniforms {
if (link == "_textexttool") { // Opacity map for text
return UITrait.inst.textToolImage;
}
if (link == "_texdecalmask") { // Opacity map for decal
return UITrait.inst.decalMaskImage;
}
if (link == "_texbrushmask") {
return UITrait.inst.brushMaskImage;
}
-12
View File
@@ -144,8 +144,6 @@ class UITrait {
public var textToolImage: Image = null;
public var textToolText = "Text";
public var textToolHandle = new Handle();
public var decalMaskImage: Image = null;
public var decalMaskHandle = new Handle();
public var particleMaterial: MaterialData = null;
public var layerFilter = 0;
@@ -1107,7 +1105,6 @@ class UITrait {
if (brushScaleHandle.changed) {
if (Context.tool == ToolDecal || Context.tool == ToolText) {
ui.g.end();
RenderUtil.makeDecalMaskPreview();
RenderUtil.makeDecalPreview();
ui.g.begin(false);
}
@@ -1141,15 +1138,6 @@ class UITrait {
MaterialParser.parsePaintMaterial();
}
}
if (Context.tool == ToolDecal) {
ui.combo(decalMaskHandle, ["Rectangle", "Circle", "Triangle"], "Mask");
if (decalMaskHandle.changed) {
ui.g.end();
RenderUtil.makeDecalMaskPreview();
RenderUtil.makeDecalPreview();
ui.g.begin(false);
}
}
if (Context.tool == ToolText) {
ui.combo(textToolHandle, ImportFont.fontList, "Font");
var h = Id.handle();
-22
View File
@@ -179,26 +179,4 @@ class RenderUtil {
if (fontName == "default.ttf") return UITrait.inst.ui.ops.font;
return ImportFont.fontMap.get(fontName);
}
public static function makeDecalMaskPreview() {
var texw = 1024;
var off = 12;
if (UITrait.inst.decalMaskImage == null) {
UITrait.inst.decalMaskImage = Image.createRenderTarget(texw, texw, TextureFormat.L8);
}
var g2 = UITrait.inst.decalMaskImage.g2;
g2.begin(true, 0xff000000);
g2.color = 0xffffffff;
var mask = UITrait.inst.decalMaskHandle.position;
if (mask == 0) {
g2.fillRect(off, off, texw - off, texw - off);
}
else if (mask == 1) {
kha.graphics2.GraphicsExtension.fillCircle(g2, texw / 2, texw / 2, texw / 2 - off);
}
else if (mask == 2) {
g2.fillTriangle(texw / 2, off, off, texw - off, texw - off, texw - off);
}
g2.end();
}
}