mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
Compare commits
7 commits
99cc2d1e72
...
75cb0ead6b
Author | SHA1 | Date | |
---|---|---|---|
griffi-gh | 75cb0ead6b | ||
griffi-gh | 487cf31843 | ||
griffi-gh | 7aa91b6414 | ||
griffi-gh | 196a7010b6 | ||
griffi-gh | c8cacafab5 | ||
griffi-gh | d738b228f2 | ||
griffi-gh | 811bd8d8b4 |
|
@ -40,7 +40,7 @@ var s_diffuse: sampler;
|
|||
@fragment
|
||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
let color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.uv, in.tex_index);
|
||||
if (color.a == 0.) {
|
||||
if (color.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
return color;
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn process_winit_events(world: &mut World, event: &Event<()>) {
|
|||
EventComponent,
|
||||
InputDeviceEvent {
|
||||
device_id: *device_id,
|
||||
event: DeviceEvent::Key(RawKeyEvent {
|
||||
event: DeviceEvent::Key(winit::event::RawKeyEvent {
|
||||
physical_key: event.physical_key,
|
||||
state: event.state,
|
||||
})
|
||||
|
|
|
@ -70,7 +70,7 @@ pub fn load_prefabs(
|
|||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest, //TODO min_filter Linear, requires filtering sampler
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
|
@ -82,7 +82,7 @@ pub fn load_prefabs(
|
|||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: false },
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
view_dimension: wgpu::TextureViewDimension::D2Array,
|
||||
multisampled: false,
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ pub fn load_prefabs(
|
|||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::NonFiltering),
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: None,
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, SystemModificator, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator};
|
||||
use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator};
|
||||
use winit::dpi::PhysicalSize;
|
||||
use glam::Vec3;
|
||||
use crate::{events::WindowResizedEvent, state::is_ingame};
|
||||
|
||||
mod renderer;
|
||||
mod primitives;
|
||||
pub use renderer::Renderer;
|
||||
|
||||
use self::{camera::CameraUniformBuffer, world::WorldRenderState};
|
||||
|
||||
pub mod background;
|
||||
pub mod world;
|
||||
pub mod camera;
|
||||
pub mod depth;
|
||||
|
@ -28,11 +28,14 @@ pub struct RenderCtx<'a> {
|
|||
pub surface_view: &'a wgpu::TextureView,
|
||||
}
|
||||
|
||||
//TODO run init_world_render_state only once ingame?
|
||||
|
||||
pub fn init_rendering() -> Workload {
|
||||
(
|
||||
depth::init_depth_texture,
|
||||
camera::init_camera_uniform_buffer,
|
||||
world::init_world_render_state, //TODO run only once ingame
|
||||
world::init_world_render_state, //requires depth and camera buffers
|
||||
primitives::init_primitives,
|
||||
).into_sequential_workload()
|
||||
}
|
||||
|
||||
|
@ -58,39 +61,18 @@ pub fn render_master(storages: AllStoragesViewMut) {
|
|||
let surface_texture = renderer.surface().get_current_texture().unwrap();
|
||||
let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
{
|
||||
let bg = storages.borrow::<UniqueView<BackgroundColor>>().unwrap().0;
|
||||
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("rpass_background"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &surface_view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: bg.x as f64,
|
||||
g: bg.y as f64,
|
||||
b: bg.z as f64,
|
||||
a: 1.0,
|
||||
}),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
let mut data = RenderCtx {
|
||||
renderer: &renderer,
|
||||
encoder: &mut encoder,
|
||||
surface_view: &surface_view,
|
||||
};
|
||||
|
||||
storages.run_with_data(background::clear_bg, &mut data);
|
||||
if storages.run(is_ingame) {
|
||||
storages.run_with_data(world::draw_world, &mut data);
|
||||
}
|
||||
|
||||
renderer.queue().submit(std::iter::once(encoder.finish()));
|
||||
renderer.queue().submit([encoder.finish()]);
|
||||
surface_texture.present();
|
||||
}
|
||||
|
||||
|
@ -104,30 +86,6 @@ pub fn resize_renderer(
|
|||
}
|
||||
}
|
||||
|
||||
//Deprecated WindowSize thingy
|
||||
|
||||
// #[derive(Unique, Clone, Copy)]
|
||||
// #[repr(transparent)]
|
||||
// #[deprecated = "use Renderer.size instead"]
|
||||
// #[allow(deprecated)]
|
||||
// pub struct WindowSize(pub UVec2);
|
||||
|
||||
// pub fn init_window_size(storages: AllStoragesView) {
|
||||
// let size = storages.borrow::<View<WindowResizedEvent>>().unwrap().iter().next().unwrap().0;
|
||||
// storages.add_unique(WindowSize(size))
|
||||
// }
|
||||
|
||||
// pub fn update_window_size(
|
||||
// mut win_size: UniqueViewMut<WindowSize>,
|
||||
// resize: View<WindowResizedEvent>,
|
||||
// ) {
|
||||
// if let Some(resize) = resize.iter().next() {
|
||||
// win_size.0 = resize.0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn if_resized (
|
||||
// resize: View<WindowResizedEvent>,
|
||||
// ) -> bool {
|
||||
// pub fn if_resized (resize: View<WindowResizedEvent>,) -> bool {
|
||||
// resize.len() > 0
|
||||
// }
|
||||
|
|
25
kubi/src/rendering/background.rs
Normal file
25
kubi/src/rendering/background.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use shipyard::UniqueView;
|
||||
use super::{BackgroundColor, RenderCtx};
|
||||
|
||||
pub fn clear_bg(
|
||||
ctx: &mut RenderCtx,
|
||||
bg: UniqueView<BackgroundColor>,
|
||||
) {
|
||||
let _rpass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("clear_bg"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: ctx.surface_view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: bg.0.x as f64,
|
||||
g: bg.0.y as f64,
|
||||
b: bg.0.z as f64,
|
||||
a: 1.0,
|
||||
}),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
..Default::default()
|
||||
});
|
||||
}
|
|
@ -1,30 +1,24 @@
|
|||
// use shipyard::{Workload, IntoWorkload};
|
||||
// use glium::implement_vertex;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use shipyard::{IntoWorkload, Workload};
|
||||
|
||||
// pub mod cube;
|
||||
// pub mod rect;
|
||||
// pub mod stri;
|
||||
mod cube;
|
||||
|
||||
// use cube::init_cube_primitive;
|
||||
// use rect::init_rect_primitive;
|
||||
// use stri::init_stri_primitive;
|
||||
pub fn init_primitives() -> Workload {
|
||||
(
|
||||
cube::init_cube_primitive,
|
||||
).into_workload()
|
||||
}
|
||||
|
||||
// #[derive(Clone, Copy, Default)]
|
||||
// pub struct PositionOnlyVertex {
|
||||
// pub position: [f32; 3],
|
||||
// }
|
||||
// implement_vertex!(PositionOnlyVertex, position);
|
||||
#[derive(Clone, Copy, Default, Pod, Zeroable)]
|
||||
#[repr(C, packed)]
|
||||
pub struct PrimitiveVertex {
|
||||
pub position: [f32; 3],
|
||||
}
|
||||
|
||||
// #[derive(Clone, Copy, Default)]
|
||||
// pub struct PositionOnlyVertex2d {
|
||||
// pub position: [f32; 2],
|
||||
// }
|
||||
// implement_vertex!(PositionOnlyVertex2d, position);
|
||||
|
||||
// pub fn init_primitives() -> Workload {
|
||||
// (
|
||||
// init_cube_primitive,
|
||||
// init_rect_primitive,
|
||||
// init_stri_primitive,
|
||||
// ).into_workload()
|
||||
// }
|
||||
impl PrimitiveVertex {
|
||||
pub const LAYOUT: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<PrimitiveVertex>() as wgpu::BufferAddress,
|
||||
step_mode: wgpu::VertexStepMode::Vertex,
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float32x3],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,85 +1,49 @@
|
|||
// use shipyard::{AllStoragesView, NonSendSync, UniqueView, Unique};
|
||||
// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
||||
// use crate::rendering::Renderer;
|
||||
// use super::PositionOnlyVertex;
|
||||
use shipyard::{AllStoragesView, Unique, UniqueView};
|
||||
use wgpu::util::DeviceExt;
|
||||
use crate::rendering::{BufferPair, Renderer};
|
||||
use super::PrimitiveVertex;
|
||||
|
||||
// #[derive(Unique)]
|
||||
// pub struct CubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
|
||||
#[derive(Unique)]
|
||||
pub struct CubePrimitive(pub BufferPair);
|
||||
|
||||
// #[derive(Unique)]
|
||||
// pub struct CenteredCubePrimitive(pub VertexBuffer<PositionOnlyVertex>, pub IndexBuffer<u16>);
|
||||
/// Vertices for a centered cube with a side length of 1
|
||||
const CUBE_VERTICES: &[PrimitiveVertex] = &[
|
||||
// front
|
||||
PrimitiveVertex { position: [-0.5, -0.5, 0.5] },
|
||||
PrimitiveVertex { position: [ 0.5, -0.5, 0.5] },
|
||||
PrimitiveVertex { position: [ 0.5, 0.5, 0.5] },
|
||||
PrimitiveVertex { position: [-0.5, 0.5, 0.5] },
|
||||
// back
|
||||
PrimitiveVertex { position: [-0.5, -0.5, -0.5] },
|
||||
PrimitiveVertex { position: [ 0.5, -0.5, -0.5] },
|
||||
PrimitiveVertex { position: [ 0.5, 0.5, -0.5] },
|
||||
PrimitiveVertex { position: [-0.5, 0.5, -0.5] },
|
||||
];
|
||||
|
||||
// const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[
|
||||
// // front
|
||||
// PositionOnlyVertex { position: [-0.5, -0.5, 0.5] },
|
||||
// PositionOnlyVertex { position: [ 0.5, -0.5, 0.5] },
|
||||
// PositionOnlyVertex { position: [ 0.5, 0.5, 0.5] },
|
||||
// PositionOnlyVertex { position: [-0.5, 0.5, 0.5] },
|
||||
// // back
|
||||
// PositionOnlyVertex { position: [-0.5, -0.5, -0.5] },
|
||||
// PositionOnlyVertex { position: [ 0.5, -0.5, -0.5] },
|
||||
// PositionOnlyVertex { position: [ 0.5, 0.5, -0.5] },
|
||||
// PositionOnlyVertex { position: [-0.5, 0.5, -0.5] },
|
||||
// ];
|
||||
// const CUBE_VERTICES: &[PositionOnlyVertex] = &[
|
||||
// // front
|
||||
// PositionOnlyVertex { position: [0.0, 0.0, 1.0] },
|
||||
// PositionOnlyVertex { position: [1.0, 0.0, 1.0] },
|
||||
// PositionOnlyVertex { position: [1.0, 1.0, 1.0] },
|
||||
// PositionOnlyVertex { position: [0.0, 1.0, 1.0] },
|
||||
// // back
|
||||
// PositionOnlyVertex { position: [0.0, 0.0, 0.0] },
|
||||
// PositionOnlyVertex { position: [1.0, 0.0, 0.0] },
|
||||
// PositionOnlyVertex { position: [1.0, 1.0, 0.0] },
|
||||
// PositionOnlyVertex { position: [0.0, 1.0, 0.0] },
|
||||
// ];
|
||||
// const CUBE_INDICES: &[u16] = &[
|
||||
// // front
|
||||
// 0, 1, 2,
|
||||
// 2, 3, 0,
|
||||
// // right
|
||||
// 1, 5, 6,
|
||||
// 6, 2, 1,
|
||||
// // back
|
||||
// 7, 6, 5,
|
||||
// 5, 4, 7,
|
||||
// // left
|
||||
// 4, 0, 3,
|
||||
// 3, 7, 4,
|
||||
// // bottom
|
||||
// 4, 5, 1,
|
||||
// 1, 0, 4,
|
||||
// // top
|
||||
// 3, 2, 6,
|
||||
// 6, 7, 3
|
||||
// ];
|
||||
/// Indices for a cube primitive
|
||||
const CUBE_INDICES: &[u16] = &[
|
||||
0, 1, 2, 2, 3, 0, // front
|
||||
1, 5, 6, 6, 2, 1, // right
|
||||
7, 6, 5, 5, 4, 7, // back
|
||||
4, 0, 3, 3, 7, 4, // left
|
||||
4, 5, 1, 1, 0, 4, // bottom
|
||||
3, 2, 6, 6, 7, 3, // top
|
||||
];
|
||||
|
||||
// pub(super) fn init_cube_primitive(
|
||||
// storages: AllStoragesView,
|
||||
// display: NonSendSync<UniqueView<Renderer>>
|
||||
// ) {
|
||||
// {
|
||||
// let vert = VertexBuffer::immutable(
|
||||
// &display.display,
|
||||
// CUBE_VERTICES
|
||||
// ).unwrap();
|
||||
// let index = IndexBuffer::immutable(
|
||||
// &display.display,
|
||||
// PrimitiveType::TrianglesList,
|
||||
// CUBE_INDICES
|
||||
// ).unwrap();
|
||||
// storages.add_unique_non_send_sync(CubePrimitive(vert, index));
|
||||
// }
|
||||
// {
|
||||
// let vert = VertexBuffer::immutable(
|
||||
// &display.display,
|
||||
// CENTERED_CUBE_VERTICES
|
||||
// ).unwrap();
|
||||
// let index = IndexBuffer::immutable(
|
||||
// &display.display,
|
||||
// PrimitiveType::TrianglesList,
|
||||
// CUBE_INDICES
|
||||
// ).unwrap();
|
||||
// storages.add_unique_non_send_sync(CenteredCubePrimitive(vert, index));
|
||||
// }
|
||||
// }
|
||||
pub fn init_cube_primitive(storages: AllStoragesView) {
|
||||
let renderer = storages.borrow::<UniqueView<Renderer>>().unwrap();
|
||||
storages.add_unique(CubePrimitive(BufferPair {
|
||||
index: renderer.device().create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("cube_index_buffer"),
|
||||
contents: bytemuck::cast_slice(CUBE_INDICES),
|
||||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::INDEX,
|
||||
}),
|
||||
index_len: CUBE_INDICES.len() as u32,
|
||||
vertex: renderer.device().create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("cube_vertex_buffer"),
|
||||
contents: bytemuck::cast_slice(CUBE_VERTICES),
|
||||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::VERTEX,
|
||||
}),
|
||||
vertex_len: CUBE_VERTICES.len() as u32,
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
// use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView};
|
||||
// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
||||
// use crate::rendering::Renderer;
|
||||
// use super::PositionOnlyVertex2d;
|
||||
|
||||
// #[derive(Unique)]
|
||||
// pub struct RectPrimitive(pub VertexBuffer<PositionOnlyVertex2d>, pub IndexBuffer<u16>);
|
||||
|
||||
// const RECT_VERTEX: &[PositionOnlyVertex2d] = &[
|
||||
// PositionOnlyVertex2d { position: [0., 0.] },
|
||||
// PositionOnlyVertex2d { position: [1., 0.] },
|
||||
// PositionOnlyVertex2d { position: [0., 1.] },
|
||||
// PositionOnlyVertex2d { position: [1., 1.] },
|
||||
// ];
|
||||
// const RECT_INDEX: &[u16] = &[0, 1, 2, 1, 3, 2];
|
||||
|
||||
// pub(super) fn init_rect_primitive(
|
||||
// storages: AllStoragesView,
|
||||
// display: NonSendSync<UniqueView<Renderer>>
|
||||
// ) {
|
||||
// let vert = VertexBuffer::immutable(
|
||||
// &display.display,
|
||||
// RECT_VERTEX
|
||||
// ).unwrap();
|
||||
// let index = IndexBuffer::immutable(
|
||||
// &display.display,
|
||||
// PrimitiveType::TrianglesList,
|
||||
// RECT_INDEX
|
||||
// ).unwrap();
|
||||
// storages.add_unique_non_send_sync(RectPrimitive(vert, index));
|
||||
// }
|
|
@ -1,30 +0,0 @@
|
|||
// use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView};
|
||||
// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
||||
// use crate::rendering::Renderer;
|
||||
// use super::PositionOnlyVertex2d;
|
||||
|
||||
// #[derive(Unique)]
|
||||
// pub struct STriPrimitive(pub VertexBuffer<PositionOnlyVertex2d>, pub IndexBuffer<u16>);
|
||||
|
||||
// const STRI_VERTEX: &[PositionOnlyVertex2d] = &[
|
||||
// PositionOnlyVertex2d { position: [-1., -1.] },
|
||||
// PositionOnlyVertex2d { position: [ 3., -1.] },
|
||||
// PositionOnlyVertex2d { position: [-1., 3.] },
|
||||
// ];
|
||||
// const STRI_INDEX: &[u16] = &[0, 1, 2];
|
||||
|
||||
// pub(super) fn init_stri_primitive(
|
||||
// storages: AllStoragesView,
|
||||
// display: NonSendSync<UniqueView<Renderer>>
|
||||
// ) {
|
||||
// let vert = VertexBuffer::immutable(
|
||||
// &display.display,
|
||||
// STRI_VERTEX
|
||||
// ).unwrap();
|
||||
// let index = IndexBuffer::immutable(
|
||||
// &display.display,
|
||||
// PrimitiveType::TrianglesList,
|
||||
// STRI_INDEX
|
||||
// ).unwrap();
|
||||
// storages.add_unique_non_send_sync(STriPrimitive(vert, index));
|
||||
// }
|
|
@ -107,7 +107,7 @@ impl Renderer {
|
|||
&wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
required_features: wgpu::Features::empty(),
|
||||
required_limits: wgpu::Limits::downlevel_defaults(),
|
||||
required_limits: wgpu::Limits::default(),
|
||||
},
|
||||
None,
|
||||
).block_on().unwrap();
|
||||
|
|
|
@ -1,59 +1,9 @@
|
|||
// use glam::{Mat4, Vec3, Quat};
|
||||
// use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
|
||||
// use glium::{
|
||||
// Surface,
|
||||
// DrawParameters,
|
||||
// BackfaceCullingMode,
|
||||
// Blend, Depth, DepthTest,
|
||||
// uniform,
|
||||
// };
|
||||
// use crate::{
|
||||
// world::raycast::LookingAtBlock,
|
||||
// camera::Camera,
|
||||
// prefabs::ColoredShaderPrefab
|
||||
// };
|
||||
// use super::{
|
||||
// RenderTarget,
|
||||
// primitives::cube::CubePrimitive,
|
||||
// };
|
||||
mod pipeline;
|
||||
|
||||
// const SMOL: f32 = 0.0025;
|
||||
|
||||
// pub fn render_selection_box(
|
||||
// lookat: View<LookingAtBlock>,
|
||||
// camera: View<Camera>,
|
||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
// program: NonSendSync<UniqueView<ColoredShaderPrefab>>,
|
||||
// buffers: NonSendSync<UniqueView<CubePrimitive>>,
|
||||
// ) {
|
||||
// let camera = camera.iter().next().unwrap();
|
||||
// let Some(lookat) = lookat.iter().next() else { return };
|
||||
// let Some(lookat) = lookat.0 else { return };
|
||||
|
||||
// //Darken block
|
||||
// target.0.draw(
|
||||
// &buffers.0,
|
||||
// &buffers.1,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// color: [0., 0., 0., 0.5_f32],
|
||||
// model: Mat4::from_scale_rotation_translation(
|
||||
// Vec3::splat(1. + SMOL * 2.),
|
||||
// Quat::default(),
|
||||
// lookat.block_position.as_vec3() - Vec3::splat(SMOL)
|
||||
// ).to_cols_array_2d(),
|
||||
// perspective: camera.perspective_matrix.to_cols_array_2d(),
|
||||
// view: camera.view_matrix.to_cols_array_2d(),
|
||||
// },
|
||||
// &DrawParameters {
|
||||
// backface_culling: BackfaceCullingMode::CullClockwise,
|
||||
// blend: Blend::alpha_blending(),
|
||||
// depth: Depth {
|
||||
// //this may be unreliable... unless scale is applied! hacky...
|
||||
// test: DepthTest::IfLessOrEqual,
|
||||
// ..Default::default()
|
||||
// },
|
||||
// ..Default::default()
|
||||
// }
|
||||
// ).unwrap();
|
||||
// }
|
||||
pub fn draw_selection_box(
|
||||
ctx: &mut RenderCtx,
|
||||
lookat: View<LookingAtBlock>,
|
||||
camera: View<Camera>,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
|
0
kubi/src/rendering/selection_box/pipeline.rs
Normal file
0
kubi/src/rendering/selection_box/pipeline.rs
Normal file
|
@ -1,13 +1,12 @@
|
|||
use glam::{IVec3, Vec3};
|
||||
use shipyard::{AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View};
|
||||
use kubi_shared::{chunk::CHUNK_SIZE, transform::Transform};
|
||||
use glam::Vec3;
|
||||
use shipyard::{AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, View};
|
||||
use kubi_shared::chunk::CHUNK_SIZE;
|
||||
use crate::{
|
||||
camera::Camera,
|
||||
prefabs::TexturePrefabs,
|
||||
settings::GameSettings,
|
||||
world::{ChunkMeshStorage, ChunkStorage},
|
||||
};
|
||||
use super::{camera::{self, CameraUniformBuffer}, depth::DepthTexture, RenderCtx};
|
||||
use super::{camera::CameraUniformBuffer, depth::DepthTexture, RenderCtx};
|
||||
|
||||
mod pipeline;
|
||||
mod vertex;
|
||||
|
@ -16,19 +15,19 @@ pub use vertex::ChunkVertex;
|
|||
#[derive(Unique)]
|
||||
pub struct WorldRenderState {
|
||||
pub pipeline: wgpu::RenderPipeline,
|
||||
pub trans_chunk_queue: Vec<IVec3>,
|
||||
//pub trans_chunk_queue: Vec<IVec3>,
|
||||
}
|
||||
|
||||
pub fn init_world_render_state(storages: AllStoragesView) {
|
||||
storages.add_unique(WorldRenderState {
|
||||
pipeline: storages.run(pipeline::init_world_pipeline),
|
||||
trans_chunk_queue: Vec::with_capacity(512),
|
||||
//trans_chunk_queue: Vec::with_capacity(512),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn draw_world(
|
||||
ctx: &mut RenderCtx,
|
||||
mut state: UniqueViewMut<WorldRenderState>,
|
||||
state: UniqueView<WorldRenderState>,
|
||||
camera_ubo: UniqueView<CameraUniformBuffer>,
|
||||
depth: UniqueView<DepthTexture>,
|
||||
textures: UniqueView<TexturePrefabs>,
|
||||
|
@ -95,210 +94,3 @@ pub fn draw_world(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fn draw_params(settings: &GameSettings) -> DrawParameters {
|
||||
// DrawParameters {
|
||||
// depth: Depth {
|
||||
// test: DepthTest::IfLess,
|
||||
// write: true,
|
||||
// ..Default::default()
|
||||
// },
|
||||
// multisampling: settings.msaa.is_some(),
|
||||
// polygon_mode: PolygonMode::Fill, //Change to Line for wireframe
|
||||
// backface_culling: BackfaceCullingMode::CullClockwise,
|
||||
// ..Default::default()
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn texture_sampler<'a, T>(texture: &'a T, settings: &GameSettings) -> Sampler<'a, T> {
|
||||
// Sampler(texture, SamplerBehavior {
|
||||
// minify_filter: MinifySamplerFilter::LinearMipmapLinear,
|
||||
// magnify_filter: MagnifySamplerFilter::Nearest,
|
||||
// max_anisotropy: settings.max_anisotropy.unwrap_or_default(),
|
||||
// wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp),
|
||||
// depth_texture_comparison: None,
|
||||
// })
|
||||
// }
|
||||
|
||||
// pub fn draw_world(
|
||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
// chunks: UniqueView<ChunkStorage>,
|
||||
// meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||
// program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
|
||||
// texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
|
||||
// transform: View<Transform>,
|
||||
// camera: View<Camera>,
|
||||
// settings: UniqueView<GameSettings>,
|
||||
// mut trans_queue: UniqueViewMut<TransChunkQueue>,
|
||||
// ) {
|
||||
// // let (camera, transform) = (&camera, &transform).iter().next().expect("No cameras in the scene");
|
||||
// // let camera_position = transform.0.to_scale_rotation_translation().2;
|
||||
|
||||
// let camera = camera.iter().next().expect("No cameras in the scene");
|
||||
// let view = camera.view_matrix.to_cols_array_2d();
|
||||
// let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||
|
||||
// let draw_parameters = draw_params(&settings);
|
||||
// let texture_sampler = texture_sampler(&texture.0, &settings);
|
||||
|
||||
// for (&position, chunk) in &chunks.chunks {
|
||||
// if let Some(key) = chunk.mesh_index {
|
||||
// let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
|
||||
// let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||
|
||||
// //Skip mesh if its empty
|
||||
// if mesh.index_buffer.len() == 0 && mesh.trans_index_buffer.len() == 0 {
|
||||
// continue
|
||||
// }
|
||||
|
||||
// //Frustum culling
|
||||
// {
|
||||
// let minp = world_position;
|
||||
// let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32);
|
||||
// if !camera.frustum.is_box_visible(minp, maxp) {
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
|
||||
// //Draw chunk mesh
|
||||
// if mesh.index_buffer.len() > 0 {
|
||||
// target.0.draw(
|
||||
// &mesh.vertex_buffer,
|
||||
// &mesh.index_buffer,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// position_offset: world_position.to_array(),
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// tex: texture_sampler,
|
||||
// discard_alpha: true,
|
||||
// },
|
||||
// &draw_parameters
|
||||
// ).unwrap();
|
||||
// }
|
||||
|
||||
// if mesh.trans_index_buffer.len() > 0 {
|
||||
// trans_queue.0.push(position);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // const HALF_CHUNK_SIZE: IVec3 = IVec3::splat((CHUNK_SIZE >> 1) as i32);
|
||||
// // trans_queue.0.sort_by_cached_key(|&pos| -(
|
||||
// // (pos + HALF_CHUNK_SIZE).distance_squared(camera_position.as_ivec3())
|
||||
// // ));
|
||||
// }
|
||||
|
||||
// pub fn draw_world_trans(
|
||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
// chunks: UniqueView<ChunkStorage>,
|
||||
// meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||
// program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
|
||||
// texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
|
||||
// camera: View<Camera>,
|
||||
// settings: UniqueView<GameSettings>,
|
||||
// mut trans_queue: UniqueViewMut<TransChunkQueue>,
|
||||
// ) {
|
||||
// let camera = camera.iter().next().expect("No cameras in the scene");
|
||||
// let view = camera.view_matrix.to_cols_array_2d();
|
||||
// let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||
|
||||
// let mut draw_parameters = draw_params(&settings);
|
||||
// draw_parameters.blend = Blend::alpha_blending();
|
||||
// draw_parameters.backface_culling = BackfaceCullingMode::CullingDisabled;
|
||||
// draw_parameters.smooth = Some(Smooth::Fastest);
|
||||
|
||||
// let texture_sampler = texture_sampler(&texture.0, &settings);
|
||||
|
||||
// for position in trans_queue.0.drain(..).rev() {
|
||||
// let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||
// let mesh_idx = chunks.chunks[&position].mesh_index.expect("No mesh index");
|
||||
// let mesh = meshes.get(mesh_idx).expect("Mesh index pointing to nothing");
|
||||
// target.0.draw(
|
||||
// &mesh.trans_vertex_buffer,
|
||||
// &mesh.trans_index_buffer,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// position_offset: world_position.to_array(),
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// tex: texture_sampler,
|
||||
// discard_alpha: false,
|
||||
// },
|
||||
// &draw_parameters
|
||||
// ).unwrap();
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn draw_current_chunk_border(
|
||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
// player: View<MainPlayer>,
|
||||
// transforms: View<Transform, track::All>,
|
||||
// buffers: NonSendSync<UniqueView<CubePrimitive>>,
|
||||
// program: NonSendSync<UniqueView<ColoredShaderPrefab>>,
|
||||
// camera: View<Camera>,
|
||||
// settings: UniqueView<GameSettings>,
|
||||
// ) {
|
||||
// if cfg!(target_os = "android") {
|
||||
// return
|
||||
// }
|
||||
// if !settings.debug_draw_current_chunk_border {
|
||||
// return
|
||||
// }
|
||||
// let camera = camera.iter().next().expect("No cameras in the scene");
|
||||
// let view = camera.view_matrix.to_cols_array_2d();
|
||||
// let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||
// let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player");
|
||||
// let (_, _, player_position) = player_transform.0.to_scale_rotation_translation();
|
||||
// let player_in_chunk = ivec3(
|
||||
// (player_position.x as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
// (player_position.y as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
// (player_position.z as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
// );
|
||||
// let world_position = player_in_chunk.as_vec3() * CHUNK_SIZE as f32;
|
||||
// target.0.draw(
|
||||
// &buffers.0,
|
||||
// &buffers.1,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// model: Mat4::from_scale_rotation_translation(
|
||||
// Vec3::splat(CHUNK_SIZE as f32),
|
||||
// Quat::default(),
|
||||
// world_position
|
||||
// ).to_cols_array_2d(),
|
||||
// color: [0.25f32; 4],
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// },
|
||||
// &DrawParameters {
|
||||
// depth: Depth {
|
||||
// test: DepthTest::IfLess,
|
||||
// ..Default::default()
|
||||
// },
|
||||
// blend: Blend::alpha_blending(),
|
||||
// ..Default::default()
|
||||
// }
|
||||
// ).unwrap();
|
||||
// target.0.draw(
|
||||
// &buffers.0,
|
||||
// &buffers.1,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// model: Mat4::from_scale_rotation_translation(
|
||||
// Vec3::splat(CHUNK_SIZE as f32),
|
||||
// Quat::default(),
|
||||
// world_position
|
||||
// ).to_cols_array_2d(),
|
||||
// color: [0.0f32; 4],
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// },
|
||||
// &DrawParameters {
|
||||
// polygon_mode: PolygonMode::Point,
|
||||
// line_width: Some(2.),
|
||||
// point_size: Some(5.),
|
||||
// ..Default::default()
|
||||
// }
|
||||
// ).unwrap();
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue