mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'zesterer/small-fixes' into 'master'
Performance Improvements See merge request veloren/veloren!3481
This commit is contained in:
commit
7e27d33632
@ -99,7 +99,11 @@ void main() {
|
||||
float jump = max(min(deltas.x, deltas.y) * scale, PLANCK);
|
||||
t += jump;
|
||||
|
||||
if (t >= 64.0) { break; }
|
||||
#if (CLOUD_MODE >= CLOUD_MODE_MEDIUM)
|
||||
if (t >= 64.0) { break; }
|
||||
#else
|
||||
if (t >= 16.0) { break; }
|
||||
#endif
|
||||
|
||||
rpos = rorigin + adjusted_dir * t;
|
||||
|
||||
|
@ -92,9 +92,9 @@ void main() {
|
||||
// vec3 f_col = f_col_light.rgb;
|
||||
// float f_ao = f_col_light.a;
|
||||
|
||||
float f_ao, f_glow, f_ao_unused;
|
||||
float f_ao;
|
||||
uint material = 0xFFu;
|
||||
vec3 f_col = greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_ao, f_glow, f_ao_unused, material);
|
||||
vec3 f_col = greedy_extract_col_light_figure(t_col_light, s_col_light, f_uv_pos, f_ao, material);
|
||||
|
||||
#ifdef EXPERIMENTAL_BAREMINIMUM
|
||||
tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_ao), 1);
|
||||
|
@ -620,8 +620,11 @@ vec3 compute_attenuation_point(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_a
|
||||
//}
|
||||
//#endif
|
||||
|
||||
vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out float f_ao, out uint f_attr) {
|
||||
vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out float f_ao, out uint f_attr, out float f_sky_exposure) {
|
||||
// TODO: Figure out how to use `texture` and modulation to avoid needing to do manual filtering
|
||||
// TODO: Use `texture` instead
|
||||
//vec2 light = texture(t_col_light, f_uv_pos).xy / 31;
|
||||
|
||||
uvec4 tex_00 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 0), 0) * 255);
|
||||
uvec4 tex_10 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0) * 255);
|
||||
uvec4 tex_01 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0) * 255);
|
||||
@ -633,8 +636,6 @@ vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, v
|
||||
vec3 light_0 = mix(light_00, light_01, fract(f_uv_pos.y));
|
||||
vec3 light_1 = mix(light_10, light_11, fract(f_uv_pos.y));
|
||||
vec3 light = mix(light_0, light_1, fract(f_uv_pos.x));
|
||||
// TODO: Use `texture` instead
|
||||
//vec2 light = texture(t_col_light, f_uv_pos).xy / 31;
|
||||
|
||||
vec3 f_col = vec3(
|
||||
float(((tex_00.r & 0x7u) << 1u) | (tex_00.b & 0xF0u)),
|
||||
@ -644,14 +645,26 @@ vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, v
|
||||
|
||||
f_ao = light.z;
|
||||
f_light = light.x / 31.0;
|
||||
f_sky_exposure = light.x / 31.0 + (1.0 - f_ao) * 0.5;
|
||||
f_glow = light.y / 31.0;
|
||||
f_attr = tex_00.g >> 3u;
|
||||
return srgb_to_linear(f_col);
|
||||
}
|
||||
|
||||
vec3 greedy_extract_col_light_glow(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_ao, out float f_glow) {
|
||||
uint f_attr;
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_ao, f_attr);
|
||||
vec3 greedy_extract_col_light_terrain(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out float f_ao, out float f_sky_exposure) {
|
||||
float _f_attr;
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_ao, _f_attr, f_sky_exposure);
|
||||
}
|
||||
|
||||
vec3 greedy_extract_col_light_sprite(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light) {
|
||||
float _f_sky_exposure, _f_light, _f_glow, _f_ao;
|
||||
uint _f_attr;
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, _f_glow, _f_ao, _f_attr, _f_sky_exposure);
|
||||
}
|
||||
|
||||
vec3 greedy_extract_col_light_figure(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out uint f_attr) {
|
||||
float _f_sky_exposure, _f_light, _f_glow, _f_ao;
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, _f_glow, _f_ao, f_attr, _f_sky_exposure);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -40,8 +40,8 @@ layout(location = 0) out vec4 tgt_color;
|
||||
const float FADE_DIST = 32.0;
|
||||
|
||||
void main() {
|
||||
float f_ao, f_glow, f_ao_unused;
|
||||
vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_ao, f_ao_unused, f_glow);
|
||||
float f_ao;
|
||||
vec3 f_col = greedy_extract_col_light_sprite(t_col_light, s_col_light, f_uv_pos, f_ao);
|
||||
|
||||
#ifdef EXPERIMENTAL_BAREMINIMUM
|
||||
tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_ao), 1);
|
||||
|
@ -84,8 +84,8 @@ void main() {
|
||||
vec2 f_uv_pos = f_uv_pos + atlas_offs.xy;
|
||||
// vec4 f_col_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0)));//(f_uv_pos/* + 0.5*/) / texSize);
|
||||
// float f_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0))).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0;
|
||||
float f_light, f_glow, f_ao;
|
||||
vec3 f_col = greedy_extract_col_light_glow(t_col_light, s_col_light, f_uv_pos, f_light, f_ao, f_glow);
|
||||
float f_light, f_glow, f_ao, f_sky_exposure;
|
||||
vec3 f_col = greedy_extract_col_light_terrain(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_ao, f_sky_exposure);
|
||||
|
||||
#ifdef EXPERIMENTAL_BAREMINIMUM
|
||||
tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_light), 1);
|
||||
@ -244,13 +244,30 @@ void main() {
|
||||
drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0));
|
||||
vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z));
|
||||
|
||||
if (rain_occlusion_at(f_pos.xyz + vec3(0, 0, 0.25)) > 0.5) {
|
||||
#ifdef EXPERIMENTAL_WETNESS
|
||||
float puddle = clamp((noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.03) - 0.5) * 20.0, 0.0, 1.0) * min(rain_density * 10.0, 1.0);
|
||||
#else
|
||||
const float puddle = 1.0;
|
||||
#endif
|
||||
#ifdef EXPERIMENTAL_WETNESS
|
||||
float puddle = clamp((noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.03) - 0.5) * 20.0, 0.0, 1.0)
|
||||
* min(rain_density * 10.0, 1.0)
|
||||
* clamp((f_sky_exposure - 0.9) * 50.0, 0.0, 1.0);
|
||||
#else
|
||||
const float puddle = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef EXPERIMENTAL_WETNESS
|
||||
if (puddle > 0.0) {
|
||||
float h = (noise_2d((f_pos.xy + focus_off.xy) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
float hx = (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
float hy = (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
f_norm.xy += mix(vec2(0), vec2(h - hx, h - hy) / 0.1 * 0.03, puddle);
|
||||
alpha = mix(1.0, 0.2, puddle);
|
||||
f_col.rgb *= mix(1.0, 0.7, puddle);
|
||||
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), puddle);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (rain_occlusion_at(f_pos.xyz + vec3(0, 0, 0.25)) > 0.5) {
|
||||
if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * 2.0 && puddle > 0.3) {
|
||||
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;
|
||||
@ -273,21 +290,6 @@ void main() {
|
||||
* sign(dist - drop_rad)
|
||||
* max(drop_pos.z - near_cell.z, 0);
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL_WETNESS
|
||||
if (puddle > 0.0) {
|
||||
float h = (noise_2d((f_pos.xy + focus_off.xy) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
float hx = (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
float hy = (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
|
||||
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
|
||||
f_norm.xy += mix(vec2(0), vec2(h - hx, h - hy) / 0.1 * 0.03, puddle);
|
||||
alpha = mix(1.0, 0.2, puddle);
|
||||
f_col.rgb *= mix(1.0, 0.7, puddle);
|
||||
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), puddle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@ enum FaceKind {
|
||||
}
|
||||
|
||||
pub const SUNLIGHT: u8 = 24;
|
||||
pub const SUNLIGHT_INV: f32 = 1.0 / SUNLIGHT as f32;
|
||||
pub const MAX_LIGHT_DIST: i32 = SUNLIGHT as i32;
|
||||
|
||||
fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
|
||||
@ -217,7 +218,7 @@ fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
|
||||
.unwrap_or(default_light);
|
||||
|
||||
if l != OPAQUE && l != UNKNOWN {
|
||||
l as f32 / SUNLIGHT as f32
|
||||
l as f32 * SUNLIGHT_INV
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
|
@ -6411,6 +6411,8 @@ impl<S: Skeleton> FigureState<S> {
|
||||
// get the rider offset
|
||||
skel_body: S::Body,
|
||||
) {
|
||||
span!(_guard, "update", "FigureState::update");
|
||||
|
||||
// NOTE: As long as update() always gets called after get_or_create_model(), and
|
||||
// visibility is not set again until after the model is rendered, we
|
||||
// know we don't pair the character model with invalid model state.
|
||||
@ -6475,6 +6477,11 @@ impl<S: Skeleton> FigureState<S> {
|
||||
|
||||
let (light, glow) = terrain
|
||||
.map(|t| {
|
||||
span!(
|
||||
_guard,
|
||||
"light_glow",
|
||||
"FigureState::update (fetch light/glow)"
|
||||
);
|
||||
// Sample the location a little above to avoid clipping into terrain
|
||||
// TODO: Try to make this faster? It might be fine though
|
||||
let wpos = Vec3::from(pos.into_array()) + Vec3::unit_z();
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
mesh::{
|
||||
greedy::{GreedyMesh, SpriteAtlasAllocator},
|
||||
segment::generate_mesh_base_vol_sprite,
|
||||
terrain::{generate_mesh, SUNLIGHT},
|
||||
terrain::{generate_mesh, SUNLIGHT, SUNLIGHT_INV},
|
||||
},
|
||||
render::{
|
||||
pipelines::{self, ColLights},
|
||||
@ -775,23 +775,27 @@ impl<V: RectRasterableVol> Terrain<V> {
|
||||
let chunk_pos = wpos_chunk + rpos;
|
||||
self.chunks
|
||||
.get(&chunk_pos)
|
||||
.map(|c| c.blocks_of_interest.lights.iter())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(move |(lpos, level)| {
|
||||
(
|
||||
Vec3::<i32>::from(
|
||||
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
|
||||
) + *lpos,
|
||||
level,
|
||||
)
|
||||
.flat_map(|c| c.blocks_of_interest.lights.iter())
|
||||
.filter_map(move |(lpos, level)| {
|
||||
if (*lpos - wpos_chunk).map(|e| e.abs()).reduce_min() < SUNLIGHT as i32 + 2
|
||||
{
|
||||
Some((
|
||||
Vec3::<i32>::from(
|
||||
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
|
||||
) + *lpos,
|
||||
level,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.fold(
|
||||
(Vec3::broadcast(0.001), 0.0),
|
||||
|(bias, total), (lpos, level)| {
|
||||
let rpos = lpos.map(|e| e as f32 + 0.5) - wpos;
|
||||
let level = (*level as f32 - rpos.magnitude()).max(0.0) / SUNLIGHT as f32;
|
||||
let level = (*level as f32 - rpos.magnitude()).max(0.0) * SUNLIGHT_INV;
|
||||
(
|
||||
bias + rpos.try_normalized().unwrap_or_else(Vec3::zero) * level,
|
||||
total + level,
|
||||
|
@ -71,6 +71,9 @@ impl BlocksOfInterest {
|
||||
let mut flowers = Vec::new();
|
||||
let mut interactables = Vec::new();
|
||||
let mut lights = Vec::new();
|
||||
// Lights that can be omitted at random if we have too many and need to cull
|
||||
// some of them
|
||||
let mut minor_lights = Vec::new();
|
||||
let mut fire_bowls = Vec::new();
|
||||
let mut snow = Vec::new();
|
||||
let mut cricket1 = Vec::new();
|
||||
@ -168,10 +171,25 @@ impl BlocksOfInterest {
|
||||
interactables.push((pos, Interaction::Collect));
|
||||
}
|
||||
if let Some(glow) = block.get_glow() {
|
||||
lights.push((pos, glow));
|
||||
// Currently, we count filled blocks as 'minor' lights, and sprites as
|
||||
// non-minor.
|
||||
if block.get_sprite().is_none() {
|
||||
minor_lights.push((pos, glow));
|
||||
} else {
|
||||
lights.push((pos, glow));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Come up with a better way to prune many light sources: grouping them
|
||||
// into larger lights with k-means clustering, perhaps?
|
||||
const MAX_MINOR_LIGHTS: usize = 64;
|
||||
lights.extend(
|
||||
minor_lights
|
||||
.choose_multiple(&mut rng, MAX_MINOR_LIGHTS)
|
||||
.copied(),
|
||||
);
|
||||
|
||||
Self {
|
||||
leaves,
|
||||
drip,
|
||||
|
Loading…
Reference in New Issue
Block a user