multi oriel draft

This commit is contained in:
spatialfree 2022-10-19 02:42:07 -04:00
parent fa5f92ead1
commit 90b058786d
12 changed files with 488 additions and 207 deletions

View file

@ -51,7 +51,11 @@ psIn vs(vsIn input, uint id : SV_InstanceID) {
} }
float3 cross(float3 a, float3 b) { 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); 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) { float dot(float3 a, float3 b) {
@ -74,7 +78,21 @@ float raymarch(float3 origin, float3 direction) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
float3 pos = origin + dist * direction; float3 pos = origin + dist * direction;
float step = sdBox(pos, _dimensions / 2.0); float step = sdBox(pos, _dimensions / 2.0);
if (step < 0.0001 || dist > 100) break; // 100 == distmax if (step < 0.0001 || dist > 100) break; // 100 == distmax
dist += step;
}
return dist;
}
float raymarchy(float3 origin, float3 direction) {
origin = mul(float4(origin, 1), _matrix).xyz;
direction = mul(float4(direction, 0), _matrix).xyz;
float dist = 0.0;
for (int i = 0; i < 256; i++) {
float3 pos = origin + dist * direction;
float step = sdBox(pos, _dimensions / 4.0);
if (step < 0.0001 || dist > 100) break; // 100 == distmax
dist += step; dist += step;
} }
@ -93,6 +111,18 @@ psOut ps(psIn input) {
origin += ol * direction; origin += ol * direction;
float oll = raymarchy(origin, direction);
if (oll < 99) {
o.color = float4(1, 1, 1, 1);
float3 origin2 = origin + oll * direction;
float4 og = mul(float4(origin2, 1), sk_viewproj[input.view_id]);
// o.depth = og.z;
o.depth = (og * rcp(og.w)).z;
return o;
}
clip(distance(input.campos, input.world) - distance(input.campos, origin)); clip(distance(input.campos, input.world) - distance(input.campos, origin));
float t = 1 - (1 + dot(input.normal, _light)) / 2; float t = 1 - (1 + dot(input.normal, _light)) / 2;

View file

@ -61,9 +61,9 @@ float sdSphere(float3 p, float r) {
return length(p) - r; return length(p) - r;
} }
float raymarch(float3 ro, float3 rd) { float raymarch(float4x4 m, float3 ro, float3 rd) {
ro = mul(float4(ro, 1), oriel_matrix).xyz; ro = mul(float4(ro, 1), m).xyz;
rd = mul(float4(rd, 0), oriel_matrix).xyz; rd = mul(float4(rd, 0), m).xyz;
float dist = 0.0; float dist = 0.0;
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
float3 pos = ro + dist * rd; float3 pos = ro + dist * rd;
@ -101,7 +101,7 @@ float4 ps(psIn input) : SV_TARGET {
float3 ro = input.campos; float3 ro = input.campos;
float3 rd = normalize(input.world - ro); float3 rd = normalize(input.world - ro);
float ol = raymarch(ro, rd); float ol = raymarch(oriel_matrix, ro, rd);
clip(-(100 - (ol + 1))); clip(-(100 - (ol + 1)));
// if ((100 - (ol + 1)) > 0) { // if ((100 - (ol + 1)) > 0) {
@ -122,5 +122,5 @@ float4 ps(psIn input) : SV_TARGET {
// float value = (col.r + col.r + col.g + col.g + col.g + col.b) / 6; // float value = (col.r + col.r + col.g + col.g + col.g + col.b) / 6;
// return float4(value, value, value, 1); // return float4(value, value, value, 1);
return col; return col * 0.333;
} }

126
app/Backrooms/Mono.cs Normal file
View file

@ -0,0 +1,126 @@
using Oriels;
namespace Backrooms;
public class Mono {
public Oriel oriel = new Oriel(
new Vec3(-1.0f,-0.5f, 0.5f),
Quat.FromAngles(0, 90, 0),
new Vec3( 0.8f, 0.5f, 0.5f)
) { color = new Color(0, 0, 0) };
Matrix matrix = Matrix.Identity;
Vec3 offset = new Vec3(2, 1, -2);
public float height = 1f;
Vec3 angle = new Vec3(0, 0, 0);
Thing[] thing;
Model model = Model.FromFile("/backrooms/backrooms.glb");
public void Init() {
thing = new Thing[] {
new Thing(
model.GetMesh("Carpet"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Carpet.png"
),
new Thing(
model.GetMesh("Walls"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Walls.png"
),
new Thing(
model.GetMesh("Ceiling"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Ceiling.png"
),
new Thing(
model.GetMesh("Vents"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Vents.png"
),
new Thing(
model.GetMesh("Lights"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Lights.png"
),
};
}
public void Frame() {
Oriels.Rig rig = Oriels.Mono.inst.rig;
// angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf;
// angle.x = PullRequest.Clamp(angle.x, -89, 89);
angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf;
Vec3 input = new Vec3(
rig.lCon.device.stick.x,
0,
rig.lCon.device.stick.y
);
if (input.MagnitudeSq > 0.01f) {
input = (
// Quat.FromAngles(angle.x, 0, 0).Inverse *
Quat.FromAngles(0, angle.y, 0).Inverse *
rig.lCon.ori *
oriel.ori.Inverse
).Normalized * input;
input.y = 0;
offset += input * Time.Elapsedf;
}
offset.y = -height;
// Oriel
float scale = 1f; // oriel.scale * oriel.multiplier;
// scale w/height?
// scale *= oriel.bounds.dimensions.y;
matrix = Matrix.TRS(
Vec3.Zero, // -oriel.bounds.dimensions.y / 2.01f
Quat.FromAngles(angle.x, 0, 0) *
Quat.FromAngles(0, angle.y, 0),
Vec3.One * scale
);
}
public void Render() {
for (int i = 0; i < thing.Length; i++) {
Thing t = thing[i];
t.mat.SetVector("_center", oriel.bounds.center);
t.mat.SetVector("_dimensions", oriel.bounds.dimensions);
t.mat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
t.mat.SetFloat("_lit", 0);
t.mat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
t.mesh.Draw(t.mat,
Matrix.TRS(
offset,
Quat.Identity,
new Vec3(1f, 1f, 1f)
) * matrix * oriel.matrix,
Color.White
);
}
}
}
// temp placement
[Serializable]
public class Thing {
public Mesh mesh;
public Material mat;
public Thing(Mesh mesh, Material mat, string tex) {
this.mesh = mesh;
this.mat = mat;
mat.SetMat(101, Cull.None, true);
// mat.Transparency = Transparency.Add;
// mat.DepthTest = DepthTest.Always;
mat.SetTexture("diffuse", Tex.FromFile(tex));
}
}

99
app/Compositor.cs Normal file
View file

@ -0,0 +1,99 @@
namespace Oriels;
public class Compositor {
// these are in a weird place,
// as a process would not be hosted by a compositor...
Backrooms.Mono backrooms = new Backrooms.Mono();
Greenyard.Mono greenyard = new Greenyard.Mono();
bool other = false;
public void Init() {
backrooms.Init();
greenyard.Init();
}
public void Frame() {
Mono mono = Mono.inst;
// backrooms.oriel.Frame();
// greenyard.oriel.Frame();
// // mono.space.Frame();
// Glove rGlove = Mono.inst.rGlove;
// Vec3 cursor = rGlove.virtualGlove.position;
// if (other) {
// greenyard.Frame();
// Vec3 localCursor = backrooms.oriel.matrixInv.Transform(cursor);
// if (backrooms.oriel.bounds.Contains(localCursor + backrooms.oriel.bounds.center)) {
// Console.WriteLine("in backrooms");
// other = false;
// }
// } else {
// backrooms.Frame();
// Vec3 localCursor = greenyard.oriel.matrixInv.Transform(cursor);
// if (greenyard.oriel.bounds.Contains(localCursor + greenyard.oriel.bounds.center)) {
// Console.WriteLine("in greenyard");
// other = true;
// }
// }
// render buffers ? or just use the depth buffer?
mono.space.Frame();
// backrooms.oriel.Render(); // -> Frame() by moving Input specific parts to the compositor?
// backrooms.Render();
// greenyard.oriel.Render();
// greenyard.Render();
// active oriel
// how to show this?
// well popping up a wireframe would get in the way and look bad
// and a glow would be hard to keep consistent across backgrounds
// am I bringing the crown back?
// matFrame.Wireframe = true;
// matFrame.DepthTest = DepthTest.Always;
// matFrame.SetVector("_cursor", cursor);
// matFrame.SetFloat("_time", Time.Totalf);
// Mesh.Cube.Draw(matFrame,
// Matrix.TRS(bounds.center, ori, bounds.dimensions),
// new Color(0.1f, 0.1f, 0.1f)
// );
// Model model = Model.FromFile("oriel.glb");
// ~ Mesh mesh = model.GetMesh("oriel");
}
void Place() {
}
}
/*
COMMENTS
mono (kernel)
compositor
oriel (client)
app
Frame and Render is not a useful distinction
cycle or loop or step instead of frame?
draw instead of render?
we keep combining the two, and it's not a good idea
as input can be polled at a higher frequency than rendering can be output?
Hertz & Frame
does a process ever not have a GUI? *can be hidden &| locked
we are trying to skip the tty!
would be nice to have a dedicated thread(s)
for essential GUI
*/

View file

@ -125,6 +125,14 @@ public class Glove {
Vec3 thumb = hand.Get(FingerId.Thumb, JointId.Tip).position - con.pos; Vec3 thumb = hand.Get(FingerId.Thumb, JointId.Tip).position - con.pos;
virtualGlove.position += Vec3.Lerp(index, thumb, 0.5f); virtualGlove.position += Vec3.Lerp(index, thumb, 0.5f);
Vec3 delta = virtualGlove.position - con.pos;
HandJoint[] joints = hand.fingers;
for (int i = 0; i < joints.Length; i++) {
joints[i].position += delta - Vec3.Lerp(index, thumb, 0.5f);
}
Input.HandOverride(chirality ? Handed.Right : Handed.Left, joints);
Render(con.pose, virtualGlove, wrist, stretch, twist, chirality); Render(con.pose, virtualGlove, wrist, stretch, twist, chirality);
} }
@ -168,3 +176,11 @@ public class Glove {
// model.Draw(glove.ToMatrix(Vec3.One / 10)); // model.Draw(glove.ToMatrix(Vec3.One / 10));
} }
} }
/*
COMMENTS
con -> hand
*/

View file

@ -2,145 +2,87 @@ using Oriels;
namespace Greenyard; namespace Greenyard;
public class Mono { public class Mono {
// Model greenyardModel = Model.FromFile("greenyard.glb"); public Oriel oriel = new Oriel(
// Mesh[] greenyard; new Vec3(0.0f, -0.5f, 0.5f),
// Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); Quat.FromAngles(0, 90, 0),
new Vec3(0.8f, 0.5f, 0.5f)
) { color = new Color(78 / 256f, 142 / 256f, 191 / 256f) * 0.333f };
Vec3 offset = new Vec3(2, 1, -2); Model greenyardModel = Model.FromFile("greenyard.glb");
public float height = 1f; Mesh[] greenyard;
Vec3 angle = new Vec3(0, 0, 0); Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
Thing[] thing; Matrix matrix = Matrix.Identity;
Model model = Model.FromFile("/backrooms/backrooms.glb"); Vec3 offset = new Vec3(2, 1, -12);
public float height = 6f;
Vec3 angle = new Vec3(0, 180, 0);
public Mono() { public void Init() {
greenyard = new Mesh[12];
} for (int i = 0; i < greenyard.Length; i++) {
greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2));
}
greenyardMat.SetMat(101, Cull.None, true);
// greenyardMat.Transparency = Transparency.Add;
// greenyardMat.DepthTest = DepthTest.Always;
greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg"));
}
public void Init() { public void Frame() {
// greenyard = new Mesh[12]; Oriels.Rig rig = Oriels.Mono.inst.rig;
// for (int i = 0; i < greenyard.Length; i++) {
// greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2));
// }
// greenyardMat.SetMat(101, Cull.None, true);
// greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg"));
thing = new Thing[] { // angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf;
new Thing( // angle.x = PullRequest.Clamp(angle.x, -89, 89);
model.GetMesh("Carpet"), angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf;
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Carpet.png"
),
new Thing(
model.GetMesh("Walls"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Walls.png"
),
new Thing(
model.GetMesh("Ceiling"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Ceiling.png"
),
new Thing(
model.GetMesh("Vents"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Vents.png"
),
new Thing(
model.GetMesh("Lights"),
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
"backrooms/Lights.png"
),
};
}
public void Frame() { Vec3 input = new Vec3(
Oriels.Rig rig = Oriels.Mono.inst.rig; rig.lCon.device.stick.x,
Oriels.Oriel oriel = Oriels.Mono.inst.oriel; 0,
rig.lCon.device.stick.y
// angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf; );
// angle.x = PullRequest.Clamp(angle.x, -89, 89); if (input.MagnitudeSq > 0.01f) {
angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf; input = (
// Quat.FromAngles(angle.x, 0, 0).Inverse *
Vec3 input = new Vec3( Quat.FromAngles(0, angle.y, 0).Inverse *
rig.lCon.device.stick.x, rig.lCon.ori *
0, oriel.ori.Inverse
rig.lCon.device.stick.y ).Normalized * input;
);
if (input.MagnitudeSq > 0.01f) { input.y = 0;
input = ( offset += input * Time.Elapsedf;
// Quat.FromAngles(angle.x, 0, 0).Inverse * }
Quat.FromAngles(0, angle.y, 0).Inverse * offset.y = -height;
rig.lCon.ori *
oriel.ori.Inverse
).Normalized * input;
input.y = 0;
offset += input * Time.Elapsedf;
}
offset.y = -height;
// Oriel // Oriel
float scale = oriel.scale * oriel.multiplier; float scale = 0.1f; // oriel.scale * oriel.multiplier;
if (oriel.scaleWithHeight) { // scale w/height?
scale *= oriel.bounds.dimensions.y; // scale *= oriel.bounds.dimensions.y;
}
Matrix simMatrix = Matrix.TRS( matrix = Matrix.TRS(
Vec3.Zero, // -oriel.bounds.dimensions.y / 2.01f Vec3.Zero, // -oriel.bounds.dimensions.y / 2.01f
Quat.FromAngles(angle.x, 0, 0) * Quat.FromAngles(angle.x, 0, 0) *
Quat.FromAngles(0, angle.y, 0), Quat.FromAngles(0, angle.y, 0),
Vec3.One * scale Vec3.One * scale
); );
}
// Render public void Render() {
// greenyardMat.SetVector("_center", oriel.bounds.center); greenyardMat.SetVector("_center", oriel.bounds.center);
// greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions); greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions);
// greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f)); greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
// greenyardMat.SetFloat("_lit", 0); greenyardMat.SetFloat("_lit", 0);
// greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
// for (int i = 0; i < greenyard.Length; i++) { for (int i = 0; i < greenyard.Length; i++) {
// greenyard[i].Draw(greenyardMat, greenyard[i].Draw(greenyardMat,
// Matrix.TRS( Matrix.TRS(
// offset, offset,
// Quat.Identity, Quat.Identity,
// new Vec3(1f, 1f, 1f) new Vec3(1f, 1f, 1f)
// ) * simMatrix * oriel.matrix, ) * matrix * oriel.matrix,
// Color.White Color.White
// ); );
// } }
}
for (int i = 0; i < thing.Length; i++) {
Thing t = thing[i];
t.mat.SetVector("_center", oriel.bounds.center);
t.mat.SetVector("_dimensions", oriel.bounds.dimensions);
t.mat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
t.mat.SetFloat("_lit", 0);
t.mat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
t.mesh.Draw(t.mat,
Matrix.TRS(
offset,
Quat.Identity,
new Vec3(1f, 1f, 1f)
) * simMatrix * oriel.matrix,
Color.White
);
}
}
}
[Serializable]
public class Thing {
public Mesh mesh;
public Material mat;
public Thing(Mesh mesh, Material mat, string tex) {
this.mesh = mesh;
this.mat = mat;
mat.SetMat(101, Cull.None, true);
mat.SetTexture("diffuse", Tex.FromFile(tex));
}
} }

View file

@ -219,7 +219,6 @@ public static class PullRequest {
// return Vec3.Lerp(a * (float)Math.Sin(theta - theta * t) / sinTheta, b * (float)Math.Sin(theta * t) / sinTheta, t); // return Vec3.Lerp(a * (float)Math.Sin(theta - theta * t) / sinTheta, b * (float)Math.Sin(theta * t) / sinTheta, t);
// } // }
[Serializable]
public class Noise { public class Noise {
const uint CAP = 4294967295; const uint CAP = 4294967295;
const uint BIT_NOISE1 = 0xB5297A4D; const uint BIT_NOISE1 = 0xB5297A4D;
@ -285,7 +284,6 @@ public static class PullRequest {
return MathF.Max(min, MathF.Min(max, v)); return MathF.Max(min, MathF.Min(max, v));
} }
[Serializable]
public class PID { public class PID {
public float p, i; public float p, i;
float integral = 0f; float integral = 0f;
@ -305,7 +303,6 @@ public static class PullRequest {
} }
} }
[Serializable]
public class Lerper { public class Lerper {
public float t = 0; public float t = 0;
public float spring = 1; public float spring = 1;
@ -335,4 +332,77 @@ public static class PullRequest {
t = vel = 0; t = vel = 0;
} }
} }
public class OneEuroFilter {
public OneEuroFilter(double minCutoff, double beta) {
firstTime = true;
this.minCutoff = minCutoff;
this.beta = beta;
xFilt = new LowpassFilter();
dxFilt = new LowpassFilter();
dcutoff = 1;
}
protected bool firstTime;
protected double minCutoff;
protected double beta;
protected LowpassFilter xFilt;
protected LowpassFilter dxFilt;
protected double dcutoff;
public double MinCutoff {
get { return minCutoff; }
set { minCutoff = value; }
}
public double Beta {
get { return beta; }
set { beta = value; }
}
public double Filter(double x, double rate) {
double dx = firstTime ? 0 : (x - xFilt.Last()) * rate;
if (firstTime) {
firstTime = false;
}
var edx = dxFilt.Filter(dx, Alpha(rate, dcutoff));
var cutoff = minCutoff + beta * Math.Abs(edx);
return xFilt.Filter(x, Alpha(rate, cutoff));
}
protected double Alpha(double rate, double cutoff) {
var tau = 1.0 / (2 * Math.PI * cutoff);
var te = 1.0 / rate;
return 1.0 / (1.0 + tau / te);
}
}
public class LowpassFilter {
public LowpassFilter() {
firstTime = true;
}
protected bool firstTime;
protected double hatXPrev;
public double Last() {
return hatXPrev;
}
public double Filter(double x, double alpha) {
double hatX = 0;
if (firstTime) {
firstTime = false;
hatX = x;
} else
hatX = alpha * x + (1 - alpha) * hatXPrev;
hatXPrev = hatX;
return hatX;
}
}
} }

View file

@ -82,7 +82,7 @@ public class Rig {
public class Con { public class Con {
public Controller device; public Controller device;
public Vec3 pos; public Vec3 pos;
public Quat ori; public Quat ori = Quat.Identity;
public Pose pose; public Pose pose;
public Vec3 backhandDir; public Vec3 backhandDir;
public Btn gripBtn; public Btn gripBtn;
@ -91,7 +91,7 @@ public class Con {
public void Step(bool chirality) { public void Step(bool chirality) {
device = Input.Controller(chirality ? Handed.Right : Handed.Left); device = Input.Controller(chirality ? Handed.Right : Handed.Left);
pose.position = pos = device.pose.position; pose.position = pos = device.pose.position;
pose.orientation = ori = device.aim.orientation; pose.orientation = ori = Quat.Identity; // device.pose.orientation;
backhandDir = ori * (chirality ? Vec3.Right : -Vec3.Right); backhandDir = ori * (chirality ? Vec3.Right : -Vec3.Right);
gripBtn.Step(device.grip > 0.5f); gripBtn.Step(device.grip > 0.5f);
triggerBtn.Step(device.trigger > 0.5f); triggerBtn.Step(device.trigger > 0.5f);

View file

@ -8,7 +8,7 @@ struct BufferData {
public float time; public float time;
} }
public class Scene { public class Space {
MaterialBuffer<BufferData> buffer; MaterialBuffer<BufferData> buffer;
BufferData data = new BufferData(); BufferData data = new BufferData();
@ -18,7 +18,7 @@ public class Scene {
Solid floor; Solid floor;
public Scene() { public Space() {
buffer = new MaterialBuffer<BufferData>(3); // index buffer = new MaterialBuffer<BufferData>(3); // index
@ -41,23 +41,19 @@ public class Scene {
public Vec3 floorScale; public Vec3 floorScale;
public void Step() { public void Frame() {
Oriel oriel = Mono.inst.oriel; // Oriel oriel = Mono.inst.oriel;
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); // data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
data.dimensions = oriel.bounds.dimensions; // data.dimensions = oriel.bounds.dimensions;
// data.dimensions = Vec3.Zero;
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(Matrix.T(Vec3.Up));
data.dimensions = new Vec3(0.1f, 0.1f, 0.1f);
buffer.Set(data); buffer.Set(data);
// PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.333f, matFloor); // PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.333f, matFloor);
// foreach (ModelNode node in shed.Visuals) { // foreach (ModelNode node in shed.Visuals) {

View file

@ -11,6 +11,11 @@ using Oriels;
namespace Space; namespace Space;
public class Mono { public class Mono {
public Oriel oriel = new Oriel(
new Vec3(1.0f, -0.5f, 0.5f),
Quat.Identity,
new Vec3(0.8f, 0.5f, 0.5f)
);
Node[] nodes = new Node[18]; Node[] nodes = new Node[18];
Vec3 playerPos; Vec3 playerPos;
List<Vec3> enemies = new List<Vec3>(); List<Vec3> enemies = new List<Vec3>();
@ -53,7 +58,6 @@ public class Mono {
public void Frame() { public void Frame() {
Oriels.Rig rig = Oriels.Mono.inst.rig; Oriels.Rig rig = Oriels.Mono.inst.rig;
Oriels.Oriel oriel = Oriels.Mono.inst.oriel;
Matrix simMatrix = Matrix.TRS( Matrix simMatrix = Matrix.TRS(
-playerPos * 0.5f * oriel.bounds.dimensions.y, //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z), -playerPos * 0.5f * oriel.bounds.dimensions.y, //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z),

View file

@ -15,6 +15,8 @@ if (!SK.Initialize(settings))
Input.HandSolid(Handed.Max, false); Input.HandSolid(Handed.Max, false);
Input.HandVisible(Handed.Max, true); Input.HandVisible(Handed.Max, true);
Renderer.EnableSky = false;
Renderer.ClearColor = new Color(0f, 0f, 0f);
Oriels.Mono mono = Oriels.Mono.inst; Oriels.Mono mono = Oriels.Mono.inst;
mono.Init(); mono.Init();

View file

@ -1,9 +1,6 @@
namespace Oriels; namespace Oriels;
public class Oriel { public class Oriel {
Model model = Model.FromFile("oriel.glb");
Mesh meshCube, meshSphere;
Material matClear = new Material(Shader.Default); Material matClear = new Material(Shader.Default);
public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl")); public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl"));
@ -13,31 +10,26 @@ public class Oriel {
public Matrix matrix, matrixInv; public Matrix matrix, matrixInv;
public Bounds bounds; public Bounds bounds;
public Quat ori = Quat.Identity; public Quat ori = Quat.Identity;
public Color color = new Color(0.5f, 0.5f, 0.5f);
// inner matrix public Oriel(Vec3 pos, Quat ori, Vec3 dimensions) {
public bool scaleWithHeight = false;
public float scale = 0.5f;
public float multiplier = 1f;
public Oriel() {
// meshCube = model.GetMesh("oriel");
meshCube = Mesh.Cube;
meshSphere = Mesh.Sphere;
matClear.Transparency = Transparency.Add; matClear.Transparency = Transparency.Add;
matFrame.SetMat(102, Cull.Back, true); matFrame.SetMat(102, Cull.Back, true);
matFrame.Transparency = Transparency.Blend; // matFrame.Transparency = Transparency.Add;
matFrame.SetTexture("dither", Tex.FromFile("dither.png")); matFrame.SetTexture("dither", Tex.FromFile("dither.png"));
matPanes.SetMat(100, Cull.Front, false);
matOriel.SetMat(101, Cull.None, true); matPanes.SetMat(100, Cull.Front, false); // true?
// matPanes.Transparency = Transparency.Add;
// matPanes.DepthTest = DepthTest.Always;
bounds = new Bounds( matOriel.SetMat(101, Cull.None, true);
new Vec3(-1.0f, -0.5f, 0.5f), // matOriel.Transparency = Transparency.Add;
// Vec3.Zero, // matOriel.DepthTest = DepthTest.Always;
new Vec3(0.8f, 0.5f, 0.5f)
); bounds = new Bounds(pos, dimensions);
ori = Quat.FromAngles(0, 90, 0); this.ori = ori;
matrix = Matrix.TR(bounds.center, ori); matrix = Matrix.TR(bounds.center, this.ori);
matrixInv = matrix.Inverse; matrixInv = matrix.Inverse;
@ -95,22 +87,26 @@ public class Oriel {
Glove rGlove = Mono.inst.rGlove; Glove rGlove = Mono.inst.rGlove;
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position; // Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
// glove // glove
// bool frameDown = rig.rCon.triggerBtn.frameDown; Hand rHand = Input.Hand(Handed.Right);
// bool held = rig.rCon.triggerBtn.held; // why do I have to do this?
// bool frameUp = rig.rCon.triggerBtn.frameUp; // rHand.IsJustPinched ||
// cursor = rGlove.virtualGlove.position; bool frameDown = Input.Key(Key.MouseLeft).IsJustActive() || rig.rCon.triggerBtn.frameDown;
// cursorOri = rGlove.virtualGlove.orientation; bool held = Input.Key(Key.MouseLeft).IsActive() || rig.rCon.triggerBtn.held;
bool frameUp = Input.Key(Key.MouseLeft).IsJustInactive() || rig.rCon.triggerBtn.frameUp;
cursor = rGlove.virtualGlove.position;
cursorOri = rGlove.virtualGlove.orientation;
// hand // hand
Trackballer tb = (Trackballer)Mono.inst.dofs[3]; // Trackballer tb = (Trackballer)Mono.inst.dofs[3];
bool frameDown = tb.btnOut.frameDown; // bool frameDown = tb.btnOut.frameDown;
bool held = tb.btnOut.held; // bool held = tb.btnOut.held;
bool frameUp = tb.btnOut.frameUp; // bool frameUp = tb.btnOut.frameUp;
WaveCursor wc = (WaveCursor)Mono.inst.dofs[1]; // WaveCursor wc = (WaveCursor)Mono.inst.dofs[1];
cursor = wc.cursor.position; // cursor = wc.cursor.position;
cursorOri = Quat.Identity; // wc.cursor.orientation; // cursorOri = Quat.Identity; // wc.cursor.orientation;
// debug // debug
@ -159,7 +155,7 @@ public class Oriel {
qOffset = (ori.Inverse * cursorOri).Normalized; qOffset = (ori.Inverse * cursorOri).Normalized;
mOffset = matrix; mOffset = matrix;
interacting = frameDown; interacting = frameDown && minDist < cursorRadius;
scaling = false; scaling = false;
cornerDetect = Vec3.Zero; cornerDetect = Vec3.Zero;
} }
@ -232,17 +228,16 @@ public class Oriel {
// matFrame.DepthTest = DepthTest.Always; // matFrame.DepthTest = DepthTest.Always;
// matFrame.SetVector("_cursor", cursor); // matFrame.SetVector("_cursor", cursor);
// matFrame.SetFloat("_time", Time.Totalf); // matFrame.SetFloat("_time", Time.Totalf);
// meshCube.Draw(matFrame, // Mesh.Cube.Draw(matFrame,
// Matrix.TRS(bounds.center, ori, bounds.dimensions), // Matrix.TRS(bounds.center, ori, bounds.dimensions),
// new Color(0.1f, 0.1f, 0.1f) // new Color(0.1f, 0.1f, 0.1f)
// ); // );
// matPanes.DepthTest = DepthTest.Greater; // matPanes.DepthTest = DepthTest.Greater;
matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv); matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv);
meshCube.Draw(matPanes, Mesh.Cube.Draw(matPanes,
Matrix.TRS(bounds.center, ori, bounds.dimensions), Matrix.TRS(bounds.center, ori, bounds.dimensions),
new Color(0f, 0f, 0f) color
// new Color(78 / 256f, 142 / 256f, 191 / 256f)
); );
matOriel.SetVector("_center", bounds.center); matOriel.SetVector("_center", bounds.center);
@ -261,7 +256,7 @@ public class Oriel {
) / cursorRadius; ) / cursorRadius;
if (detectCount == 1 || detectCount == 2) { if (detectCount == 1 || detectCount == 2) {
Vec3 edge = Vec3.One - detect.Abs(); Vec3 edge = Vec3.One - detect.Abs();
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS( Matrix.TS(
LocalAnchor, LocalAnchor,
(Vec3.One * thk) + (edge * bounds.dimensions / 3f * prx) (Vec3.One * thk) + (edge * bounds.dimensions / 3f * prx)
@ -269,19 +264,19 @@ public class Oriel {
); );
} }
if (detectCount == 3) { if (detectCount == 3) {
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS( Matrix.TS(
Vec3.Lerp(XAnchor, LocalAnchor, 0.5f), Vec3.Lerp(XAnchor, LocalAnchor, 0.5f),
new Vec3(MathF.Abs(XAnchor.x - LocalAnchor.x), thk, thk) new Vec3(MathF.Abs(XAnchor.x - LocalAnchor.x), thk, thk)
) * matrix, col ) * matrix, col
); );
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS( Matrix.TS(
Vec3.Lerp(YAnchor, LocalAnchor, 0.5f), Vec3.Lerp(YAnchor, LocalAnchor, 0.5f),
new Vec3(thk, MathF.Abs(YAnchor.y - LocalAnchor.y), thk) new Vec3(thk, MathF.Abs(YAnchor.y - LocalAnchor.y), thk)
) * matrix, col ) * matrix, col
); );
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS( Matrix.TS(
Vec3.Lerp(ZAnchor, LocalAnchor, 0.5f), Vec3.Lerp(ZAnchor, LocalAnchor, 0.5f),
new Vec3(thk, thk, MathF.Abs(ZAnchor.z - LocalAnchor.z)) new Vec3(thk, thk, MathF.Abs(ZAnchor.z - LocalAnchor.z))
@ -290,31 +285,31 @@ public class Oriel {
// draw cube(s) on intersecting corner ends // draw cube(s) on intersecting corner ends
if (cornerDetect.x > 0) { if (cornerDetect.x > 0) {
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix, Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix,
new Color(1, 0, 0) new Color(1, 0, 0)
); );
} }
if (cornerDetect.y > 0) { if (cornerDetect.y > 0) {
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS(YAnchor, Vec3.One * thk * 2) * matrix, Matrix.TS(YAnchor, Vec3.One * thk * 2) * matrix,
new Color(0, 1, 0) new Color(0, 1, 0)
); );
} }
if (cornerDetect.z > 0) { if (cornerDetect.z > 0) {
meshCube.Draw(matClear, Mesh.Cube.Draw(matClear,
Matrix.TS(ZAnchor, Vec3.One * thk * 2) * matrix, Matrix.TS(ZAnchor, Vec3.One * thk * 2) * matrix,
new Color(0, 0, 1) new Color(0, 0, 1)
); );
} }
} }
meshCube.Draw(Mono.inst.matHolo, Mesh.Sphere.Draw(Mono.inst.matHolo,
Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.005f, 0.02f)), Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.02f, 0.02f)),
cursorColor cursorColor
); );
meshSphere.Draw(Mono.inst.matHolo, Mesh.Sphere.Draw(Mono.inst.matHolo,
Matrix.TS(cursor, new Vec3(1f, 1f, 1f) * cursorRadius * 2), Matrix.TS(cursor, new Vec3(1f, 1f, 1f) * cursorRadius * 2),
new Color(0.1f, 0.1f, 0.1f) new Color(0.1f, 0.1f, 0.1f)
); );
@ -350,4 +345,5 @@ public class Oriel {
compositor compositor
multi-oriel requires a compositor approach multi-oriel requires a compositor approach
even if you just start with input management even if you just start with input management
*/ */