mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Better LoD detail
This commit is contained in:
parent
47d502fa56
commit
f1ee52b2cc
@ -35,7 +35,15 @@ layout(location = 1) out uvec4 tgt_mat;
|
||||
#include <light.glsl>
|
||||
#include <lod.glsl>
|
||||
|
||||
const float FADE_DIST = 32.0;
|
||||
float lod_voxel_noise(vec3 f_pos) {
|
||||
#ifdef EXPERIMENTAL_PROCEDURALLODDETAIL
|
||||
vec3 block_pos = floor(f_pos) + 0.5;
|
||||
//return (hash_three(uvec3((block_pos + focus_off.xyz) * 0.35)) - 0.5) * 5.0;
|
||||
return floor((noise_3d((block_pos + focus_off.xyz) * 0.015) - 0.5) * 5.0);
|
||||
#else
|
||||
return 0.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main() {
|
||||
#ifdef EXPERIMENTAL_BAREMINIMUM
|
||||
@ -94,20 +102,22 @@ void main() {
|
||||
vec3 top_norm = vec3(0, 0, 1);
|
||||
voxel_norm = normalize(mix(side_norm, top_norm, cam_dir.z));
|
||||
#else
|
||||
float t = -1.5;
|
||||
while (t < 1.5) {
|
||||
float base_surf_depth = lod_voxel_noise(f_pos);
|
||||
float t = -1.5 + base_surf_depth;
|
||||
while (t < 1.5 + base_surf_depth) {
|
||||
vec3 deltas = (step(vec3(0), -cam_dir) - fract(f_pos - cam_dir * t)) / -cam_dir;
|
||||
float m = min(min(deltas.x, deltas.y), deltas.z);
|
||||
|
||||
t += max(m, 0.01);
|
||||
|
||||
vec3 block_pos = floor(f_pos - cam_dir * t) + 0.5;
|
||||
if (dot(block_pos - f_pos, -f_norm) < 0.0) {
|
||||
float surf_depth = lod_voxel_noise(f_pos);
|
||||
if (dot(block_pos - f_pos - f_norm * surf_depth, -f_norm) < 0.0) {
|
||||
vec3 to_center = abs(block_pos - (f_pos - cam_dir * t));
|
||||
voxel_norm = step(max(max(to_center.x, to_center.y), to_center.z), to_center) * sign(-cam_dir);
|
||||
voxel_norm = mix(f_norm, voxel_norm, voxelize_factor);
|
||||
surf_color *= mix(0.65, 1.0, hash_three(uvec3(block_pos + focus_off.xyz)));
|
||||
f_ao = mix(1.0, clamp(1.0 + t, 0.2, 1.0), voxelize_factor);
|
||||
f_ao = mix(1.0, clamp(1.0 + t - surf_depth, 0.1, 1.0), voxelize_factor * max(0.0, -dot(cam_dir, f_norm)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -130,13 +130,13 @@ void main() {
|
||||
voxel_norm = normalize(mix(side_norm, top_norm, max(cam_dir.z, 0.0)));
|
||||
#else
|
||||
#ifdef EXPERIMENTAL_PROCEDURALLODDETAIL
|
||||
float nz_offset = (noise_2d((f_pos.xy + focus_off.xy) * 0.01) - 0.5) * 3.0 / f_norm.z;
|
||||
float nz_offset = floor((noise_2d(round(f_pos.xy + focus_off.xy) * 0.01) - 0.5) * 3.0 / max(f_norm.z, 0.01));
|
||||
#else
|
||||
const float nz_offset = 0.0;
|
||||
#endif
|
||||
|
||||
float t = -2.0;
|
||||
while (t < 2.0) {
|
||||
float t = -2.0 + nz_offset;
|
||||
while (t < 2.0 + nz_offset) {
|
||||
vec3 deltas = (step(vec3(0), -cam_dir) - fract(f_pos - cam_dir * t)) / -cam_dir;
|
||||
float m = min(min(deltas.x, deltas.y), deltas.z);
|
||||
|
||||
@ -147,7 +147,7 @@ void main() {
|
||||
vec3 to_center = abs(block_pos - (f_pos - cam_dir * t));
|
||||
voxel_norm = step(max(max(to_center.x, to_center.y), to_center.z), to_center) * sign(-cam_dir);
|
||||
voxel_norm = mix(f_norm, voxel_norm, voxelize_factor);
|
||||
f_ao = mix(1.0, clamp(1.0 + (t - nz_offset) * 0.5, 0.1, 1.0), voxelize_factor);
|
||||
f_ao = mix(1.0, clamp(1.0 + (t - nz_offset) * 0.5, 0.1, 1.0), voxelize_factor * max(0.0, -dot(cam_dir, f_norm)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user