having issues with blending...

This commit is contained in:
griffi-gh 2023-01-28 20:56:17 +01:00
parent 2bb22ddaec
commit a4f4a765ae
4 changed files with 71 additions and 30 deletions

View file

@ -72,6 +72,7 @@ fn render() -> Workload {
( (
clear_background, clear_background,
draw_world, draw_world,
render_selection_box,
).into_sequential_workload() ).into_sequential_workload()
} }
fn after_frame_end() -> Workload { fn after_frame_end() -> Workload {

View file

@ -1,4 +1,3 @@
use glam::Mat4;
use shipyard::{Component, AllStoragesViewMut}; use shipyard::{Component, AllStoragesViewMut};
use crate::{ use crate::{
transform::Transform, transform::Transform,

View file

@ -1,16 +1,16 @@
const CUBE_VERTICES: &[f32] = &[ pub const CUBE_VERTICES: &[f32] = &[
// front // front
-1.0, -1.0, 1.0, 0.0, 0.0, 1.0,
1.0, -1.0, 1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
-1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
// back // back
-1.0, -1.0, -1.0, 0.0, 0.0, 0.0,
1.0, -1.0, -1.0, 1.0, 0.0, 0.0,
1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
-1.0, 1.0, -1.0 0.0, 1.0, 0.0
]; ];
const CUBE_INDICES: &[u16] = &[ pub const CUBE_INDICES: &[u16] = &[
// front // front
0, 1, 2, 0, 1, 2,
2, 3, 0, 2, 3, 0,

View file

@ -1,35 +1,76 @@
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut}; use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
use glium::{Surface, implement_vertex}; use glium::{Surface, implement_vertex, IndexBuffer, index::PrimitiveType, VertexBuffer, uniform, DrawParameters, Blend, BackfaceCullingMode};
use crate::{ use crate::{
world::raycast::LookingAtBlock, world::raycast::LookingAtBlock,
camera::Camera camera::Camera, prefabs::SelBoxShaderPrefab
};
use super::{
RenderTarget,
primitives::{CUBE_INDICES, CUBE_VERTICES}, Renderer
}; };
use super::RenderTarget;
#[derive(Clone, Copy)] #[derive(Clone, Copy, Default)]
pub struct SelBoxVertex { pub struct SelBoxVertex {
pub position: [f32; 3], pub position: [f32; 3],
} }
implement_vertex!(SelBoxVertex, position); implement_vertex!(SelBoxVertex, position);
const fn box_vertices() -> [SelBoxVertex; CUBE_VERTICES.len() / 3] {
let mut arr = [SelBoxVertex { position: [0., 0., 0.] }; CUBE_VERTICES.len() / 3];
let mut ptr = 0;
loop {
arr[ptr] = SelBoxVertex {
position: [
CUBE_VERTICES[ptr * 3],
CUBE_VERTICES[(ptr * 3) + 1],
CUBE_VERTICES[(ptr * 3) + 2]
]
};
ptr += 1;
if ptr >= CUBE_VERTICES.len() / 3 {
return arr
}
}
}
const BOX_VERTICES: &[SelBoxVertex] = &box_vertices();
//wip //wip
pub fn render_selection_box( pub fn render_selection_box(
lookat: View<LookingAtBlock>, lookat: View<LookingAtBlock>,
camera: View<Camera>, camera: View<Camera>,
mut target: NonSendSync<UniqueViewMut<RenderTarget>>, mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
display: NonSendSync<UniqueView<Renderer>>,
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
) { ) {
for lookat in lookat.iter() { let camera = camera.iter().next().unwrap();
// target.0.draw( let Some(lookat) = lookat.iter().next() else { return };
// &mesh.vertex_buffer, let Some(lookat) = lookat.0 else { return };
// &mesh.index_buffer,
// &program.0, //this may be slow but the amount of vertices is very low
// &uniform! { let vert = VertexBuffer::new(
// position_offset: world_position.to_array(), &display.display,
// view: view, BOX_VERTICES
// perspective: perspective, ).unwrap();
// tex: texture_sampler, let index = IndexBuffer::new(
// }, &display.display,
// &draw_parameters PrimitiveType::TrianglesList,
// ).unwrap(); CUBE_INDICES
} ).unwrap();
target.0.draw(
&vert,
&index,
&program.0,
&uniform! {
color: [0., 0., 0., 0.5_f32],
u_position: lookat.block_position.as_vec3().to_array(),
perspective: camera.perspective_matrix.to_cols_array_2d(),
view: camera.view_matrix.to_cols_array_2d(),
},
&DrawParameters {
blend: Blend::alpha_blending(),
backface_culling: BackfaceCullingMode::CullClockwise,
..Default::default()
}
).unwrap();
} }