diff --git a/Shaders/view2d.frag.glsl b/Shaders/view2d.frag.glsl new file mode 100644 index 00000000..1c4155b0 --- /dev/null +++ b/Shaders/view2d.frag.glsl @@ -0,0 +1,14 @@ +#version 450 + +uniform sampler2D tex; +in vec2 texCoord; +in vec4 color; +out vec4 FragColor; + + +void main() { + // Show basecolor + vec4 texcolor = texture(tex, texCoord) * color; + // texcolor.rgb *= color.a; + FragColor = vec4(texcolor.rgb, 1.0); +} diff --git a/Shaders/view2d.vert.glsl b/Shaders/view2d.vert.glsl new file mode 100644 index 00000000..37e00e8f --- /dev/null +++ b/Shaders/view2d.vert.glsl @@ -0,0 +1,14 @@ +#version 450 + +in vec3 vertexPosition; +in vec2 texPosition; +in vec4 vertexColor; +uniform mat4 projectionMatrix; +out vec2 texCoord; +out vec4 color; + +void main() { + gl_Position = projectionMatrix * vec4(vertexPosition, 1.0); + texCoord = texPosition; + color = vertexColor; +} diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 13494c2d..ee1dd7c3 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -55,6 +55,7 @@ class App extends iron.Trait { notifyOnRender2D(render); object.addTrait(new UITrait()); object.addTrait(new UINodes()); + object.addTrait(new UIView2D()); object.addTrait(new FlyCamera()); object.addTrait(new OrbitCamera()); }); @@ -69,7 +70,7 @@ class App extends iron.Trait { if (UINodes.inst == null || UITrait.inst == null) { res = kha.System.windowWidth() - UITrait.defaultWindowW; } - else if (UINodes.inst.show) { + else if (UINodes.inst.show || UIView2D.inst.show) { res = Std.int((kha.System.windowWidth() - UITrait.inst.windowW) / 2); } else { diff --git a/Sources/arm/UITrait.hx b/Sources/arm/UITrait.hx index d485d016..e4ee212d 100644 --- a/Sources/arm/UITrait.hx +++ b/Sources/arm/UITrait.hx @@ -334,6 +334,7 @@ class UITrait extends iron.Trait { var kb = iron.system.Input.getKeyboard(); var shift = kb.down("shift"); if (kb.started("tab")) { + UIView2D.inst.show = false; UINodes.inst.show = !UINodes.inst.show; arm.App.resize(); } @@ -474,17 +475,25 @@ class UITrait extends iron.Trait { } function showMaterialNodes() { + UIView2D.inst.show = false; if (UINodes.inst.show && !UINodes.inst.isBrush) UINodes.inst.show = false; else { UINodes.inst.show = true; UINodes.inst.isBrush = false; } arm.App.resize(); } function showBrushNodes() { + UIView2D.inst.show = false; if (UINodes.inst.show && UINodes.inst.isBrush) UINodes.inst.show = false; else { UINodes.inst.show = true; UINodes.inst.isBrush = true; } arm.App.resize(); } + function show2DView() { + UINodes.inst.show = false; + UIView2D.inst.show = !UIView2D.inst.show; + arm.App.resize(); + } + var outputType = 0; var isBase = true; var isOpac = true; @@ -890,7 +899,7 @@ class UITrait extends iron.Trait { if (ui.panel(Id.handle({selected: true}), "Layers")) { if (ui.button("2D View")) { - + show2DView(); } // Picked color ui.image(iron.RenderPath.active.renderTargets.get("texpaint_colorid0").image, 0xffffffff, 64); diff --git a/Sources/arm/UIView2D.hx b/Sources/arm/UIView2D.hx index 6e24aedf..af3d284c 100644 --- a/Sources/arm/UIView2D.hx +++ b/Sources/arm/UIView2D.hx @@ -1,7 +1,54 @@ package arm; -class UIView2D { +import zui.*; + +class UIView2D extends iron.Trait { + + public static var inst:UIView2D; + + public var show = false; + public var wx:Int; + public var wy:Int; + public var ww:Int; + + var pipe:kha.graphics4.PipelineState; + public function new() { + super(); + inst = this; + + pipe = new kha.graphics4.PipelineState(); + pipe.fragmentShader = kha.Shaders.view2d_frag; + pipe.vertexShader = kha.Shaders.view2d_vert; + var vs = new kha.graphics4.VertexStructure(); + vs.add("vertexPosition", kha.graphics4.VertexData.Float3); + vs.add("texPosition", kha.graphics4.VertexData.Float2); + vs.add("vertexColor", kha.graphics4.VertexData.Float4); + pipe.inputLayout = [vs]; + pipe.compile(); + + notifyOnRender2D(render2D); + } + + function render2D(g:kha.graphics2.Graphics) { + ww = Std.int(iron.App.w()); + wx = Std.int(iron.App.w()); + wy = 0; + + if (!show) return; + g.end(); + if (UINodes.inst.grid == null) UINodes.inst.drawGrid(); + g.begin(false); + + g.color = 0xffffffff; + g.drawImage(UINodes.inst.grid, wx, wy); + + var tw = Std.int(iron.App.w() * 0.95); + var tx = Std.int(iron.App.w() + (iron.App.w() - tw) / 2); + var ty = Std.int(iron.App.h() / 2 - tw / 2); + g.pipeline = pipe; + g.drawScaledImage(UITrait.inst.texpaint, tx, ty, tw, tw); + g.pipeline = null; } } diff --git a/armorpaint.blend b/armorpaint.blend index 1c95e225..8f385e88 100644 Binary files a/armorpaint.blend and b/armorpaint.blend differ