Add option to view all visible layers in 2d view

This commit is contained in:
luboslenco
2021-02-12 12:47:43 +01:00
parent 08932d8ed5
commit ca0fac6091
5 changed files with 77 additions and 47 deletions
@@ -60,14 +60,12 @@ class RenderPathRaytrace {
var bnoise_sobol = Scene.active.embedded.get("bnoise_sobol.k");
var bnoise_scramble = Scene.active.embedded.get("bnoise_scramble.k");
var bnoise_rank = Scene.active.embedded.get("bnoise_rank.k");
Layers.makeExportImg();
Layers.makeTempImg();
flattenLayers();
Layers.flatten(true);
Krom.raytraceSetTextures(Layers.expa.renderTarget_, Layers.expb.renderTarget_, Layers.expc.renderTarget_, savedEnvmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_);
}
if (Context.pdirty > 0 || dirty > 0) {
flattenLayers();
Layers.flatten(true);
}
var cam = Scene.active.camera;
@@ -113,49 +111,6 @@ class RenderPathRaytrace {
// Context.ddirty = 1; // _RENDER
}
static function flattenLayers() {
var l = Project.layers[0];
path.setTarget("expa", ["expb", "expc"]);
path.bindTarget("texpaint" + l.id, "tex0");
path.bindTarget("texpaint_nor" + l.id, "tex1");
path.bindTarget("texpaint_pack" + l.id, "tex2");
path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass");
var l0 = { texpaint: Layers.expa, texpaint_nor: Layers.expb, texpaint_pack: Layers.expc, texpaint_mask: l.texpaint_mask };
if (l0.texpaint_mask != null) {
Layers.applyMask(untyped l0);
}
if (Project.layers.length > 1) {
for (i in 1...Project.layers.length) {
Layers.mergeLayer(untyped l0, Project.layers[i], true);
}
}
// Merge height map into normal map
if (MakeMaterial.heightUsed) {
Layers.imga.g2.begin(false);
Layers.imga.g2.pipeline = Layers.pipeCopy;
Layers.imga.g2.drawImage(l0.texpaint_nor, 0, 0);
Layers.imga.g2.pipeline = null;
Layers.imga.g2.end();
var empty = RenderPath.active.renderTargets.get("empty_white").image;
l0.texpaint_nor.g4.begin();
l0.texpaint_nor.g4.setPipeline(Layers.pipeMerge);
l0.texpaint_nor.g4.setTexture(Layers.tex0, Layers.imga);
l0.texpaint_nor.g4.setTexture(Layers.tex1, l0.texpaint_pack);
l0.texpaint_nor.g4.setTexture(Layers.texmask, empty);
l0.texpaint_nor.g4.setTexture(Layers.texa, empty);
l0.texpaint_nor.g4.setFloat(Layers.opac, 1.0);
l0.texpaint_nor.g4.setInt(Layers.blending, -4);
l0.texpaint_nor.g4.setVertexBuffer(iron.data.ConstData.screenAlignedVB);
l0.texpaint_nor.g4.setIndexBuffer(iron.data.ConstData.screenAlignedIB);
l0.texpaint_nor.g4.drawIndexedVertices();
l0.texpaint_nor.g4.end();
}
}
public static function commandsBake() {
if (!ready || !isBake || lastBake != Context.bakeType) {
var rebuild = !(ready && isBake && lastBake != Context.bakeType);
+5
View File
@@ -205,6 +205,11 @@ package arm;
var View2DFont = 2;
}
@:enum abstract View2DLayerMode(Int) from Int to Int {
var View2DVisible = 0;
var View2DSelected = 1;
}
@:enum abstract BorderSide(Int) from Int to Int {
var SideLeft = 0;
var SideRight = 1;
+53
View File
@@ -427,6 +427,59 @@ class Layers {
}
}
public static function flatten(heightToNormal = false): TLayerData {
Layers.makeExportImg();
Layers.makeTempImg();
var path = RenderPath.active;
var l = Project.layers[0];
if (l.visible) {
path.setTarget("expa", ["expb", "expc"]);
path.bindTarget("texpaint" + l.id, "tex0");
path.bindTarget("texpaint_nor" + l.id, "tex1");
path.bindTarget("texpaint_pack" + l.id, "tex2");
path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass");
}
else {
Layers.expa.g2.begin(true, 0x00000000);
Layers.expa.g2.end();
}
var l0 = { texpaint: Layers.expa, texpaint_nor: Layers.expb, texpaint_pack: Layers.expc, texpaint_mask: l.visible ? l.texpaint_mask : null };
if (l0.texpaint_mask != null) {
Layers.applyMask(untyped l0);
}
for (i in 1...Project.layers.length) {
Layers.mergeLayer(untyped l0, Project.layers[i], true);
}
// Merge height map into normal map
if (heightToNormal && MakeMaterial.heightUsed) {
Layers.imga.g2.begin(false);
Layers.imga.g2.pipeline = Layers.pipeCopy;
Layers.imga.g2.drawImage(l0.texpaint_nor, 0, 0);
Layers.imga.g2.pipeline = null;
Layers.imga.g2.end();
var empty = path.renderTargets.get("empty_white").image;
l0.texpaint_nor.g4.begin();
l0.texpaint_nor.g4.setPipeline(Layers.pipeMerge);
l0.texpaint_nor.g4.setTexture(Layers.tex0, Layers.imga);
l0.texpaint_nor.g4.setTexture(Layers.tex1, l0.texpaint_pack);
l0.texpaint_nor.g4.setTexture(Layers.texmask, empty);
l0.texpaint_nor.g4.setTexture(Layers.texa, empty);
l0.texpaint_nor.g4.setFloat(Layers.opac, 1.0);
l0.texpaint_nor.g4.setInt(Layers.blending, -4);
l0.texpaint_nor.g4.setVertexBuffer(iron.data.ConstData.screenAlignedVB);
l0.texpaint_nor.g4.setIndexBuffer(iron.data.ConstData.screenAlignedIB);
l0.texpaint_nor.g4.drawIndexedVertices();
l0.texpaint_nor.g4.end();
}
return untyped l0;
}
public static function applyMask(l: LayerSlot) {
if (l.texpaint_mask == null) return;
+1
View File
@@ -145,6 +145,7 @@ class TabLayers {
if (ui.image(icons, col, null, r.x, r.y, r.w, r.h) == Released) {
l.visible = !l.visible;
UIView2D.inst.hwnd.redraws = 2;
MakeMaterial.parseMeshMaterial();
}
ui._x -= 2;
+16
View File
@@ -33,6 +33,7 @@ class UIView2D {
public var panY = 0.0;
public var panScale = 1.0;
var texType = TexBase;
var layerMode = View2DSelected;
var uvmapShow = false;
var tiledShow = false;
@@ -105,6 +106,14 @@ class UIView2D {
if (Config.raw.brush_live && RenderPathPaint.liveLayerDrawn > 0) {
layer = RenderPathPaint.liveLayer;
}
if (layerMode == View2DVisible) {
var current = @:privateAccess kha.graphics2.Graphics.current;
if (current != null) current.end();
layer = untyped Layers.flatten();
if (current != null) current.begin(false);
}
tex =
Context.layerIsMask ? layer.texpaint_mask :
texType == TexBase ? layer.texpaint :
@@ -222,6 +231,13 @@ class UIView2D {
ui._w = ew;
if (type == View2DLayer) {
layerMode = ui.combo(Id.handle({position: layerMode}), [
tr("Visible"),
tr("Selected"),
], tr("Layers"));
ui._x += ew + 3;
ui._y = 2;
if (!Context.layerIsMask) {
texType = ui.combo(Id.handle({position: texType}), [
tr("Base Color"),