Fixed calculation of LoD normals

This commit is contained in:
Joshua Barretto 2024-03-28 17:39:35 +00:00
parent 0aa034e30a
commit a4f4e78ac6
3 changed files with 13 additions and 11 deletions

View File

@ -443,6 +443,8 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve
#ifdef EXPERIMENTAL_PHOTOREALISTIC
vec3 lrf = light_reflection_factor(norm, dir, -norm, k_d, vec3(0.0), alpha, voxel_norm, voxel_lighting);
#else
// In practice, for gameplay purposes, we often want extra light at earlier and later times, so we use a
// non-physical LRF to boost light during dawn and dusk.
float lrf = pow(dot(norm, vec3(0, 0, 1)) + 1, 2) * 0.25;
#endif
vec3 light_frac = R_t_b * (sun_chroma * SUN_AMBIANCE + moon_chroma * MOON_AMBIANCE) * lrf;

View File

@ -90,9 +90,9 @@ void main() {
float voxelize_factor = clamp(1.0 - (distance(cam_pos.xy, f_pos.xy) - view_distance.x) * (1.0 / VOXELIZE_DIST), 0, 1.0);
vec3 cam_dir = cam_to_frag;
#ifdef EXPERIMENTAL_NOLODVOXELS
vec3 side_norm = normalize(vec3(f_norm.xy, 0));
vec3 top_norm = vec3(0, 0, 1);
voxel_norm = normalize(mix(side_norm, top_norm, cam_dir.z));
//vec3 side_norm = normalize(vec3(f_norm.xy, 0));
//vec3 top_norm = vec3(0, 0, 1);
voxel_norm = f_norm;//normalize(mix(side_norm, top_norm, cam_dir.z));
#else
float base_surf_depth = lod_voxel_noise(f_pos);
float t = -1.5 + base_surf_depth;

View File

@ -60,19 +60,19 @@ void main() {
vec4(f_pos, 1);
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); */
vec3 my_pos = vec3(f_pos.xy, my_alt);
vec3 my_norm = lod_norm(f_pos.xy/*, f_square*/);
//vec3 my_norm = lod_norm(f_pos.xy/*, f_square*/);
float which_norm = dot(my_norm, normalize(cam_pos.xyz - my_pos));
//float which_norm = dot(my_norm, normalize(cam_pos.xyz - my_pos));
// which_norm = 0.5 + which_norm * 0.5;
// which_norm = pow(max(0.0, which_norm), /*0.03125*/1 / 8.0);// * 0.5;
// smoothstep
which_norm = which_norm * which_norm * (3 - 2 * abs(which_norm));
//which_norm = which_norm * which_norm * (3 - 2 * abs(which_norm));
// which_norm = mix(0.0, 1.0, which_norm > 0.0);
// vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
vec3 f_norm = mix(faceforward(f_norm, cam_pos.xyz - f_pos, -f_norm), my_norm, which_norm);
vec3 f_pos = mix(f_pos, my_pos, which_norm);
vec3 f_norm = lod_norm(f_pos.xy);//mix(faceforward(f_norm, cam_pos.xyz - f_pos, -f_norm), my_norm, which_norm);
vec3 f_pos = mix(f_pos, my_pos, f_norm);
// vec3 fract_pos = fract(f_pos);
/* if (length(f_pos - cam_pos.xyz) <= view_distance.x + 32.0) {
vec4 new_f_pos;
@ -125,9 +125,9 @@ void main() {
float voxelize_factor = clamp(1.0 - (distance(cam_pos.xy, f_pos.xy) - view_distance.x) * (1.0 / VOXELIZE_DIST), 0, 1);
vec3 cam_dir = cam_to_frag;
#ifdef EXPERIMENTAL_NOLODVOXELS
vec3 side_norm = normalize(vec3(my_norm.xy, 0.01));
vec3 top_norm = vec3(0, 0, 1);
voxel_norm = normalize(mix(side_norm, top_norm, max(cam_dir.z, 0.0)));
//vec3 side_norm = normalize(vec3(my_norm.xy, 0.01));
//vec3 top_norm = vec3(0, 0, 1);
voxel_norm = f_norm;//normalize(mix(side_norm, top_norm, max(cam_dir.z, 0.0)));
#else
#ifdef EXPERIMENTAL_PROCEDURALLODDETAIL
float nz_offset = floor((noise_2d((floor(f_pos.xy) + focus_off.xy) * 0.01) - 0.5) * 3.0 / max(f_norm.z, 0.01));