Avoid expense when LoD voxels are disabled

This commit is contained in:
Joshua Barretto 2022-05-11 15:20:19 +01:00
parent 01e1cb34b0
commit b42ee3fce2
2 changed files with 32 additions and 33 deletions

View File

@ -80,6 +80,10 @@ void main() {
vec3 cam_dir = normalize(cam_pos.xyz - f_pos.xyz); vec3 cam_dir = normalize(cam_pos.xyz - f_pos.xyz);
vec3 side_norm = normalize(vec3(my_norm.xy, 0)); vec3 side_norm = normalize(vec3(my_norm.xy, 0));
vec3 top_norm = vec3(0, 0, 1); vec3 top_norm = vec3(0, 0, 1);
#ifdef EXPERIMENTAL_NOLODVOXELS
f_ao = 1.0;
voxel_norm = normalize(mix(side_norm, top_norm, cam_dir.z));
#else
float side_factor = 1.0 - my_norm.z; float side_factor = 1.0 - my_norm.z;
// min(dot(vec3(0, -sign(cam_dir.y), 0), -cam_dir), dot(vec3(-sign(cam_dir.x), 0, 0), -cam_dir)) // min(dot(vec3(0, -sign(cam_dir.y), 0), -cam_dir), dot(vec3(-sign(cam_dir.x), 0, 0), -cam_dir))
if (max(abs(my_norm.x), abs(my_norm.y)) < 0.01 || fract(my_alt) * clamp(dot(normalize(vec3(cam_dir.xy, 0)), side_norm), 0, 1) < cam_dir.z / my_norm.z) { if (max(abs(my_norm.x), abs(my_norm.y)) < 0.01 || fract(my_alt) * clamp(dot(normalize(vec3(cam_dir.xy, 0)), side_norm), 0, 1) < cam_dir.z / my_norm.z) {
@ -96,10 +100,6 @@ void main() {
} }
f_ao = min(f_ao, max(f_norm.z * 0.5 + 0.5, 0.0)); f_ao = min(f_ao, max(f_norm.z * 0.5 + 0.5, 0.0));
voxel_norm = mix(my_norm, voxel_norm == vec3(0.0) ? f_norm : voxel_norm, voxelize_factor); voxel_norm = mix(my_norm, voxel_norm == vec3(0.0) ? f_norm : voxel_norm, voxelize_factor);
#ifdef EXPERIMENTAL_NOLODVOXELS
f_ao = 1.0;
voxel_norm = normalize(mix(side_norm, top_norm, cam_dir.z));
#endif #endif
vec3 emitted_light, reflected_light; vec3 emitted_light, reflected_light;

View File

@ -333,12 +333,15 @@ void main() {
hit_xy ? vec3(0.0, 0.0, sides.z) : vec3(0.0, 0.0, 0.0); hit_xy ? vec3(0.0, 0.0, sides.z) : vec3(0.0, 0.0, 0.0);
*/ */
vec3 voxel_norm; vec3 voxel_norm;
const float VOXELIZE_DIST = 2000; const float VOXELIZE_DIST = 2000;
float voxelize_factor = clamp(1.0 - (distance(focus_pos.xy, f_pos.xy) - view_distance.x) / VOXELIZE_DIST, 0, 1); float voxelize_factor = clamp(1.0 - (distance(focus_pos.xy, f_pos.xy) - view_distance.x) / VOXELIZE_DIST, 0, 1);
vec3 cam_dir = normalize(cam_pos.xyz - f_pos.xyz); vec3 cam_dir = normalize(cam_pos.xyz - f_pos.xyz);
vec3 side_norm = normalize(vec3(my_norm.xy, 0)); vec3 side_norm = normalize(vec3(my_norm.xy, 0));
vec3 top_norm = vec3(0, 0, 1); vec3 top_norm = vec3(0, 0, 1);
#ifdef EXPERIMENTAL_NOLODVOXELS
f_ao = 1.0;
voxel_norm = normalize(mix(side_norm, top_norm, max(cam_dir.z, 0.0)));
#else
float side_factor = 1.0 - my_norm.z; float side_factor = 1.0 - my_norm.z;
// min(dot(vec3(0, -sign(cam_dir.y), 0), -cam_dir), dot(vec3(-sign(cam_dir.x), 0, 0), -cam_dir)) // min(dot(vec3(0, -sign(cam_dir.y), 0), -cam_dir), dot(vec3(-sign(cam_dir.x), 0, 0), -cam_dir))
if (max(abs(my_norm.x), abs(my_norm.y)) < 0.01 || fract(my_alt) * clamp(dot(normalize(vec3(cam_dir.xy, 0)), side_norm), 0, 1) < cam_dir.z / my_norm.z) { if (max(abs(my_norm.x), abs(my_norm.y)) < 0.01 || fract(my_alt) * clamp(dot(normalize(vec3(cam_dir.xy, 0)), side_norm), 0, 1) < cam_dir.z / my_norm.z) {
@ -353,10 +356,6 @@ void main() {
voxel_norm = vec3(0, sign(cam_dir.y), 0); voxel_norm = vec3(0, sign(cam_dir.y), 0);
} }
} }
#ifdef EXPERIMENTAL_NOLODVOXELS
f_ao = 1.0;
voxel_norm = normalize(mix(side_norm, top_norm, max(cam_dir.z, 0.0)));
#endif #endif
// vec3 f_ao_view = max(vec3(dot(f_orig_view_dir.yz, sides.yz), dot(f_orig_view_dir.xz, sides.xz), dot(f_orig_view_dir.xy, sides.xy)), 0.0); // vec3 f_ao_view = max(vec3(dot(f_orig_view_dir.yz, sides.yz), dot(f_orig_view_dir.xz, sides.xz), dot(f_orig_view_dir.xy, sides.xy)), 0.0);