Fixed maths, improved LoD resolution

This commit is contained in:
Joshua Barretto 2020-02-24 12:38:53 +00:00
parent 5481df38fe
commit 9fea150473
2 changed files with 9 additions and 27 deletions

View File

@ -16,16 +16,12 @@ float alt_at(vec2 pos) {
+ texture(t_noise, pos * 0.003).x * 30.0;
}
vec2 splay(vec2 pos, float e) {
return pos * pow(length(pos), e);
}
float splay_scale(vec2 pos, float e) {
return distance(splay(pos, e), splay(pos + 0.001, e)) * 1000000.0;
vec2 splay(vec2 pos) {
return pos * pow(length(pos) * 0.5, 3.0);
}
vec3 lod_norm(vec2 pos) {
const float SAMPLE_W = 16;
const float SAMPLE_W = 32;
float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W);
float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W);
@ -41,34 +37,20 @@ vec3 lod_norm(vec2 pos) {
}
vec3 lod_pos(vec2 v_pos, vec2 focus_pos) {
vec2 hpos = focus_pos.xy + splay(v_pos, 4.0) * 1000000.0;
vec2 hpos = focus_pos.xy + splay(v_pos) * 1000000.0;
// Remove spiking by "pushing" vertices towards local optima
vec2 nhpos = hpos;
for (int i = 0; i < 5; i ++) {
nhpos -= lod_norm(hpos).xy * 5.0;
nhpos -= lod_norm(hpos).xy * 10.0;
}
hpos = nhpos;
hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32);
return vec3(hpos, alt_at(hpos));
}
vec3 lod_col(vec2 pos) {
//return vec3(0, 1, 0);
//return vec3(0, 0.5, 0);
return texture(t_map, pos_to_uv(pos)).rgb;
//+ (texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.005).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x - 0.5) * 0.1;
vec3 warmth = mix(
vec3(0.05, 0.4, 0.1),
vec3(0.5, 0.4, 0.0),
(texture(t_noise, pos * 0.0002).x - 0.5) * 2.0 + 0.5
);
vec3 color = mix(
warmth,
vec3(0.3, 0.3, 0.4),
alt_at(pos) / 1200.0
);
return color;
}

View File

@ -16,11 +16,11 @@ impl Lod {
pub fn new(renderer: &mut Renderer, client: &Client) -> Self {
Self {
model: renderer
.create_model(&create_lod_terrain_mesh(300)) //175
.create_model(&create_lod_terrain_mesh(500))
.unwrap(),
locals: renderer.create_consts(&[Locals::default()]).unwrap(),
map: renderer
.create_texture(&client.world_map.0, Some(FilterMethod::Bilinear), None)
.create_texture(&client.world_map.0, Some(FilterMethod::Trilinear), None)
.expect("Failed to generate map texture"),
}
}