diff --git a/assets/voxygen/shaders/include/cloud/none.glsl b/assets/voxygen/shaders/include/cloud/none.glsl index a20fb82326..917fd5e60c 100644 --- a/assets/voxygen/shaders/include/cloud/none.glsl +++ b/assets/voxygen/shaders/include/cloud/none.glsl @@ -1,5 +1,3 @@ -uniform sampler2D t_noise; - vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) { return vec4(0.0); } diff --git a/assets/voxygen/shaders/include/cloud/regular.glsl b/assets/voxygen/shaders/include/cloud/regular.glsl index 285a5d3646..e55209b9b5 100644 --- a/assets/voxygen/shaders/include/cloud/regular.glsl +++ b/assets/voxygen/shaders/include/cloud/regular.glsl @@ -1,4 +1,4 @@ -uniform sampler2D t_noise; +#include const float CLOUD_AVG_HEIGHT = 1025.0; const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 50.0; diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 5c11207d22..8c9b8a0f16 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -104,80 +104,6 @@ float is_star_at(vec3 dir) { return 0.0; } -const float CLOUD_AVG_HEIGHT = 1025.0; -const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 35.0; -const float CLOUD_HEIGHT_MAX = CLOUD_AVG_HEIGHT + 35.0; -const float CLOUD_THRESHOLD = 0.3; -const float CLOUD_SCALE = 1.0; -const float CLOUD_DENSITY = 100.0; - -float vsum(vec3 v) { - return v.x + v.y + v.z; -} - -vec2 cloud_at(vec3 pos) { - float tick_offs = 0.0 - + texture(t_noise, pos.xy * 0.0001 + tick.x * 0.001).x * 1.0 - + texture(t_noise, pos.xy * 0.000003).x * 5.0; - - float value = ( - 0.0 - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0003 + tick_offs).x - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0009 - tick_offs).x * 0.5 - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0025 - tick.x * 0.01).x * 0.25 - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.008 + tick.x * 0.02).x * 0.1 - ) / 3.0; - - float density = max((value - CLOUD_THRESHOLD) - abs(pos.z - CLOUD_AVG_HEIGHT) / 500.0, 0.0) * CLOUD_DENSITY; - - float shade = ((pos.z - CLOUD_AVG_HEIGHT) / (CLOUD_AVG_HEIGHT - CLOUD_HEIGHT_MIN) + 0.5); - - return vec2(shade, density / (1.0 + vsum(abs(pos - cam_pos.xyz)) / 10000)); -} - -vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) { - - const float INCR = 0.06; - - float mind = (CLOUD_HEIGHT_MIN - origin.z) / dir.z; - float maxd = (CLOUD_HEIGHT_MAX - origin.z) / dir.z; - - float start = max(min(mind, maxd), 0.0); - float cloud_delta = abs(mind - maxd); - float delta = min(cloud_delta, max_dist); - - bool do_cast = true; - if (mind < 0.0 && maxd < 0.0) { - do_cast = false; - } - - float incr = INCR; - - float fuzz = sin(texture(t_noise, dir.xz * 100000.0).x * 100.0) * incr * delta; - - float cloud_shade = 1.0; - float passthrough = 1.0; - if (do_cast) { - for (float d = 0.0; d < 1.0; d += incr) { - float dist = start + d * delta; - dist += fuzz * min(pow(dist * 0.005, 2.0), 1.0); - - vec3 pos = origin + dir * min(dist, max_dist); - vec2 sample = cloud_at(pos); - - float integral = sample.y * incr; - passthrough *= max(1.0 - integral, 0.0); - cloud_shade = mix(cloud_shade, sample.x, passthrough * integral); - } - } - - float total_density = 1.0 - passthrough / (1.0 + (max_dist / (1.0 + max(abs(dir.z), 0.03) * 100.0)) * 0.00003); - - total_density = max(total_density - 1.0 / pow(max_dist, 0.25), 0.0); // Hack - - return vec4(vec3(cloud_shade), total_density); -} - vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_stars, out vec4 clouds) { // Sky color vec3 sun_dir = get_sun_dir(time_of_day); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index b6a17e48f2..97fcbfb4e1 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -3,7 +3,7 @@ #include in vec3 f_pos; -in vec3 f_norm; +flat in uint f_pos_norm; in vec3 f_col; in float f_light; diff --git a/assets/voxygen/shaders/terrain-vert.glsl b/assets/voxygen/shaders/terrain-vert.glsl index 0c08908a76..52b21fad54 100644 --- a/assets/voxygen/shaders/terrain-vert.glsl +++ b/assets/voxygen/shaders/terrain-vert.glsl @@ -13,7 +13,7 @@ uniform u_locals { }; out vec3 f_pos; -out vec3 f_norm; +flat out uint f_pos_norm; out vec3 f_col; out float f_light; @@ -27,15 +27,7 @@ void main() { f_light = float(v_col_light & 0xFFu) / 255.0; - // First 3 normals are negative, next 3 are positive - vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(0,-1,0), vec3(0,0,-1), vec3(1,0,0), vec3(0,1,0), vec3(0,0,1)); - - // TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction. - uint norm_axis = (v_pos_norm >> 30) & 0x3u; - // Increase array access by 3 to access positive values - uint norm_dir = ((v_pos_norm >> 29) & 0x1u) * 3u; - // Use an array to avoid conditional branching - f_norm = normals[norm_axis + norm_dir]; + f_pos_norm = v_pos_norm; gl_Position = all_mat * diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 3a8a5a01fc..ac6845772c 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -1,11 +1,13 @@ pub mod camera; pub mod figure; +pub mod lod; pub mod terrain; use self::{ camera::{Camera, CameraMode}, figure::FigureMgr, music::MusicMgr, + lod::Lod, terrain::Terrain, }; use crate::{