content experimentation + set back to one oriel

This commit is contained in:
spatialfree 2022-05-12 19:52:32 -04:00
parent 8616919cd3
commit 7349b53ef1
34 changed files with 39552 additions and 54 deletions

11
add/megaman/license.txt Normal file
View file

@ -0,0 +1,11 @@
Model Information:
* title: Megaman X4 - Cyber Space
* source: https://sketchfab.com/3d-models/megaman-x4-cyber-space-5fdca251c4734ec49e77c72903b1d234
* author: Sah Niemeyer (https://sketchfab.com/sahailaway)
Model License:
* license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
* requirements: Author must be credited. Commercial use is allowed.
If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
This work is based on "Megaman X4 - Cyber Space" (https://sketchfab.com/3d-models/megaman-x4-cyber-space-5fdca251c4734ec49e77c72903b1d234) by Sah Niemeyer (https://sketchfab.com/sahailaway) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)

BIN
add/megaman/scene.bin Normal file

Binary file not shown.

37519
add/megaman/scene.gltf Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,011 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -53,6 +53,10 @@ float sdBox(float3 p, float3 b) {
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0); return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
} }
float sdSphere(float3 p, float r) {
return length(p) - r;
}
float raymarch(float3 origin, float3 direction) { float raymarch(float3 origin, float3 direction) {
origin = mul(float4(origin, 1), _matrix).xyz; origin = mul(float4(origin, 1), _matrix).xyz;
direction = mul(float4(direction, 0), _matrix).xyz; direction = mul(float4(direction, 0), _matrix).xyz;
@ -60,6 +64,7 @@ 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);
// float step = sdSphere(pos, _dimensions.y / 2.0);
if (step < 0.0001 || dist > 100) break; // 100 == distmax if (step < 0.0001 || dist > 100) break; // 100 == distmax
dist += step; dist += step;
} }
@ -90,6 +95,13 @@ psOut ps(psIn input) {
// backface // backface
float3 localPos = mul(float4(input.world, 1), _matrix).xyz;
// localPos.y < -_dimensions.y / 2.99
if (localPos.y < -_dimensions.y / 2.99) {
clip(-1);
}
if (dot(direction, input.normal) > 0) { if (dot(direction, input.normal) > 0) {
o.color = float4(0.5, 0.5, 0.5, 1); o.color = float4(0.5, 0.5, 0.5, 1);
} }

View file

@ -57,6 +57,10 @@ float sdBox(float3 p, float3 b) {
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0); return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
} }
float sdSphere(float3 p, float r) {
return length(p) - r;
}
float raymarch(float3 ro, float3 rd) { float raymarch(float3 ro, float3 rd) {
ro = mul(float4(ro, 1), oriel_matrix).xyz; ro = mul(float4(ro, 1), oriel_matrix).xyz;
rd = mul(float4(rd, 0), oriel_matrix).xyz; rd = mul(float4(rd, 0), oriel_matrix).xyz;
@ -64,6 +68,7 @@ float raymarch(float3 ro, float3 rd) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
float3 pos = ro + dist * rd; float3 pos = ro + dist * rd;
float step = sdBox(pos, dimensions / 2.0); float step = sdBox(pos, dimensions / 2.0);
// float step = sdSphere(pos, dimensions.y / 2.0);
if (step < 0.0001 || dist > 100) break; // 100 == distmax if (step < 0.0001 || dist > 100) break; // 100 == distmax
dist += step; dist += step;
} }

11
add/skatepark/license.txt Normal file
View file

@ -0,0 +1,11 @@
Model Information:
* title: Southbank Undercroft Skatepark
* source: https://sketchfab.com/3d-models/southbank-undercroft-skatepark-add37d5dc6a2456eb0d7607c6fbd884d
* author: artfletch (https://sketchfab.com/artfletch)
Model License:
* license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
* requirements: Author must be credited. Commercial use is allowed.
If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
This work is based on "Southbank Undercroft Skatepark" (https://sketchfab.com/3d-models/southbank-undercroft-skatepark-add37d5dc6a2456eb0d7607c6fbd884d) by artfletch (https://sketchfab.com/artfletch) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)

BIN
add/skatepark/scene.bin Normal file

Binary file not shown.

1868
add/skatepark/scene.gltf Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 MiB

View file

@ -63,7 +63,7 @@ public class Mono {
// ------------------------------------------------- // -------------------------------------------------
// rGlove.Step(); lGlove.Step(); rGlove.Step(); lGlove.Step();
// rBlock.Step(); lBlock.Step(); // rBlock.Step(); lBlock.Step();
@ -73,48 +73,51 @@ public class Mono {
// colorCube.Palm(lCon.device); // colorCube.Palm(lCon.device);
// oriel.Step(); oriel.Step();
//// ////
// °board [ pseudo code ] // °board [ pseudo code ]
// handling = 200± // // handling = 200±
// speed = 10± // // speed = 10±
// board.dir = Vec3.fwd // // board.dir = Vec3.fwd
// con.grip.frameDown: // // con.grip.frameDown:
// handle = con // // handle = con
// board.pos = FloorCenter // // board.pos = FloorCenter
// newDir = handle.pos.X0Z - board.pos.X0Z // // newDir = handle.pos.X0Z - board.pos.X0Z
// board.dir = newDir.MagSq > 0.001f ? newDir.normalized : board.dir // // board.dir = newDir.MagSq > 0.001f ? newDir.normalized : board.dir
// board.ori = Quat.LookDir(board.dir) // // board.ori = Quat.LookDir(board.dir)
// twist = handle.grip * -(Quat.LookDir(board.dir).Inverse * handle.backhandDir).x // // twist = handle.grip * -(Quat.LookDir(board.dir).Inverse * handle.backhandDir).x
// rig.ori *= Quat(0, twist * handling * delta, 0) // // rig.ori *= Quat(0, twist * handling * delta, 0)
// accel = handle.trigger // // accel = handle.trigger
// rig.pos += board.dir * accel * speed * delta // // rig.pos += board.dir * accel * speed * delta
// °board [ implementation ] // // °board [ implementation ]
float handling = 200; // float handling = 200;
float speed = 10; // float speed = 10;
Vec3 boardPos = rig.FloorCenter; // Vec3 boardPos = rig.FloorCenter;
Vec3 newDir = rig.HandleCon.pos.X0Z - boardPos.X0Z; // Vec3 newDir = rig.HandleCon.pos.X0Z - boardPos.X0Z;
boardDir = newDir.MagnitudeSq > 0.001f ? newDir.Normalized : boardDir; // boardDir = newDir.MagnitudeSq > 0.001f ? newDir.Normalized : boardDir;
Quat boardOri = Quat.LookDir(boardDir); // Quat boardOri = Quat.LookDir(boardDir);
float twist = rig.HandleCon.device.grip * -(Quat.LookDir(boardDir).Inverse * rig.HandleCon.backhandDir).x; // float twist = rig.HandleCon.device.grip * -(Quat.LookDir(boardDir).Inverse * rig.HandleCon.backhandDir).x;
rig.ori *= Quat.FromAngles(0f, twist * handling * Time.Elapsedf, 0f); // rig.ori *= Quat.FromAngles(0f, twist * handling * Time.Elapsedf, 0f);
float accel = rig.HandleCon.device.trigger; // float accel = rig.HandleCon.device.trigger;
rig.pos += boardDir * accel * speed * Time.Elapsedf; // rig.pos += boardDir * accel * speed * Time.Elapsedf;
// // Lines.Add(rig.HandleCon.pos, rig.HandleCon.pos + rig.HandleCon.backhandDir, Color.White, 0.01f);
// Mesh.Cube.Draw(Material.Default, Matrix.TRS(boardPos, boardOri, new Vec3(0.18f, 0.06f, 0.6f)));
// Lines.Add(rig.HandleCon.pos, rig.HandleCon.pos + rig.HandleCon.backhandDir, Color.White, 0.01f);
Mesh.Cube.Draw(Material.Default, Matrix.TRS(boardPos, boardOri, new Vec3(0.18f, 0.06f, 0.6f)));
// DEPRECATED // DEPRECATED
// PullRequest.Slerp(boardDir.Normalized, handleDelta.Normalized, handleDelta.Magnitude * handling * Time.Elapsedf) : boardDir; // PullRequest.Slerp(boardDir.Normalized, handleDelta.Normalized, handleDelta.Magnitude * handling * Time.Elapsedf) : boardDir;

View file

@ -7,6 +7,7 @@ public class Oriel {
static Material matFrame = new Material(Shader.FromFile("wireframe.hlsl")); static Material matFrame = new Material(Shader.FromFile("wireframe.hlsl"));
static Material matPanes = new Material(Shader.FromFile("panes.hlsl")); static Material matPanes = new Material(Shader.FromFile("panes.hlsl"));
static Material matOriel = new Material(Shader.FromFile("oriel.hlsl")); static Material matOriel = new Material(Shader.FromFile("oriel.hlsl"));
static Model modelArena = Model.FromFile("megaman/scene.gltf");
static Model model = Model.FromFile("colorball.glb"); static Model model = Model.FromFile("colorball.glb");
Mesh meshCube, meshFrame; Mesh meshCube, meshFrame;
@ -28,7 +29,7 @@ public class Oriel {
public Oriel() { public Oriel() {
bounds = new Bounds( bounds = new Bounds(
Input.Head.position + new Vec3(-0.5f, 0, -1f), new Vec3(-1.0f, -0.5f, 0.0f),
new Vec3(0.8f, 0.5f, 0.5f) new Vec3(0.8f, 0.5f, 0.5f)
); );
@ -42,6 +43,35 @@ public class Oriel {
meshFrame = model.GetMesh("Wireframe"); meshFrame = model.GetMesh("Wireframe");
meshCube = Mesh.Cube; meshCube = Mesh.Cube;
meshCube = Mesh.Sphere;
Gen(); Gen();
} }
@ -156,10 +186,10 @@ public class Oriel {
matFrame.Wireframe = true; matFrame.Wireframe = true;
matFrame.DepthTest = DepthTest.Always; matFrame.DepthTest = DepthTest.Always;
matFrame.SetVector("_rGlovePos", rGlovePos); matFrame.SetVector("_rGlovePos", rGlovePos);
meshFrame.Draw(matFrame, // meshFrame.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)
); // );
if (detectCount > 0) { if (detectCount > 0) {
meshCube.Draw(Material.Default, meshCube.Draw(Material.Default,
Matrix.TS(detect * (bounds.dimensions / 2), Vec3.One * 0.01f) * matrix.Inverse Matrix.TS(detect * (bounds.dimensions / 2), Vec3.One * 0.01f) * matrix.Inverse
@ -168,10 +198,10 @@ public class Oriel {
// matPanes.DepthTest = DepthTest.Greater; // matPanes.DepthTest = DepthTest.Greater;
matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix); matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix);
meshCube.Draw(matPanes, // meshCube.Draw(matPanes,
Matrix.TRS(bounds.center, ori, bounds.dimensions), // Matrix.TRS(bounds.center, ori, bounds.dimensions),
new Color(0.0f, 0.0f, 0.5f) // new Color(0.0f, 0.0f, 0.5f)
); // );
matOriel.SetVector("_center", bounds.center); matOriel.SetVector("_center", bounds.center);
matOriel.SetVector("_dimensions", bounds.dimensions); matOriel.SetVector("_dimensions", bounds.dimensions);
@ -181,6 +211,15 @@ public class Oriel {
// modelArena.Draw(Matrix.TRS(
// new Vec3(-1, -0.6f, 1.8f),
// Quat.FromAngles(0, -90, 0),
// Vec3.One * 0.002f
// ));
@ -188,7 +227,15 @@ public class Oriel {
// APP // APP
Vec3 playerWorldPos = playerPos * 0.5f * bounds.dimensions.y; Vec3 playerWorldPos = playerPos * 0.5f * bounds.dimensions.y;
Matrix orielSimMatrix = Matrix.TRS( Matrix orielSimMatrix = Matrix.TRS(
new Vec3(0, -bounds.dimensions.y / 2, -playerWorldPos.z),
// new Vec3(0, -bounds.dimensions.y / 2, -playerWorldPos.z),
new Vec3(0, -bounds.dimensions.y / 3, -playerWorldPos.z),
Quat.Identity, Quat.Identity,
Vec3.One * 0.5f * bounds.dimensions.y Vec3.One * 0.5f * bounds.dimensions.y
); );
@ -224,8 +271,9 @@ public class Oriel {
// destroy enemies that are too close to the playerPos // destroy enemies that are too close to the playerPos
for (int i = 0; i < enemies.Count; i++) { for (int i = 0; i < enemies.Count; i++) {
if (Vec3.Distance(enemies[i], playerPos) < 0.5f) { if (Vec3.Distance(enemies[i], playerPos) < 0.5f) {
enemies.RemoveAt(i); // enemies.RemoveAt(i);
i--; // i--;
enemies[i] = playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8;
} }
} }
@ -243,25 +291,44 @@ public class Oriel {
// new Color(0.9f, 0.5f, 0.5f) // new Color(0.9f, 0.5f, 0.5f)
// ); // );
if (Time.Totalf > spawnTime) { if (enemies.Count < 100 && Time.Totalf > spawnTime) {
enemies.Add(playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8); enemies.Add(playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8);
spawnTime = Time.Totalf + 1; spawnTime = Time.Totalf + 0.05f;
} }
for (int i = 0; i < enemies.Count; i++) { for (int i = 0; i < enemies.Count; i++) {
// move towards player // move towards player
Vec3 toPlayer = (playerPos - enemies[i]).Normalized; Vec3 toPlayer = (playerPos - enemies[i]).Normalized;
float variation = Mono.inst.noise.D1(i);
toPlayer *= Quat.FromAngles(0, MathF.Sin(Time.Totalf * variation) * 90 * variation, 0);
Vec3 newPos = enemies[i] + toPlayer * Time.Elapsedf * 0.5f; Vec3 newPos = enemies[i] + toPlayer * Time.Elapsedf * 0.5f;
// if far enough away from other enemies than set new pos // if far enough away from other enemies than set new pos
bool setNewPos = true; bool setNewPos = true;
for (int j = 0; j < enemies.Count; j++) { int iteration = 0;
if (i == j) continue; while (iteration < 6) {
if ((newPos - enemies[j]).Length < 0.5f) { for (int j = 0; j < enemies.Count; j++) {
setNewPos = false; if (i == j) continue;
break; // intersection depth
float radius = 0.5f;
// (newPos - enemies[j]).Length
float depth = (newPos - enemies[j]).Length - radius;
if (depth < 0) {
// pull back
Vec3 toEnemy = (enemies[j] - newPos).Normalized;
newPos = enemies[j] - toEnemy * radius * 1.01f;
// bump
// enemies[j] += toEnemy * Time.Elapsedf * 0.5f;
// setNewPos = false;
// break;
// break;
}
} }
iteration++;
} }
if (setNewPos) { if (setNewPos) {

View file

@ -15,7 +15,8 @@ public class Scene {
Material matFloor = new Material(Shader.Default); Material matFloor = new Material(Shader.Default);
// Model room = Model.FromFile("room/room.glb", Shader.FromFile("room.hlsl")); // Model room = Model.FromFile("room/room.glb", Shader.FromFile("room.hlsl"));
Model room = Model.FromFile("shed/shed.glb", Shader.FromFile("room.hlsl")); Model shed = Model.FromFile("shed/shed.glb", Shader.FromFile("room.hlsl"));
// Model skatepark = Model.FromFile("skatepark/scene.gltf", Shader.FromFile("room.hlsl"));
Solid floor; Solid floor;
@ -55,7 +56,7 @@ public class Scene {
data.dimensions = Vec3.Zero; // data.dimensions = Vec3.Zero;
@ -70,7 +71,7 @@ public class Scene {
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 room.Visuals) { // foreach (ModelNode node in shed.Visuals) {
// Console.WriteLine(i + " - " + node.Name); // Console.WriteLine(i + " - " + node.Name);
@ -82,13 +83,14 @@ public class Scene {
// node.Mesh.Draw(matRoom, Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One)); // node.Mesh.Draw(matRoom, Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One));
// Console.WriteLine(matRoom.ParamCount + " test " + node.Material.ParamCount); // Console.WriteLine(matRoom.ParamCount + " test " + node.Material.ParamCount);
} // }
// room.RootNode.Material.SetVector("_center", oriel.bounds.center); // room.RootNode.Material.SetVector("_center", oriel.bounds.center);
// room.RootNode.Material.SetVector("_dimensions", oriel.bounds.dimensions); // room.RootNode.Material.SetVector("_dimensions", oriel.bounds.dimensions);
// room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix); // room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
// Shader. // Shader.
// World.BoundsPose.position.y // World.BoundsPose.position.y
room.Draw(Matrix.TRS(new Vec3(0, -1.6f, 0), Quat.Identity, Vec3.One)); shed.Draw(Matrix.TRS(new Vec3(0, -1.6f, 0), Quat.Identity, Vec3.One));
// skatepark.Draw(Matrix.TRS(new Vec3(0, -5.6f, 0), Quat.Identity, Vec3.One));
} }
} }