From ea9c782fd9dd4b0809cb4a110e07e5d6a30e7f15 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Sun, 16 Jul 2023 16:05:44 -0400 Subject: [PATCH] polish --- add/shaders/window.hlsl | 62 +++++++++++++++++++++++++++++++++++++++++ src/Mono.cs | 18 +++++++++--- src/_Init.cs | 2 ++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 add/shaders/window.hlsl diff --git a/add/shaders/window.hlsl b/add/shaders/window.hlsl new file mode 100644 index 0000000..3d9af00 --- /dev/null +++ b/add/shaders/window.hlsl @@ -0,0 +1,62 @@ +#include "stereokit.hlsli" + +//--name = dofdev/window + +//--color:color = 1,1,1,1 +//--tex_scale = 1 +//--diffuse = white +//--clearcolor:color = 0,0,0,0 + +float4 color; +float tex_scale; +Texture2D diffuse : register(t0); +SamplerState diffuse_s : register(s0); +float4 clearcolor; + +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; + float4 world : WORLD; + float4 color : COLOR0; + float3 campos : TEXCOORD1; + 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); + o.pos = mul(o.world, sk_viewproj[o.view_id]); + + o.norm = normalize(mul(input.norm, (float3x3)sk_inst[id].world)); + + o.uv = input.uv * tex_scale; + o.color = color * input.col * sk_inst[id].color; + o.color.rgb *= Lighting(o.norm); + // o.color.rgb *= sk_lighting(o.normal); + return o; +} + +float4 ps(psIn input) : SV_TARGET { + float glow = FingerGlow(input.world.xyz, input.norm); + // glow = 0; + float4 col = float4(lerp(input.color.rgb, float3(2,2,2), glow), input.color.a); + + // clip(input.world.y); + + // float4 col = diffuse.Sample(diffuse_s, input.uv); + // col = col * input.color; + + return col; +} \ No newline at end of file diff --git a/src/Mono.cs b/src/Mono.cs index f199b23..0d3c2dd 100644 --- a/src/Mono.cs +++ b/src/Mono.cs @@ -201,14 +201,23 @@ public class Mono { } int dofIndex = 0; - Pose windowPose = new Pose(0, 1.5f, -0.5f, Quat.FromAngles(0, 0, 0)); - TextStyle style = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, Color.White); + Pose windowPose = new Pose(0, 1.2f, -0.6f, Quat.FromAngles(0, 180, 0)); + Material windowMat = new Material(Shader.FromFile("window.hlsl")); + TextStyle style = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, Color.Black); TextStyle style2 = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, new Color(0.5f, 0.5f, 0.5f)); Vec2 fieldSize = new Vec2(6f * U.cm, 3f * U.cm); void ShowWindowButton() { + windowMat.Transparency = Transparency.Add; + windowMat.FaceCull = Cull.None; + windowMat.DepthWrite = false; + UI.SetElementVisual(UIVisual.WindowBody, Mesh.Quad, windowMat, Vec2.One); + UI.SetElementVisual(UIVisual.WindowHead, Mesh.Quad, windowMat, Vec2.One); UI.WindowBegin("design vars", ref windowPose); - UI.SetThemeColor(UIColor.Background, new Color(0f, 0f, 0f)); - UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f)); + // UI.SetThemeColor(UIColor.Primary, new Color(1f, 1f, 1f)); + // UI.HandleBegin("design", ref windowPose, new Bounds(V.XYZ(0.02f, 0.02f, 0.02f)), true, UIMove.FaceUser); + UI.SetThemeColor(UIColor.Background, new Color(0.2f, 0.2f, 0.3f)); + UI.SetThemeColor(UIColor.Primary, new Color(0.4f, 0.4f, 0.6f)); + UI.SetThemeColor(UIColor.Common, new Color(1.0f, 1.0f, 1.0f)); UI.PushTextStyle(style); // if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; } @@ -265,6 +274,7 @@ public class Mono { } UI.WindowEnd(); + // UI.HandleEnd(); } void RenderDof(Interaction dof) { diff --git a/src/_Init.cs b/src/_Init.cs index d977c5c..2919029 100644 --- a/src/_Init.cs +++ b/src/_Init.cs @@ -17,6 +17,8 @@ Input.HandSolid(Handed.Max, false); Input.HandVisible(Handed.Max, true); // Input.HandMaterial(Handed.Max, Material.Default); +Renderer.Scaling = 2; +Renderer.Multisample = 0; Renderer.SetClip(0.02f, 100f); Renderer.EnableSky = false; Renderer.ClearColor = new Color(0f / 256f, 162f / 256f, 206f / 256f);