as above so below
This commit is contained in:
parent
e5468d2403
commit
9befafe2d5
9 changed files with 244 additions and 26 deletions
68
add/shaders/above.hlsl
Normal file
68
add/shaders/above.hlsl
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include "stereokit.hlsli"
|
||||
|
||||
//--name = dofdev/above
|
||||
|
||||
//--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;
|
||||
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]);
|
||||
|
||||
float3 normal = 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(normal);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 ps(psIn input) : SV_TARGET {
|
||||
// clip(input.world.y);
|
||||
|
||||
float4 col = diffuse.Sample(diffuse_s, input.uv);
|
||||
col = col * input.color;
|
||||
|
||||
if (input.world.y < 0) {
|
||||
col.r = col.r * 0.0;
|
||||
col.g = col.g * 0.0;
|
||||
col.b = col.b * 0.3;
|
||||
|
||||
col.rgb *= 0.1;
|
||||
} else {
|
||||
col.rgb = lerp(col.rgb, float3(0.3, 1, 0.2), (input.world.y / 20));
|
||||
}
|
||||
|
||||
// dist magnitude from center X0Z
|
||||
float dist = max(1 - (length(input.world.xz) / 10.0), 0.0);
|
||||
return lerp(clearcolor, col, 1 - ((1 - dist) * (1 - dist)));
|
||||
}
|
99
add/shaders/below.hlsl
Normal file
99
add/shaders/below.hlsl
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include "stereokit.hlsli"
|
||||
|
||||
//--name = dofdev/below
|
||||
|
||||
//--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;
|
||||
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.world.y = -o.world.y;
|
||||
o.pos = mul(o.world, sk_viewproj[o.view_id]);
|
||||
|
||||
float3 normal = 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(normal);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 ps(psIn input) : SV_TARGET {
|
||||
clip(-input.world.y);
|
||||
|
||||
float4 col = diffuse.Sample(diffuse_s, input.uv);
|
||||
col = col * input.color;
|
||||
|
||||
// dot product of the view direction and the normal
|
||||
float3 tocam = normalize(input.campos - input.world.xyz);
|
||||
float3 normal = normalize(float3(0, 1, 0));
|
||||
float dotprod = max(dot(tocam, normal), 0.0);
|
||||
float radians = acos(dotprod);
|
||||
float degrees = radians * 180.0 / 3.14159;
|
||||
float a = input.world.y * 2.0;
|
||||
// float bdeg = (1.0 - dotprod) * 90.0;
|
||||
float bdeg = degrees;
|
||||
float angle = 180.0 - (bdeg * 2.0);
|
||||
|
||||
// float depth = max(1.0 - (input.world.y / -3.0), 0.0);
|
||||
float x = angle / 180.0;
|
||||
x = 1 - x;
|
||||
x = x * 0.1;
|
||||
x = x + 0.9;
|
||||
|
||||
// dist magnitude from center X0Z
|
||||
float dist = max(1 - (length(input.world.xz) / 10.0), 0.0);
|
||||
float t = (x * x) * (dist * dist);
|
||||
// bluer
|
||||
col.r *= 1 - (t / 10);
|
||||
col.g *= 1 - (t / 10);
|
||||
|
||||
col.rgb = lerp(col.rgb, float3(0.3, 1, 0.2), (-input.world.y / 20));
|
||||
|
||||
return lerp(clearcolor, col, t);
|
||||
|
||||
|
||||
// float r = (a / sin(angle)) * sin(bdeg);
|
||||
|
||||
// float3 topWorld = float3(input.world.x, 0, input.world.z);
|
||||
// float3 camWorld = float3(input.campos.x, 0, input.campos.z);
|
||||
// float3 proj = normalize(camWorld - topWorld);
|
||||
|
||||
// float3 reflectionPoint = topWorld + (proj * r);
|
||||
|
||||
// float val = max(dot(normalize(input.campos - reflectionPoint), normal), 0.0);
|
||||
|
||||
// return col * val;
|
||||
|
||||
|
||||
|
||||
}
|
36
app/Mono.cs
36
app/Mono.cs
|
@ -7,7 +7,10 @@ public class Mono {
|
|||
public PullRequest.Noise noise = new PullRequest.Noise(939949595);
|
||||
|
||||
public Material matDev;
|
||||
public Material matHolo;
|
||||
public Material matHoloframe = new Material(Shader.FromFile("shaders/above.hlsl"));
|
||||
Material matHoloframeUnder = new Material(Shader.FromFile("shaders/below.hlsl"));
|
||||
public Material matHolo = new Material(Shader.FromFile("shaders/above.hlsl"));
|
||||
Material matHoloUnder = new Material(Shader.FromFile("shaders/below.hlsl"));
|
||||
|
||||
public Rig rig = new Rig();
|
||||
public Space space = new Space();
|
||||
|
@ -65,13 +68,24 @@ public class Mono {
|
|||
|
||||
matDev = Material.Default.Copy();
|
||||
matDev.SetTexture("diffuse", Tex.DevTex);
|
||||
matHolo = Material.Default.Copy();
|
||||
matHolo.Transparency = Transparency.Add;
|
||||
matHolo.DepthWrite = false;
|
||||
// matHolo.DepthTest = DepthTest.Always;
|
||||
matHolo.FaceCull = Cull.None;
|
||||
// matHolo.SetTexture("diffuse", Tex.DevTex);
|
||||
matHolo.Wireframe = true;
|
||||
|
||||
matHolo.SetColor("clearcolor", Renderer.ClearColor);
|
||||
matHoloUnder.SetColor("clearcolor", Renderer.ClearColor);
|
||||
matHoloUnder.FaceCull = Cull.None;
|
||||
matHolo.Chain = matHoloUnder;
|
||||
|
||||
|
||||
matHoloframe.SetColor("clearcolor", Color.Black);
|
||||
matHoloframe.Transparency = Transparency.Add;
|
||||
matHoloframe.DepthWrite = false;
|
||||
matHoloframe.FaceCull = Cull.None;
|
||||
matHoloframe.Wireframe = true;
|
||||
matHoloframeUnder.SetColor("clearcolor", Color.Black);
|
||||
matHoloframeUnder.Transparency = Transparency.Add;
|
||||
matHoloframeUnder.DepthWrite = false;
|
||||
matHoloframeUnder.FaceCull = Cull.None;
|
||||
matHoloframeUnder.Wireframe = true;
|
||||
matHoloframe.Chain = matHoloframeUnder;
|
||||
}
|
||||
|
||||
public void Frame() {
|
||||
|
@ -120,6 +134,7 @@ public class Mono {
|
|||
if (rtb.Active) {
|
||||
rtb.Demo();
|
||||
}
|
||||
|
||||
// </Heresy>
|
||||
|
||||
// rBlock.Step(); lBlock.Step();
|
||||
|
@ -322,6 +337,11 @@ public class Design {
|
|||
demo
|
||||
virtual shapes -> that can be slotted
|
||||
physics boxes
|
||||
|
||||
mirror
|
||||
mirroring vectors(line segments) is really easy
|
||||
easier than rendering.. actually just render twice with the material chain
|
||||
stereonick mentioned
|
||||
|
||||
debug bool
|
||||
rendering the raw output
|
||||
|
|
34
app/Space.cs
34
app/Space.cs
|
@ -13,8 +13,8 @@ public class Space {
|
|||
BufferData data = new BufferData();
|
||||
|
||||
Material matFloor = new Material(Shader.Default);
|
||||
Model shed = Model.FromFile("shed/shed.glb", Shader.FromFile("/shaders/room.hlsl"));
|
||||
Model leek = Model.FromFile("houseleek_plant.glb", Shader.FromFile("/shaders/room.hlsl"));
|
||||
Model shed = Model.FromFile("shed/shed.glb", Shader.FromFile("shaders/room.hlsl"));
|
||||
Model leek = Model.FromFile("houseleek_plant.glb", Shader.FromFile("shaders/room.hlsl"));
|
||||
Mesh cube = Mesh.Cube;
|
||||
|
||||
Solid floor;
|
||||
|
@ -104,6 +104,34 @@ public class Space {
|
|||
|
||||
shed.Draw(Matrix.Identity);
|
||||
|
||||
leek.Draw(Matrix.TRS(new Vec3(2.5f, 0, -2.5f) * 1.2f, Quat.FromAngles(180f, 30f, 0f), 1.2f));
|
||||
// leek.Draw(Matrix.TRS(new Vec3(2.5f, 0, -2.5f) * 1.2f, Quat.FromAngles(180f, 30f, 0f), 1.2f));
|
||||
|
||||
// draw grid of pillars
|
||||
float radius = 9;
|
||||
Vec3 pillarsOffset = new Vec3(0, 0, -10);
|
||||
for (float x = -radius; x < radius; x++) {
|
||||
for (float z = -radius; z < radius; z++) {
|
||||
float height = 3f;
|
||||
Mesh.Cube.Draw(
|
||||
Mono.inst.matHolo,
|
||||
Matrix.TRS(
|
||||
new Vec3(pillarsOffset.x + x, (height * 0.5f), pillarsOffset.z - z),
|
||||
Quat.FromAngles(0, 0, 0),
|
||||
new Vec3(0.1f, height, 0.1f)
|
||||
),
|
||||
new Color(1f, 1f, 1f, 1f)
|
||||
);
|
||||
|
||||
Mesh.Cube.Draw(
|
||||
Mono.inst.matHolo,
|
||||
Matrix.TRS(
|
||||
new Vec3(pillarsOffset.x + x, height, pillarsOffset.z - z),
|
||||
Quat.FromAngles(0, 0, 0),
|
||||
new Vec3(0.95f, 1f, 0.95f)
|
||||
),
|
||||
new Color(0.3f, 1f, 0.2f, 1f)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,11 +16,10 @@ if (!SK.Initialize(settings))
|
|||
Input.HandSolid(Handed.Max, false);
|
||||
Input.HandVisible(Handed.Max, true);
|
||||
Renderer.EnableSky = false;
|
||||
Renderer.ClearColor = new Color(0f, 0f, 0f);
|
||||
Renderer.ClearColor = new Color(0f / 256f, 162f / 256f, 206f / 256f);
|
||||
|
||||
Oriels.Mono mono = Oriels.Mono.inst;
|
||||
mono.Init();
|
||||
SK.Run(() => {
|
||||
mono.Frame();
|
||||
});
|
||||
// SK.Shutdown();
|
||||
});
|
|
@ -304,12 +304,12 @@ public class Oriel {
|
|||
}
|
||||
}
|
||||
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo,
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe,
|
||||
Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.02f, 0.02f)),
|
||||
cursorColor
|
||||
);
|
||||
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo,
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe,
|
||||
Matrix.TS(cursor, new Vec3(1f, 1f, 1f) * cursorRadius * 2),
|
||||
new Color(0.1f, 0.1f, 0.1f)
|
||||
);
|
||||
|
|
|
@ -43,9 +43,9 @@ class WaveCursor : dof {
|
|||
cursor.pos.z = (float)zF.Filter(cursor.raw.z, (double)Time.Elapsedf);
|
||||
cursor.smooth = Vec3.Lerp(cursor.smooth, cursor.pos, Time.Elapsedf * 6f);
|
||||
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0));
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1));
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0));
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1));
|
||||
|
||||
|
||||
// pinch is more than just the thumb and index finger
|
||||
|
@ -141,7 +141,7 @@ class WaveCursor : dof {
|
|||
Vec3 from = i > 0 ? points[i - 1] : nextPos;
|
||||
Quat ori = Quat.LookDir(Vec3.Direction(points[i], from));
|
||||
Mesh.Cube.Draw(
|
||||
Mono.inst.matHolo,
|
||||
Mono.inst.matHoloframe,
|
||||
Matrix.TRS(
|
||||
points[i] + ori * new Vec3(0, 0, 0.01f) * scale,
|
||||
ori,
|
||||
|
|
|
@ -48,7 +48,7 @@ class Trackballer : dof {
|
|||
thumbJoint.orientation,
|
||||
new Vec3(handed == Handed.Left ? -1f : 1f, 1f, 1f) * 0.1666f
|
||||
);
|
||||
mesh.Draw(Mono.inst.matHolo, pad, new Color(0, 1, 1));
|
||||
mesh.Draw(Mono.inst.matHoloframe, pad, new Color(0, 1, 1));
|
||||
|
||||
// Ball anchor
|
||||
HandJoint ballJoint = hand.Get(FingerId.Index, JointId.KnuckleMajor);
|
||||
|
@ -97,7 +97,7 @@ class Trackballer : dof {
|
|||
btnPull.Frame(pull > 1f, pull > 0.333f); // magic sticky var
|
||||
|
||||
float pullScalar = btnPull.held ? MathF.Max((pull - 0.333f) / 0.666f, 0) : MathF.Max(1 - pull, 0);
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo,
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe,
|
||||
Matrix.TRS(anchorPos, thumbJoint.orientation, pullScalar * radius.value),
|
||||
new Color(0, 1, 1) * (btnPull.held ? 1f : 0.0666f)
|
||||
);
|
||||
|
@ -105,7 +105,7 @@ class Trackballer : dof {
|
|||
anchor.Transform(point), anchorPos,
|
||||
new Color(0, 1, 1), 1f * U.mm
|
||||
);
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo,
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe,
|
||||
Matrix.TRS(anchor.Transform(point), thumbJoint.orientation, 2f * U.mm),
|
||||
new Color(0, 1, 1)
|
||||
);
|
||||
|
@ -116,7 +116,7 @@ class Trackballer : dof {
|
|||
btnPush.Frame(push > 1f, push > 0.333f); // magic sticky var
|
||||
|
||||
float pushScalar = btnPush.held ? MathF.Max((MathF.Min(push, 1f) - 0.333f) / 0.666f, 0) : MathF.Max(1 - push, 0);
|
||||
Mesh.Sphere.Draw(Mono.inst.matHolo,
|
||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe,
|
||||
Matrix.TRS(anchorPos, ori, (radius.value * 2) * pushScalar),
|
||||
new Color(1, 0, 0) * (btnPush.held ? 1f : 0.2f)
|
||||
);
|
||||
|
@ -148,7 +148,7 @@ class Trackballer : dof {
|
|||
|
||||
// Draw ball result
|
||||
Mesh.Sphere.Draw(
|
||||
Mono.inst.matHolo,
|
||||
Mono.inst.matHoloframe,
|
||||
Matrix.TRS(anchorPos, ori, radius.value * 2),
|
||||
new Color(0.8f, 0, 0)
|
||||
);
|
||||
|
@ -178,7 +178,7 @@ class Trackballer : dof {
|
|||
float width = 52 * U.cm;
|
||||
float height = 29f * U.cm;
|
||||
Mesh.Quad.Draw(
|
||||
Mono.inst.matHolo,
|
||||
Mono.inst.matHoloframe,
|
||||
Matrix.S(new Vec3(width, height, 1)) * panel,
|
||||
new Color(1, 1, 1)
|
||||
);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<None Remove="add/shaders/panes.hlsl" />
|
||||
<None Remove="add/shaders/frame.hlsl" />
|
||||
<None Remove="add/shaders/room.hlsl" />
|
||||
<None Remove="add/shaders/above.hlsl" />
|
||||
<None Remove="add/shaders/below.hlsl" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -30,6 +32,8 @@
|
|||
<SKShader Include="add/shaders/panes.hlsl" />
|
||||
<SKShader Include="add/shaders/frame.hlsl" />
|
||||
<SKShader Include="add/shaders/room.hlsl" />
|
||||
<SKShader Include="add/shaders/above.hlsl" />
|
||||
<SKShader Include="add/shaders/below.hlsl" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Add table
Reference in a new issue