Skip to content

Commit

Permalink
enable player visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
coderedart committed Sep 13, 2023
1 parent a8d5295 commit 198819a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
7 changes: 4 additions & 3 deletions crates/joko_marker_format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ complain about it.
Marker Pack

1. Textures
1. identified by the relative path. case insensitive.
1. identified by the relative path. case sensitive. But to accommodate case-insensitive MS windows packs, we will convert all paths to lowercase when importing.
2. png format.
3. need to convert to a srgba texture and upload to gpu to use it
4. mostly tiny images. here's the composition of tekkit's pack textures
Expand All @@ -46,12 +46,13 @@ Marker Pack
| 435 | 500x500 |

2. Tbins
1. binary data of a series of vec3 positions. + mapid
1. binary data of a series of vec3 positions. + mapid + a version (just ver 2 for now)
2. need to generate a mesh to be usable to upload on gpu. different mesh for 2d map / minimap. trail_scale an affect width of the generated mesh
3. anim_speed attr needs dynamic texture coords (probably based on time delta)
3. anim_speed attr needs dynamic texture coords (probably based on time delta offset)
4. color attribute requires blending.
5. uses texture
6. can be statically or dynamically filtered (culled). but no cooldowns.

3. MarkerCategories
1. create a tree structure of menu to be displayed.
2. identified by their name (and parents in the hierarchy) as a unique path.
Expand Down
Empty file.
86 changes: 52 additions & 34 deletions crates/joko_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use billboard::MarkerObject;
use billboard::TrailObject;
use bytemuck::cast_slice;
use egui_backend::{egui, GfxBackend, WindowBackend};
use egui_render_wgpu::wgpu::util::BufferInitDescriptor;
use egui_render_wgpu::wgpu::util::DeviceExt;
use egui_render_wgpu::wgpu::*;
use egui_render_wgpu::EguiPainter;
use egui_render_wgpu::SurfaceManager;
use egui_render_wgpu::WgpuConfig;
use glam::vec2;
use glam::Mat4;
use glam::Vec3;
use jokolink::MumbleLink;
Expand All @@ -18,7 +21,9 @@ use tracing::info;
pub struct JokoRenderer {
mvp_bg: BindGroup,
mvp_ub: Buffer,
view_proj: Mat4,
player_visibility_pipeline: RenderPipeline,
viewport_buffer: Buffer,
pub billboard_renderer: BillBoardRenderer,
link: Option<Arc<MumbleLink>>,
painter: EguiPainter,
Expand Down Expand Up @@ -175,8 +180,21 @@ impl GfxBackend for JokoRenderer {
});
let billboard_renderer =
BillBoardRenderer::new(&dev, &mvp_bgl, surface_manager.surface_config.format);
let viewport_buffer = dev.create_buffer_init(&BufferInitDescriptor {
label: Some("viewport quad buffer"),
contents: bytemuck::cast_slice(&[
vec2(-1.0, -1.0),
vec2(-1.0, 1.0),
vec2(1.0, 1.0),
vec2(1.0, 1.0),
vec2(1.0, -1.0),
vec2(-1.0, -1.0),
]),
usage: BufferUsages::VERTEX,
});
Self {
player_visibility_pipeline,
viewport_buffer,
mvp_bg,
mvp_ub,
surface_manager,
Expand All @@ -187,6 +205,7 @@ impl GfxBackend for JokoRenderer {
billboard_renderer,
painter,
link: None,
view_proj: Default::default(),
}
}

Expand Down Expand Up @@ -239,7 +258,7 @@ impl GfxBackend for JokoRenderer {
);
}
{
let mut render_pass = command_encoder.begin_render_pass(&RenderPassDescriptor {
let mut rpass = command_encoder.begin_render_pass(&RenderPassDescriptor {
label: Some("joko render pass"),
color_attachments: &[Some(RenderPassColorAttachment {
view: self
Expand All @@ -255,35 +274,36 @@ impl GfxBackend for JokoRenderer {
})],
depth_stencil_attachment: None,
});
self.billboard_renderer.render(
&mut render_pass,
&self.mvp_bg,
&self.painter.managed_textures,
);
render_pass.set_pipeline(&self.player_visibility_pipeline);
/*
let point_on_screen = self.mvp.project_point3(self.player_position);
let width = self.wgpu_backend.surface_manager.surface_config.width as f32;
let height = self.wgpu_backend.surface_manager.surface_config.height as f32;
let x = point_on_screen.x * width / 2.0;
let y = point_on_screen.y * height / 2.0;
let x = width / 2.0 + x;
let y = height / 2.0 - y;
if let Some(link) = self.link.as_ref() {
self.billboard_renderer.render(
&mut rpass,
&self.mvp_bg,
&self.painter.managed_textures,
);
// clear any pixels that are right over player
rpass.set_pipeline(&self.player_visibility_pipeline);
let point_on_screen = self.view_proj.project_point3(link.f_avatar_position);
let width = self.surface_manager.surface_config.width as f32;
let height = self.surface_manager.surface_config.height as f32;
let x = point_on_screen.x * width / 2.0;
let y = point_on_screen.y * height / 2.0;
let x = width / 2.0 + x;
let y = height / 2.0 - y;

rpass.set_viewport(
f32::max(x - width * 0.1 / 2.0, 0.0),
f32::max(y - height * 0.2 / 2.0, 0.0),
width * 0.1,
height * 0.2,
0.0,
1.0,
);
// rpass.set_viewport(0.0, 0.0, 300.0, 300.0, 0.0, 1.0);
rpass.set_vertex_buffer(0, self.viewport_buffer.slice(..));
rpass.draw(0..6, 0..1);
*/
rpass.set_viewport(
f32::max(x - width * 0.1 / 2.0, 0.0),
f32::max(y - height * 0.2 / 2.0, 0.0),
width * 0.1,
height * 0.2,
0.0,
1.0,
);
rpass.set_vertex_buffer(0, self.viewport_buffer.slice(..));
rpass.draw(0..6, 0..1);
rpass.set_viewport(0.0, 0.0, width, height, 0.0, 1.0);
}
self.painter
.draw_egui_with_renderpass(&mut render_pass, draw_calls);
.draw_egui_with_renderpass(&mut rpass, draw_calls);
}
self.queue.submit(std::iter::once(command_encoder.finish()));
}
Expand Down Expand Up @@ -329,12 +349,10 @@ impl JokoRenderer {

let projection_matrix = Mat4::perspective_lh(link.fov, viewport_ratio, 1.0, 1000.0);

let view_projection_matrix = projection_matrix * view_matrix;
self.queue.write_buffer(
&self.mvp_ub,
0,
cast_slice(view_projection_matrix.as_ref().as_slice()),
);
let view_proj = projection_matrix * view_matrix;
self.queue
.write_buffer(&self.mvp_ub, 0, cast_slice(view_proj.as_ref().as_slice()));
self.view_proj = view_proj;
}
self.link = link;
}
Expand Down

0 comments on commit 198819a

Please sign in to comment.