mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 03:48:21 -06:00
add overlay when submerged
This commit is contained in:
parent
8e39fc24fd
commit
f157e2dab3
|
@ -1,3 +1,4 @@
|
|||
use glam::{vec4, Vec4};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use strum::EnumIter;
|
||||
use num_enum::TryFromPrimitive;
|
||||
|
@ -53,6 +54,7 @@ impl Block {
|
|||
collision: CollisionType::None,
|
||||
raycast_collision: false,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Marker => BlockDescriptor {
|
||||
name: "marker",
|
||||
|
@ -60,6 +62,7 @@ impl Block {
|
|||
collision: CollisionType::None,
|
||||
raycast_collision: false,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Stone => BlockDescriptor {
|
||||
name: "stone",
|
||||
|
@ -70,6 +73,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Dirt => BlockDescriptor {
|
||||
name: "dirt",
|
||||
|
@ -80,6 +84,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Grass => BlockDescriptor {
|
||||
name: "grass",
|
||||
|
@ -94,6 +99,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Sand => BlockDescriptor {
|
||||
name: "sand",
|
||||
|
@ -104,6 +110,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Cobblestone => BlockDescriptor {
|
||||
name: "cobblestone",
|
||||
|
@ -114,6 +121,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::TallGrass => BlockDescriptor {
|
||||
name: "tall grass",
|
||||
|
@ -121,6 +129,7 @@ impl Block {
|
|||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Planks => BlockDescriptor {
|
||||
name: "planks",
|
||||
|
@ -131,6 +140,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Torch => BlockDescriptor {
|
||||
name: "torch",
|
||||
|
@ -138,6 +148,7 @@ impl Block {
|
|||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Wood => BlockDescriptor {
|
||||
name: "leaf",
|
||||
|
@ -148,6 +159,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Leaf => BlockDescriptor {
|
||||
name: "leaf",
|
||||
|
@ -158,6 +170,7 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: None,
|
||||
},
|
||||
Self::Water => BlockDescriptor {
|
||||
name: "water",
|
||||
|
@ -168,6 +181,7 @@ impl Block {
|
|||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
submerge: Some(vec4(0., 0., 0.25, 0.75)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -180,6 +194,7 @@ pub struct BlockDescriptor {
|
|||
pub collision: CollisionType,
|
||||
pub raycast_collision: bool,
|
||||
pub drops: Option<Item>,
|
||||
pub submerge: Option<Vec4>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
10
kubi/shaders/colored2.frag
Normal file
10
kubi/shaders/colored2.frag
Normal file
|
@ -0,0 +1,10 @@
|
|||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
out vec4 out_color;
|
||||
uniform vec4 color;
|
||||
|
||||
void main() {
|
||||
out_color = color;
|
||||
}
|
9
kubi/shaders/colored2.vert
Normal file
9
kubi/shaders/colored2.vert
Normal file
|
@ -0,0 +1,9 @@
|
|||
#version 300 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
|
@ -76,6 +76,7 @@ use rendering::{
|
|||
world::{draw_world, draw_current_chunk_border},
|
||||
selection_box::render_selection_box,
|
||||
entities::render_entities,
|
||||
sumberge::render_submerged_view,
|
||||
};
|
||||
use block_placement::update_block_placement;
|
||||
use delta_time::{DeltaTime, init_delta_time};
|
||||
|
@ -178,6 +179,7 @@ fn render() -> Workload {
|
|||
draw_current_chunk_border,
|
||||
render_selection_box,
|
||||
render_entities,
|
||||
render_submerged_view,
|
||||
).into_sequential_workload().run_if(is_ingame),
|
||||
kubi_ui_draw,
|
||||
).into_sequential_workload()
|
||||
|
|
|
@ -51,6 +51,10 @@ pub struct ChunkShaderPrefab(pub Program);
|
|||
#[repr(transparent)]
|
||||
pub struct ColoredShaderPrefab(pub Program);
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct Colored2ShaderPrefab(pub Program);
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct UiFontPrefab(pub FontHandle);
|
||||
|
@ -98,6 +102,14 @@ pub fn load_prefabs(
|
|||
&renderer.display
|
||||
)
|
||||
));
|
||||
storages.add_unique_non_send_sync(Colored2ShaderPrefab(
|
||||
include_shader_prefab!(
|
||||
"colored",
|
||||
"../shaders/colored2.vert",
|
||||
"../shaders/colored2.frag",
|
||||
&renderer.display
|
||||
)
|
||||
));
|
||||
|
||||
log::info!("releasing shader compiler");
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ pub mod primitives;
|
|||
pub mod world;
|
||||
pub mod selection_box;
|
||||
pub mod entities;
|
||||
pub mod sumberge;
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
|
|
|
@ -1,27 +1,30 @@
|
|||
use shipyard::{Workload, IntoWorkload};
|
||||
use glium::implement_vertex;
|
||||
|
||||
pub mod cube;
|
||||
pub mod rect;
|
||||
|
||||
use cube::init_cube_primitive;
|
||||
use rect::init_rect_primitive;
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct PositionOnlyVertex {
|
||||
pub position: [f32; 3],
|
||||
}
|
||||
implement_vertex!(PositionOnlyVertex, position);
|
||||
|
||||
#[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,
|
||||
).into_sequential_workload()
|
||||
}
|
||||
use shipyard::{Workload, IntoWorkload};
|
||||
use glium::implement_vertex;
|
||||
|
||||
pub mod cube;
|
||||
pub mod rect;
|
||||
pub mod stri;
|
||||
|
||||
use cube::init_cube_primitive;
|
||||
use rect::init_rect_primitive;
|
||||
use stri::init_stri_primitive;
|
||||
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct PositionOnlyVertex {
|
||||
pub position: [f32; 3],
|
||||
}
|
||||
implement_vertex!(PositionOnlyVertex, position);
|
||||
|
||||
#[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()
|
||||
}
|
||||
|
|
30
kubi/src/rendering/primitives/stri.rs
Normal file
30
kubi/src/rendering/primitives/stri.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
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));
|
||||
}
|
39
kubi/src/rendering/sumberge.rs
Normal file
39
kubi/src/rendering/sumberge.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use glium::{uniform, Blend, DrawParameters, Surface};
|
||||
use kubi_shared::transform::Transform;
|
||||
use shipyard::{IntoIter, NonSendSync, UniqueView, UniqueViewMut, View};
|
||||
use crate::{
|
||||
player::MainPlayer,
|
||||
prefabs::Colored2ShaderPrefab,
|
||||
rendering::primitives::stri::STriPrimitive,
|
||||
world::ChunkStorage,
|
||||
};
|
||||
use super::RenderTarget;
|
||||
|
||||
pub fn render_submerged_view(
|
||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
primitive: NonSendSync<UniqueView<STriPrimitive>>,
|
||||
program: NonSendSync<UniqueView<Colored2ShaderPrefab>>,
|
||||
plr: View<MainPlayer>,
|
||||
trans: View<Transform>,
|
||||
world: UniqueView<ChunkStorage>,
|
||||
) {
|
||||
let (_, plr_trans) = (&plr, &trans).iter().next().expect("Main player MIA");
|
||||
let plr_pos = plr_trans.0.to_scale_rotation_translation().2;
|
||||
let block_at_pos = world.get_block(plr_pos.floor().as_ivec3());
|
||||
let Some(block_at_pos) = block_at_pos else { return };
|
||||
let Some(color) = block_at_pos.descriptor().submerge else { return };
|
||||
|
||||
let draw_parameters = DrawParameters {
|
||||
blend: Blend::alpha_blending(),
|
||||
..Default::default()
|
||||
};
|
||||
target.0.draw(
|
||||
&primitive.0,
|
||||
&primitive.1,
|
||||
&program.0,
|
||||
&uniform! {
|
||||
color: color.to_array(),
|
||||
},
|
||||
&draw_parameters,
|
||||
).unwrap();
|
||||
}
|
Loading…
Reference in a new issue