partial voxel | No optimizations
This commit is contained in:
parent
30830d4d90
commit
94b3d01dc2
6
NOTES.md
Normal file
6
NOTES.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
- [ ] Crafting
|
||||
- [ ] Crafting List
|
||||
|
||||
- [ ] Armory
|
||||
- [ ] Placeable Tower Shields
|
||||
- [ ] Black Powder Weaponry
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
in vec3 position;
|
||||
|
||||
uniform uint type;
|
||||
|
||||
|
||||
void main() {
|
||||
// v_type = type;
|
||||
gl_Position = vec4(position, 1.0);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ use crate::{config::CHUNK_SIZE, vertex::Vertex, voxel::VoxelData};
|
|||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub struct Chunk {
|
||||
inner_data: [[[VoxelData; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE],
|
||||
chunk_position: Coordinates,
|
||||
pub chunk_position: Coordinates,
|
||||
}
|
||||
|
||||
impl Chunk {
|
||||
|
|
|
@ -3,4 +3,6 @@
|
|||
pub const CHUNK_SIZE: usize = 32;
|
||||
|
||||
pub const PLAYER_HEIGHT: f64 = 1.7;
|
||||
|
||||
pub const PARTICLE_SCALE: f32 = 0.004;
|
||||
pub const VOXEL_SCALE: f32 = 0.5;
|
||||
|
|
74
src/main.rs
74
src/main.rs
|
@ -1,7 +1,5 @@
|
|||
#![feature(const_fn_trait_bound)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
|
||||
|
@ -10,7 +8,7 @@ use glium::{
|
|||
Surface,
|
||||
};
|
||||
|
||||
use crate::particle_system::{generate_particle_vertexs, Particle, ParticleType};
|
||||
use crate::particle_system::{generate_particle_vertexs, Particle};
|
||||
pub mod chunk;
|
||||
pub mod config;
|
||||
pub mod coordinates;
|
||||
|
@ -21,15 +19,12 @@ pub mod voxel;
|
|||
|
||||
fn main() {
|
||||
let _chunk = chunk::Chunk::half_chunk_filled();
|
||||
// println!("{:?}", chunk);
|
||||
|
||||
bruh();
|
||||
}
|
||||
|
||||
mod teapot;
|
||||
|
||||
pub type ShaderList = HashMap<String, glium::Program>;
|
||||
|
||||
pub fn bruh() {
|
||||
let event_loop = glutin::event_loop::EventLoop::new();
|
||||
let wb = glutin::window::WindowBuilder::new()
|
||||
|
@ -60,19 +55,6 @@ pub fn bruh() {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let textured_particles_vertex_shader_src =
|
||||
include_str!("../assets/shaders/particles/textured_particle.vert");
|
||||
let textured_particles_fragment_shader_src =
|
||||
include_str!("../assets/shaders/particles/textured_particle.frag");
|
||||
|
||||
let textured_particles_program = glium::Program::from_source(
|
||||
&display,
|
||||
textured_particles_vertex_shader_src,
|
||||
textured_particles_fragment_shader_src,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut particles_vec: Vec<Particle> = Vec::new();
|
||||
for _ in 0..=10000 {
|
||||
particles_vec.push(Particle::random_particle());
|
||||
|
@ -136,7 +118,7 @@ pub fn bruh() {
|
|||
|
||||
target.clear_color_and_depth((0.0, 0.0, 1.0, 1.0), 1.0);
|
||||
|
||||
{
|
||||
if false {
|
||||
// Teapot stage
|
||||
|
||||
let positions = glium::VertexBuffer::new(&display, &teapot::VERTICES).unwrap();
|
||||
|
@ -177,6 +159,42 @@ pub fn bruh() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
// Solid Voxel stage
|
||||
let particle_group_color: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
|
||||
|
||||
let shape = voxel::VoxelData::new(
|
||||
0,
|
||||
voxel::Light {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0,
|
||||
sun: 0,
|
||||
},
|
||||
)
|
||||
.construct_vertexes(coordinates::Coordinates {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
});
|
||||
|
||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||
|
||||
let uniforms = uniform! {
|
||||
u_color: particle_group_color,
|
||||
};
|
||||
|
||||
target
|
||||
.draw(
|
||||
&vertex_buffer,
|
||||
&glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||
&solid_color_particles_program,
|
||||
&uniforms,
|
||||
&Default::default(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if render_particles {
|
||||
// Particle Stage
|
||||
|
||||
|
@ -185,28 +203,16 @@ pub fn bruh() {
|
|||
let shape = generate_particle_vertexs(&mut particles_vec);
|
||||
|
||||
let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
|
||||
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
|
||||
|
||||
let uniforms = uniform! {
|
||||
u_color: particle_group_color,
|
||||
};
|
||||
let shader_to_use;
|
||||
let ptype = ParticleType::SolidColor;
|
||||
match ptype {
|
||||
ParticleType::SolidColor => {
|
||||
shader_to_use = &solid_color_particles_program;
|
||||
}
|
||||
ParticleType::Texture => {
|
||||
shader_to_use = &textured_particles_program;
|
||||
todo!("Texteured particles are not implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
target
|
||||
.draw(
|
||||
&vertex_buffer,
|
||||
&indices,
|
||||
&shader_to_use,
|
||||
&glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
|
||||
&solid_color_particles_program,
|
||||
&uniforms,
|
||||
&Default::default(),
|
||||
)
|
||||
|
|
119
src/voxel.rs
119
src/voxel.rs
|
@ -1,3 +1,9 @@
|
|||
use crate::{
|
||||
config::VOXEL_SCALE,
|
||||
coordinates::{self, Coordinates},
|
||||
vertex::Vertex,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub struct Light {
|
||||
|
@ -12,3 +18,116 @@ pub struct VoxelData {
|
|||
pub id: u32,
|
||||
pub light_level: Light,
|
||||
}
|
||||
impl VoxelData {
|
||||
pub fn new(id: u32, light_level: Light) -> Self {
|
||||
Self { id, light_level }
|
||||
}
|
||||
|
||||
pub fn construct_vertexes(&self, coordinates: Coordinates) -> Vec<Vertex> {
|
||||
let mut shape = Vec::new();
|
||||
let half_voxel = VOXEL_SCALE / 2.0;
|
||||
{
|
||||
// Top Hexagon
|
||||
let vert_center = Vertex {
|
||||
position: (coordinates.x, coordinates.y, coordinates.z),
|
||||
};
|
||||
|
||||
let vert_1 = Vertex {
|
||||
position: (
|
||||
coordinates.x - half_voxel,
|
||||
coordinates.y,
|
||||
coordinates.z + VOXEL_SCALE,
|
||||
),
|
||||
};
|
||||
let vert_2 = Vertex {
|
||||
position: (
|
||||
coordinates.x + half_voxel,
|
||||
coordinates.y,
|
||||
coordinates.z + VOXEL_SCALE,
|
||||
),
|
||||
};
|
||||
|
||||
let vert_3 = Vertex {
|
||||
position: (coordinates.x + VOXEL_SCALE, coordinates.y, coordinates.z),
|
||||
};
|
||||
|
||||
let vert_4 = Vertex {
|
||||
position: (
|
||||
coordinates.x + half_voxel,
|
||||
coordinates.y,
|
||||
coordinates.z - VOXEL_SCALE,
|
||||
),
|
||||
};
|
||||
|
||||
let vert_5 = Vertex {
|
||||
position: (
|
||||
coordinates.x - half_voxel,
|
||||
coordinates.y,
|
||||
coordinates.z - VOXEL_SCALE,
|
||||
),
|
||||
};
|
||||
|
||||
let vert_6 = Vertex {
|
||||
position: (coordinates.x - VOXEL_SCALE, coordinates.y, coordinates.z),
|
||||
};
|
||||
|
||||
// TRIANGLE 1
|
||||
shape.append(&mut vec![vert_1, vert_2, vert_center]);
|
||||
|
||||
// TRIANGLE 2
|
||||
shape.append(&mut vec![vert_2, vert_3, vert_center]);
|
||||
|
||||
// TRIANGLE 3
|
||||
shape.append(&mut vec![vert_3, vert_4, vert_center]);
|
||||
|
||||
// TRIANGLE 4
|
||||
shape.append(&mut vec![vert_4, vert_5, vert_center]);
|
||||
|
||||
// TRIANGLE 5
|
||||
shape.append(&mut vec![vert_5, vert_6, vert_center]);
|
||||
|
||||
// TRIANGLE 6
|
||||
shape.append(&mut vec![vert_6, vert_1, vert_center]);
|
||||
}
|
||||
{
|
||||
// Side Face 1
|
||||
let vert_1 = Vertex {
|
||||
position: (
|
||||
coordinates.x - VOXEL_SCALE,
|
||||
coordinates.y + VOXEL_SCALE,
|
||||
coordinates.z,
|
||||
),
|
||||
};
|
||||
let vert_2 = Vertex {
|
||||
position: (
|
||||
coordinates.x + VOXEL_SCALE,
|
||||
coordinates.y + VOXEL_SCALE,
|
||||
coordinates.z,
|
||||
),
|
||||
};
|
||||
|
||||
let vert_3 = Vertex {
|
||||
position: (
|
||||
coordinates.x - VOXEL_SCALE,
|
||||
coordinates.y - VOXEL_SCALE,
|
||||
coordinates.z,
|
||||
),
|
||||
};
|
||||
let vert_4 = Vertex {
|
||||
position: (
|
||||
coordinates.x + VOXEL_SCALE,
|
||||
coordinates.y - VOXEL_SCALE,
|
||||
coordinates.z,
|
||||
),
|
||||
};
|
||||
|
||||
// TRIANGLE 1
|
||||
shape.append(&mut vec![vert_1, vert_2, vert_3]);
|
||||
|
||||
// TRIANGLE 2
|
||||
shape.append(&mut vec![vert_2, vert_3, vert_4]);
|
||||
}
|
||||
|
||||
shape
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue