optimization and TexturedParticle work
This commit is contained in:
parent
6b699e942f
commit
30830d4d90
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
in vec4 v_color;
|
uniform vec4 u_color;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = v_color;
|
color = u_color;
|
||||||
}
|
}
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
in vec3 position;
|
in vec3 position;
|
||||||
|
|
||||||
out vec4 v_color;
|
uniform uint type;
|
||||||
|
|
||||||
uniform vec4 color;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_color = color;
|
// v_type = type;
|
||||||
gl_Position = vec4(position, 1.0);
|
gl_Position = vec4(position, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
10
assets/shaders/particles/textured_particle.frag
Normal file
10
assets/shaders/particles/textured_particle.frag
Normal 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);
|
||||||
|
}
|
12
assets/shaders/particles/textured_particle.vert
Normal file
12
assets/shaders/particles/textured_particle.vert
Normal 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);
|
||||||
|
}
|
45
src/main.rs
45
src/main.rs
|
@ -9,12 +9,8 @@ use glium::{
|
||||||
glutin::{self, event::KeyboardInput},
|
glutin::{self, event::KeyboardInput},
|
||||||
Surface,
|
Surface,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::particle_system::{generate_particle_vertexs, Particle, ParticleType};
|
||||||
config::PARTICLE_SCALE,
|
|
||||||
particle_system::{generate_particle_vertexs, Particle},
|
|
||||||
};
|
|
||||||
pub mod chunk;
|
pub mod chunk;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod coordinates;
|
pub mod coordinates;
|
||||||
|
@ -51,14 +47,28 @@ pub fn bruh() {
|
||||||
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
|
glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let particles_vertex_shader_src = include_str!("../assets/shaders/particles/solid_color.vert");
|
let solid_color_particles_vertex_shader_src =
|
||||||
let particles_fragment_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");
|
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,
|
&display,
|
||||||
particles_vertex_shader_src,
|
solid_color_particles_vertex_shader_src,
|
||||||
particles_fragment_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,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -178,14 +188,25 @@ pub fn bruh() {
|
||||||
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
|
let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList);
|
||||||
|
|
||||||
let uniforms = uniform! {
|
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
|
target
|
||||||
.draw(
|
.draw(
|
||||||
&vertex_buffer,
|
&vertex_buffer,
|
||||||
&indices,
|
&indices,
|
||||||
&particles_program,
|
&shader_to_use,
|
||||||
&uniforms,
|
&uniforms,
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,6 +2,11 @@ use rand::Rng;
|
||||||
|
|
||||||
use crate::{config::PARTICLE_SCALE, vertex};
|
use crate::{config::PARTICLE_SCALE, vertex};
|
||||||
|
|
||||||
|
pub enum ParticleType {
|
||||||
|
SolidColor = 0,
|
||||||
|
Texture,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Default)]
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
pub struct Particle {
|
pub struct Particle {
|
||||||
pub position: [f32; 3],
|
pub position: [f32; 3],
|
||||||
|
|
Loading…
Reference in a new issue