mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
put rain_density in uniform
This commit is contained in:
parent
5b7b13adce
commit
80e29e2c20
@ -113,8 +113,7 @@ void main() {
|
|||||||
// called each iteration of the loop. With the current implementation
|
// called each iteration of the loop. With the current implementation
|
||||||
// of rain_dir this has issues with being in a place where it doesn't rain
|
// of rain_dir this has issues with being in a place where it doesn't rain
|
||||||
// and seeing rain.
|
// and seeing rain.
|
||||||
float rain = rain_density_at(cam_wpos.xy);
|
if (medium.x == MEDIUM_AIR && rain_density > 0.0) {
|
||||||
if (medium.x == MEDIUM_AIR && rain > 0.0) {
|
|
||||||
float rain_dist = 50.0;
|
float rain_dist = 50.0;
|
||||||
for (int i = 0; i < 4; i ++) {
|
for (int i = 0; i < 4; i ++) {
|
||||||
float old_rain_dist = rain_dist;
|
float old_rain_dist = rain_dist;
|
||||||
@ -141,7 +140,7 @@ void main() {
|
|||||||
if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) {
|
if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
float rain_density = rain * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
|
float rain_density = rain_density * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0;
|
||||||
|
|
||||||
if (rain_density < 0.001 || fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) {
|
if (rain_density < 0.001 || fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -149,7 +149,6 @@ void main() {
|
|||||||
wave_sample_dist / slope
|
wave_sample_dist / slope
|
||||||
);
|
);
|
||||||
|
|
||||||
float rain_density = rain_density_at(f_pos.xy + focus_off.xy) * rain_occlusion_at(f_pos.xyz) * 50.0;
|
|
||||||
if (rain_density > 0 && surf_norm.z > 0.5) {
|
if (rain_density > 0 && surf_norm.z > 0.5) {
|
||||||
vec3 drop_density = vec3(2, 2, 2);
|
vec3 drop_density = vec3(2, 2, 2);
|
||||||
vec3 drop_pos = wave_pos + vec3(0, 0, -time_of_day.x * 0.025);
|
vec3 drop_pos = wave_pos + vec3(0, 0, -time_of_day.x * 0.025);
|
||||||
@ -158,7 +157,7 @@ void main() {
|
|||||||
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
|
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
|
||||||
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
|
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
|
||||||
|
|
||||||
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density) {
|
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
|
||||||
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
|
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
|
||||||
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
|
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ uniform u_rain_occlusion {
|
|||||||
mat4 rain_occlusion_texture_mat;
|
mat4 rain_occlusion_texture_mat;
|
||||||
mat4 rel_rain_dir_mat;
|
mat4 rel_rain_dir_mat;
|
||||||
float integrated_rain_vel;
|
float integrated_rain_vel;
|
||||||
vec3 occlusion_dummy; // Fix alignment.
|
float rain_density;
|
||||||
|
vec2 occlusion_dummy; // Fix alignment.
|
||||||
};
|
};
|
||||||
|
|
||||||
float rain_occlusion_at(in vec3 fragPos)
|
float rain_occlusion_at(in vec3 fragPos)
|
||||||
|
@ -30,7 +30,8 @@ uniform u_rain_occlusion {
|
|||||||
mat4 rain_occlusion_texture_mat;
|
mat4 rain_occlusion_texture_mat;
|
||||||
mat4 rel_rain_dir_mat;
|
mat4 rel_rain_dir_mat;
|
||||||
float integrated_rain_vel;
|
float integrated_rain_vel;
|
||||||
vec3 occlusion_dummy; // Fix alignment.
|
float rain_density;
|
||||||
|
vec2 occlusion_dummy; // Fix alignment.
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Accurate packed shadow maps for many lights at once!
|
/* Accurate packed shadow maps for many lights at once!
|
||||||
|
@ -32,7 +32,8 @@ uniform u_rain_occlusion {
|
|||||||
mat4 texture_mat;
|
mat4 texture_mat;
|
||||||
mat4 rel_rain_dir_mat;
|
mat4 rel_rain_dir_mat;
|
||||||
float integrated_rain_vel;
|
float integrated_rain_vel;
|
||||||
vec3 occlusion_dummy; // Fix alignment.
|
float rain_density;
|
||||||
|
vec2 occlusion_dummy; // Fix alignment.
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Accurate packed shadow maps for many lights at once!
|
/* Accurate packed shadow maps for many lights at once!
|
||||||
|
@ -231,12 +231,11 @@ void main() {
|
|||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
vec3 k_s = vec3(R_s);
|
vec3 k_s = vec3(R_s);
|
||||||
|
|
||||||
vec3 pos = f_pos + focus_off.xyz;
|
|
||||||
float rain_density = rain_density_at(pos.xy) * rain_occlusion_at(f_pos.xyz) * 50.0;
|
|
||||||
// Toggle to see rain_occlusion
|
// Toggle to see rain_occlusion
|
||||||
// tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0);
|
// tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0);
|
||||||
// return;
|
// return;
|
||||||
if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) {
|
if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) {
|
||||||
|
vec3 pos = f_pos + focus_off.xyz;
|
||||||
vec3 drop_density = vec3(2, 2, 2);
|
vec3 drop_density = vec3(2, 2, 2);
|
||||||
vec3 drop_pos = pos + vec3(pos.zz, 0) + vec3(0, 0, -tick.x * 1.0);
|
vec3 drop_pos = pos + vec3(pos.zz, 0) + vec3(0, 0, -tick.x * 1.0);
|
||||||
drop_pos.z += noise_2d(floor(drop_pos.xy * drop_density.xy) * 13.1) * 10;
|
drop_pos.z += noise_2d(floor(drop_pos.xy * drop_density.xy) * 13.1) * 10;
|
||||||
@ -244,7 +243,7 @@ void main() {
|
|||||||
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
|
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
|
||||||
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
|
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
|
||||||
|
|
||||||
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density) {
|
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) {
|
||||||
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
|
vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0);
|
||||||
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
|
vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density;
|
||||||
|
|
||||||
|
@ -3656,7 +3656,7 @@ fn handle_weather_zone(
|
|||||||
add_zone(weather::Weather {
|
add_zone(weather::Weather {
|
||||||
cloud: 0.3,
|
cloud: 0.3,
|
||||||
rain: 0.3,
|
rain: 0.3,
|
||||||
wind: Vec2::new(15.0,20.0),
|
wind: Vec2::new(15.0, 20.0),
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,9 @@ pub struct Locals {
|
|||||||
rel_rain_dir_mat: [[f32; 4]; 4],
|
rel_rain_dir_mat: [[f32; 4]; 4],
|
||||||
/// A value to offset the rain, to make it move over time.
|
/// A value to offset the rain, to make it move over time.
|
||||||
integrated_rain_vel: f32,
|
integrated_rain_vel: f32,
|
||||||
|
rain_density: f32,
|
||||||
// To keep 16-byte-aligned.
|
// To keep 16-byte-aligned.
|
||||||
occlusion_dummy: [f32; 3],
|
occlusion_dummy: [f32; 2],
|
||||||
}
|
}
|
||||||
/// Make sure Locals is 16-byte-aligned.
|
/// Make sure Locals is 16-byte-aligned.
|
||||||
const _: () = assert!(core::mem::size_of::<Locals>() % 16 == 0);
|
const _: () = assert!(core::mem::size_of::<Locals>() % 16 == 0);
|
||||||
@ -25,6 +26,7 @@ impl Locals {
|
|||||||
rain_occlusion_matrices: Mat4<f32>,
|
rain_occlusion_matrices: Mat4<f32>,
|
||||||
rain_occlusion_texture_mat: Mat4<f32>,
|
rain_occlusion_texture_mat: Mat4<f32>,
|
||||||
rel_rain_dir_mat: Mat4<f32>,
|
rel_rain_dir_mat: Mat4<f32>,
|
||||||
|
rain_density: f32,
|
||||||
integrated_rain_vel: f32,
|
integrated_rain_vel: f32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -32,7 +34,8 @@ impl Locals {
|
|||||||
rain_occlusion_texture_mat: rain_occlusion_texture_mat.into_col_arrays(),
|
rain_occlusion_texture_mat: rain_occlusion_texture_mat.into_col_arrays(),
|
||||||
rel_rain_dir_mat: rel_rain_dir_mat.into_col_arrays(),
|
rel_rain_dir_mat: rel_rain_dir_mat.into_col_arrays(),
|
||||||
integrated_rain_vel,
|
integrated_rain_vel,
|
||||||
occlusion_dummy: [0.0; 3],
|
rain_density,
|
||||||
|
occlusion_dummy: [0.0; 2],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,12 +1027,16 @@ impl Scene {
|
|||||||
shadow_mat,
|
shadow_mat,
|
||||||
texture_mat,
|
texture_mat,
|
||||||
rel_rain_dir_mat,
|
rel_rain_dir_mat,
|
||||||
|
weather.rain,
|
||||||
self.integrated_rain_vel,
|
self.integrated_rain_vel,
|
||||||
);
|
);
|
||||||
|
|
||||||
renderer.update_consts(&mut self.data.rain_occlusion_mats, &[rain_occlusion_locals]);
|
renderer.update_consts(&mut self.data.rain_occlusion_mats, &[rain_occlusion_locals]);
|
||||||
} else {
|
} else if self.integrated_rain_vel > 0.0 {
|
||||||
self.integrated_rain_vel = 0.0;
|
self.integrated_rain_vel = 0.0;
|
||||||
|
// Need to set rain to zero
|
||||||
|
let rain_occlusion_locals = RainOcclusionLocals::default();
|
||||||
|
renderer.update_consts(&mut self.data.rain_occlusion_mats, &[rain_occlusion_locals]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sun_dir = scene_data.get_sun_dir();
|
let sun_dir = scene_data.get_sun_dir();
|
||||||
|
Loading…
Reference in New Issue
Block a user