Compare commits

...

26 commits

Author SHA1 Message Date
4ae3e435bd draw cluster of leafs at top of bamboo using noise offstep 2024-12-21 09:48:30 -05:00
b5cae879a6 pos to point var rename for bezier 2024-12-21 09:47:57 -05:00
b7d508b7a0 random leaf spawn at bamboo tip 2024-12-21 09:47:13 -05:00
c434d7f866 arrange bamboo around center 2024-12-21 09:46:50 -05:00
724bc153be hacky offset stepper for noise 2024-12-21 09:46:05 -05:00
04c35d6107 render ripples particle system 2024-12-21 09:45:22 -05:00
25faa58e35 render leafs particle system 2024-12-21 09:45:03 -05:00
adcf0960b6 update data ref on render generic ps 2024-12-21 09:44:46 -05:00
232edb1b41 continuos particle flow on slash hit test 2024-12-21 09:43:57 -05:00
3a81917a24 render gray ground circle 2024-12-21 09:42:03 -05:00
064f5c3254 absolute file path for font due to sk version downgrade 2024-12-21 09:41:38 -05:00
b0414df2d1 additive mat 2024-12-21 09:39:58 -05:00
d15cb8e093 ripples frame system 2024-12-21 09:39:26 -05:00
ebef28435b leafs frame system 2024-12-21 09:39:20 -05:00
21f619b607 ripple spawn particle system function 2024-12-21 09:38:41 -05:00
25829de17b leaf spawn particle system function 2024-12-21 09:38:32 -05:00
784364e23d update data ref for generic particle system 2024-12-21 09:37:58 -05:00
22d7a22fd1 init leafs and ripples particle systems alongside generic 2024-12-21 09:37:16 -05:00
c87a7ab183 particle color 2024-12-21 09:36:33 -05:00
12ae8adca6 delta bool particle state 2024-12-21 09:36:15 -05:00
705614909b particle system abstraction to support multiple particle systems 2024-12-21 09:35:48 -05:00
82eefebb7c render the world back a bit in sim 2024-12-21 09:34:37 -05:00
c9889b50d2 swap out sim conditional check 2024-12-21 09:33:55 -05:00
c46be74112 toggle flatscreen 2024-12-21 09:32:21 -05:00
cf12207557 leaf, ripple and circle mesh 2024-12-21 09:32:05 -05:00
6e82ae9955 downgrade stereokit version to get around dri2 display error 2024-12-21 09:31:43 -05:00
7 changed files with 205 additions and 45 deletions

BIN
Assets/meshes/assets.glb (Stored with Git LFS)

Binary file not shown.

View file

@ -20,6 +20,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="StereoKit" Version="0.3.9" /> <PackageReference Include="StereoKit" Version="0.3.8" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -9,6 +9,7 @@ static class Arts
static Dictionary<string, Mesh> meshes = new(); static Dictionary<string, Mesh> meshes = new();
static Material mat_mono = new Material("mono.hlsl"); static Material mat_mono = new Material("mono.hlsl");
static Material mat_unlit = new Material("unlit.hlsl"); static Material mat_unlit = new Material("unlit.hlsl");
static Material mat_add = new Material("unlit.hlsl");
static Material mat_both = new Material("unlit.hlsl"); static Material mat_both = new Material("unlit.hlsl");
static Material mat_backface = new Material("backface.hlsl"); static Material mat_backface = new Material("backface.hlsl");
static Material mat_justcolor = new Material("justcolor.hlsl"); static Material mat_justcolor = new Material("justcolor.hlsl");
@ -52,11 +53,15 @@ static class Arts
} }
text_style = TextStyle.FromFont( text_style = TextStyle.FromFont(
Font.FromFile("Staatliches.ttf"), Font.FromFile("Assets/Staatliches.ttf"),
1.0f * U.cm, 1.0f * U.cm,
Color.White Color.White
); );
mat_add.Transparency = Transparency.Add;
mat_add.DepthTest = DepthTest.LessOrEq;
mat_add.DepthWrite = false;
mat_backface.FaceCull = Cull.Front; mat_backface.FaceCull = Cull.Front;
mat_backface.Transparency = Transparency.Add; mat_backface.Transparency = Transparency.Add;
mat_backface.DepthTest = DepthTest.LessOrEq; mat_backface.DepthTest = DepthTest.LessOrEq;
@ -67,6 +72,10 @@ static class Arts
mat_slash.FaceCull = Cull.None; mat_slash.FaceCull = Cull.None;
} }
// [!] hacky offset stepper for noise
public static int offset = 0;
static int offstep() => offset += 100;
public static void Frame() public static void Frame()
{ {
// Input.HandVisible(Handed.Max, false); // Input.HandVisible(Handed.Max, false);
@ -75,30 +84,46 @@ static class Arts
Matrix m4_world = Mono.world_pose.ToMatrix(); Matrix m4_world = Mono.world_pose.ToMatrix();
Hierarchy.Push(m4_world); Hierarchy.Push(m4_world);
// mesh test // ground
meshes["_dmg"].Draw( meshes["circle"].Draw(
mat_mono, mat_unlit,
Matrix.TRS( Matrix.TRS(
V.XYZ(0, 0, -1), V.XYZ(0, 0, 0),
Quat.Identity, Quat.Identity,
0.1f 12.0f
) ),
Color.Hex(0x808080FF).ToLinear()
); );
// bamboo // bamboo
for (int i = -12; i <= 12; i++) offset = 0;
int s_len = 24;
for (int i = -s_len; i <= s_len; i++)
{ {
float z_offset = Noise.s_scalar_x(i) * 2.0f; Quat q = Quat.FromAngles(0, i * 3, 0);
float x_offset = Noise.s_scalar_x(i + 32) * 0.2f; Vec3 pos = q * V.XYZ(0, 0, -10 + (Maths.smooth_stop(Noise.u_scalar_x(i + s_len * 2)) * 5));
float x_wind = Maths.smooth_stop(Maths.u_scalar(SKMath.Sin((i * 0.16f) - Time.Totalf))); // float z_offset = Noise.s_scalar_x(i + 32) * 2.0f;
float x_offset = Noise.s_scalar_x(i + s_len * 4) * 0.2f;
float x_wind = Maths.smooth_stop(Maths.u_scalar(SKMath.Sin((pos.x * 0.5f) - Time.Totalf)));
Vec3[] p = new Vec3[] { Vec3[] p = new Vec3[] {
V.XYZ(i * 0.3f, 0, -10 + z_offset), pos + V.XYZ(0, 0, 0),
V.XYZ(i * 0.3f, 1, -10 + z_offset), pos + V.XYZ(0, 1, 0),
V.XYZ(i * 0.3f, 4, -10 + z_offset), pos + V.XYZ(0, 4, 0),
V.XYZ(i * 0.3f + x_offset + x_wind, 5, -10 + z_offset), pos + V.XYZ(x_offset + x_wind, 5, 0),
}; };
if (Noise.u_scalar < 0.1f * Time.Stepf)
{
VFX.Leaf(p[3]);
// static float fall_timer = 0.0f;
// fall_timer -= Time.Stepf;
// if (fall_timer <= 0.0f)
// {
// fall_timer = 1.0f;
// }
}
// debug bezier points // debug bezier points
// for (int i = 0; i < p.Length; i++) // for (int i = 0; i < p.Length; i++)
// { // {
@ -123,7 +148,7 @@ static class Arts
// ); // );
int steps = 92; int steps = 92;
Vec3 pastPos = p[0]; Vec3 pastPoint = p[0];
float pastThc = 0.0f; float pastThc = 0.0f;
for (int j = 0; j < steps; j++) for (int j = 0; j < steps; j++)
{ {
@ -131,17 +156,39 @@ static class Arts
Vec3 a = Vec3.Lerp(p[0], p[1], t); Vec3 a = Vec3.Lerp(p[0], p[1], t);
Vec3 b = Vec3.Lerp(p[1], p[2], t); Vec3 b = Vec3.Lerp(p[1], p[2], t);
Vec3 c = Vec3.Lerp(p[2], p[3], t); Vec3 c = Vec3.Lerp(p[2], p[3], t);
Vec3 pos = Vec3.Lerp(Vec3.Lerp(a, b, t), Vec3.Lerp(b, c, t), t); Vec3 point = Vec3.Lerp(Vec3.Lerp(a, b, t), Vec3.Lerp(b, c, t), t);
float thc = (1.0f + Maths.precision((1.0f - t), Maths.lerp(0.1f, 0.2f, Noise.u_scalar_x(i))) * 2.0f) * U.cm * 6.0f; float thc = (1.0f + Maths.precision((1.0f - t), Maths.lerp(0.1f, 0.2f, Noise.u_scalar_x(i))) * 2.0f) * U.cm * 6.0f;
Lines.Add( Lines.Add(
pastPos, pastPoint,
pos, point,
thc != pastThc ? Color.Hex(0x959493FF).ToLinear() : Color.Hex(0xB9E7AFFF).ToLinear(), thc != pastThc ? Color.Hex(0x959493FF).ToLinear() : Color.Hex(0xB9E7AFFF).ToLinear(),
thc thc
); );
pastPos = pos; pastPoint = point;
pastThc = thc; pastThc = thc;
} }
// leaves
for (int j = 0; j < 10; j++)
{
meshes["leaf"].Draw(
mat_unlit,
Matrix.TRS(
p[3] + Quat.LookAt(p[3], p[2], Vec3.Right) * V.XYZ(
Noise.s_scalar_x(j + offstep()),
Noise.s_scalar_x(j + offstep()),
Noise.s_scalar_x(j + offstep()) * 3
) * 0.2f,
(
Quat.FromAngles(Noise.s_scalar_x(j + offstep()) * 180f, 0, 0) *
Quat.FromAngles(0, Noise.s_scalar_x(j + offstep()) * 180f, 0) *
Quat.FromAngles(0, 0, Noise.s_scalar_x(j + offstep()) * 180f)
),
0.1f
),
Color.Hex(0xBAE8B0FF).ToLinear()
);
}
} }
// unit cube // unit cube
@ -234,10 +281,8 @@ static class Arts
), ),
Color.White Color.White
); );
if (Rig.btn_select.state) VFX.Play(min_hit_pos);
{
VFX.Play(min_hit_pos);
}
} }
} }
@ -298,10 +343,9 @@ static class Arts
} }
// particles // particles
Particle[] particles = VFX.particles; for (int i = 0; i < VFX.ps.count; i++)
for (int i = 0; i < particles.Length; i++)
{ {
Particle particle = particles[i]; Particle particle = VFX.ps.particles[i];
Mesh.Sphere.Draw( Mesh.Sphere.Draw(
mat_unlit, mat_unlit,
Matrix.TRS( Matrix.TRS(
@ -312,6 +356,35 @@ static class Arts
Color.Hex(0xC75A09FF).ToLinear() Color.Hex(0xC75A09FF).ToLinear()
); );
} }
for (int i = 0; i < VFX.leafs.count; i++)
{
Particle particle = VFX.leafs.particles[i];
meshes["leaf"].Draw(
mat_unlit,
Matrix.TRS(
particle.pos,
particle.ori,
particle.scl
),
Color.Hex(0xBAE8B0FF).ToLinear()
);
}
for (int i = 0; i < VFX.ripples.count; i++)
{
Particle particle = VFX.ripples.particles[i];
if (particle.state.state)
{
meshes["ripple"].Draw(
mat_add,
Matrix.TRS(
particle.pos,
particle.ori,
particle.scl
),
particle.col.ToLinear()
);
}
}
Hierarchy.Pop(); Hierarchy.Pop();

View file

@ -28,7 +28,7 @@ static class Mono
public static void Init() public static void Init()
{ {
game_time = 0.0; game_time = 0.0;
world_pose = new(0, -1, -2); world_pose = new(0, 0, 0);
menu = new(false); menu = new(false);
menu_pose = new(0, 0, 0); menu_pose = new(0, 0, 0);
menu_scale = 1 * U.cm; menu_scale = 1 * U.cm;
@ -60,8 +60,10 @@ static class Mono
} }
// flatscreen dev controls // flatscreen dev controls
if (Device.Name == "Simulator") if (Device.DisplayType == DisplayType.Flatscreen)// Device.Name == "Simulator")
{ {
world_pose = new(0, -1, -2);
if (Input.Key(Key.MouseCenter).IsActive()) if (Input.Key(Key.MouseCenter).IsActive())
{ {
float sx = Input.Mouse.posChange.x; float sx = Input.Mouse.posChange.x;

View file

@ -22,7 +22,8 @@ class Program
disableFlatscreenMRSim = true, disableFlatscreenMRSim = true,
renderScaling = 2, renderScaling = 2,
renderMultisample = 0, renderMultisample = 0,
// mode = AppMode.Simulator,
// displayPreference = DisplayMode.Flatscreen
}; };
if (!SK.Initialize(settings)) if (!SK.Initialize(settings))

View file

@ -27,7 +27,7 @@ static class Rig
head = Input.Head; head = Input.Head;
// flatscreen dev controls // flatscreen dev controls
if (Device.Name == "Simulator") if (Device.DisplayType == DisplayType.Flatscreen)// Device.Name == "Simulator")
{ {
btn_select.Step(Input.Key(Key.MouseLeft).IsActive()); btn_select.Step(Input.Key(Key.MouseLeft).IsActive());
btn_back.Step(Input.Key(Key.MouseRight).IsActive()); btn_back.Step(Input.Key(Key.MouseRight).IsActive());

View file

@ -5,23 +5,23 @@ namespace slash;
static class VFX static class VFX
{ {
public static Particle[] particles = new Particle[64]; public static ParticleSystem ps = new(64);
static int index = 0; public static ParticleSystem leafs = new(64);
public static ParticleSystem ripples = new(64);
public static void Init() public static void Init()
{ {
for (int i = 0; i < particles.Length; i++) ps.Init();
{ leafs.Init();
particles[i] = new(); ripples.Init();
}
} }
public static void Play(Vec3 pos) public static void Play(Vec3 pos)
{ {
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
index = (index + 1) % particles.Length; ps.index = (ps.index + 1) % ps.count;
Particle particle = particles[index]; Particle particle = ps.particles[ps.index];
particle.pos = pos; particle.pos = pos;
particle.vel = Quat.FromAngles(Noise.u_scalar * 360, 0, 0) * Quat.FromAngles(0, Noise.u_scalar * 360, 0) * Vec3.Forward * 3.0f; particle.vel = Quat.FromAngles(Noise.u_scalar * 360, 0, 0) * Quat.FromAngles(0, Noise.u_scalar * 360, 0) * Vec3.Forward * 3.0f;
particle.ori = Quat.Identity; particle.ori = Quat.Identity;
@ -29,11 +29,33 @@ static class VFX
} }
} }
public static void Leaf(Vec3 pos)
{
leafs.index = (leafs.index + 1) % leafs.count;
Particle particle = leafs.particles[leafs.index];
particle.state.Step(true);
particle.pos = pos;
particle.vel = V.XYZ(0, 0, 0); // Quat.FromAngles(Noise.u_scalar * 360, 0, 0) * Quat.FromAngles(0, Noise.u_scalar * 360, 0) * Vec3.Forward * 3.0f;
particle.ori = Quat.FromAngles(Noise.s_scalar * 180, 0, 0) * Quat.FromAngles(0, Noise.s_scalar * 180, 0);
particle.scl = 0.1f; // (1.0f / 3) * Maths.smooth_start(Noise.u_scalar);
}
static void Ripple(Vec3 pos)
{
ripples.index = (ripples.index + 1) % ripples.count;
Particle particle = ripples.particles[ripples.index];
particle.state.Step(true);
particle.pos = pos;
particle.vel = V.XYZ(0, 0, 0); // Quat.FromAngles(Noise.u_scalar * 360, 0, 0) * Quat.FromAngles(0, Noise.u_scalar * 360, 0) * Vec3.Forward * 3.0f;
particle.ori = Quat.Identity;
particle.scl = 0.1f; // (1.0f / 3) * Maths.smooth_start(Noise.u_scalar);
}
public static void Frame() public static void Frame()
{ {
for (int i = 0; i < particles.Length; i++) for (int i = 0; i < ps.count; i++)
{ {
Particle particle = particles[i]; Particle particle = ps.particles[i];
if (particle.vel.MagnitudeSq > float.Epsilon) if (particle.vel.MagnitudeSq > float.Epsilon)
{ {
particle.pos += particle.vel * Time.Stepf; particle.pos += particle.vel * Time.Stepf;
@ -52,20 +74,82 @@ static class VFX
// } // }
} }
} }
for (int i = 0; i < leafs.count; i++)
{
Particle particle = leafs.particles[i];
particle.state.Step(particle.pos.y > 0);
if (particle.state.state)
{
particle.pos += particle.vel * Time.Stepf;
float x_wind = Maths.smooth_stop(Maths.u_scalar(SKMath.Sin((particle.pos.x * 0.5f) - Time.Totalf)));
particle.vel.x += x_wind * Time.Stepf;
particle.vel += Vec3.Up * -9.81f * 0.1f * Time.Stepf;
particle.ori = Quat.LookDir(particle.vel) * Quat.FromAngles(0, 0, 90);
}
else
{
particle.pos.y = 0;
particle.vel = Vec3.Zero;
if (particle.state.delta == -1)
{
Ripple(particle.pos);
}
}
}
for (int i = 0; i < ripples.count; i++)
{
Particle particle = ripples.particles[i];
particle.state.Step(particle.scl < 1.0);
if (particle.state.state)
{
particle.scl += Time.Stepf;
float val = 1.0f - particle.scl;
particle.col = new Color(val, val, val);
}
}
} }
} }
public class Particle public class Particle
{ {
public DeltaBool state;
public Vec3 pos, vel; public Vec3 pos, vel;
public Quat ori; public Quat ori;
public float scl; public float scl;
public Color col;
public Particle() public Particle()
{ {
this.state = new(false);
this.pos = Vec3.Zero; this.pos = Vec3.Zero;
this.vel = Vec3.Zero; this.vel = Vec3.Zero;
this.ori = Quat.Identity; this.ori = Quat.Identity;
this.scl = 0.0f; this.scl = 0.0f;
this.col = Color.White;
}
}
public class ParticleSystem
{
public Particle[] particles;
public int count;
public int index;
public ParticleSystem(int count)
{
this.particles = new Particle[count];
this.count = count;
this.index = 0;
}
public void Init()
{
for (int i = 0; i < particles.Length; i++)
{
particles[i] = new();
}
} }
} }