From 24681f6e9817d19687fe021a30f897f1a25c332d Mon Sep 17 00:00:00 2001 From: luboslenco Date: Tue, 12 Mar 2019 17:54:08 +0100 Subject: [PATCH] Reducing gpu mem usage, unstable --- Sources/arm/Exporter.hx | 56 ++++----- Sources/arm/Importer.hx | 2 - Sources/arm/LayerSlot.hx | 52 ++++----- Sources/arm/Layers.hx | 34 ------ Sources/arm/MaterialBuilder.hx | 113 ++++++++----------- Sources/arm/Project.hx | 12 +- Sources/arm/ProjectFormat.hx | 1 - Sources/arm/Uniforms.hx | 4 - Sources/arm/renderpath/RenderPathDeferred.hx | 38 +++---- Sources/arm/ui/UITrait.hx | 5 +- 10 files changed, 115 insertions(+), 202 deletions(-) diff --git a/Sources/arm/Exporter.hx b/Sources/arm/Exporter.hx index bee72a67..e8439fef 100644 --- a/Sources/arm/Exporter.hx +++ b/Sources/arm/Exporter.hx @@ -169,34 +169,34 @@ class Exporter { #end } - if (UITrait.inst.isHeight && selectedLayer.texpaint_opt != null) { - pixels = selectedLayer.texpaint_opt.getPixels(); - if (UITrait.inst.isHeightSpace == 1) { - for (i in 0...Std.int(pixels.length / 4)) { - pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255)); - pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255)); - pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255)); - // pixels.set(i * 4 + 3, 255); - } - } - bo = new haxe.io.BytesOutput(); - if (formatType == 0) { - var jpgdata:iron.format.jpg.Data.Data = { - width: textureSize, - height: textureSize, - quality: formatQuality, - pixels: pixels - }; - var jpgwriter = new iron.format.jpg.Writer(bo); - jpgwriter.write(jpgdata, 1); - } - else { - var pngwriter = new iron.format.png.Writer(bo); - pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels)); - } - #if kha_krom - Krom.fileSaveBytes(path + "/" + f + "_height" + ext, bo.getBytes().getData()); - #end + if (UITrait.inst.isHeight) { + // pixels = selectedLayer.texpaint_opt.getPixels(); + // if (UITrait.inst.isHeightSpace == 1) { + // for (i in 0...Std.int(pixels.length / 4)) { + // pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255)); + // pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255)); + // pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255)); + // // pixels.set(i * 4 + 3, 255); + // } + // } + // bo = new haxe.io.BytesOutput(); + // if (formatType == 0) { + // var jpgdata:iron.format.jpg.Data.Data = { + // width: textureSize, + // height: textureSize, + // quality: formatQuality, + // pixels: pixels + // }; + // var jpgwriter = new iron.format.jpg.Writer(bo); + // jpgwriter.write(jpgdata, 1); + // } + // else { + // var pngwriter = new iron.format.png.Writer(bo); + // pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels)); + // } + // #if kha_krom + // Krom.fileSaveBytes(path + "/" + f + "_height" + ext, bo.getBytes().getData()); + // #end } // if (UITrait.inst.isOpac) Krom.fileSaveBytes(path + "/tex_opac" + ext, bo.getBytes().getData()); diff --git a/Sources/arm/Importer.hx b/Sources/arm/Importer.hx index 9856f427..a68bec98 100644 --- a/Sources/arm/Importer.hx +++ b/Sources/arm/Importer.hx @@ -686,7 +686,6 @@ class Importer { UINodes.inst.parseMeshMaterial(); UINodes.inst.parsePaintMaterial(); iron.App.notifyOnRender(Layers.initLayers); - if (UITrait.inst.paintHeight) iron.App.notifyOnRender(Layers.initHeightLayer); UITrait.inst.paintObject.setData(md); UITrait.inst.paintObject.name = mesh.name; @@ -742,7 +741,6 @@ class Importer { object.skip_context = "paint"; // iron.App.notifyOnRender(Layers.initLayers); - // if (UITrait.inst.paintHeight) iron.App.notifyOnRender(Layers.initHeightLayer); // object.transform.scale.setFrom(UITrait.inst.paintObject.transform.scale); // object.transform.buildMatrix(); diff --git a/Sources/arm/LayerSlot.hx b/Sources/arm/LayerSlot.hx index 2cc854f0..4f9c5484 100644 --- a/Sources/arm/LayerSlot.hx +++ b/Sources/arm/LayerSlot.hx @@ -12,13 +12,35 @@ class LayerSlot { public var texpaint:kha.Image; public var texpaint_nor:kha.Image; public var texpaint_pack:kha.Image; - public var texpaint_opt:kha.Image; // For undo layer public var targetLayer:LayerSlot = null; public var targetObject:iron.object.MeshObject = null; + static var first = true; + public function new(ext = "") { + + if (first) { + first = false; + { + var t = new RenderTargetRaw(); + t.name = "texpaint_mask0"; + t.width = Config.getTextureRes(); + t.height = Config.getTextureRes(); + t.format = 'R8'; + RenderPath.active.createRenderTarget(t); + } + { + var t = new RenderTargetRaw(); + t.name = "texpaint_mask1"; + t.width = Config.getTextureRes(); + t.height = Config.getTextureRes(); + t.format = 'R8'; + RenderPath.active.createRenderTarget(t); + } + } + if (ext == "") { id = counter++; ext = id + ""; @@ -50,21 +72,6 @@ class LayerSlot { t.format = 'RGBA32'; texpaint_pack = RenderPath.active.createRenderTarget(t).image; } - - if (UITrait.inst.paintHeight) make_texpaint_opt(); - } - - public function make_texpaint_opt() { - if (texpaint_opt != null) return; - - { - var t = new RenderTargetRaw(); - t.name = "texpaint_opt" + ext; - t.width = Config.getTextureRes(); - t.height = Config.getTextureRes(); - t.format = 'RGBA32'; - texpaint_opt = RenderPath.active.createRenderTarget(t).image; - } } public function unload() { @@ -80,11 +87,6 @@ class LayerSlot { RenderPath.active.renderTargets.remove("texpaint" + ext); RenderPath.active.renderTargets.remove("texpaint_nor" + ext); RenderPath.active.renderTargets.remove("texpaint_pack" + ext); - - if (texpaint_opt != null) { - texpaint_opt.unload(); - RenderPath.active.renderTargets.remove("texpaint_opt" + ext); - } } public function swap(other:LayerSlot) { @@ -107,14 +109,6 @@ class LayerSlot { other.texpaint = tp; other.texpaint_nor = tp_nor; other.texpaint_pack = tp_pack; - - if (texpaint_opt != null) { - var tp_opt = texpaint_opt; - RenderPath.active.renderTargets.get("texpaint_opt" + ext).image = other.texpaint_opt; - RenderPath.active.renderTargets.get("texpaint_opt" + other.ext).image = texpaint_opt; - texpaint_opt = other.texpaint_opt; - other.texpaint_opt = tp_opt; - } // var tp_rt = rt; // rt = other.rt; diff --git a/Sources/arm/Layers.hx b/Sources/arm/Layers.hx index 8c4013f1..d9f0e786 100644 --- a/Sources/arm/Layers.hx +++ b/Sources/arm/Layers.hx @@ -27,18 +27,6 @@ class Layers { UITrait.inst.ddirty = 3; } - public static function initHeightLayer(g:kha.graphics4.Graphics) { - g.end(); - - var layers = UITrait.inst.layers; - layers[0].texpaint_opt.g4.begin(); - layers[0].texpaint_opt.g4.clear(kha.Color.fromFloats(1.0, 0.0, 0.0, 0.0)); // Opac, emis, height - layers[0].texpaint_opt.g4.end(); - - g.begin(); - iron.App.removeRender(initHeightLayer); - } - public static function clearLastLayer(g:kha.graphics4.Graphics) { g.end(); @@ -56,12 +44,6 @@ class Layers { layers[i].texpaint_pack.g4.clear(kha.Color.fromFloats(1.0, 0.0, 0.0, 0.0)); // Occ, rough, met layers[i].texpaint_pack.g4.end(); - if (layers[i].texpaint_opt != null) { - layers[i].texpaint_opt.g4.begin(); - layers[i].texpaint_opt.g4.clear(kha.Color.fromFloats(0.0, 0.0, 0.0, 0.0)); // Opac, emis, height - layers[i].texpaint_opt.g4.end(); - } - g.begin(); iron.App.removeRender(clearLastLayer); } @@ -73,12 +55,10 @@ class Layers { var texpaint = l.texpaint; var texpaint_nor = l.texpaint_nor; var texpaint_pack = l.texpaint_pack; - var texpaint_opt = l.texpaint_opt; l.texpaint = kha.Image.createRenderTarget(res, res, kha.graphics4.TextureFormat.RGBA32, kha.graphics4.DepthStencilFormat.Depth16); l.texpaint_nor = kha.Image.createRenderTarget(res, res, kha.graphics4.TextureFormat.RGBA32, kha.graphics4.DepthStencilFormat.NoDepthAndStencil); l.texpaint_pack = kha.Image.createRenderTarget(res, res, kha.graphics4.TextureFormat.RGBA32, kha.graphics4.DepthStencilFormat.NoDepthAndStencil); - if (l.texpaint_opt != null) l.texpaint_opt = kha.Image.createRenderTarget(res, res, kha.graphics4.TextureFormat.RGBA32, kha.graphics4.DepthStencilFormat.NoDepthAndStencil); l.texpaint.g2.begin(false); l.texpaint.g2.drawScaledImage(texpaint, 0, 0, res, res); @@ -92,17 +72,9 @@ class Layers { l.texpaint_pack.g2.drawScaledImage(texpaint_pack, 0, 0, res, res); l.texpaint_pack.g2.end(); - if (texpaint_opt != null) { - l.texpaint_opt.g2.begin(false); - l.texpaint_opt.g2.drawScaledImage(texpaint_opt, 0, 0, res, res); - l.texpaint_opt.g2.end(); - rts.get("texpaint_opt" + l.ext).image = l.texpaint_opt; - } - texpaint.unload(); texpaint_nor.unload(); texpaint_pack.unload(); - if (texpaint_opt != null) texpaint_opt.unload(); rts.get("texpaint" + l.ext).image = l.texpaint; rts.get("texpaint_nor" + l.ext).image = l.texpaint_nor; @@ -171,12 +143,6 @@ class Layers { l0.texpaint_pack.g2.drawImage(l1.texpaint_pack, 0, 0); l0.texpaint_pack.g2.end(); - if (l0.texpaint_opt != null) { - l0.texpaint_opt.g2.begin(false); - l0.texpaint_opt.g2.drawImage(l1.texpaint_opt, 0, 0); - l0.texpaint_opt.g2.end(); - } - g.begin(); deleteSelectedLayer(); diff --git a/Sources/arm/MaterialBuilder.hx b/Sources/arm/MaterialBuilder.hx index 88e3cbe5..448fdfcc 100644 --- a/Sources/arm/MaterialBuilder.hx +++ b/Sources/arm/MaterialBuilder.hx @@ -23,12 +23,12 @@ class MaterialBuilder { compare_mode: 'always', // TODO: align texcoords winding order // cull_mode: 'counter_clockwise', cull_mode: 'none', - blend_source: layered ? 'blend_one' : 'source_alpha', - blend_destination: layered ? 'blend_zero' : 'inverse_source_alpha', - blend_operation: 'add', - alpha_blend_source: 'blend_one', - alpha_blend_destination: eraser ? 'blend_zero' : 'blend_one', - alpha_blend_operation: 'add', + // blend_source: layered ? 'blend_one' : 'source_alpha', + // blend_destination: layered ? 'blend_zero' : 'inverse_source_alpha', + // blend_operation: 'add', + // alpha_blend_source: 'blend_one', + // alpha_blend_destination: eraser ? 'blend_zero' : 'blend_one', + // alpha_blend_operation: 'add', vertex_elements: [{name: "pos", data: 'short4norm'},{name: "nor", data: 'short2norm'},{name: "tex", data: 'short2norm'}] }); con_paint.data.color_writes_red = [true, true, true, true]; @@ -112,7 +112,7 @@ class MaterialBuilder { frag.add_uniform('sampler2D paintdb'); - var numTex = UITrait.inst.paintHeight ? 4 : 3; + var numTex = 4; frag.add_out('vec4 fragColor[$numTex]'); frag.add_uniform('float brushRadius', '_brushRadius'); @@ -340,12 +340,25 @@ class MaterialBuilder { frag.write('str = clamp(str, 0.0, 1.0);'); } - frag.write(' fragColor[0] = vec4(basecol, str);'); - frag.write(' fragColor[1] = vec4(nortan, str);'); - frag.write(' fragColor[2] = vec4(occlusion, roughness, metallic, str);'); - if (UITrait.inst.paintHeight) { - frag.write(' fragColor[3] = vec4(1.0, 0.0, height, str);'); - } + // Manual blending to preserve memory + frag.wvpposition = true; + frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); + frag.add_uniform('sampler2D texpaint_nor_undo', '_texpaint_nor_undo'); + frag.add_uniform('sampler2D texpaint_pack_undo', '_texpaint_pack_undo'); + frag.write('vec2 sample_tc = vec2(wvpposition.x, wvpposition.y) * 0.5 + 0.5;'); + frag.write('sample_tc.y = 1.0 - sample_tc.y;'); + frag.write('vec4 sample_undo = textureLod(texpaint_undo, sample_tc, 0);'); + frag.write('vec4 sample_nor_undo = textureLod(texpaint_nor_undo, sample_tc, 0);'); + frag.write('vec4 sample_pack_undo = textureLod(texpaint_pack_undo, sample_tc, 0);'); + + frag.add_uniform('sampler2D paintmask'); + frag.write('float sample_mask = textureLod(paintmask, sample_tc, 0).r;'); + frag.write('str = max(str, sample_mask);'); + + frag.write(' fragColor[0] = vec4(basecol * str + sample_undo.rgb * (1.0 - str), 1.0);'); + frag.write(' fragColor[1] = vec4(nortan * str + sample_nor_undo.rgb * (1.0 - str), 1.0);'); + frag.write(' fragColor[2] = vec4(occlusion * str + sample_pack_undo.r * (1.0 - str), roughness * str + sample_pack_undo.g * (1.0 - str), metallic * str + sample_pack_undo.b * (1.0 - str), 1.0);'); + frag.write(' fragColor[3].r = str;'); if (!UITrait.inst.paintBase) frag.write('fragColor[0].a = 0.0;'); if (!UITrait.inst.paintNor) frag.write('fragColor[1].a = 0.0;'); @@ -486,29 +499,8 @@ class MaterialBuilder { frag.ins = vert.outs; - // if (shadowmap) { - // if (UITrait.inst.paintHeight) { - // con_depth.add_elem('nor', 'short2norm'); - // vert.wposition = true; - // vert.n = true; - // vert.add_uniform('sampler2D texpaint_opt'); - // vert.write('vec4 opt = textureLod(texpaint_opt, tex, 0);'); - // vert.write('float height = opt.b;'); - // var displaceStrength = UITrait.inst.displaceStrength * 0.1; - // vert.write('wposition += wnormal * height * $displaceStrength;'); - - // vert.add_uniform('mat4 LVP', '_lightViewProjectionMatrix'); - // vert.write('gl_Position = LVP * vec4(wposition, 1.0);'); - // } - // else { - // vert.add_uniform('mat4 LWVP', '_lightWorldViewProjectionMatrix'); - // vert.write('gl_Position = mul(vec4(pos.xyz, 1.0), LWVP);'); - // } - // } - // else { - vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix'); - vert.write('gl_Position = mul(vec4(pos.xyz, 1.0), WVP);'); - // } + vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix'); + vert.write('gl_Position = mul(vec4(pos.xyz, 1.0), WVP);'); var parse_opacity = shadowmap; // arm_discard if (parse_opacity) { @@ -562,12 +554,12 @@ class MaterialBuilder { // TODO: can cause TAA issues if (UITrait.inst.paintHeight) { #if (!kha_direct3d11) // TODO: unable to bind texpaint_opt to both vs and fs in d3d11 - vert.add_uniform('sampler2D texpaint_opt'); - vert.write('vec4 opt = textureLod(texpaint_opt, tex, 0);'); - vert.write('float height = opt.b;'); - var displaceStrength = UITrait.inst.displaceStrength * 0.1; - vert.n = true; - vert.write('wposition += wnormal * height * $displaceStrength;'); + // vert.add_uniform('sampler2D texpaint_opt'); + // vert.write('vec4 opt = textureLod(texpaint_opt, tex, 0);'); + // vert.write('float height = opt.b;'); + // var displaceStrength = UITrait.inst.displaceStrength * 0.1; + // vert.n = true; + // vert.write('wposition += wnormal * height * $displaceStrength;'); #end } // @@ -626,18 +618,18 @@ class MaterialBuilder { // Height if (UITrait.inst.paintHeight) { - frag.add_uniform('sampler2D texpaint_opt'); - frag.write('vec4 vech;'); - frag.write('vech.x = textureOffset(texpaint_opt, texCoord, ivec2(-1, 0)).b;'); - frag.write('vech.y = textureOffset(texpaint_opt, texCoord, ivec2(1, 0)).b;'); - frag.write('vech.z = textureOffset(texpaint_opt, texCoord, ivec2(0, -1)).b;'); - frag.write('vech.w = textureOffset(texpaint_opt, texCoord, ivec2(0, 1)).b;'); - // Displace normal strength - frag.write('vech *= 15 * 7; float h1 = vech.x - vech.y; float h2 = vech.z - vech.w;'); - frag.write('vec3 va = normalize(vec3(2.0, 0.0, h1));'); - frag.write('vec3 vb = normalize(vec3(0.0, 2.0, h2));'); - frag.write('vec3 vc = normalize(vec3(h1, h2, 2.0));'); - frag.write('n = normalize(mul(n, mat3(va, vb, vc)));'); + // frag.add_uniform('sampler2D texpaint_opt'); + // frag.write('vec4 vech;'); + // frag.write('vech.x = textureOffset(texpaint_opt, texCoord, ivec2(-1, 0)).b;'); + // frag.write('vech.y = textureOffset(texpaint_opt, texCoord, ivec2(1, 0)).b;'); + // frag.write('vech.z = textureOffset(texpaint_opt, texCoord, ivec2(0, -1)).b;'); + // frag.write('vech.w = textureOffset(texpaint_opt, texCoord, ivec2(0, 1)).b;'); + // // Displace normal strength + // frag.write('vech *= 15 * 7; float h1 = vech.x - vech.y; float h2 = vech.z - vech.w;'); + // frag.write('vec3 va = normalize(vec3(2.0, 0.0, h1));'); + // frag.write('vec3 vb = normalize(vec3(0.0, 2.0, h2));'); + // frag.write('vec3 vc = normalize(vec3(h1, h2, 2.0));'); + // frag.write('n = normalize(mul(n, mat3(va, vb, vc)));'); } // @@ -739,18 +731,7 @@ class MaterialBuilder { frag.write('vec2 posa = (wvpposition.xy / wvpposition.w) * 0.5 + 0.5;'); frag.write('vec2 posb = (prevwvpposition.xy / prevwvpposition.w) * 0.5 + 0.5;'); - - var writeTC = (UITrait.inst.brushType == 2 && UITrait.inst.fillTypeHandle.position == 1) || // Face fill - UITrait.inst.brushType == 4 || // Colorid pick - UITrait.inst.brushType == 7 || // Clone - UITrait.inst.brushType == 8; // Blur - - if (writeTC) { - frag.write('fragColor[2] = vec4(posa - posb, texCoord.xy);'); - } - else { - frag.write('fragColor[2] = vec4(posa - posb, 0.0, 0.0);'); - } + frag.write('fragColor[2] = vec4(posa - posb, texCoord.xy);'); Cycles.finalize(con_mesh); con_mesh.data.shader_from_source = true; diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index 699ad9ba..467530fd 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -47,8 +47,7 @@ class Project { res: l.texpaint.width, texpaint: l.texpaint.getPixels(), texpaint_nor: l.texpaint_nor.getPixels(), - texpaint_pack: l.texpaint_pack.getPixels(), - texpaint_opt: l.texpaint_opt != null ? l.texpaint_opt.getPixels() : null, + texpaint_pack: l.texpaint_pack.getPixels() }); } @@ -141,7 +140,6 @@ class Project { UITrait.inst.layers = [new LayerSlot()]; UITrait.inst.selectedLayer = UITrait.inst.layers[0]; iron.App.notifyOnRender(Layers.initLayers); - if (UITrait.inst.paintHeight) iron.App.notifyOnRender(Layers.initHeightLayer); } UINodes.inst.updateCanvasMap(); @@ -252,14 +250,6 @@ class Project { l.texpaint_pack.g2.drawImage(texpaint_pack, 0, 0); l.texpaint_pack.g2.end(); // texpaint_pack.unload(); - - if (ld.texpaint_opt != null) { - var texpaint_opt = kha.Image.fromBytes(ld.texpaint_opt, ld.res, ld.res); - l.texpaint_opt.g2.begin(false); - l.texpaint_opt.g2.drawImage(texpaint_opt, 0, 0); - l.texpaint_opt.g2.end(); - // texpaint_opt.unload(); - } } UITrait.inst.selectedLayer = UITrait.inst.layers[0]; diff --git a/Sources/arm/ProjectFormat.hx b/Sources/arm/ProjectFormat.hx index 70db53c0..ae069fba 100644 --- a/Sources/arm/ProjectFormat.hx +++ b/Sources/arm/ProjectFormat.hx @@ -17,7 +17,6 @@ typedef TLayerData = { public var texpaint:haxe.io.Bytes; public var texpaint_nor:haxe.io.Bytes; public var texpaint_pack:haxe.io.Bytes; - public var texpaint_opt:haxe.io.Bytes; } typedef TAPConfig = { diff --git a/Sources/arm/Uniforms.hx b/Sources/arm/Uniforms.hx index 9eb054ab..e408a27e 100644 --- a/Sources/arm/Uniforms.hx +++ b/Sources/arm/Uniforms.hx @@ -128,10 +128,6 @@ class Uniforms { var i = UITrait.inst.undoI - 1 < 0 ? UITrait.inst.C.undo_steps - 1 : UITrait.inst.undoI - 1; return iron.RenderPath.active.renderTargets.get("texpaint_pack_undo" + i).image; } - else if (link == "_texpaint_opt_undo") { - var i = UITrait.inst.undoI - 1 < 0 ? UITrait.inst.C.undo_steps - 1 : UITrait.inst.undoI - 1; - return iron.RenderPath.active.renderTargets.get("texpaint_opt_undo" + i).image; - } return null; } } diff --git a/Sources/arm/renderpath/RenderPathDeferred.hx b/Sources/arm/renderpath/RenderPathDeferred.hx index 85939e09..0e375c40 100644 --- a/Sources/arm/renderpath/RenderPathDeferred.hx +++ b/Sources/arm/renderpath/RenderPathDeferred.hx @@ -16,6 +16,7 @@ class RenderPathDeferred { #end static var initVoxels = true; // Bake AO static var taaFrame = 0; + static var maskFrame = 0; public static function init(_path:RenderPath) { @@ -162,23 +163,11 @@ class RenderPathDeferred { if (UITrait.inst.pushUndo && UITrait.inst.C.undo_steps > 0) { var i = UITrait.inst.undoI; - if (UITrait.inst.paintHeight) { - path.setTarget("texpaint_undo" + i, ["texpaint_nor_undo" + i, "texpaint_pack_undo" + i, "texpaint_opt_undo" + i]); - } - else { - path.setTarget("texpaint_undo" + i, ["texpaint_nor_undo" + i, "texpaint_pack_undo" + i]); - } - + path.setTarget("texpaint_undo" + i, ["texpaint_nor_undo" + i, "texpaint_pack_undo" + i]); path.bindTarget("texpaint" + tid, "tex0"); path.bindTarget("texpaint_nor" + tid, "tex1"); path.bindTarget("texpaint_pack" + tid, "tex2"); - if (UITrait.inst.paintHeight) { - path.bindTarget("texpaint_opt" + tid, "tex3"); - path.drawShader("shader_datas/copy_mrt4_pass/copy_mrt4_pass"); - } - else { - path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass"); - } + path.drawShader("shader_datas/copy_mrt3_pass/copy_mrt3_pass"); UITrait.inst.undoLayers[UITrait.inst.undoI].targetObject = UITrait.inst.paintObject; UITrait.inst.undoLayers[UITrait.inst.undoI].targetLayer = UITrait.inst.selectedLayer; UITrait.inst.undoI = (UITrait.inst.undoI + 1) % UITrait.inst.C.undo_steps; @@ -231,13 +220,12 @@ class RenderPathDeferred { #end // - if (UITrait.inst.paintHeight) { - path.setTarget("texpaint" + tid, ["texpaint_nor" + tid, "texpaint_pack" + tid, "texpaint_opt" + tid]); - } - else { - path.setTarget("texpaint" + tid, ["texpaint_nor" + tid, "texpaint_pack" + tid]); - } + var maskA = maskFrame % 2 == 0 ? "texpaint_mask0" : "texpaint_mask1"; + var maskB = maskFrame % 2 == 0 ? "texpaint_mask1" : "texpaint_mask0"; + maskFrame++; + path.setTarget("texpaint" + tid, ["texpaint_nor" + tid, "texpaint_pack" + tid, maskA]); path.bindTarget("_paintdb", "paintdb"); + path.bindTarget(maskB, "paintmask"); if (UITrait.inst.brushType == 3) { // Bake AO path.bindTarget("voxels", "voxels"); } @@ -267,6 +255,12 @@ class RenderPathDeferred { } // + if (UITrait.inst.maskDirty) { + UITrait.inst.maskDirty = false; + path.setTarget("texpaint_mask0", ["texpaint_mask1"]); + path.clearTarget(0x00000000); + } + path.setTarget("gbuffer0"); // Only clear gbuffer0 path.clearTarget(null, 1.0); #if rp_gbuffer2 @@ -286,15 +280,11 @@ class RenderPathDeferred { path.bindTarget("texpaint" + tid, "texpaint"); path.bindTarget("texpaint_nor" + tid, "texpaint_nor"); path.bindTarget("texpaint_pack" + tid, "texpaint_pack"); - if (UITrait.inst.paintHeight) { - path.bindTarget("texpaint_opt" + tid, "texpaint_opt"); - } for (i in 1...UITrait.inst.layers.length) { tid = UITrait.inst.layers[i].id; path.bindTarget("texpaint" + tid, "texpaint" + tid); path.bindTarget("texpaint_nor" + tid, "texpaint_nor" + tid); path.bindTarget("texpaint_pack" + tid, "texpaint_pack" + tid); - if (UITrait.inst.paintHeight) path.bindTarget("texpaint_opt" + tid, "texpaint_opt" + tid); } // diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index 26db3427..14b92c34 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -59,6 +59,7 @@ class UITrait extends iron.Trait { public var ddirty = 0; public var pdirty = 0; public var rdirty = 0; + public var maskDirty = true; public var windowW = 280; // Panel width public var toolbarw = 54; @@ -684,6 +685,7 @@ class UITrait extends iron.Trait { else if (brushTime > 0) { brushTime = 0; ddirty = 3; + maskDirty = true; } var undoPressed = kb.down("control") && !kb.down("shift") && kb.started("z"); @@ -1658,9 +1660,6 @@ class UITrait extends iron.Trait { var heightHandle = Id.handle({selected: paintHeight}); paintHeight = ui.check(heightHandle, "Height"); if (heightHandle.changed) { - for (l in layers) l.make_texpaint_opt(); - for (l in undoLayers) l.make_texpaint_opt(); - iron.App.notifyOnRender(Layers.initHeightLayer); UINodes.inst.updateCanvasMap(); UINodes.inst.parsePaintMaterial(); }