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,
draw_world,
render_selection_box,
).into_sequential_workload()
}
fn after_frame_end() -> Workload {

View file

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

View file

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

View file

@ -1,35 +1,76 @@
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut};
use glium::{Surface, implement_vertex};
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
use glium::{Surface, implement_vertex, IndexBuffer, index::PrimitiveType, VertexBuffer, uniform, DrawParameters, Blend, BackfaceCullingMode};
use crate::{
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 position: [f32; 3],
}
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
pub fn render_selection_box(
lookat: View<LookingAtBlock>,
camera: View<Camera>,
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
display: NonSendSync<UniqueView<Renderer>>,
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
) {
for lookat in lookat.iter() {
// 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,
// },
// &draw_parameters
// ).unwrap();
let camera = camera.iter().next().unwrap();
let Some(lookat) = lookat.iter().next() else { return };
let Some(lookat) = lookat.0 else { return };
//this may be slow but the amount of vertices is very low
let vert = VertexBuffer::new(
&display.display,
BOX_VERTICES
).unwrap();
let index = IndexBuffer::new(
&display.display,
PrimitiveType::TrianglesList,
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();
}