Dynamically relocate LoD vertices to enhance details

This commit is contained in:
Joshua Barretto 2020-02-24 11:22:50 +00:00
parent a3e36a50ab
commit 5481df38fe
2 changed files with 19 additions and 18 deletions

View File

@ -21,23 +21,11 @@ vec2 splay(vec2 pos, float e) {
} }
float splay_scale(vec2 pos, float e) { float splay_scale(vec2 pos, float e) {
return distance(splay(pos, e), splay(pos + 0.001, e)) * 5000000.0; return distance(splay(pos, e), splay(pos + 0.001, e)) * 1000000.0;
}
vec3 lod_pos(vec2 v_pos) {
vec2 hpos = focus_pos.xy + splay(v_pos, 8.0) * 1000000.0;
float splay = splay_scale(v_pos, 8.0) * 1.0;
return vec3(hpos, (
alt_at(hpos) +
alt_at(hpos + vec2(-1, 1) * splay) +
alt_at(hpos + vec2(1, 1) * splay) +
alt_at(hpos + vec2(1, -1) * splay) +
alt_at(hpos + vec2(-1, -1) * splay)
) / 5.0);
} }
vec3 lod_norm(vec2 pos) { vec3 lod_norm(vec2 pos) {
const float SAMPLE_W = 8; const float SAMPLE_W = 16;
float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W); float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W);
float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W); float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W);
@ -52,10 +40,23 @@ 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;
// 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;
}
hpos = nhpos;
return vec3(hpos, alt_at(hpos));
}
vec3 lod_col(vec2 pos) { vec3 lod_col(vec2 pos) {
//return vec3(1); //return vec3(0, 1, 0);
return texture(t_map, pos_to_uv(pos)).rgb 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; //+ (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 warmth = mix(
vec3(0.05, 0.4, 0.1), vec3(0.05, 0.4, 0.1),

View File

@ -16,7 +16,7 @@ out vec3 f_norm;
out float f_light; out float f_light;
void main() { void main() {
f_pos = lod_pos(v_pos); f_pos = lod_pos(v_pos, focus_pos.xy);
f_norm = lod_norm(f_pos.xy); f_norm = lod_norm(f_pos.xy);