fiddling with shaders
This commit is contained in:
parent
305491d317
commit
a01cebb0ec
7 changed files with 110 additions and 27 deletions
|
@ -15,7 +15,7 @@ struct psIn {
|
|||
float4 pos : SV_POSITION;
|
||||
float3 norm : NORMAL0;
|
||||
float2 uv : TEXCOORD0;
|
||||
float1 depth : TEXCOORD1;
|
||||
// float1 depth : TEXCOORD1;
|
||||
float4 color : COLOR0;
|
||||
uint view_id : SV_RenderTargetArrayIndex;
|
||||
};
|
||||
|
@ -31,11 +31,13 @@ psIn vs(vsIn input, uint id : SV_InstanceID) {
|
|||
|
||||
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]));
|
||||
float lighting = dot(o.norm, normalize(float3(0.3, -0.6, -0.1)));
|
||||
o.color.rgb = o.color.rgb * lighting;
|
||||
// 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);
|
||||
// clip(input.depth);
|
||||
return input.color;
|
||||
}
|
16
ColorCube.cs
16
ColorCube.cs
|
@ -11,11 +11,11 @@ class ColorCube {
|
|||
public Color color = Color.White * 0.5f;
|
||||
public float thickness {
|
||||
set {
|
||||
_thickness = value;
|
||||
_thiccness = value;
|
||||
colorCube.RootNode.Material["border_size"] = value;
|
||||
}
|
||||
}
|
||||
float _thickness = 0.01f;
|
||||
float _thiccness = 0.01f;
|
||||
|
||||
public ColorCube() {
|
||||
SetColor(Vec3.Zero);
|
||||
|
@ -59,10 +59,12 @@ class ColorCube {
|
|||
|
||||
Vec3 orbPos = Col2Vec(color);
|
||||
|
||||
Lines.Add(matrix * new Vec3(-0.5f, orbPos.y, orbPos.z), matrix * new Vec3(0.5f, orbPos.y, orbPos.z), new Color(0, color.g, color.b), new Color(1, color.g, color.b), _thickness);
|
||||
Lines.Add(matrix * new Vec3(orbPos.x, -0.5f, orbPos.z), matrix * new Vec3(orbPos.x, 0.5f, orbPos.z), new Color(color.r, 0, color.b), new Color(color.r, 1, color.b), _thickness);
|
||||
Lines.Add(matrix * new Vec3(orbPos.x, orbPos.y, -0.5f), matrix * new Vec3(orbPos.x, orbPos.y, 0.5f), new Color(color.r, color.g, 0), new Color(color.r, color.g, 1), _thickness);
|
||||
Lines.Add(matrix * new Vec3(-0.5f, orbPos.y, orbPos.z), matrix * new Vec3(0.5f, orbPos.y, orbPos.z), new Color(0, color.g, color.b), new Color(1, color.g, color.b), _thiccness);
|
||||
Lines.Add(matrix * new Vec3(orbPos.x, -0.5f, orbPos.z), matrix * new Vec3(orbPos.x, 0.5f, orbPos.z), new Color(color.r, 0, color.b), new Color(color.r, 1, color.b), _thiccness);
|
||||
Lines.Add(matrix * new Vec3(orbPos.x, orbPos.y, -0.5f), matrix * new Vec3(orbPos.x, orbPos.y, 0.5f), new Color(color.r, color.g, 0), new Color(color.r, color.g, 1), _thiccness);
|
||||
|
||||
orb.Draw(Matrix.TS(matrix * orbPos, _thickness * 2));
|
||||
}
|
||||
orb.Draw(Matrix.TS(matrix * orbPos, _thiccness * 2));
|
||||
|
||||
PullRequest.BoundsDraw(bounds, Color.White);
|
||||
}
|
||||
}
|
||||
|
|
44
Program.cs
44
Program.cs
|
@ -1,9 +1,13 @@
|
|||
using System;
|
||||
using StereoKit;
|
||||
using AutoUpdaterDotNET;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
SKSettings settings = new SKSettings {
|
||||
// AutoUpdater.InstalledVersion = new Version("0.0.0.2");
|
||||
// AutoUpdater.Start("https://github.com/dofdev/oriels/blob/main/oriels.xml");
|
||||
|
||||
SKSettings settings = new SKSettings {
|
||||
appName = "oriels",
|
||||
assetsFolder = "Assets",
|
||||
};
|
||||
|
@ -26,12 +30,14 @@ public static class Mono {
|
|||
OrbitalView.distance = 0.4f;
|
||||
cube.thickness = 0.01f;
|
||||
|
||||
|
||||
ReachCursor reachCursor = new ReachCursor();
|
||||
SupineCursor supineCursor = new SupineCursor();
|
||||
BallsCursor ballsCursor = new BallsCursor();
|
||||
|
||||
Oriel oriel = new Oriel();
|
||||
|
||||
Pose p = new Pose(Vec3.One, Quat.Identity); // ACTUALLY COOL
|
||||
|
||||
oriel.Start();
|
||||
|
||||
while (SK.Step(() => {
|
||||
|
@ -43,13 +49,14 @@ public static class Mono {
|
|||
// Default.MaterialHand["color"] = cube.color;
|
||||
|
||||
// reachCursor.Step();
|
||||
supineCursor.Step(
|
||||
mainHand.aim.position,
|
||||
offHand.aim.orientation,
|
||||
mainHand.aim.orientation,
|
||||
Mono.mainHand.IsStickClicked
|
||||
);
|
||||
// oriel.Step();
|
||||
// supineCursor.Step(
|
||||
// offHand.aim.orientation,
|
||||
// mainHand.aim.position,
|
||||
// mainHand.aim.orientation,
|
||||
// Mono.mainHand.IsStickClicked
|
||||
// );
|
||||
|
||||
oriel.Step();
|
||||
|
||||
// cursor.Draw(Matrix.S(0.1f));
|
||||
})) ;
|
||||
|
@ -63,6 +70,7 @@ public class Oriel {
|
|||
// render
|
||||
Material mat = new Material(Shader.FromFile("oriel.hlsl"));
|
||||
Mesh mesh = Mesh.GenerateCube(new Vec3(1, 1, 1));
|
||||
Model model = Model.FromFile("oriel.glb", Default.ShaderUnlit);
|
||||
|
||||
public void Start() {
|
||||
bounds = new Bounds(Vec3.Zero, new Vec3(1f, 0.5f, 0.5f));
|
||||
|
@ -75,6 +83,22 @@ public class Oriel {
|
|||
}
|
||||
|
||||
public void Step() {
|
||||
mesh.Draw(mat, Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions));
|
||||
model.Draw(Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions));
|
||||
// mesh.Draw(mat, Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions));
|
||||
}
|
||||
}
|
||||
|
||||
public static class PullRequest {
|
||||
public static Vec3 VecMulti(Vec3 a, Vec3 b) { return new Vec3(a.x * b.x, a.y * b.y, a.z * b.z); }
|
||||
|
||||
public static void BoundsDraw(Bounds b, Color color) {
|
||||
Vec3 c = Vec3.One / 2;
|
||||
Vec3 ds = b.dimensions;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Quat q = Quat.FromAngles(i * 90, 0, 0);
|
||||
Lines.Add(q * VecMulti(new Vec3(0, 0, 0) - c, ds), q * VecMulti(new Vec3(0, 1, 0) - c, ds), color, color, 0.01f);
|
||||
Lines.Add(q * VecMulti(new Vec3(0, 1, 0) - c, ds), q * VecMulti(new Vec3(1, 1, 0) - c, ds), color, color, 0.01f);
|
||||
Lines.Add(q * VecMulti(new Vec3(1, 1, 0) - c, ds), q * VecMulti(new Vec3(1, 0, 0) - c, ds), color, color, 0.01f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TwistCursor : SpatialCursor {
|
|||
public class SupineCursor : SpatialCursor {
|
||||
float calibStr;
|
||||
Quat calibQuat;
|
||||
public void Step(Vec3 mainPos, Quat offQuat, Quat mainQuat, bool calibrate = false) {
|
||||
public void Step(Quat offQuat, Vec3 mainPos, Quat mainQuat, bool calibrate = false) {
|
||||
Quat rel = Quat.LookAt(Vec3.Zero, offQuat * Vec3.Forward);
|
||||
float twist = (Vec3.Dot(rel * -Vec3.Right, offQuat * Vec3.Up) + 1) / 2;
|
||||
|
||||
|
@ -69,11 +69,54 @@ public class SupineCursor : SpatialCursor {
|
|||
}
|
||||
}
|
||||
|
||||
public class TankCursor : SpatialCursor {
|
||||
public void Step() {
|
||||
pos = Vec3.Zero;
|
||||
rot = Quat.Identity;
|
||||
public class BallsCursor : SpatialCursor {
|
||||
Vec3 offPivot, mainPivot;
|
||||
Quat offBall, mainBall;
|
||||
Quat oldOffQuat, oldMainQuat;
|
||||
float offRadius, mainRadius;
|
||||
bool offPress, mainPress;
|
||||
public void Step(
|
||||
Vec3 offPos, Quat offQuat,
|
||||
Vec3 mainPos, Quat mainQuat,
|
||||
bool offGrip, bool mainGrip, bool calibrate = false
|
||||
) {
|
||||
|
||||
Function(offPos, ref offPivot, ref offBall, offQuat, ref oldOffQuat, ref offRadius, offGrip, ref offPress);
|
||||
Function(mainPos, ref mainPivot, ref mainBall, mainQuat, ref oldMainQuat, ref mainRadius, mainGrip, ref mainPress);
|
||||
|
||||
void Function(Vec3 handPos, ref Vec3 pivot, ref Quat ball, Quat quat, ref Quat oldQuat, ref float radius, bool grip, ref bool press) {
|
||||
if (grip) {
|
||||
if (!press) {
|
||||
pivot = pos + ball * Vec3.Forward * radius;
|
||||
oldQuat = quat;
|
||||
press = true;
|
||||
}
|
||||
ball = Quat.Difference(oldQuat, quat) * ball;
|
||||
pos = pivot + (ball * -Vec3.Forward * radius);
|
||||
|
||||
oldQuat = quat;
|
||||
}
|
||||
else {
|
||||
press = false;
|
||||
}
|
||||
|
||||
// Sphere sphere = new Sphere(pos, mainDiameter);
|
||||
Default.MeshSphere.Draw(
|
||||
clearMat,
|
||||
Matrix.TS(pos + ball * Vec3.Forward * radius, radius * 2)
|
||||
);
|
||||
}
|
||||
|
||||
if (calibrate)
|
||||
{
|
||||
pos = Vec3.Lerp(offPos, mainPos, 0.5f);
|
||||
offRadius = mainRadius = Vec3.Distance(offPos, mainPos) / 2;
|
||||
offBall = Quat.LookAt(mainPos, offPos);
|
||||
mainBall = Quat.LookAt(offPos, mainPos);
|
||||
}
|
||||
|
||||
model.Draw(Matrix.TS(pos, 0.06f));
|
||||
clearMat.SetColor("color", new Color(1, 1, 1, 0.1f));
|
||||
}
|
||||
}
|
||||
Material clearMat = Default.MaterialHand;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
dotnet build
|
||||
pause
|
||||
cd bin/Debug/netcoreapp3.1/
|
||||
cd bin/Debug
|
||||
@REM echo "zipping into dofdev site"
|
||||
@REM 7z u oriels.zip %cd%/netcoreapp3.1
|
||||
@REM Xcopy "oriels.zip" "C:/dofdev/Web Development/dofdev/res/oriels.zip" /F /Y
|
||||
cd netcoreapp3.1
|
||||
oriels.exe
|
|
@ -3,9 +3,11 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.0" />
|
||||
<PackageReference Include="StereoKit" Version="0.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
6
oriels.xml
Normal file
6
oriels.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>0.0.0.1</version>
|
||||
<url>https://dofdev.org/res/oriels.zip</url>
|
||||
<mandatory>true</mandatory>
|
||||
</item>
|
Loading…
Add table
Reference in a new issue