Compare commits
3 Commits
bfc0c6cc39
...
4cc52535fc
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cc52535fc | |||
| 4ed3e17432 | |||
| 4ffcbdab19 |
@ -259,7 +259,7 @@ draw_tools_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) {
|
|||||||
groundType = .WATER;
|
groundType = .WATER;
|
||||||
}
|
}
|
||||||
r.y += r.h;
|
r.y += r.h;
|
||||||
if GR.button(r, "Sand", *t_button_selectable(theme, groundType == .WATER)) {
|
if GR.button(r, "Sand", *t_button_selectable(theme, groundType == .SAND)) {
|
||||||
groundType = .SAND;
|
groundType = .SAND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -254,87 +254,10 @@ draw_material_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {
|
|||||||
|
|
||||||
|
|
||||||
draw_trile_editor :: () {
|
draw_trile_editor :: () {
|
||||||
|
create_set_cam_rendering_task(get_trile_editor_camera());
|
||||||
draw_trile();
|
w := New(World,, temp);
|
||||||
}
|
create_sky_rendering_task(*w.conf);
|
||||||
|
create_trixel_rendering_task(editor_current_trile);
|
||||||
draw_trile :: () {
|
|
||||||
return; // @ToDo: Implement this using the new drawing commands.
|
|
||||||
if is_in_reflection_pass then return; // We don't want to double update the buffer.
|
|
||||||
|
|
||||||
if editor_current_trile == null then return;
|
|
||||||
cam := get_trile_editor_camera();
|
|
||||||
|
|
||||||
mvp := create_viewproj(*cam);
|
|
||||||
vs_params : Vs_Params;
|
|
||||||
vs_params.mvp = mvp.floats;
|
|
||||||
vs_params.camera = cam.position.component;
|
|
||||||
|
|
||||||
world_conf : Trixel_World_Config;
|
|
||||||
wc : *World_Config = *(World_Config.{});
|
|
||||||
world_config_to_shader_type(wc, *world_conf);
|
|
||||||
|
|
||||||
trixels : [4096]Position_Color;
|
|
||||||
|
|
||||||
min_distance : float = 999.0;
|
|
||||||
|
|
||||||
|
|
||||||
ray := get_mouse_ray(*cam);
|
|
||||||
|
|
||||||
hovered_trixel_x = -1;
|
|
||||||
hovered_trixel_y = -1;
|
|
||||||
hovered_trixel_z = -1;
|
|
||||||
|
|
||||||
for x: 0..15 {
|
|
||||||
for y: 0..15 {
|
|
||||||
for z: 0..15 {
|
|
||||||
if editor_current_trile.trixels[x][y][z].empty then continue;
|
|
||||||
hit := does_ray_hit_cube(ray, .{ .{x * TRIXEL_SIZE, y * TRIXEL_SIZE, z * TRIXEL_SIZE}, .{TRIXEL_SIZE, TRIXEL_SIZE, TRIXEL_SIZE}});
|
|
||||||
if hit.hit && hit.distance < min_distance {
|
|
||||||
hovered_trixel_x = x;
|
|
||||||
hovered_trixel_y = y;
|
|
||||||
hovered_trixel_z = z;
|
|
||||||
min_distance = hit.distance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trixel_count : s32 = 0;
|
|
||||||
|
|
||||||
for x: 0..15 {
|
|
||||||
for y: 0..15 {
|
|
||||||
for z: 0..15 {
|
|
||||||
if editor_current_trile.trixels[x][y][z].empty then continue;
|
|
||||||
|
|
||||||
trixels[trixel_count].pos.x = x * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
|
||||||
trixels[trixel_count].pos.y = y * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
|
||||||
trixels[trixel_count].pos.z = z * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
|
||||||
trixels[trixel_count].pos.w = 1.0;
|
|
||||||
trixel_color := editor_current_trile.trixels[x][y][z].material.color;
|
|
||||||
|
|
||||||
if hovered_trixel_x == x &&
|
|
||||||
hovered_trixel_y == y &&
|
|
||||||
hovered_trixel_z == z {
|
|
||||||
trixel_color = .{1.0, 0.0, 0.0};
|
|
||||||
}
|
|
||||||
|
|
||||||
trixels[trixel_count].col = .{trixel_color.x, trixel_color.y, trixel_color.z, material_encode_to_float(editor_current_trile.trixels[x][y][z].material)};
|
|
||||||
trixel_count += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sg_update_buffer(gPipelines.trixel.bind.vertex_buffers[2], *(sg_range.{
|
|
||||||
ptr = trixels.data,
|
|
||||||
size = size_of(type_of(trixels)),
|
|
||||||
}));
|
|
||||||
|
|
||||||
sg_apply_pipeline(gPipelines.trixel.pipeline);
|
|
||||||
sg_apply_bindings(*gPipelines.trixel.bind);
|
|
||||||
sg_apply_uniforms(UB_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params)) }));
|
|
||||||
sg_apply_uniforms(UB_trixel_world_config, *(sg_range.{ptr = *world_conf, size = size_of(type_of(world_conf))}));
|
|
||||||
sg_draw(0, 36, trixel_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trile_editor_shortcuts :: () {
|
trile_editor_shortcuts :: () {
|
||||||
|
|||||||
@ -18,6 +18,8 @@ Render_Command_Type :: enum {
|
|||||||
GENERATE_GROUND;
|
GENERATE_GROUND;
|
||||||
ADD_TRILE_POSITIONS;
|
ADD_TRILE_POSITIONS;
|
||||||
DRAW_TRILE_POSITIONS;
|
DRAW_TRILE_POSITIONS;
|
||||||
|
UPDATE_TRIXELS;
|
||||||
|
DRAW_TRIXELS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Render_Command :: struct {
|
Render_Command :: struct {
|
||||||
@ -44,6 +46,17 @@ Render_Command_Draw_Trile_Positions :: struct {
|
|||||||
conf : *World_Config;
|
conf : *World_Config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Render_Command_Update_Trixels :: struct {
|
||||||
|
#as using c : Render_Command;
|
||||||
|
c.type = .UPDATE_TRIXELS;
|
||||||
|
trile : *Trile;
|
||||||
|
}
|
||||||
|
|
||||||
|
Render_Command_Draw_Trixels :: struct {
|
||||||
|
#as using c : Render_Command;
|
||||||
|
c.type = .DRAW_TRIXELS;
|
||||||
|
}
|
||||||
|
|
||||||
Render_Command_Draw_Ground :: struct {
|
Render_Command_Draw_Ground :: struct {
|
||||||
#as using c : Render_Command;
|
#as using c : Render_Command;
|
||||||
c.type = .DRAW_GROUND;
|
c.type = .DRAW_GROUND;
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
camera: Camera;
|
camera: Camera;
|
||||||
|
|
||||||
|
trixel_count : s32 = 0;
|
||||||
|
|
||||||
trile_offsets : [..]s32;
|
trile_offsets : [..]s32;
|
||||||
current_trile_offset_index : s32 = 0;
|
current_trile_offset_index : s32 = 0;
|
||||||
|
|
||||||
@ -23,10 +25,62 @@ backend_handle_command :: (cmd: *Render_Command) {
|
|||||||
case .DRAW_GROUND;
|
case .DRAW_GROUND;
|
||||||
ground_command := cast(*Render_Command_Draw_Ground)cmd;
|
ground_command := cast(*Render_Command_Draw_Ground)cmd;
|
||||||
backend_draw_ground(ground_command.worldConfig);
|
backend_draw_ground(ground_command.worldConfig);
|
||||||
|
case .UPDATE_TRIXELS;
|
||||||
|
trixel_update_command := cast(*Render_Command_Update_Trixels)cmd;
|
||||||
|
backend_update_trixels(trixel_update_command.trile);
|
||||||
|
case .DRAW_TRIXELS;
|
||||||
|
backend_draw_trixels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backend_update_trixels :: (trile: *Trile) {
|
||||||
|
if trile == null then return;
|
||||||
|
|
||||||
|
trixels : [4096]Position_Color;
|
||||||
|
trixel_count = 0;
|
||||||
|
|
||||||
|
for x: 0..15 {
|
||||||
|
for y: 0..15 {
|
||||||
|
for z: 0..15 {
|
||||||
|
if trile.trixels[x][y][z].empty then continue;
|
||||||
|
|
||||||
|
trixels[trixel_count].pos.x = x * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
||||||
|
trixels[trixel_count].pos.y = y * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
||||||
|
trixels[trixel_count].pos.z = z * (1.0 / 16.0) + TRIXEL_SIZE_HALF;
|
||||||
|
trixels[trixel_count].pos.w = 1.0;
|
||||||
|
trixel_color := trile.trixels[x][y][z].material.color;
|
||||||
|
|
||||||
|
trixels[trixel_count].col = .{trixel_color.x, trixel_color.y, trixel_color.z, material_encode_to_float(trile.trixels[x][y][z].material)};
|
||||||
|
trixel_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sg_update_buffer(gPipelines.trixel.bind.vertex_buffers[2], *(sg_range.{
|
||||||
|
ptr = trixels.data,
|
||||||
|
size = size_of(type_of(trixels)),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
backend_draw_trixels :: () {
|
||||||
|
if trixel_count == 0 then return;
|
||||||
|
|
||||||
|
mvp := create_viewproj(*camera);
|
||||||
|
vs_params : Vs_Params;
|
||||||
|
vs_params.mvp = mvp.floats;
|
||||||
|
vs_params.camera = camera.position.component;
|
||||||
|
|
||||||
|
world_conf : Trixel_World_Config;
|
||||||
|
wc : *World_Config = *(World_Config.{});
|
||||||
|
world_config_to_shader_type(wc, *world_conf);
|
||||||
|
|
||||||
|
sg_apply_pipeline(gPipelines.trixel.pipeline);
|
||||||
|
sg_apply_bindings(*gPipelines.trixel.bind);
|
||||||
|
sg_apply_uniforms(UB_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params)) }));
|
||||||
|
sg_apply_uniforms(UB_trixel_world_config, *(sg_range.{ptr = *world_conf, size = size_of(type_of(world_conf))}));
|
||||||
|
sg_draw(0, 36, trixel_count);
|
||||||
|
}
|
||||||
|
|
||||||
backend_add_trile_positions :: (positions : []Vector4) {
|
backend_add_trile_positions :: (positions : []Vector4) {
|
||||||
offset := sg_append_buffer(gPipelines.trile.bind.vertex_buffers[3], *(sg_range.{
|
offset := sg_append_buffer(gPipelines.trile.bind.vertex_buffers[3], *(sg_range.{
|
||||||
ptr = positions.data,
|
ptr = positions.data,
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
|
|
||||||
@ -1,8 +1,6 @@
|
|||||||
create_world_rendering_tasks :: (world: *World) {
|
create_world_rendering_tasks :: (world: *World) {
|
||||||
skytask := Rendering_Task_Sky.{type = .SKY, worldConfig = *world.conf};
|
create_sky_rendering_task(*world.conf);
|
||||||
add_rendering_task(skytask);
|
create_ground_rendering_task(world);
|
||||||
groundtask := Rendering_Task_Ground.{type = .GROUND, world = world};
|
|
||||||
add_rendering_task(groundtask);
|
|
||||||
for world.positions {
|
for world.positions {
|
||||||
triletask := Rendering_Task_Trile.{};
|
triletask := Rendering_Task_Trile.{};
|
||||||
triletask.trile = it.trileName;
|
triletask.trile = it.trileName;
|
||||||
@ -12,6 +10,22 @@ create_world_rendering_tasks :: (world: *World) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_sky_rendering_task :: (conf: *World_Config) {
|
||||||
|
skytask := Rendering_Task_Sky.{type = .SKY, worldConfig = conf};
|
||||||
|
add_rendering_task(skytask);
|
||||||
|
}
|
||||||
|
|
||||||
|
create_trixel_rendering_task :: (trile: *Trile) {
|
||||||
|
trixeltask := Rendering_Task_Trixels.{type = .TRIXELS, trile = trile};
|
||||||
|
add_rendering_task(trixeltask);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
create_ground_rendering_task :: (world: *World) {
|
||||||
|
groundtask := Rendering_Task_Ground.{type = .GROUND, world = world};
|
||||||
|
add_rendering_task(groundtask);
|
||||||
|
}
|
||||||
|
|
||||||
create_set_cam_rendering_task :: (cam: Camera) {
|
create_set_cam_rendering_task :: (cam: Camera) {
|
||||||
camtask := Rendering_Task_Set_Camera.{type = .SET_CAMERA, camera = cam};
|
camtask := Rendering_Task_Set_Camera.{type = .SET_CAMERA, camera = cam};
|
||||||
add_rendering_task(camtask);
|
add_rendering_task(camtask);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ Rendering_Task_Type :: enum {
|
|||||||
SKY;
|
SKY;
|
||||||
SET_CAMERA;
|
SET_CAMERA;
|
||||||
TRILE; // not implemented yet
|
TRILE; // not implemented yet
|
||||||
|
TRIXELS;
|
||||||
SPRITE; // not implemented yet
|
SPRITE; // not implemented yet
|
||||||
PARTICLES; // not implemented yet
|
PARTICLES; // not implemented yet
|
||||||
};
|
};
|
||||||
@ -39,6 +40,12 @@ Rendering_Task_Trile :: struct {
|
|||||||
worldConf : *World_Config;
|
worldConf : *World_Config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rendering_Task_Trixels :: struct {
|
||||||
|
#as using t : Rendering_Task;
|
||||||
|
t.type = .TRIXELS;
|
||||||
|
trile : *Trile;
|
||||||
|
}
|
||||||
|
|
||||||
Rendering_Task_Set_Camera :: struct {
|
Rendering_Task_Set_Camera :: struct {
|
||||||
#as using t : Rendering_Task;
|
#as using t : Rendering_Task;
|
||||||
camera : Camera;
|
camera : Camera;
|
||||||
@ -59,6 +66,16 @@ rendering_tasklist : [..]*Rendering_Task;
|
|||||||
tasks_to_commands :: () {
|
tasks_to_commands :: () {
|
||||||
for rendering_tasklist {
|
for rendering_tasklist {
|
||||||
if it.type == {
|
if it.type == {
|
||||||
|
case .TRIXELS;
|
||||||
|
trixelsTask := (cast(*Rendering_Task_Trixels)it);
|
||||||
|
updateCommand := New(Render_Command_Update_Trixels,, temp);
|
||||||
|
updateCommand.trile = trixelsTask.trile;
|
||||||
|
array_add(*render_command_buckets.setup, updateCommand);
|
||||||
|
drawCommand := New(Render_Command_Draw_Trixels,, temp);
|
||||||
|
array_add(*render_command_buckets.main, drawCommand);
|
||||||
|
// Currently no need to draw trixels anywhere but the editor so no
|
||||||
|
// need for drawing them in the planar reflection pass...
|
||||||
|
// array_add(*render_command_buckets.reflection, drawCommand);
|
||||||
case .TRILE;
|
case .TRILE;
|
||||||
trileTask := (cast(*Rendering_Task_Trile)it);
|
trileTask := (cast(*Rendering_Task_Trile)it);
|
||||||
addPositionsCmd := New(Render_Command_Add_Trile_Positions,, temp);
|
addPositionsCmd := New(Render_Command_Add_Trile_Positions,, temp);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user