diff --git a/Libraries/armory b/Libraries/armory index 00237fdd..060448e5 160000 --- a/Libraries/armory +++ b/Libraries/armory @@ -1 +1 @@ -Subproject commit 00237fdd4204a85490f69adcf28916ca498fc12d +Subproject commit 060448e55593977adbc53cae451738cee45ce95a diff --git a/Libraries/iron b/Libraries/iron index 3ed12c09..12c37150 160000 --- a/Libraries/iron +++ b/Libraries/iron @@ -1 +1 @@ -Subproject commit 3ed12c09e10a3e19f111ac0ed1a1b9cc22a5c310 +Subproject commit 12c3715016d3c95239d09f9593358dc4669fd34d diff --git a/Sources/arm/ConstData.hx b/Sources/arm/ConstData.hx index 5605d421..900d37fd 100644 --- a/Sources/arm/ConstData.hx +++ b/Sources/arm/ConstData.hx @@ -165,6 +165,7 @@ void main() { uniform float4x4 VP; uniform float4x4 invVP; uniform float2 mouse; +uniform float radius; Texture2D gbufferD; SamplerState _gbufferD_sampler; Texture2D gbuffer0; @@ -194,7 +195,7 @@ SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 t 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.xyz += mul(mul(pos.xyz / float3(8,8,8), rotAxis(float3(0,0,1), ax + 3.14/2)), + wpos.xyz += 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)); stage_output.gl_Position = mul(float4(wpos.xyz, 1.0), VP); stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5; @@ -205,7 +206,7 @@ SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 t Texture2D tex; SamplerState _tex_sampler; float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 { - return tex.SampleLevel(_tex_sampler, texCoord, 0); + return float4(1.0, 1.0, 1.0, tex.SampleLevel(_tex_sampler, texCoord, 0).a); } "; @@ -215,6 +216,7 @@ float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 { uniform mat4 VP; uniform mat4 invVP; uniform vec2 mouse; +uniform float radius; uniform sampler2D gbufferD; uniform sampler2D gbuffer0; in vec4 pos; @@ -246,7 +248,7 @@ void main() { wpos.xyz += rotAxis(vec3(1,0,0), -az * sy + 3.14/2) * rotAxis(vec3(0,0,1), ax + 3.14/2) * - (pos.xyz / 8); + (pos.xyz * radius); gl_Position = VP * vec4(wpos.xyz, 1.0); } "; @@ -255,8 +257,7 @@ uniform sampler2D tex; in vec2 texCoord; out vec4 FragColor; void main() { - FragColor = textureLod(tex, texCoord, 0.0); - FragColor.rgb = vec3(1.0); + FragColor = vec4(1.0, 1.0, 1.0, textureLod(tex, texCoord, 0.0).a); } "; diff --git a/Sources/arm/Layers.hx b/Sources/arm/Layers.hx index dc42bb4a..9204ff0f 100644 --- a/Sources/arm/Layers.hx +++ b/Sources/arm/Layers.hx @@ -32,6 +32,7 @@ class Layers { public static var cursorVP:ConstantLocation; public static var cursorInvVP:ConstantLocation; public static var cursorMouse:ConstantLocation; + public static var cursorRadius:ConstantLocation; public static var cursorTex:TextureUnit; public static var cursorGbufferD:TextureUnit; public static var cursorGbuffer0:TextureUnit; @@ -173,6 +174,7 @@ class Layers { cursorVP = pipeCursor.getConstantLocation("VP"); cursorInvVP = pipeCursor.getConstantLocation("invVP"); cursorMouse = pipeCursor.getConstantLocation("mouse"); + cursorRadius = pipeCursor.getConstantLocation("radius"); cursorGbufferD = pipeCursor.getTextureUnit("gbufferD"); cursorGbuffer0 = pipeCursor.getTextureUnit("gbuffer0"); cursorTex = pipeCursor.getTextureUnit("tex"); diff --git a/Sources/arm/MaterialBuilder.hx b/Sources/arm/MaterialBuilder.hx index ce8f6b4b..5e2c2a1a 100644 --- a/Sources/arm/MaterialBuilder.hx +++ b/Sources/arm/MaterialBuilder.hx @@ -175,33 +175,79 @@ class MaterialBuilder { frag.write('float dist = 0.0;'); } else { - frag.write('vec2 binp = inp.xy * 2.0 - 1.0;'); - frag.write('binp.x *= aspectRatio;'); - frag.write('binp = binp * 0.5 + 0.5;'); + if (UITrait.inst.brush3d) { + #if (kha_opengl || kha_webgl) + frag.write('float depth = textureLod(paintdb, vec2(inp.x, 1.0 - inp.y), 0.0).r;'); + #else + frag.write('float depth = textureLod(paintdb, inp.xy, 0.0).r;'); + #end + frag.add_uniform('mat4 invVP', '_inverseViewProjectionMatrix'); + #if (kha_opengl || kha_webgl) + frag.write('vec2 inp2 = inp;'); + #else + frag.write('vec2 inp2 = vec2(inp.x, 1.0 - inp.y);'); + #end + frag.write('float4 winp = float4(inp2.xy * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);'); + frag.write('winp = mul(winp, invVP);'); + frag.write('winp.xyz /= winp.w;'); + frag.wposition = true; - // Continuos paint - frag.write('vec2 binplast = inplast.xy * 2.0 - 1.0;'); - frag.write('binplast.x *= aspectRatio;'); - frag.write('binplast = binplast * 0.5 + 0.5;'); - - frag.write('vec2 pa = bsp.xy - binp.xy, ba = binplast.xy - binp.xy;'); - frag.write('float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);'); - frag.write('float dist = length(pa - ba * h);'); - - if (!UITrait.inst.mirrorX) { + // frag.write('float dist = distance(wposition, winp);'); + // frag.write('if (dist > brushRadius) { discard; }'); + + // Continuos paint + #if (kha_opengl || kha_webgl) + frag.write('float depthlast = textureLod(paintdb, vec2(inplast.x, 1.0 - inplast.y), 0.0).r;'); + #else + frag.write('float depthlast = textureLod(paintdb, inplast.xy, 0.0).r;'); + #end + #if (kha_opengl || kha_webgl) + frag.write('vec2 inplast2 = inplast;'); + #else + frag.write('vec2 inplast2 = vec2(inplast.x, 1.0 - inplast.y);'); + #end + frag.write('float4 winplast = float4(inplast2.xy * 2.0 - 1.0, depthlast * 2.0 - 1.0, 1.0);'); + frag.write('winplast = mul(winplast, invVP);'); + frag.write('winplast.xyz /= winplast.w;'); + + frag.write('vec3 pa = wposition - winp;'); + frag.write('vec3 ba = winplast - winp;'); + frag.write('float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);'); + frag.write('float dist = length(pa - ba * h);'); frag.write('if (dist > brushRadius) { discard; }'); + + // if (UITrait.inst.mirrorX) {} } else { - frag.write('vec2 binp2 = vec2(0.5 - (binp.x - 0.5), binp.y), binplast2 = vec2(0.5 - (binplast.x - 0.5), binplast.y);'); - frag.write('vec2 pa2 = bsp.xy - binp2.xy, ba2 = binplast2.xy - binp2.xy;'); - frag.write('float h2 = clamp(dot(pa2, ba2) / dot(ba2, ba2), 0.0, 1.0);'); - frag.write('float dist2 = length(pa2 - ba2 * h2);'); - frag.write('if (dist > brushRadius && dist2 > brushRadius) { discard; }'); - } - // + frag.write('vec2 binp = inp.xy * 2.0 - 1.0;'); + frag.write('binp.x *= aspectRatio;'); + frag.write('binp = binp * 0.5 + 0.5;'); - // frag.write('float dist = distance(bsp.xy, binp.xy);'); - // frag.write('if (dist > brushRadius) { discard; }'); + // Continuos paint + frag.write('vec2 binplast = inplast.xy * 2.0 - 1.0;'); + frag.write('binplast.x *= aspectRatio;'); + frag.write('binplast = binplast * 0.5 + 0.5;'); + + frag.write('vec2 pa = bsp.xy - binp.xy;'); + frag.write('vec2 ba = binplast.xy - binp.xy;'); + frag.write('float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);'); + frag.write('float dist = length(pa - ba * h);'); + + if (!UITrait.inst.mirrorX) { + frag.write('if (dist > brushRadius) { discard; }'); + } + else { + frag.write('vec2 binp2 = vec2(0.5 - (binp.x - 0.5), binp.y), binplast2 = vec2(0.5 - (binplast.x - 0.5), binplast.y);'); + frag.write('vec2 pa2 = bsp.xy - binp2.xy, ba2 = binplast2.xy - binp2.xy;'); + frag.write('float h2 = clamp(dot(pa2, ba2) / dot(ba2, ba2), 0.0, 1.0);'); + frag.write('float dist2 = length(pa2 - ba2 * h2);'); + frag.write('if (dist > brushRadius && dist2 > brushRadius) { discard; }'); + } + // + + // frag.write('float dist = distance(bsp.xy, binp.xy);'); + // frag.write('if (dist > brushRadius) { discard; }'); + } } } else { // Fill, Bake diff --git a/Sources/arm/Uniforms.hx b/Sources/arm/Uniforms.hx index efe67160..2191bae5 100644 --- a/Sources/arm/Uniforms.hx +++ b/Sources/arm/Uniforms.hx @@ -19,7 +19,8 @@ class Uniforms { var val = (UITrait.inst.brushRadius * UITrait.inst.brushNodesRadius) / 15.0; var pen = iron.system.Input.getPen(); if (UITrait.penPressureRadius && pen.down()) val *= pen.pressure; - val *= 900 / App.h(); // Projection ratio + if (UITrait.inst.brush3d) val *= 2; + else val *= 900 / App.h(); // Projection ratio return val; } else if (link == '_brushOpacity') { diff --git a/Sources/arm/renderpath/RenderPathDeferred.hx b/Sources/arm/renderpath/RenderPathDeferred.hx index c361a969..361a96ae 100644 --- a/Sources/arm/renderpath/RenderPathDeferred.hx +++ b/Sources/arm/renderpath/RenderPathDeferred.hx @@ -186,10 +186,7 @@ class RenderPathDeferred { ssaa4 ? path.drawShader("shader_datas/supersample_resolve/supersample_resolve") : path.drawShader("shader_datas/copy_pass/copy_pass"); - - if (UITrait.inst.brushWarp) { - RenderPathPaint.commandsCursor(); - } + if (UITrait.inst.brush3d) RenderPathPaint.commandsCursor(); return; } @@ -752,6 +749,8 @@ class RenderPathDeferred { } #end + if (UITrait.inst.brush3d) RenderPathPaint.commandsCursor(); + taaFrame++; UITrait.inst.ddirty--; UITrait.inst.pdirty--; diff --git a/Sources/arm/renderpath/RenderPathPaint.hx b/Sources/arm/renderpath/RenderPathPaint.hx index a4ea9dbc..5704e810 100644 --- a/Sources/arm/renderpath/RenderPathPaint.hx +++ b/Sources/arm/renderpath/RenderPathPaint.hx @@ -171,6 +171,7 @@ class RenderPathPaint { var mx = iron.system.Input.getMouse().x / iron.App.w(); var my = 1.0 - (iron.system.Input.getMouse().y / iron.App.h()); g.setFloat2(Layers.cursorMouse, mx, my); + g.setFloat(Layers.cursorRadius, UITrait.inst.brushRadius / 3.4); g.setMatrix(Layers.cursorVP, iron.Scene.active.camera.VP.self); var helpMat = iron.math.Mat4.identity(); helpMat.getInverse(iron.Scene.active.camera.VP); diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index 87d90bc7..0c4ad2b6 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -205,6 +205,9 @@ class UINodes extends iron.Trait { wx = lay == 0 ? Std.int(iron.App.w()) : UITrait.inst.windowW; wx += UITrait.inst.toolbarw; wy = UITrait.inst.headerh * 2; + if (UIView2D.inst.show) { + wy += Std.int(iron.App.h() / 2); + } var mx = mouse.x + App.x(); var my = mouse.y + App.y(); if (mx < wx || my < wy) return; diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index b76375f7..cb69abc9 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -187,7 +187,7 @@ class UITrait extends iron.Trait { public var brushBias = 1.0; public var brushPaint = 0; public var selectedTool = 0; - public var brushWarp = false; + public var brush3d = true; public var bakeType = 0; public var bakeStrength = 1.0; public var bakeRadius = 1.0; @@ -816,7 +816,7 @@ class UITrait extends iron.Trait { g.color = 0xffffffff; // Brush - if (arm.App.uienabled && worktab.position == 0 && !brushWarp) { + if (arm.App.uienabled && worktab.position == 0 && !brush3d) { var cursorImg = Res.get('cursor.png'); var mouse = iron.system.Input.getMouse(); var mx = mouse.x + iron.App.x(); @@ -1834,7 +1834,9 @@ class UITrait extends iron.Trait { ui.g.begin(false); armory.data.Config.save(); } - brushWarp = ui.check(Id.handle({selected: brushWarp}), "Brush Warp"); + var brush3dHandle = Id.handle({selected: brush3d}); + brush3d = ui.check(brush3dHandle, "3D Brush Cursor"); + if (brush3dHandle.changed) MaterialParser.parsePaintMaterial(); } ui.separator();