Improve 3d cursor

This commit is contained in:
unknown
2019-06-01 23:34:35 +02:00
parent 4172034f5a
commit 790a8c7c5a
8 changed files with 76 additions and 21 deletions
+10
View File
@@ -115,6 +115,7 @@ class App extends iron.Trait {
color_wheel = image;
zui.Nodes.getEnumTexts = getEnumTexts;
zui.Nodes.mapEnum = mapEnum;
Zui.alwaysRedrawWindow = false;
uibox = new Zui({ font: f, scaleFactor: armory.data.Config.raw.window_scale });
iron.App.notifyOnInit(function() {
@@ -271,6 +272,15 @@ class App extends iron.Trait {
UINodes.inst.grid.unload();
UINodes.inst.grid = null;
}
UITrait.inst.hwnd.redraws = 2;
UITrait.inst.hwnd1.redraws = 2;
UITrait.inst.hwnd2.redraws = 2;
UITrait.inst.headerHandle.redraws = 2;
UITrait.inst.toolbarHandle.redraws = 2;
UITrait.inst.statusHandle.redraws = 2;
UITrait.inst.menuHandle.redraws = 2;
UITrait.inst.workspaceHandle.redraws = 2;
}
static function update() {
+30 -10
View File
@@ -165,6 +165,7 @@ void main() {
uniform float4x4 VP;
uniform float4x4 invVP;
uniform float2 mouse;
uniform float2 step;
uniform float radius;
Texture2D<float4> gbufferD;
SamplerState _gbufferD_sampler;
@@ -178,6 +179,13 @@ float3x3 rotAxis(float3 axis, float a) {
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 getNormal(float2 uv) {
float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, uv, 0.0).rg;
float3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
return n;
}
struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; };
SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 tex : TEXCOORD2) {
SPIRV_Cross_Output stage_output;
@@ -187,11 +195,13 @@ SPIRV_Cross_Output main(float4 pos : TEXCOORD1, float2 nor : TEXCOORD0, float2 t
float4 wpos = float4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
wpos = mul(wpos, invVP);
wpos.xyz /= wpos.w;
float2 g0 = gbuffer0.SampleLevel(_gbuffer0_sampler, mouseinv, 0.0).rg;
float3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
n = normalize(n);
float3 n = normalize(
getNormal(mouseinv + float2(step.x, step.y)) +
getNormal(mouseinv + float2(-step.x, step.y)) +
getNormal(mouseinv + float2(-step.x, -step.y)) +
getNormal(mouseinv + float2(step.x, -step.y)) +
getNormal(mouseinv)
);
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);
@@ -216,6 +226,7 @@ float4 main(float2 texCoord : TEXCOORD0) : SV_Target0 {
uniform mat4 VP;
uniform mat4 invVP;
uniform vec2 mouse;
uniform vec2 step;
uniform float radius;
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
@@ -231,17 +242,26 @@ mat3 rotAxis(vec3 axis, float a) {
mat3 q = mat3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
return p * (1.0 - c) + q;
}
vec3 getNormal(vec2 uv) {
vec2 g0 = textureLod(gbuffer0, mouse, 0.0).rg;
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
return n;
}
void main() {
texCoord = tex;
float depth = textureLod(gbufferD, mouse, 0.0).r;
vec4 wpos = vec4(mouse * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
wpos = invVP * wpos;
wpos.xyz /= wpos.w;
vec2 g0 = textureLod(gbuffer0, mouse, 0.0).rg;
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
n = normalize(n);
vec3 n = normalize(
getNormal(mouseinv + vec2(step.x, step.y)) +
getNormal(mouseinv + vec2(-step.x, step.y)) +
getNormal(mouseinv + vec2(-step.x, -step.y)) +
getNormal(mouseinv + vec2(step.x, -step.y)) +
getNormal(mouseinv)
);
float ax = acos(dot(vec3(1,0,0), vec3(n.x,0,0)));
float az = acos(dot(vec3(0,0,1), vec3(0,0,n.z)));
float sy = -sign(n.y);
+2
View File
@@ -32,6 +32,7 @@ class Layers {
public static var cursorVP:ConstantLocation;
public static var cursorInvVP:ConstantLocation;
public static var cursorMouse:ConstantLocation;
public static var cursorStep:ConstantLocation;
public static var cursorRadius:ConstantLocation;
public static var cursorTex:TextureUnit;
public static var cursorGbufferD:TextureUnit;
@@ -174,6 +175,7 @@ class Layers {
cursorVP = pipeCursor.getConstantLocation("VP");
cursorInvVP = pipeCursor.getConstantLocation("invVP");
cursorMouse = pipeCursor.getConstantLocation("mouse");
cursorStep = pipeCursor.getConstantLocation("step");
cursorRadius = pipeCursor.getConstantLocation("radius");
cursorGbufferD = pipeCursor.getTextureUnit("gbufferD");
cursorGbuffer0 = pipeCursor.getTextureUnit("gbuffer0");
+1
View File
@@ -33,6 +33,7 @@ class Uniforms {
var val = UITrait.inst.brushHardness * UITrait.inst.brushNodesHardness;
var pen = iron.system.Input.getPen();
if (UITrait.penPressureHardness && pen.down()) val *= pen.pressure;
if (UITrait.inst.brush3d) val *= val;
return val;
}
else if (link == '_brushScale') {
+18 -6
View File
@@ -173,20 +173,32 @@ class RenderPathDeferred {
//
}
static var lastX = -1.0;
static var lastY = -1.0;
@:access(iron.RenderPath)
public static function commands() {
if (kha.System.windowWidth() == 0 || kha.System.windowHeight() == 0) return;
var ssaa4 = armory.data.Config.raw.rp_supersample == 4 ? true : false;
var mouse = iron.system.Input.getMouse();
var mx = lastX;
var my = lastY;
lastX = mouse.x;
lastY = mouse.y;
if (!UITrait.inst.dirty()) {
path.setTarget("");
path.bindTarget(taaFrame % 2 == 0 ? "taa" : "taa2", "tex");
ssaa4 ?
path.drawShader("shader_datas/supersample_resolve/supersample_resolve") :
path.drawShader("shader_datas/copy_pass/copy_pass");
if (UITrait.inst.brush3d) RenderPathPaint.commandsCursor();
if (mx != lastX || my != lastY || UITrait.inst.ddirty == 0) {
UITrait.inst.ddirty--;
path.setTarget("");
path.bindTarget(taaFrame % 2 == 0 ? "taa" : "taa2", "tex");
ssaa4 ?
path.drawShader("shader_datas/supersample_resolve/supersample_resolve") :
path.drawShader("shader_datas/copy_pass/copy_pass");
if (UITrait.inst.brush3d) RenderPathPaint.commandsCursor();
}
return;
}
+8 -2
View File
@@ -166,11 +166,17 @@ class RenderPathPaint {
var decal = UITrait.inst.selectedTool == ToolDecal || UITrait.inst.selectedTool == ToolText;
var img = decal ? UITrait.inst.decalImage : Res.get("cursor.png");
g.setTexture(Layers.cursorTex, img);
g.setTextureDepth(Layers.cursorGbufferD, path.renderTargets.get("gbuffer0").image);
g.setTexture(Layers.cursorGbuffer0, path.renderTargets.get("gbuffer0").image);
var gbuffer0 = path.renderTargets.get("gbuffer0").image;
g.setTextureDepth(Layers.cursorGbufferD, gbuffer0);
g.setTexture(Layers.cursorGbuffer0, gbuffer0);
var mx = iron.system.Input.getMouse().x / iron.App.w();
var my = 1.0 - (iron.system.Input.getMouse().y / iron.App.h());
if (UITrait.inst.brushLocked) {
mx = (UITrait.inst.lockStartedX - iron.App.x()) / iron.App.w();
my = 1.0 - (UITrait.inst.lockStartedY - iron.App.y()) / iron.App.h();
}
g.setFloat2(Layers.cursorMouse, mx, my);
g.setFloat2(Layers.cursorStep, 2 / gbuffer0.width, 2 / gbuffer0.height);
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();
+4
View File
@@ -284,6 +284,10 @@ class UINodes extends iron.Trait {
}
if (count > 6) break;
}
if (enter && count == 0) { // Hide popup on enter when node is not found
ui.changed = true;
searchHandle.text = "";
}
ui.t.BUTTON_COL = BUTTON_COL;
});
}
+3 -3
View File
@@ -217,9 +217,9 @@ class UITrait extends iron.Trait {
var altStartedX = -1.0;
var altStartedY = -1.0;
var lockStartedX = -1.0;
var lockStartedY = -1.0;
var brushLocked = false;
public var lockStartedX = -1.0;
public var lockStartedY = -1.0;
public var brushLocked = false;
var brushCanLock = false;
var brushCanUnlock = false;
public var cameraType = 0;