diff --git a/Assets/DMMono-Regular.ttf b/Assets/DMMono-Regular.ttf new file mode 100644 index 0000000..1cdda91 Binary files /dev/null and b/Assets/DMMono-Regular.ttf differ diff --git a/Assets/example.hlsl b/Assets/example.hlsl index 1294b9f..fd0258c 100644 --- a/Assets/example.hlsl +++ b/Assets/example.hlsl @@ -1,13 +1,12 @@ #include "stereokit.hlsli" -//--name = sk/unlit +//--name = dofdev/unlit //--color:color = 1, 1, 1, 1 //--diffuse = white float4 color; Texture2D diffuse : register(t0); SamplerState diffuse_s : register(s0); - struct vsIn { float4 pos : SV_Position; float3 norm : NORMAL0; @@ -31,9 +30,11 @@ psIn vs(vsIn input, uint id : SV_InstanceID) { o.uv = input.uv; o.color = input.col * color * sk_inst[id].color; + o.color = float4(0, 1, 1, 1); return o; } float4 ps(psIn input) : SV_TARGET { + float4 col = diffuse.Sample(diffuse_s, input.uv); col = col * input.color; diff --git a/Assets/oriel.glb b/Assets/oriel.glb new file mode 100644 index 0000000..bf6ec3b Binary files /dev/null and b/Assets/oriel.glb differ diff --git a/Assets/oriel.hlsl b/Assets/oriel.hlsl new file mode 100644 index 0000000..1100eba --- /dev/null +++ b/Assets/oriel.hlsl @@ -0,0 +1,41 @@ +#include "stereokit.hlsli" + +//--name = dofdev/oriel +// float4 color; +// Texture2D diffuse : register(t0); +// SamplerState diffuse_s : register(s0); + +struct vsIn { + float4 pos : SV_POSITION; + float3 norm : NORMAL0; + float2 uv : TEXCOORD0; + float4 col : COLOR0; +}; +struct psIn { + float4 pos : SV_POSITION; + float3 norm : NORMAL0; + float2 uv : TEXCOORD0; + float1 depth : TEXCOORD1; + float4 color : COLOR0; + uint view_id : SV_RenderTargetArrayIndex; +}; + +psIn vs(vsIn input, uint id : SV_InstanceID) { + psIn o; + o.view_id = id % sk_view_count; + id = id / sk_view_count; + + float3 world = mul(input.pos, sk_inst[id].world).xyz; + o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]); + o.norm = normalize(mul(input.norm, (float3x3)sk_inst[id].world)); + + o.uv = input.uv; + o.color = input.col; + o.depth = dot(float4(o.norm, 1), normalize(float4(world,1) - sk_camera_pos[o.view_id])); + return o; +} + +float4 ps(psIn input) : SV_TARGET { + clip(input.depth); + return input.color; +} \ No newline at end of file diff --git a/Oriel.cs b/Oriel.cs deleted file mode 100644 index af14375..0000000 --- a/Oriel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using StereoKit; - -class Oriel { - RenderLayer renderLayer; - - public Oriel(RenderLayer layer) { - this.renderLayer = layer; - } - - -} \ No newline at end of file diff --git a/Program.cs b/Program.cs index cfd09a5..d6d5524 100644 --- a/Program.cs +++ b/Program.cs @@ -3,34 +3,73 @@ using StereoKit; class Program { static void Main(string[] args) { - SKSettings settings = new SKSettings - { + SKSettings settings = new SKSettings { appName = "oriels", assetsFolder = "Assets", }; if (!SK.Initialize(settings)) Environment.Exit(1); - Model cursor = Model.FromFile("cursor.glb"); + // TextStyle style = Text.MakeStyle(Font.FromFile("DMMono-Regular.ttf"), 0.1f, Color.White); - ColorCube cube = new ColorCube(); - OrbitalView.strength = 4; - OrbitalView.distance = 0.4f; - cube.thickness = 0.01f; - - ReachCursor reachCursor = new ReachCursor(); - - Material addMat = new Material(Shader.FromFile("example.hlsl")); - - while(SK.Step(() => { - // Matrix orbitMatrix = OrbitalView.transform; - // cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); - // Default.MaterialHand["color"] = cube.color; - - reachCursor.Step(); - - // cursor.Draw(Matrix.S(0.1f)); - })); - SK.Shutdown(); + Mono.Run(); } } + +public static class Mono { + + public static Controller offHand, mainHand; + + public static void Run() { + ColorCube cube = new ColorCube(); + OrbitalView.strength = 4; + OrbitalView.distance = 0.4f; + cube.thickness = 0.01f; + + + ReachCursor reachCursor = new ReachCursor(); + SupineCursor supineCursor = new SupineCursor(); + + Oriel oriel = new Oriel(); + + oriel.Start(); + + while (SK.Step(() => { + offHand = Input.Controller(Handed.Left); + mainHand = Input.Controller(Handed.Right); + + // Matrix orbitMatrix = OrbitalView.transform; + // cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); + // Default.MaterialHand["color"] = cube.color; + + // reachCursor.Step(); + supineCursor.Step(); + // oriel.Step(); + + // cursor.Draw(Matrix.S(0.1f)); + })) ; + SK.Shutdown(); + } +} + +public class Oriel { + public Bounds bounds; + + // render + Material mat = new Material(Shader.FromFile("oriel.hlsl")); + Mesh mesh = Mesh.GenerateCube(new Vec3(1, 1, 1)); + + public void Start() { + bounds = new Bounds(Vec3.Zero, new Vec3(1f, 0.5f, 0.5f)); + + // Vertex[] verts = mesh.GetVerts(); + // for (int i = 0; i < verts.Length; i++) { + // verts[i].norm *= -1f; + // } + // mesh.SetVerts(verts); + } + + public void Step() { + mesh.Draw(mat, Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions)); + } +} diff --git a/ReachCursor.cs b/ReachCursor.cs deleted file mode 100644 index ee74128..0000000 --- a/ReachCursor.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using StereoKit; - -public class ReachCursor { - static Material unlitMat = Default.MaterialUnlit.Copy(); - - static Model modelCursor = Model.FromFile("cursor.glb", Shader.Default); - static Model modelSphere = new Model(Default.MeshSphere, unlitMat); - - static Vec3[] pullPoints = new Vec3[2]; - - public void Step() { - Matrix matrix = new Matrix(); - matrix.Translation = new Vec3(0, 0, -1); - - for (int h = 0; h < (int)Handed.Max; h++) - { - // Get the pose for the index fingertip - Hand hand = Input.Hand((Handed)h); - Vec3 indexTip = hand[FingerId.Index, JointId.Tip].Pose.position; - Vec3 thumbTip = hand[FingerId.Thumb, JointId.Tip].Pose.position; - Vec3 pinchPos = Vec3.Lerp(indexTip, thumbTip, 0.5f); - if (hand.IsPinched) - { - pullPoints[h] = pinchPos; - } - - float stretch = (pullPoints[h] - pinchPos).Length; - Vec3 dir = (pinchPos - pullPoints[h]).Normalized; - Vec3 pos = pinchPos + dir * stretch * 3; - modelCursor.Draw(Matrix.TS(pos, 0.06f)); - Lines.Add(pullPoints[h], pos, Color.White, 0.01f); - modelSphere.Draw(Matrix.TS(pullPoints[h], 0.04f)); - } - } -} \ No newline at end of file diff --git a/Resources/oriel.blend b/Resources/oriel.blend new file mode 100644 index 0000000..3e4c007 Binary files /dev/null and b/Resources/oriel.blend differ diff --git a/SpatialCursor.cs b/SpatialCursor.cs new file mode 100644 index 0000000..9168a58 --- /dev/null +++ b/SpatialCursor.cs @@ -0,0 +1,82 @@ +using System; +using StereoKit; + +// build this out tentatively +public abstract class SpatialCursor { + public Vec3 pos; + public Quat rot; + + public static Model model = Model.FromFile("cursor.glb", Shader.Default); +} + +// : SpatialCursor +public class ReachCursor { + static Material unlitMat = Default.MaterialUnlit.Copy(); + static Model modelCursor = Model.FromFile("cursor.glb", Shader.Default); + static Model modelSphere = new Model(Default.MeshSphere, unlitMat); + + static Vec3[] pullPoints = new Vec3[2]; + + public void Step() { + for (int h = 0; h < (int)Handed.Max; h++) { + // Get the pose for the index fingertip + Hand hand = Input.Hand((Handed)h); + Vec3 indexTip = hand[FingerId.Index, JointId.Tip].Pose.position; + Vec3 thumbTip = hand[FingerId.Thumb, JointId.Tip].Pose.position; + Vec3 pinchPos = Vec3.Lerp(indexTip, thumbTip, 0.5f); + if (hand.IsPinched) { + pullPoints[h] = pinchPos; + } + + float stretch = (pullPoints[h] - pinchPos).Length; + Vec3 dir = (pinchPos - pullPoints[h]).Normalized; + Vec3 pos = pinchPos + dir * stretch * 3; + modelCursor.Draw(Matrix.TS(pos, 0.06f)); + Lines.Add(pullPoints[h], pos, Color.White, 0.01f); + modelSphere.Draw(Matrix.TS(pullPoints[h], 0.04f)); + } + } +} + +public class TwistCursor : SpatialCursor { + public void Step() { + Quat rel = Quat.LookAt(Vec3.Zero, Mono.mainHand.aim.orientation * Vec3.Forward); + float twist = Vec3.Dot(rel * Vec3.Up, Mono.mainHand.aim.orientation * Vec3.Up); + twist = MathF.Max(twist - 0.05f, 0); + pos = Mono.mainHand.aim.position + Mono.mainHand.aim.orientation * Vec3.Forward * twist; + + model.Draw(Matrix.TS(pos, 0.06f)); + } +} + +public class SupineCursor : SpatialCursor { + float calibStr; + Quat calibQuat; + + public void Step() { + // calibration + if (Mono.mainHand.IsStickClicked) { + Vec3 target = Input.Head.position + Input.Head.Forward; + calibStr = Vec3.Distance(Mono.mainHand.aim.position, target) * 2; + + Quat calibAlign = Quat.LookAt(Mono.mainHand.aim.position, target); + calibQuat = Mono.mainHand.aim.orientation.Inverse * calibAlign; + } + + Quat rel = Quat.LookAt(Vec3.Zero, Mono.offHand.aim.orientation * Vec3.Forward); + float twist = (Vec3.Dot(rel * -Vec3.Right, Mono.offHand.aim.orientation * Vec3.Up) + 1) / 2; + + pos = Mono.mainHand.aim.position + Mono.mainHand.aim.orientation * calibQuat * Vec3.Forward * calibStr * twist; + + model.Draw(Matrix.TS(pos, 0.06f)); + } +} + +public class TankCursor : SpatialCursor { + public void Step() { + pos = Vec3.Zero; + rot = Quat.Identity; + + model.Draw(Matrix.TS(pos, 0.06f)); + } +} \ No newline at end of file diff --git a/oriels.bat b/oriels.bat new file mode 100644 index 0000000..9018690 --- /dev/null +++ b/oriels.bat @@ -0,0 +1,4 @@ +dotnet build +pause +cd bin/Debug/netcoreapp3.1/ +oriels.exe \ No newline at end of file diff --git a/oriels.csproj b/oriels.csproj index e8f69c5..a964ba2 100644 --- a/oriels.csproj +++ b/oriels.csproj @@ -18,10 +18,12 @@ + +