From dfb9937b089c443f1f717515485ef7d080dd83a0 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Tue, 7 Dec 2021 14:43:16 +0100 Subject: [PATCH] Implement height and opacity picking --- Sources/arm/node/MakeColorIdPicker.hx | 5 ++--- Sources/arm/node/MakePaint.hx | 2 +- Sources/arm/render/RenderPathPaint.hx | 24 ++++++++++++++++++++---- Sources/arm/ui/UIHeader.hx | 4 ++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Sources/arm/node/MakeColorIdPicker.hx b/Sources/arm/node/MakeColorIdPicker.hx index f78d9c98..892ba976 100644 --- a/Sources/arm/node/MakeColorIdPicker.hx +++ b/Sources/arm/node/MakeColorIdPicker.hx @@ -39,15 +39,14 @@ class MakeColorIdPicker { frag.write('fragColor[1] = vec4(get_nor_from_depth(fragColor[0].rgb, vec2(inpLocal.x, 1.0 - inpLocal.y), invVP, vec2(1.0, 1.0) / gbufferSize, texturePass(gbufferD)), texCoordInp.y);'); } else { - frag.add_out('vec4 fragColor[3]'); + frag.add_out('vec4 fragColor[4]'); frag.add_uniform('sampler2D texpaint'); frag.add_uniform('sampler2D texpaint_nor'); frag.add_uniform('sampler2D texpaint_pack'); frag.write('fragColor[0] = textureLod(texpaint, texCoordInp, 0.0);'); frag.write('fragColor[1] = textureLod(texpaint_nor, texCoordInp, 0.0);'); frag.write('fragColor[2] = textureLod(texpaint_pack, texCoordInp, 0.0);'); - frag.write('fragColor[0].a = texCoordInp.x;'); - frag.write('fragColor[2].a = texCoordInp.y;'); + frag.write('fragColor[3].rg = texCoordInp.xy;'); } } } diff --git a/Sources/arm/node/MakePaint.hx b/Sources/arm/node/MakePaint.hx index febdbcf9..27e48475 100644 --- a/Sources/arm/node/MakePaint.hx +++ b/Sources/arm/node/MakePaint.hx @@ -25,7 +25,7 @@ class MakePaint { color_attachments: Context.tool == ToolColorId ? ["RGBA32"] : (Context.tool == ToolPicker && Context.pickPosNorTex) ? ["RGBA128", "RGBA128"] : - Context.tool == ToolPicker ? ["RGBA32", "RGBA32", "RGBA32"] : + Context.tool == ToolPicker ? ["RGBA32", "RGBA32", "RGBA32", "RGBA32"] : ["RGBA32", "RGBA32", "RGBA32", "R8"] }); diff --git a/Sources/arm/render/RenderPathPaint.hx b/Sources/arm/render/RenderPathPaint.hx index a638e162..2def85e4 100644 --- a/Sources/arm/render/RenderPathPaint.hx +++ b/Sources/arm/render/RenderPathPaint.hx @@ -88,6 +88,14 @@ class RenderPathPaint { t.format = "RGBA32"; path.createRenderTarget(t); } + { + var t = new RenderTargetRaw(); + t.name = "texpaint_uv_picker"; + t.width = 1; + t.height = 1; + t.format = "RGBA32"; + path.createRenderTarget(t); + } { var t = new RenderTargetRaw(); t.name = "texpaint_posnortex_picker0"; @@ -172,9 +180,9 @@ class RenderPathPaint { //path.clearTarget(0xff000000); //path.setTarget("texpaint_pack_picker"); //path.clearTarget(0xff000000); - path.setTarget("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker"]); + path.setTarget("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]); #else - path.setTarget("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker"]); + path.setTarget("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]); //path.clearTarget(0xff000000); #end path.bindTarget("gbuffer2", "gbuffer2"); @@ -192,9 +200,11 @@ class RenderPathPaint { var texpaint_picker = path.renderTargets.get("texpaint_picker").image; var texpaint_nor_picker = path.renderTargets.get("texpaint_nor_picker").image; var texpaint_pack_picker = path.renderTargets.get("texpaint_pack_picker").image; + var texpaint_uv_picker = path.renderTargets.get("texpaint_uv_picker").image; var a = texpaint_picker.getPixels(); var b = texpaint_nor_picker.getPixels(); var c = texpaint_pack_picker.getPixels(); + var d = texpaint_uv_picker.getPixels(); // Picked surface values #if (kha_metal || kha_vulkan) @@ -207,6 +217,10 @@ class RenderPathPaint { Context.swatch.occlusion = c.get(2) / 255; Context.swatch.roughness = c.get(1) / 255; Context.swatch.metallic = c.get(0) / 255; + Context.swatch.height = c.get(3) / 255; + Context.swatch.opacity = a.get(3) / 255; + Context.uvxPicked = d.get(2) / 255; + Context.uvyPicked = d.get(1) / 255; #else Context.swatch.base.Rb = a.get(0); Context.swatch.base.Gb = a.get(1); @@ -217,9 +231,11 @@ class RenderPathPaint { Context.swatch.occlusion = c.get(0) / 255; Context.swatch.roughness = c.get(1) / 255; Context.swatch.metallic = c.get(2) / 255; + Context.swatch.height = c.get(3) / 255; + Context.swatch.opacity = a.get(3) / 255; + Context.uvxPicked = d.get(0) / 255; + Context.uvyPicked = d.get(1) / 255; #end - Context.uvxPicked = a.get(3) / 255; - Context.uvyPicked = c.get(3) / 255; // Pick material if (Context.pickerSelectMaterial) { // matid % 3 == 0 - normal, 1 - emission, 2 - subsurface diff --git a/Sources/arm/ui/UIHeader.hx b/Sources/arm/ui/UIHeader.hx index 5177ab29..16e576b4 100644 --- a/Sources/arm/ui/UIHeader.hx +++ b/Sources/arm/ui/UIHeader.hx @@ -53,6 +53,8 @@ class UIHeader { var occlusionPicked = Math.round(Context.swatch.occlusion * 100) / 100; var roughnessPicked = Math.round(Context.swatch.roughness * 100) / 100; var metallicPicked = Math.round(Context.swatch.metallic * 100) / 100; + var heightPicked = Math.round(Context.swatch.height * 100) / 100; + var opacityPicked = Math.round(Context.swatch.opacity * 100) / 100; var h = Id.handle(); h.color.R = baseRPicked; @@ -73,6 +75,8 @@ class UIHeader { ui.text(tr("Occlusion") + ' ($occlusionPicked)'); ui.text(tr("Roughness") + ' ($roughnessPicked)'); ui.text(tr("Metallic") + ' ($metallicPicked)'); + ui.text(tr("Height") + ' ($heightPicked)'); + ui.text(tr("Opacity") + ' ($opacityPicked)'); Context.pickerSelectMaterial = ui.check(Id.handle({selected: Context.pickerSelectMaterial}), tr("Select Material")); ui.combo(Context.pickerMaskHandle, [tr("None"), tr("Material")], tr("Mask"), true); if (Context.pickerMaskHandle.changed) {