This commit is contained in:
Joshua Barretto 2020-01-19 23:59:02 +00:00
parent 745e7540dd
commit 5e6f81b86c
6 changed files with 6 additions and 88 deletions

View File

@ -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) { vec4 get_cloud_color(vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
return vec4(0.0); return vec4(0.0);
} }

View File

@ -1,4 +1,4 @@
uniform sampler2D t_noise; #include <random.glsl>
const float CLOUD_AVG_HEIGHT = 1025.0; const float CLOUD_AVG_HEIGHT = 1025.0;
const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 50.0; const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 50.0;

View File

@ -104,80 +104,6 @@ float is_star_at(vec3 dir) {
return 0.0; 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) { 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 // Sky color
vec3 sun_dir = get_sun_dir(time_of_day); vec3 sun_dir = get_sun_dir(time_of_day);

View File

@ -3,7 +3,7 @@
#include <globals.glsl> #include <globals.glsl>
in vec3 f_pos; in vec3 f_pos;
in vec3 f_norm; flat in uint f_pos_norm;
in vec3 f_col; in vec3 f_col;
in float f_light; in float f_light;

View File

@ -13,7 +13,7 @@ uniform u_locals {
}; };
out vec3 f_pos; out vec3 f_pos;
out vec3 f_norm; flat out uint f_pos_norm;
out vec3 f_col; out vec3 f_col;
out float f_light; out float f_light;
@ -27,15 +27,7 @@ void main() {
f_light = float(v_col_light & 0xFFu) / 255.0; f_light = float(v_col_light & 0xFFu) / 255.0;
// First 3 normals are negative, next 3 are positive f_pos_norm = v_pos_norm;
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];
gl_Position = gl_Position =
all_mat * all_mat *

View File

@ -1,11 +1,13 @@
pub mod camera; pub mod camera;
pub mod figure; pub mod figure;
pub mod lod;
pub mod terrain; pub mod terrain;
use self::{ use self::{
camera::{Camera, CameraMode}, camera::{Camera, CameraMode},
figure::FigureMgr, figure::FigureMgr,
music::MusicMgr, music::MusicMgr,
lod::Lod,
terrain::Terrain, terrain::Terrain,
}; };
use crate::{ use crate::{