Better LoD precision

This commit is contained in:
Joshua Barretto 2020-02-23 16:53:17 +00:00
parent 3d027aebe8
commit 255f450ae9
3 changed files with 18 additions and 10 deletions

View File

@ -25,8 +25,8 @@ float splay_scale(vec2 pos, float e) {
} }
vec3 lod_pos(vec2 v_pos) { vec3 lod_pos(vec2 v_pos) {
vec2 hpos = focus_pos.xy + splay(v_pos, 5.0) * 1000000.0; vec2 hpos = focus_pos.xy + splay(v_pos, 8.0) * 1000000.0;
float splay = splay_scale(v_pos, 5.0); float splay = splay_scale(v_pos, 8.0) * 1.0;
return vec3(hpos, ( return vec3(hpos, (
alt_at(hpos) + alt_at(hpos) +
alt_at(hpos + vec2(-1, 1) * splay) + alt_at(hpos + vec2(-1, 1) * splay) +
@ -37,21 +37,25 @@ vec3 lod_pos(vec2 v_pos) {
} }
vec3 lod_norm(vec2 pos) { vec3 lod_norm(vec2 pos) {
float alt00 = alt_at(pos); const float SAMPLE_W = 8;
float alt10 = alt_at(pos + vec2(32, 0));
float alt01 = alt_at(pos + vec2(0, 32)); float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W);
float slope = abs(alt00 - alt10) + abs(alt00 - alt01); float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W);
float alty0 = alt_at(pos + vec2(0, -1) * SAMPLE_W);
float alty1 = alt_at(pos + vec2(0, 1) * SAMPLE_W);
float slope = abs(altx1 - altx0) + abs(alty0 - alty1);
return normalize(vec3( return normalize(vec3(
(alt00 - alt10) / 32, (altx0 - altx1) / SAMPLE_W,
(alt00 - alt01) / 32, (alty0 - alty1) / SAMPLE_W,
32 / (slope + 0.00001) // Avoid NaN SAMPLE_W / (slope + 0.00001) // Avoid NaN
)); ));
} }
vec3 lod_col(vec2 pos) { vec3 lod_col(vec2 pos) {
//return vec3(1);
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.01).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x * 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

@ -6,6 +6,7 @@
#include <lod.glsl> #include <lod.glsl>
in vec3 f_pos; in vec3 f_pos;
in vec3 f_norm;
out vec4 tgt_color; out vec4 tgt_color;

View File

@ -12,11 +12,14 @@ uniform u_locals {
}; };
out vec3 f_pos; out vec3 f_pos;
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);
f_norm = lod_norm(f_pos.xy);
//f_pos.z -= 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0); //f_pos.z -= 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0);
//f_pos.z -= 100.0 * pow(1.0 + 0.01 / view_distance.x, -pow(distance(focus_pos.xy, f_pos.xy), 2.0)); //f_pos.z -= 100.0 * pow(1.0 + 0.01 / view_distance.x, -pow(distance(focus_pos.xy, f_pos.xy), 2.0));