color cube
This commit is contained in:
parent
19f90b9633
commit
ca4b715130
7 changed files with 151 additions and 30 deletions
48
Assets/colorcube.hlsl
Normal file
48
Assets/colorcube.hlsl
Normal 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)
BIN
Assets/meshes/assets.glb
(Stored with Git LFS)
Binary file not shown.
|
@ -2,8 +2,8 @@
|
||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.dofdev.dofdemo"
|
package="com.dofdev.dofdemo"
|
||||||
android:versionCode="9"
|
android:versionCode="10"
|
||||||
android:versionName="1.09"
|
android:versionName="1.10"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
>
|
>
|
||||||
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32" />
|
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32" />
|
||||||
|
|
|
@ -51,7 +51,8 @@ todo
|
||||||
|
|
||||||
featuring:
|
featuring:
|
||||||
[x] stretch_cursor
|
[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
|
[ ] orbital_view // same dis/mount system as snake in a box
|
||||||
[ ] fullstick
|
[ ] fullstick
|
||||||
[ ] twist_cursor
|
[ ] twist_cursor
|
||||||
|
|
69
src/Arts.cs
69
src/Arts.cs
|
@ -12,7 +12,8 @@ static class Arts
|
||||||
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");
|
||||||
|
static Material mat_colorcube = new Material("colorcube.hlsl");
|
||||||
|
static Material mat_colorcursor = new Material("justcolor.hlsl");
|
||||||
public static Vec3 shake = new(0, 0, 0);
|
public static Vec3 shake = new(0, 0, 0);
|
||||||
|
|
||||||
static TextStyle text_style;
|
static TextStyle text_style;
|
||||||
|
@ -39,11 +40,14 @@ static class Arts
|
||||||
mat_backface.DepthWrite = false;
|
mat_backface.DepthWrite = false;
|
||||||
|
|
||||||
mat_both.Chain = mat_backface;
|
mat_both.Chain = mat_backface;
|
||||||
|
|
||||||
|
// draw ontop of everything
|
||||||
|
mat_colorcursor.DepthTest = DepthTest.Always;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Frame()
|
public static void Frame()
|
||||||
{
|
{
|
||||||
// Input.HandVisible(Handed.Max, false);
|
Input.HandVisible(Handed.Max, false);
|
||||||
|
|
||||||
// world
|
// world
|
||||||
// Matrix m4_dof = Mono.dof_pose.ToMatrix(Mono.dof_scl);
|
// Matrix m4_dof = Mono.dof_pose.ToMatrix(Mono.dof_scl);
|
||||||
|
@ -85,33 +89,52 @@ static class Arts
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reach cursor
|
// color_cube
|
||||||
// pos = trackedPoint
|
{
|
||||||
// if down
|
meshes["color_cube"].Draw(
|
||||||
// pullPoint = pos
|
mat_colorcube,
|
||||||
|
ColorCube.grab.pose.ToMatrix(ColorCube.scl)
|
||||||
|
);
|
||||||
|
|
||||||
// stretch = distance(pullPoint, pos)
|
Hierarchy.Push(ColorCube.grab.pose.ToMatrix(ColorCube.scl));
|
||||||
// dir = (pos - pullPoint).normalized
|
// ColorCube.cursor render ontop *degree symbol with color inside
|
||||||
// cursor = pos + dir * stretch * 3
|
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();
|
// Hierarchy.Pop();
|
||||||
|
|
||||||
|
|
||||||
// particles
|
// particles
|
||||||
Particle[] particles = VFX.particles;
|
// Particle[] particles = VFX.particles;
|
||||||
for (int i = 0; i < particles.Length; i++)
|
// for (int i = 0; i < particles.Length; i++)
|
||||||
{
|
// {
|
||||||
Particle particle = particles[i];
|
// Particle particle = particles[i];
|
||||||
meshes["FoodParticle"].Draw(
|
// meshes["FoodParticle"].Draw(
|
||||||
mat_unlit,
|
// mat_unlit,
|
||||||
Matrix.TRS(
|
// Matrix.TRS(
|
||||||
particle.pos,
|
// particle.pos,
|
||||||
particle.ori,
|
// particle.ori,
|
||||||
particle.scl
|
// particle.scl
|
||||||
),
|
// ),
|
||||||
Color.Hex(0xC75A09FF).ToLinear()
|
// Color.Hex(0xC75A09FF).ToLinear()
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
// menu
|
// menu
|
||||||
Matrix m4_menu = Mono.menu_pose.ToMatrix(Mono.menu_scale);
|
Matrix m4_menu = Mono.menu_pose.ToMatrix(Mono.menu_scale);
|
||||||
|
|
46
src/Dofs.cs
46
src/Dofs.cs
|
@ -30,3 +30,49 @@ static class Stretch
|
||||||
static float deadzone = 0.1f;
|
static float deadzone = 0.1f;
|
||||||
static float strength = 3;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ static class Mono
|
||||||
// dof_pose = new(0, 0, 0); // new(0, -1, -2);
|
// dof_pose = new(0, 0, 0); // new(0, -1, -2);
|
||||||
// dof_scl = 1.0f; // 0.1f;
|
// dof_scl = 1.0f; // 0.1f;
|
||||||
Stretch.Init();
|
Stretch.Init();
|
||||||
|
ColorCube.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Frame()
|
public static void Frame()
|
||||||
|
@ -99,7 +100,8 @@ static class Mono
|
||||||
Grab[] grabs = new Grab[]
|
Grab[] grabs = new Grab[]
|
||||||
{
|
{
|
||||||
Stretch.to_grab,
|
Stretch.to_grab,
|
||||||
Stretch.from_grab
|
Stretch.from_grab,
|
||||||
|
ColorCube.grab,
|
||||||
};
|
};
|
||||||
foreach (var grab in grabs)
|
foreach (var grab in grabs)
|
||||||
{
|
{
|
||||||
|
@ -150,5 +152,6 @@ static class Mono
|
||||||
}
|
}
|
||||||
|
|
||||||
Stretch.Frame();
|
Stretch.Frame();
|
||||||
|
ColorCube.Frame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue