Added snow particles

This commit is contained in:
Joshua Barretto 2021-01-31 15:15:17 +00:00
parent b93a2b02dd
commit 60c16e57b1
5 changed files with 36 additions and 15 deletions

View File

@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Lactose tolerant golems - Lactose tolerant golems
- 6 different gems. (Topaz, Amethyst, Sapphire, Emerald, Ruby and Diamond) - 6 different gems. (Topaz, Amethyst, Sapphire, Emerald, Ruby and Diamond)
- Poise system (not currently accessible to players for balancing reasons) - Poise system (not currently accessible to players for balancing reasons)
- Snow particles
### Changed ### Changed

View File

@ -15,6 +15,7 @@
#include <globals.glsl> #include <globals.glsl>
#include <srgb.glsl> #include <srgb.glsl>
#include <random.glsl> #include <random.glsl>
#include <lod.glsl>
in vec3 v_pos; in vec3 v_pos;
// in uint v_col; // in uint v_col;
@ -55,6 +56,7 @@ const int ENERGY_NATURE = 14;
const int FLAMETHROWER = 15; const int FLAMETHROWER = 15;
const int FIRE_SHOCKWAVE = 16; const int FIRE_SHOCKWAVE = 16;
const int FIRE_BOWL = 17; const int FIRE_BOWL = 17;
const int SNOW = 18;
// meters per second squared (acceleration) // meters per second squared (acceleration)
const float earth_gravity = 9.807; const float earth_gravity = 9.807;
@ -140,6 +142,8 @@ void main() {
float rand8 = hash(vec4(inst_entropy + 8)); float rand8 = hash(vec4(inst_entropy + 8));
float rand9 = hash(vec4(inst_entropy + 9)); float rand9 = hash(vec4(inst_entropy + 9));
vec3 start_pos = inst_pos - focus_off.xyz;
Attr attr; Attr attr;
f_reflect = 1.0; f_reflect = 1.0;
@ -260,6 +264,17 @@ void main() {
vec4(vec3(0.2 + rand7 * 0.2, 0.2 + (0.5 + rand6 * 0.5) * 0.6, 0), 1), vec4(vec3(0.2 + rand7 * 0.2, 0.2 + (0.5 + rand6 * 0.5) * 0.6, 0), 1),
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5) spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
); );
} else if (inst_mode == SNOW) {
float height = mix(-4, 60, pow(start_end(1, 0), 3));
float wind_speed = (inst_pos.z - 250) * 0.025;
vec3 offset = linear_motion(vec3(0), vec3(1, 1, 0) * wind_speed);
float end_alt = alt_at(start_pos.xy + offset.xy);
attr = Attr(
offset + vec3(0, 0, end_alt - start_pos.z + height) + vec3(sin(lifetime), sin(lifetime + 0.7), sin(lifetime * 0.5)) * 3,
vec3(mix(4, 0, pow(start_end(1, 0), 4))),
vec4(1),
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
);
} else if (inst_mode == FIREFLY) { } else if (inst_mode == FIREFLY) {
float raise = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2); float raise = pow(sin(3.1416 * lifetime / inst_lifespan), 0.2);
attr = Attr( attr = Attr(
@ -341,7 +356,7 @@ void main() {
// Temporary: use shrinking particles as a substitute for fading ones // Temporary: use shrinking particles as a substitute for fading ones
attr.scale *= pow(attr.col.a, 0.25); attr.scale *= pow(attr.col.a, 0.25);
f_pos = (inst_pos - focus_off.xyz) + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs); f_pos = start_pos + (v_pos * attr.scale * SCALE * mat3(attr.rot) + attr.offs);
// First 3 normals are negative, next 3 are positive // First 3 normals are negative, next 3 are positive
// TODO: Make particle normals match orientation // TODO: Make particle normals match orientation

View File

@ -114,6 +114,7 @@ pub enum ParticleMode {
FlameThrower = 15, FlameThrower = 15,
FireShockwave = 16, FireShockwave = 16,
FireBowl = 17, FireBowl = 17,
Snow = 18,
} }
impl ParticleMode { impl ParticleMode {

View File

@ -522,6 +522,14 @@ impl ParticleMgr {
mode: ParticleMode::Bee, mode: ParticleMode::Bee,
cond: |sd| sd.state.get_day_period().is_light(), cond: |sd| sd.state.get_day_period().is_light(),
}, },
BlockParticles {
blocks: |boi| &boi.snow,
range: 4,
rate: 0.025,
lifetime: 15.0,
mode: ParticleMode::Snow,
cond: |_| true,
},
]; ];
let mut rng = thread_rng(); let mut rng = thread_rng();

View File

@ -17,6 +17,7 @@ pub struct BlocksOfInterest {
pub reeds: Vec<Vec3<i32>>, pub reeds: Vec<Vec3<i32>>,
pub flowers: Vec<Vec3<i32>>, pub flowers: Vec<Vec3<i32>>,
pub fire_bowls: Vec<Vec3<i32>>, pub fire_bowls: Vec<Vec3<i32>>,
pub snow: Vec<Vec3<i32>>,
// Note: these are only needed for chunks within the iteraction range so this is a potential // Note: these are only needed for chunks within the iteraction range so this is a potential
// area for optimization // area for optimization
pub interactables: Vec<Vec3<i32>>, pub interactables: Vec<Vec3<i32>>,
@ -37,6 +38,7 @@ impl BlocksOfInterest {
let mut interactables = Vec::new(); let mut interactables = Vec::new();
let mut lights = Vec::new(); let mut lights = Vec::new();
let mut fire_bowls = Vec::new(); let mut fire_bowls = Vec::new();
let mut snow = Vec::new();
chunk chunk
.vol_iter( .vol_iter(
@ -49,21 +51,14 @@ impl BlocksOfInterest {
) )
.for_each(|(pos, block)| { .for_each(|(pos, block)| {
match block.kind() { match block.kind() {
BlockKind::Leaves => { BlockKind::Leaves if thread_rng().gen_range(0..16) == 0 => leaves.push(pos),
if thread_rng().gen_range(0..16) == 0 { BlockKind::Grass if thread_rng().gen_range(0..16) == 0 => grass.push(pos),
leaves.push(pos) BlockKind::Water
} if chunk.meta().contains_river() && thread_rng().gen_range(0..16) == 0 =>
}, {
BlockKind::Grass => {
if thread_rng().gen_range(0..16) == 0 {
grass.push(pos)
}
},
BlockKind::Water => {
if chunk.meta().contains_river() && thread_rng().gen_range(0..16) == 0 {
river.push(pos) river.push(pos)
}
}, },
BlockKind::Snow if thread_rng().gen_range(0..16) == 0 => snow.push(pos),
_ => match block.get_sprite() { _ => match block.get_sprite() {
Some(SpriteKind::Ember) => { Some(SpriteKind::Ember) => {
fires.push(pos); fires.push(pos);
@ -107,6 +102,7 @@ impl BlocksOfInterest {
interactables, interactables,
lights, lights,
fire_bowls, fire_bowls,
snow,
} }
} }
} }