From add26db23cce96e11ab6e2720d4fef90605df3d0 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 19 Mar 2020 12:29:03 +0100 Subject: [PATCH] Fix lazy mouse precision --- Shaders/painter/hlsl/src/cursor.vert.hlsl | 14 ----------- Sources/arm/node/brush/InputNode.hx | 13 +++++----- Sources/arm/render/RenderPathPaint.hx | 29 ++++++++++++----------- Sources/arm/ui/UISidebar.hx | 16 ++++++++----- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/Shaders/painter/hlsl/src/cursor.vert.hlsl b/Shaders/painter/hlsl/src/cursor.vert.hlsl index 10fc43f9..3165d51c 100644 --- a/Shaders/painter/hlsl/src/cursor.vert.hlsl +++ b/Shaders/painter/hlsl/src/cursor.vert.hlsl @@ -9,14 +9,6 @@ SamplerState _texa_sampler; // direct3d12 unit align Texture2D gbufferD; SamplerState _gbufferD_sampler; -// float3x3 rotAxis(float3 axis, float a) { -// float c = cos(a); -// float3 as = axis * sin(a).xxx; -// float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis); -// float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c); -// return p * (1.0 - c) + q; -// } - float3 getPos(float2 uv) { float2 uvinv = float2(uv.x, 1.0 - uv.y); float depth = gbufferD.SampleLevel(_gbufferD_sampler, uvinv, 0).r; @@ -54,12 +46,6 @@ SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 t getNormal(wpos2, uv2) ); - // float ax = acos(dot(float3(1,0,0), float3(n.x,0,0))); - // float az = acos(dot(float3(0,0,1), float3(0,0,n.z))); - // float sy = -sign(n.y); - // wpos += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)), - // rotAxis(float3(1,0,0), -az * sy + 3.14/2)); - float3 n_tan; float3 n_bin; createBasis(n, n_tan, n_bin); diff --git a/Sources/arm/node/brush/InputNode.hx b/Sources/arm/node/brush/InputNode.hx index 675f508a..339d0e9c 100644 --- a/Sources/arm/node/brush/InputNode.hx +++ b/Sources/arm/node/brush/InputNode.hx @@ -81,18 +81,19 @@ class InputNode extends LogicNode { else if (kb.released(Config.keymap.brush_ruler)) { lockX = lockY = lockBegin = false; } if (UISidebar.inst.brushLazyRadius > 0) { - var v1 = new Vec4(UISidebar.inst.brushLazyX, UISidebar.inst.brushLazyY, 0.0); - var v2 = new Vec4(coords.x, coords.y, 0.0); + var ratio = iron.App.w() / iron.App.h(); + var v1 = new Vec4(UISidebar.inst.brushLazyX * ratio, UISidebar.inst.brushLazyY, 0.0); + var v2 = new Vec4(coords.x * ratio, coords.y, 0.0); var d = Vec4.distance(v1, v2); - - if (d > UISidebar.inst.brushLazyRadius / 10) { + var r = UISidebar.inst.brushLazyRadius / 10; + if (d > r) { var v3 = new Vec4(); v3.subvecs(v2, v1); v3.normalize(); v3.mult(1.0 - UISidebar.inst.brushLazyStep); - v3.mult(UISidebar.inst.brushLazyRadius / 10); + v3.mult(r); v2.addvecs(v1, v3); - coords.x = v2.x; + coords.x = v2.x / ratio; coords.y = v2.y; } diff --git a/Sources/arm/render/RenderPathPaint.hx b/Sources/arm/render/RenderPathPaint.hx index 4962a744..020ecd82 100644 --- a/Sources/arm/render/RenderPathPaint.hx +++ b/Sources/arm/render/RenderPathPaint.hx @@ -368,23 +368,24 @@ class RenderPathPaint { mx = (UISidebar.inst.lockStartedX - iron.App.x()) / iron.App.w(); my = 1.0 - (UISidebar.inst.lockStartedY - iron.App.y()) / iron.App.h(); } - drawCursor(mx, my); + drawCursor(mx, my, UISidebar.inst.brushNodesRadius * UISidebar.inst.brushRadius / 3.4); - if (UISidebar.inst.brushLazyRadius > 0 && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { - UISidebar.inst.brushRadius += UISidebar.inst.brushLazyRadius; - mx = UISidebar.inst.brushLazyX; - my = 1.0 - UISidebar.inst.brushLazyY; - if (UISidebar.inst.brushLocked) { - mx = (UISidebar.inst.lockStartedX - iron.App.x()) / iron.App.w(); - my = 1.0 - (UISidebar.inst.lockStartedY - iron.App.y()) / iron.App.h(); - } - drawCursor(mx, my, 0.2, 0.2, 0.2); - UISidebar.inst.brushRadius -= UISidebar.inst.brushLazyRadius; - } + // if (UISidebar.inst.brushLazyRadius > 0 && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { + // var _brushRadius = UISidebar.inst.brushRadius; + // UISidebar.inst.brushRadius = UISidebar.inst.brushLazyRadius; + // mx = UISidebar.inst.brushLazyX; + // my = 1.0 - UISidebar.inst.brushLazyY; + // if (UISidebar.inst.brushLocked) { + // mx = (UISidebar.inst.lockStartedX - iron.App.x()) / iron.App.w(); + // my = 1.0 - (UISidebar.inst.lockStartedY - iron.App.y()) / iron.App.h(); + // } + // drawCursor(mx, my, 0.2, 0.2, 0.2); + // UISidebar.inst.brushRadius -= UISidebar.inst.brushLazyRadius; + // } } @:access(iron.RenderPath) - static function drawCursor(mx: Float, my: Float, tintR = 1.0, tintG = 1.0, tintB = 1.0) { + static function drawCursor(mx: Float, my: Float, radius: Float, tintR = 1.0, tintG = 1.0, tintB = 1.0) { var plane = cast(Scene.active.getChild(".Plane"), MeshObject); var geom = plane.data.geom; @@ -400,7 +401,7 @@ class RenderPathPaint { g.setTextureDepth(Layers.cursorGbufferD, gbuffer0); g.setFloat2(Layers.cursorMouse, mx, my); g.setFloat2(Layers.cursorTexStep, 1 / gbuffer0.width, 1 / gbuffer0.height); - g.setFloat(Layers.cursorRadius, UISidebar.inst.brushNodesRadius * UISidebar.inst.brushRadius / 3.4); + g.setFloat(Layers.cursorRadius, radius); var right = Scene.active.camera.rightWorld().normalize(); g.setFloat3(Layers.cursorCameraRight, right.x, right.y, right.z); g.setFloat3(Layers.cursorTint, tintR, tintG, tintB); diff --git a/Sources/arm/ui/UISidebar.hx b/Sources/arm/ui/UISidebar.hx index c6fcf1e9..f05ed506 100644 --- a/Sources/arm/ui/UISidebar.hx +++ b/Sources/arm/ui/UISidebar.hx @@ -968,15 +968,19 @@ class UISidebar { Context.tool == ToolClone || Context.tool == ToolBlur || Context.tool == ToolParticle) { - if (brushLazyRadius > 0 && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { - var radius = psize + brushLazyRadius * 100; - g.color = 0x66ffffff; - g.drawScaledImage(cursorImg, mx - radius / 2, my - radius / 2, radius, radius); - g.color = 0xffffffff; - } g.drawScaledImage(cursorImg, mx - psize / 2, my - psize / 2, psize, psize); } } + + if (brushLazyRadius > 0 && !brushLocked && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { + g.fillRect(mx - 1, my - 1, 2, 2); + var mx = UISidebar.inst.brushLazyX * App.w() + App.x(); + var my = UISidebar.inst.brushLazyY * App.h() + App.y(); + var radius = brushLazyRadius * 180; + g.color = 0xff666666; + g.drawScaledImage(cursorImg, mx - radius / 2, my - radius / 2, radius, radius); + g.color = 0xffffffff; + } } }