optimization and TexturedParticle work

This commit is contained in:
Able 2022-04-02 15:34:24 -05:00
parent 6b699e942f
commit 30830d4d90
6 changed files with 68 additions and 17 deletions

View file

@ -2,8 +2,9 @@
out vec4 color;
in vec4 v_color;
uniform vec4 u_color;
void main() {
color = v_color;
color = u_color;
}

View file

@ -2,11 +2,13 @@
in vec3 position;
out vec4 v_color;
uniform uint type;
uniform vec4 color;
void main() {
v_color = color;
// v_type = type;
gl_Position = vec4(position, 1.0);
}

View file

@ -0,0 +1,10 @@
#version 140
in vec2 v_tex_coords;
out vec4 color;
uniform sampler2D tex;
void main() {
color = texture(tex, v_tex_coords);
}

View file

@ -0,0 +1,12 @@
#version 140
in vec2 position;
in vec2 tex_coords;
out vec2 v_tex_coords;
uniform mat4 matrix;
void main() {
v_tex_coords = tex_coords;
gl_Position = matrix * vec4(position, 0.0, 1.0);
}

View file

@ -9,12 +9,8 @@ use glium::{
glutin::{self, event::KeyboardInput},
Surface,
};
use rand::Rng;
use crate::{
config::PARTICLE_SCALE,
particle_system::{generate_particle_vertexs, Particle},
};
use crate::particle_system::{generate_particle_vertexs, Particle, ParticleType};
pub mod chunk;
pub mod config;
pub mod coordinates;
@ -51,14 +47,28 @@ pub fn bruh() {
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
.unwrap();
let particles_vertex_shader_src = include_str!("../assets/shaders/particles/solid_color.vert");
let particles_fragment_shader_src =
let solid_color_particles_vertex_shader_src =
include_str!("../assets/shaders/particles/solid_color.vert");
let solid_color_particles_fragment_shader_src =
include_str!("../assets/shaders/particles/solid_color.frag");
let particles_program = glium::Program::from_source(
let solid_color_particles_program = glium::Program::from_source(
&display,
particles_vertex_shader_src,
particles_fragment_shader_src,
solid_color_particles_vertex_shader_src,
solid_color_particles_fragment_shader_src,
None,
)
.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();
@ -178,14 +188,25 @@ pub fn bruh() {
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
let uniforms = uniform! {
color: particle_group_color,
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,
&particles_program,
&shader_to_use,
&uniforms,
&Default::default(),
)

View file

@ -2,6 +2,11 @@ use rand::Rng;
use crate::{config::PARTICLE_SCALE, vertex};
pub enum ParticleType {
SolidColor = 0,
Texture,
}
#[derive(Debug, Copy, Clone, Default)]
pub struct Particle {
pub position: [f32; 3],