basic patterns for incenter
This commit is contained in:
parent
0651c96f99
commit
6edb2a6d56
Binary file not shown.
|
@ -241,13 +241,13 @@ ed_sculpture_updated(App_State* state, r32 scale, r32 led_size)
|
|||
|
||||
r32 texel_x_min = (r32)pixel_x / (r32)pixels_dim;
|
||||
r32 texel_y_min = (r32)pixel_y / (r32)pixels_dim;
|
||||
r32 texel_x_max = texel_x_min + texel_dim;
|
||||
r32 texel_y_max = texel_y_min + texel_dim;
|
||||
r32 texel_x_max = texel_x_min + (texel_dim / 2);
|
||||
r32 texel_y_max = texel_y_min + (texel_dim / 2);
|
||||
|
||||
v2 t0 = (v2){texel_x_min, texel_y_min};
|
||||
v2 t1 = (v2){texel_x_max, texel_y_min};
|
||||
v2 t0 = (v2){texel_x_max, texel_y_max};
|
||||
v2 t1 = (v2){texel_x_max, texel_y_max};
|
||||
v2 t2 = (v2){texel_x_max, texel_y_max};
|
||||
v2 t3 = (v2){texel_x_min, texel_y_max};
|
||||
v2 t3 = (v2){texel_x_max, texel_y_max};
|
||||
|
||||
v3 p0 = HMM_AddVec3(c, (v3){ -r, -r, 0 });
|
||||
v3 p1 = HMM_AddVec3(c, (v3){ r, -r, 0 });
|
||||
|
@ -282,7 +282,16 @@ ed_sculpture_updated(App_State* state, r32 scale, r32 led_size)
|
|||
}
|
||||
|
||||
u8* pixels = ed_leds_to_texture(state, &scratch, pixels_dim);
|
||||
ed->sculpture_tex = texture_create(texture_desc_default(pixels_dim, pixels_dim), pixels);
|
||||
Texture_Desc pixel_texture_desc = {
|
||||
.w = pixels_dim,
|
||||
.h = pixels_dim,
|
||||
.s = pixels_dim,
|
||||
.min_filter = GL_NEAREST,
|
||||
.mag_filter = GL_NEAREST,
|
||||
.fmt_internal = GL_RGBA,
|
||||
.fmt_data = GL_RGBA
|
||||
};
|
||||
ed->sculpture_tex = texture_create(pixel_texture_desc, pixels);
|
||||
|
||||
scratch_release(scratch);
|
||||
lumenarium_env_validate();
|
||||
|
|
|
@ -85,11 +85,14 @@ ed_sculpture_visualizer(App_State* state)
|
|||
{
|
||||
Editor* ed = state->editor;
|
||||
|
||||
#define SCULPTURE_VIZ_BLOOM 0
|
||||
#if SCULPTURE_VIZ_BLOOM
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
os_gl_no_error();
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
#endif
|
||||
|
||||
// Set the viewport to the current layout's region so that the sculpture
|
||||
// never overlaps any other ui elements
|
||||
|
@ -108,10 +111,11 @@ ed_sculpture_visualizer(App_State* state)
|
|||
|
||||
// TODO(PS): TEMPORARY CAMERA CODE
|
||||
cam_theta += 0.01f;
|
||||
r32 cam_r = 100;
|
||||
v3 camera_pos = (v3){sinf(cam_theta) * cam_r, 25, cosf(cam_theta) * cam_r};
|
||||
r32 cam_r = 50;
|
||||
//v3 camera_pos = (v3){sinf(cam_theta) * cam_r, 25, cosf(cam_theta) * cam_r};
|
||||
v3 camera_pos = (v3){ 0, -4.9, -cam_r };
|
||||
r32 aspect = view_dim.x / view_dim.y;
|
||||
m44 proj = HMM_Perspective(45.0, aspect, 0.01f, 500);
|
||||
m44 proj = HMM_Perspective(72.0, aspect, 0.01f, 500);
|
||||
m44 view = HMM_LookAt(camera_pos, (v3){0,0,0}, (v3){0,1,0});
|
||||
|
||||
shader_bind(ed->sculpture_shd);
|
||||
|
@ -126,7 +130,9 @@ ed_sculpture_visualizer(App_State* state)
|
|||
geometry_drawi(ed->sculpture_geo, k, 0);
|
||||
|
||||
// reset the viewport for all other rendering
|
||||
#if SCULPTURE_VIZ_BLOOM
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
v2 wds = HMM_MultiplyVec2(ed->window_dim, ed->content_scale);
|
||||
glViewport(0, 0, (s32)wds.x, (s32)wds.y);
|
||||
|
||||
|
@ -141,4 +147,5 @@ ed_sculpture_visualizer(App_State* state)
|
|||
texture_bind(fbo_tex_c);
|
||||
geometry_bind(fs_quad);
|
||||
geometry_drawi(fs_quad, 6, 0);
|
||||
#endif // SCULPTURE_VIZ_BLOOM
|
||||
}
|
|
@ -22,6 +22,92 @@ en_frame_prepare(App_State* state)
|
|||
|
||||
global r32 tt = 0;
|
||||
|
||||
r32
|
||||
curve_ease_in_out(r32 t)
|
||||
{
|
||||
r32 tc = clamp(0, t, 1);
|
||||
r32 theta = (tc * r32_pi) - (r32_pi / 2.0f);
|
||||
r32 s = sinf(theta);
|
||||
r32 result = 0.5f + (s / 2.0f);
|
||||
return result;
|
||||
}
|
||||
|
||||
#define incenter_pos_to_unit(p) (v4){ ((p.x / 6.0f) + 0.5f), ((p.y / 6.0f) + 0.5f), ((p.z / 6.0f) + 0.5f), 1.0f }
|
||||
|
||||
void
|
||||
test_pattern(Assembly_Pixel_Buffer pixels)
|
||||
{
|
||||
for (u32 j = 0; j < pixels.len; j++)
|
||||
{
|
||||
v4 p = pixels.positions[j];
|
||||
pixels.pixels[j].r = (u8)(((sinf((5 * tt) + (p.x * 10)) + 1) * 0.5f) * 255);
|
||||
pixels.pixels[j].b = (u8)(((sinf((5 * tt) + (p.z * 10)) + 1) * 0.5f) * 255);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pattern_debug(Assembly_Pixel_Buffer pixels)
|
||||
{
|
||||
r32 scale = 6;
|
||||
r32 offset = 0;
|
||||
|
||||
for (u32 j = 0; j < pixels.len; j++)
|
||||
{
|
||||
v4 p = pixels.positions[j];
|
||||
v4 pp = incenter_pos_to_unit(p);
|
||||
pixels.pixels[j].r = pp.x * 255;
|
||||
pixels.pixels[j].g = pp.y * 255;
|
||||
pixels.pixels[j].b = pp.z * 255;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grow_pattern_sphere_function(Assembly_Pixel_Buffer pixels, v4 center, r32 radius, r32 falloff)
|
||||
{
|
||||
for (u32 j = 0; j < pixels.len; j++)
|
||||
{
|
||||
v4 p = incenter_pos_to_unit(pixels.positions[j]);
|
||||
r32 d0 = HMM_LengthVec4(HMM_SubtractVec4(p, center));
|
||||
r32 d1 = falloff - fabsf(d0 - radius);
|
||||
r32 b = d1 / falloff;
|
||||
|
||||
v3 color = {
|
||||
.x = 0.5f + 0.5f * sinf(p.x * r32_tau * 4.313f + tt * 0.53f),
|
||||
.y = 0.5f + 0.5f * cosf(0.2314f + p.y * r32_tau * 3.915f + tt * 0.5f),
|
||||
.z = 0.2f + 0.8f * p.z,
|
||||
};
|
||||
v3 color_b = HMM_MultiplyVec3f(color, b);
|
||||
|
||||
pixels.pixels[j].r = color_b.x * 255;
|
||||
pixels.pixels[j].g = color_b.y * 255;
|
||||
pixels.pixels[j].b = color_b.z * 255;
|
||||
}
|
||||
}
|
||||
void
|
||||
grow_pattern(Assembly_Pixel_Buffer pixels)
|
||||
{
|
||||
v4 center = (v4){};
|
||||
r32 radius = 0;
|
||||
r32 falloff = 0;
|
||||
//phase 1 - light up to center
|
||||
if (tt < 8)
|
||||
{
|
||||
r32 height = -0.2f + curve_ease_in_out(tt / 6) * 0.5f;
|
||||
center = (v4){ 0.5f, 0.2f + height, 0.5f, 1 };
|
||||
radius = 0.1f;
|
||||
falloff = 0.2f;
|
||||
}
|
||||
else if (tt >= 8)
|
||||
{
|
||||
r32 t = (tt - 8) / 5;
|
||||
center = (v4){ 0.5f, 0.5f, 0.5f, 1 };
|
||||
radius = 0.1f + curve_ease_in_out(t) * 0.27f;
|
||||
falloff = 0.2 - (curve_ease_in_out(t) * 0.1f);
|
||||
}
|
||||
|
||||
grow_pattern_sphere_function(pixels, center, radius, falloff);
|
||||
}
|
||||
|
||||
internal void
|
||||
en_frame(App_State* state)
|
||||
{
|
||||
|
@ -34,18 +120,14 @@ en_frame(App_State* state)
|
|||
// Temp Pattern Simulation
|
||||
|
||||
tt += 1.0f / 60.0f;
|
||||
if (tt > 50) tt = 0;
|
||||
|
||||
r32 hrange = 1;
|
||||
r32 range = hrange * 2;
|
||||
for (u32 i = 0; i < assemblies.len; i++)
|
||||
{
|
||||
Assembly_Pixel_Buffer pixels = assemblies.pixel_buffers[i];
|
||||
for (u32 j = 0; j < pixels.len; j++)
|
||||
{
|
||||
v4 p = pixels.positions[j];
|
||||
pixels.pixels[j].r = (u8)(((sinf((5 * tt) + (p.x * 10)) + 1) * 0.5f) * 255);
|
||||
pixels.pixels[j].b = (u8)(((sinf((5 * tt) + (p.z * 10)) + 1) * 0.5f) * 255);
|
||||
}
|
||||
grow_pattern(pixels);
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
|
|
@ -106,12 +106,12 @@ assembly_add_led(
|
|||
|
||||
void
|
||||
assembly_strip_create_leds(
|
||||
Assembly_Array* a,
|
||||
Assembly_Handle h,
|
||||
Assembly_Strip* strip,
|
||||
v3 start, v3 end,
|
||||
u32 led_count
|
||||
){
|
||||
Assembly_Array* a,
|
||||
Assembly_Handle h,
|
||||
Assembly_Strip* strip,
|
||||
v3 start, v3 end,
|
||||
u32 led_count
|
||||
){
|
||||
v3 delta_total = HMM_SubtractVec3(end, start);
|
||||
v3 delta_step = HMM_MultiplyVec3f(delta_total, 1.0f / (r32)led_count);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ incenter_init(App_State* state)
|
|||
{
|
||||
// create a fake sculpture
|
||||
Assembly_Handle ah = assembly_add(&state->assemblies, lit_str("test"), 5043, 41);
|
||||
//Assembly_Handle ah = assembly_add(&state->assemblies, lit_str("test"), 20000, 150);
|
||||
|
||||
scratch_get(scratch);
|
||||
Allocator* s = scratch.a;
|
||||
|
|
Loading…
Reference in New Issue