More efficient texture fetches

This commit is contained in:
Joshua Barretto 2022-06-30 11:07:03 +01:00
parent 07fc53f9bc
commit 9ad32b37e7
2 changed files with 14 additions and 10 deletions

View File

@ -629,10 +629,13 @@ vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, v
) / 255.0;
// TODO: Figure out how to use `texture` and modulation to avoid needing to do manual filtering
vec4 tex_10 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0);
vec4 tex_01 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0);
vec4 tex_11 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0);
vec3 light_00 = vec3(uvec2(f_col_light.rg) >> 3u, f_col_light.a & 1u);
vec3 light_10 = vec3(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0).rg * 255.0) >> 3u, uint(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0).a * 255.0) & 1u);
vec3 light_01 = vec3(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0).rg * 255.0) >> 3u, uint(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0).a * 255.0) & 1u);
vec3 light_11 = vec3(uvec2(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0).rg * 255.0) >> 3u, uint(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0).a * 255.0) & 1u);
vec3 light_10 = vec3(uvec2(tex_10.rg * 255.0) >> 3u, uint(tex_10.a * 255.0) & 1u);
vec3 light_01 = vec3(uvec2(tex_01.rg * 255.0) >> 3u, uint(tex_01.a * 255.0) & 1u);
vec3 light_11 = vec3(uvec2(tex_11.rg * 255.0) >> 3u, uint(tex_11.a * 255.0) & 1u);
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));

View File

@ -422,7 +422,7 @@ fn write_column<R: Rng>(
.entry((tunnel.a.wpos, wpos2d))
.or_insert_with(|| {
let mut rng = RandomPerm::new(seed);
let z_range = tunnel.z_range_at(wpos2d.map(|e| e as f64 + 0.5), nz)?.0;
let (z_range, radius) = tunnel.z_range_at(wpos2d.map(|e| e as f64 + 0.5), nz)?;
let (cavern_bottom, cavern_top, floor, water_level) = (
z_range.start,
z_range.end,
@ -430,21 +430,21 @@ fn write_column<R: Rng>(
0,
);
let pos = wpos2d.with_z(cavern_bottom + floor);
if rng.gen_bool(0.75)
&& cavern_top - cavern_bottom > 15
if rng.gen_bool(0.5 * close(radius as f32, 64.0, 48.0) as f64)
&& tunnel.biome_at(pos, &info).mushroom > 0.5
// && pos.z as i32 > water_level - 2
{
let purp = rng.gen_range(0..50);
Some(Mushroom {
pos,
stalk: 8.0
+ rng.gen::<f32>().powf(2.0)
* (cavern_top - cavern_bottom - 8) as f32
* 0.85,
* 0.75,
head_color: Rgb::new(
50,
rng.gen_range(70..110),
rng.gen_range(100..200),
40 + purp,
rng.gen_range(60..120),
rng.gen_range(80..200) + purp,
),
})
} else {
@ -697,6 +697,7 @@ fn write_column<R: Rng>(
&& z < bedrock + h
&& radius > 25.0
&& !sky_above
&& false
} {
Block::new(BlockKind::Rock, col.stone_col)
} else {