diff --git a/README.md b/README.md index 8b8376a..c471840 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,14 @@ accounts = web3() # m++ refactor(hackathon.result()) -oriels.dofs == site.dofs +oriel manipulation dofs.debug(CMY) +cursor combinatory mechanism + +oriels.dofs == site.dofs + init(oriel-game) exec(vlai) diff --git a/add/crown.hlsl b/add/crown.hlsl deleted file mode 100644 index e6d477f..0000000 --- a/add/crown.hlsl +++ /dev/null @@ -1,59 +0,0 @@ -#include "stereokit.hlsli" - -//--name = dofdev/crown - -float _height; -float _ypos; - -struct vsIn { - float4 pos : SV_POSITION; - float3 norm : NORMAL0; - float2 uv : TEXCOORD0; - float4 col : COLOR0; -}; -struct psIn { - float4 pos : SV_POSITION; - float3 campos : NORMAL0; - float3 world : NORMAL1; - float3 norm : NORMAL2; - float2 uv : TEXCOORD0; - 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; - - o.campos = sk_camera_pos[o.view_id].xyz; - o.world = mul(input.pos, sk_inst[id].world).xyz; - o.pos = mul(float4(o.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; - float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1))); - lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2; - o.color.rgb = o.color.rgb * lighting; // * sk_inst[id].color; - return o; -} - -float3 cross(float3 a, float3 b) { - return float3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); -} - -float dot(float3 a, float3 b) { - return a.x * b.x + a.y * b.y + a.z * b.z; -} - -float4 ps(psIn input) : SV_TARGET { - float4 col = float4(0, 0, 0, 0); - if (input.world.y - _ypos > (_height / 2.0) - 0.06) { - col = float4(1,1,1,1) * 0.25 * dot(input.world, input.norm); - if (input.norm.y > 0) { - col = float4(1,1,1,1) * 0.025; - } - } - return col; -} \ No newline at end of file diff --git a/add/oriel.hlsl b/add/oriel.hlsl index c2adb02..eba21d6 100644 --- a/add/oriel.hlsl +++ b/add/oriel.hlsl @@ -7,6 +7,7 @@ float _height; float _ypos; float3 _dimensions; float3 _center; +float _crown; Texture2D tex; // : register(t0); SamplerState tex_s; // : register(s0); @@ -114,19 +115,19 @@ float map(float3 pos) { float sphere = sdSphere(pos + spin - _center, 0.1); // return sdLink(pos, 0.1, 0.1, 0.1); // float octo = sdOctahedron(pos - _center - position, 0.2); - float frame = sdBoxFrame(pos - _center - position, float3(0.06, 0.06, 0.06), 0.004); + // float frame = sdBoxFrame(pos - _center - position, float3(0.06, 0.06, 0.06), 0.004); - float orielFrame = sdBoxFrame(pos - _center, _dimensions / 2, 0.0006); - float3 d = _dimensions / 2; - d.y = _height; + // float orielFrame = sdBoxFrame(pos - _center, _dimensions / 2, 0.0006); + // float3 d = _dimensions / 2; + // d.y = _height; + // float orielCrown = sdBoxFrame(pos - _center, d, 0.000); - float orielCrown = sdBoxFrame(pos - _center, d, 0.000); - // float box = sdBox(pos - _center, _dimensions / 2.1); + float box = sdBox(pos - _center, float3(0.1, 0.1, 0.1)); // return lerp(sphere, octo, time); float plane = sdPlane(pos + float3(0, 1.5, 0), float3(0, 1, 0), 0); // float blendd = lerp(octo, frame, time); - return min(plane, sphere); + return min(min(plane, sphere), box); } float raymarch(float3 ro, float3 rd) { @@ -203,6 +204,8 @@ psOut ps(psIn input) { dif *= ao * sh; col = float3(0.1, 0.5, 0.3) * amb + float3(0.6, 0.8, 0.3) * dif; + + // if (sdBox(pos - _center, _dimensions / 2) == 0.0) { // float4 clipPos = mul(float4(pos, 1), sk_viewproj[input.view_id]); // float near = 0.0; @@ -216,7 +219,7 @@ psOut ps(psIn input) { // input.color = float4(col, 1); - if (input.world.y > (_center.y + _dimensions.y / 2.0 ) - 0.0666) { + if (input.world.y > (_center.y + _dimensions.y / 2.0 ) - _crown) { float value = (col.r + col.r + col.g + col.g + col.g + col.b) / 6; float lit = abs((1 - clamp(dot(input.norm, lightDir), -1.0, 1.0)) / 2); value = (1 + lit + value) / 3; diff --git a/app/Monolith.cs b/app/Monolith.cs index 9d4b206..dd6f72e 100644 --- a/app/Monolith.cs +++ b/app/Monolith.cs @@ -76,10 +76,6 @@ public class Monolith { camMat.SetTexture("diffuse", camTex); Mesh quad = Default.MeshQuad; - bool draggingOriel = false; - Vec3 orielOffset = Vec3.Zero; - - Vec3 gripPos = Vec3.Zero; bool rightGripping = false, leftGripping = false; bool gripLeft = false; @@ -410,24 +406,7 @@ public class Monolith { - if (rCon.trigger > 0.5f && lCon.trigger > 0.5f) { - if (!draggingOriel) { - if (oriel.bounds.Contains(net.me.cursor0) || oriel.bounds.Contains(net.me.cursor3)) { - draggingOriel = true; - } - } else { - oriel.bounds.center = Vec3.Lerp(net.me.cursor0, net.me.cursor3, 0.5f); - // - float distX = Math.Abs(net.me.cursor0.x - net.me.cursor3.x); - float distY = Math.Abs(net.me.cursor0.y - net.me.cursor3.y); - float distZ = Math.Abs(net.me.cursor0.z - net.me.cursor3.z); - oriel.bounds.dimensions = new Vec3(distX, distY, distZ); - } - } else { - draggingOriel = false; - } - - oriel.Step(net.me.cursor0); + oriel.Step(net.me.cursor0, net.me.cursor3); // otherOriel.bounds.center = Vec3.Forward * -2; // otherOriel.Step(); diff --git a/app/Oriel.cs b/app/Oriel.cs index c90416d..ab1d71e 100644 --- a/app/Oriel.cs +++ b/app/Oriel.cs @@ -12,35 +12,63 @@ struct BufferData { public class Oriel { public Bounds bounds; Material mat = new Material(Shader.FromFile("oriel.hlsl")); - Material crown = new Material(Shader.FromFile("crown.hlsl")); Mesh mesh = Default.MeshCube; - Mesh quad = Default.MeshQuad; - Vec3 _dimensions; + public float crown = 0.0666f; + + bool scalingOriel = false; + bool draggingOriel = false; + Vec3 orielOffset = Vec3.Zero; MaterialBuffer buffer; public void Start(int bufferIndex) { bounds = new Bounds(Vec3.Zero, new Vec3(1f, 0.5f, 0.5f)); - _dimensions = bounds.dimensions; buffer = new MaterialBuffer(bufferIndex); } BufferData data = new BufferData(); - public void Step(Vec3 p0) { - data.position = p0; - // data.a = new Color(1.0f, 0.5f, 0.5f); - // data.b = new Color(0.5f, 1.0f, 0.5f); - // data.c = new Color(0.5f, 0.5f, 1.0f); - // data.tri = new Vec3[] { - // new Vec3(0, 0, 0), - // new Vec3(0, 0, 1), - // new Vec3(1, 0, 0), - // }; + public void Step(Vec3 cursor0, Vec3 cursor3) { + Controller rCon = Input.Controller(Handed.Right); + Controller lCon = Input.Controller(Handed.Left); + + if (rCon.trigger > 0.5f && lCon.trigger > 0.5f) { + if (!scalingOriel) { + if (bounds.Contains(cursor0) || bounds.Contains(cursor3)) { + scalingOriel = true; + } + } else { + bounds.center = Vec3.Lerp(cursor0, cursor3, 0.5f); + float distX = Math.Abs(cursor0.x - cursor3.x); + float distY = Math.Abs(cursor0.y - cursor3.y); + float distZ = Math.Abs(cursor0.z - cursor3.z); + bounds.dimensions = new Vec3(distX, distY, distZ); + } + } else { + scalingOriel = false; + } + + if (!scalingOriel && rCon.trigger > 0.5f) { + if (!draggingOriel) { + bool inCrown = cursor0.y > (bounds.center.y + bounds.dimensions.y / 2.0) - crown; + if (bounds.Contains(cursor0) && inCrown) { + orielOffset = cursor0 - bounds.center; + draggingOriel = true; + } + } else { + bounds.center = cursor0 - orielOffset; + } + } else { + draggingOriel = false; + } + + + + + data.position = cursor0; data.time = (float)Time.Total; buffer.Set(data); - // circle around center // bounds.center = Quat.FromAngles(0, 0, Time.Totalf * 60) * Vec3.Up * 0.3f; // bounds.dimensions = _dimensions * (1f + (MathF.Sin(Time.Totalf * 3) * 0.3f)); @@ -54,37 +82,11 @@ public class Oriel { mat.SetFloat("_distmax", 1000); mat.SetVector("_dimensions", bounds.dimensions); mat.SetVector("_center", bounds.center); - // mat.Wireframe = true; + mat.SetFloat("_crown", crown); Matrix m = Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions); Pose head = Input.Head; - // Vec3 quadPos = head.position + head.Forward * 0.0021f; - // if (bounds.Contains(head.position, head.position, 0.036f)) { - // mat.FaceCull = Cull.Front; - // m = Matrix.TRS(head.position, head.orientation, new Vec3(1.0f, 0.5f, 0.0088f * 2)); - // Renderer. - // } + mesh.Draw(mat, m); - - // if (bounds.Contains(head.position, quadPos)) { - // quad.Draw(mat, Matrix.TRS(quadPos, Quat.LookAt(quadPos, head.position), Vec3.One * 0.5f)); - // } - - // instead of a quad, just slap the same mesh to the head - - - // crown.SetVector("_center", bounds.center); - - - // crown.SetFloat("_height", bounds.dimensions.y); - // crown.SetFloat("_ypos", bounds.center.y); - // crown.FaceCull = Cull.Front; - // crown.Transparency = Transparency.Add; - // crown.DepthTest = DepthTest.Always; - - // // crown.QueueOffset = 0; - // // crown.DepthWrite = false; - - // mesh.Draw(crown, Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions)); } } \ No newline at end of file diff --git a/oriels.csproj b/oriels.csproj index aee5575..cf1a7d3 100644 --- a/oriels.csproj +++ b/oriels.csproj @@ -20,13 +20,11 @@ - -