color cube

This commit is contained in:
ethan merchant 2024-12-07 17:57:31 -05:00
parent 19f90b9633
commit ca4b715130
7 changed files with 151 additions and 30 deletions

48
Assets/colorcube.hlsl Normal file
View file

@ -0,0 +1,48 @@
#include "stereokit.hlsli"
//--name = dofdev/colorcube
//--color:color = 1, 1, 1, 1
float4 color;
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
};
struct psIn {
float4 pos : SV_POSITION;
float3 col_pos : TEXCOORD0;
float4 color : COLOR0;
uint view_id : SV_RenderTargetArrayIndex;
};
float f_inv(float x) {
if (x >= 0.04045) {
return pow((x + 0.055)/(1 + 0.055), 2.4);
}
return x / 12.92;
}
psIn vs(vsIn input, uint id : SV_InstanceID) {
psIn o;
o.view_id = id % sk_view_count;
id = id / sk_view_count;
float3 world = mul(float4(input.pos.xyz, 1), sk_inst[id].world).xyz;
o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]);
o.col_pos = input.pos.xyz + float3(0.5, 0.5, 0.5);
float3 normal = normalize(mul(input.norm, (float3x3)sk_inst[id].world));
o.color = color * sk_inst[id].color;
return o;
}
float4 ps(psIn input) : SV_TARGET {
// pos to color
float3 col = float3(input.col_pos);
// linear to sRGB
return float4(f_inv(col.r), f_inv(col.g), f_inv(col.b), 1);
}

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

Binary file not shown.

View file

@ -2,8 +2,8 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dofdev.dofdemo"
android:versionCode="9"
android:versionName="1.09"
android:versionCode="10"
android:versionName="1.10"
android:installLocation="auto"
>
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32" />

View file

@ -51,7 +51,8 @@ todo
featuring:
[x] stretch_cursor
[ ] color_cube // move cube around picker which is constrained by cube limits
[x] color_cube
[ ] reach_cursor
[ ] orbital_view // same dis/mount system as snake in a box
[ ] fullstick
[ ] twist_cursor

View file

@ -12,7 +12,8 @@ static class Arts
static Material mat_both = new Material("unlit.hlsl");
static Material mat_backface = new Material("backface.hlsl");
static Material mat_justcolor = new Material("justcolor.hlsl");
static Material mat_colorcube = new Material("colorcube.hlsl");
static Material mat_colorcursor = new Material("justcolor.hlsl");
public static Vec3 shake = new(0, 0, 0);
static TextStyle text_style;
@ -39,11 +40,14 @@ static class Arts
mat_backface.DepthWrite = false;
mat_both.Chain = mat_backface;
// draw ontop of everything
mat_colorcursor.DepthTest = DepthTest.Always;
}
public static void Frame()
{
// Input.HandVisible(Handed.Max, false);
Input.HandVisible(Handed.Max, false);
// world
// Matrix m4_dof = Mono.dof_pose.ToMatrix(Mono.dof_scl);
@ -85,33 +89,52 @@ static class Arts
);
}
// reach cursor
// pos = trackedPoint
// if down
// pullPoint = pos
// color_cube
{
meshes["color_cube"].Draw(
mat_colorcube,
ColorCube.grab.pose.ToMatrix(ColorCube.scl)
);
// stretch = distance(pullPoint, pos)
// dir = (pos - pullPoint).normalized
// cursor = pos + dir * stretch * 3
Hierarchy.Push(ColorCube.grab.pose.ToMatrix(ColorCube.scl));
// ColorCube.cursor render ontop *degree symbol with color inside
Mesh.Sphere.Draw(
mat_colorcursor,
Matrix.TS(
ColorCube.cursor,
24.0f * U.cm
),
Color.White
);
Mesh.Sphere.Draw(
mat_colorcursor,
Matrix.TS(
ColorCube.cursor,
16.0f * U.cm
),
ColorCube.color
);
Hierarchy.Pop();
}
// Hierarchy.Pop();
// particles
Particle[] particles = VFX.particles;
for (int i = 0; i < particles.Length; i++)
{
Particle particle = particles[i];
meshes["FoodParticle"].Draw(
mat_unlit,
Matrix.TRS(
particle.pos,
particle.ori,
particle.scl
),
Color.Hex(0xC75A09FF).ToLinear()
);
}
// Particle[] particles = VFX.particles;
// for (int i = 0; i < particles.Length; i++)
// {
// Particle particle = particles[i];
// meshes["FoodParticle"].Draw(
// mat_unlit,
// Matrix.TRS(
// particle.pos,
// particle.ori,
// particle.scl
// ),
// Color.Hex(0xC75A09FF).ToLinear()
// );
// }
// menu
Matrix m4_menu = Mono.menu_pose.ToMatrix(Mono.menu_scale);

View file

@ -30,3 +30,49 @@ static class Stretch
static float deadzone = 0.1f;
static float strength = 3;
}
static class ColorCube
{
public static float scl = 6 * U.cm;
public static Grab grab;
static Vec3 last_position;
public static Vec3 cursor;
public static Color color;
public static void Init()
{
grab = new();
}
public static void Frame()
{
Vec3 delta = grab.pose.position - last_position;
// move cube around picker which is constrained by cube limits
cursor -= delta / scl;
cursor = V.XYZ(
Maths.s_clamp(cursor.x, 0.5f),
Maths.s_clamp(cursor.y, 0.5f),
Maths.s_clamp(cursor.z, 0.5f)
);
color = new Color(
f_inv(cursor.x + 0.5f),
f_inv(cursor.y + 0.5f),
f_inv(cursor.z + 0.5f),
1
);
last_position = grab.pose.position;
}
static float f_inv(float x) {
if (x >= 0.04045f) {
return MathF.Pow((x + 0.055f) / (1 + 0.055f), 2.4f);
}
return x / 12.92f;
}
}

View file

@ -36,6 +36,7 @@ static class Mono
// dof_pose = new(0, 0, 0); // new(0, -1, -2);
// dof_scl = 1.0f; // 0.1f;
Stretch.Init();
ColorCube.Init();
}
public static void Frame()
@ -99,7 +100,8 @@ static class Mono
Grab[] grabs = new Grab[]
{
Stretch.to_grab,
Stretch.from_grab
Stretch.from_grab,
ColorCube.grab,
};
foreach (var grab in grabs)
{
@ -150,5 +152,6 @@ static class Mono
}
Stretch.Frame();
ColorCube.Frame();
}
}