mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'zesterer/shader-fixes' into 'master'
Fixed water shader, sky shader See merge request veloren/veloren!2156
This commit is contained in:
commit
faf5b40576
@ -65,8 +65,8 @@ float wave_height(vec3 pos) {
|
||||
|
||||
pos *= 0.5;
|
||||
vec3 big_warp = (
|
||||
texture(t_waves, fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
|
||||
texture(t_waves, fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
|
||||
texture(t_noise, fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
|
||||
texture(t_noise, fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
|
||||
vec3(0)
|
||||
);
|
||||
|
||||
@ -79,8 +79,8 @@ float wave_height(vec3 pos) {
|
||||
float height = (
|
||||
(texture(t_noise, (pos.xy + pos.z) * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_noise, (pos.yx + pos.z) * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
|
||||
(texture(t_waves, (pos.xy + pos.z) * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_waves, (pos.yx + pos.z) * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_noise, (pos.xy + pos.z) * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_noise, (pos.yx + pos.z) * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
|
||||
(texture(t_noise, (pos.yx + pos.z) * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, (pos.xy + pos.z) * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
|
||||
(texture(t_noise, (pos.yx + pos.z) * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
|
||||
|
@ -131,7 +131,7 @@ vec4 cloud_at(vec3 pos, float dist, out vec3 emission) {
|
||||
#if (CLOUD_MODE >= CLOUD_MODE_MEDIUM)
|
||||
emission_alt += (noise_3d(vec3(wind_pos.xy * 0.0005 + cloud_tendency * 0.2, emission_alt * 0.0001 + time_of_day.x * 0.001)) - 0.5) * 1000;
|
||||
#endif
|
||||
float tail = (texture(t_noise, wind_pos.xy * 0.000025).x - 0.5) * 5 + (pos.z - emission_alt) * 0.0001;
|
||||
float tail = (texture(t_noise, wind_pos.xy * 0.00005).x - 0.5) * 4 + (pos.z - emission_alt) * 0.0001;
|
||||
vec3 emission_col = vec3(0.8 + tail * 1.5, 0.5 - tail * 0.2, 0.3 + tail * 0.2);
|
||||
float emission_nz = max(pow(texture(t_noise, wind_pos.xy * 0.000015).x, 8), 0.01) * 0.25 / (10.0 + abs(pos.z - emission_alt) / 80);
|
||||
emission = emission_col * emission_nz * emission_strength * max(sun_dir.z, 0) * 500000 / (1000.0 + abs(pos.z - emission_alt) * 0.1);
|
||||
@ -188,7 +188,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
/* (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 1.0 - time_of_day * 0.00005).x - 0.5) * 0.2 / (1.0 + pow(dir.z, 2) * 10), */
|
||||
/* (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 1.0 - time_of_day * 0.00005).x - 0.5) * 0.2 / (1.0 + pow(dir.z, 2) * 10) */
|
||||
/* ) * 1500; */
|
||||
splay += (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 5.0 - time_of_day * 0.00005).x - 0.5) * 0.075 / (1.0 + pow(dir.z, 2) * 10);
|
||||
splay += (texture(t_noise, vec2(atan2(dir.x, dir.y) * 2 / PI, dir.z) * 5.0 - time_of_day * 0.00005).x - 0.5) * 0.025 / (1.0 + pow(dir.z, 2) * 10);
|
||||
#endif
|
||||
|
||||
/* const float RAYLEIGH = 0.25; */
|
||||
@ -199,6 +199,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
float moon_scatter = dot(-dir, moon_dir.xyz) * 0.5 + 0.7;
|
||||
float net_light = get_sun_brightness() + get_moon_brightness();
|
||||
vec3 sky_color = RAYLEIGH * net_light;
|
||||
vec3 sky_light = get_sky_light(dir, time_of_day, false);
|
||||
|
||||
float cdist = max_dist;
|
||||
float ldist = cdist;
|
||||
@ -222,8 +223,9 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
// Attenuate light passing through the clouds
|
||||
surf_color * (1.0 - cloud_scatter_factor - global_scatter_factor) +
|
||||
// Add the directed light light scattered into the camera by the clouds and the atmosphere (global illumination)
|
||||
get_sun_color() * sun_scatter * get_sun_brightness() * (sun_access * cloud_scatter_factor + sky_color * global_scatter_factor) +
|
||||
get_moon_color() * moon_scatter * get_moon_brightness() * (moon_access * cloud_scatter_factor + sky_color * global_scatter_factor) +
|
||||
get_sun_color() * sun_scatter * get_sun_brightness() * (sun_access * cloud_scatter_factor /*+ sky_color * global_scatter_factor*/) +
|
||||
get_moon_color() * moon_scatter * get_moon_brightness() * (moon_access * cloud_scatter_factor /*+ sky_color * global_scatter_factor*/) +
|
||||
sky_light * global_scatter_factor +
|
||||
emission * density_integrals.y;
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,13 @@ const vec3 SKY_DAY_TOP = vec3(0.1, 0.5, 0.9);
|
||||
const vec3 SKY_DAY_MID = vec3(0.02, 0.28, 0.8);
|
||||
const vec3 SKY_DAY_BOT = vec3(0.1, 0.2, 0.3);
|
||||
const vec3 DAY_LIGHT = vec3(3.8, 3.0, 1.8);
|
||||
const vec3 SUN_HALO_DAY = vec3(0.8, 0.8, 0.001);
|
||||
const vec3 SUN_HALO_DAY = vec3(0.25, 0.25, 0.001);
|
||||
|
||||
const vec3 SKY_DUSK_TOP = vec3(0.06, 0.1, 0.20);
|
||||
const vec3 SKY_DUSK_MID = vec3(0.35, 0.1, 0.15);
|
||||
const vec3 SKY_DUSK_MID = vec3(0.75, 0.1, 0.15);
|
||||
const vec3 SKY_DUSK_BOT = vec3(0.0, 0.1, 0.23);
|
||||
const vec3 DUSK_LIGHT = vec3(8.0, 1.5, 0.15);
|
||||
const vec3 SUN_HALO_DUSK = vec3(2.2, 0.5, 0.1);
|
||||
const vec3 SUN_HALO_DUSK = vec3(5.2, 1.0, 0.1);
|
||||
|
||||
const vec3 SKY_NIGHT_TOP = vec3(0.001, 0.001, 0.0025);
|
||||
const vec3 SKY_NIGHT_MID = vec3(0.001, 0.005, 0.02);
|
||||
@ -413,6 +413,56 @@ float is_star_at(vec3 dir) {
|
||||
return 1.0 / (1.0 + pow(dist * 750, 8));
|
||||
}
|
||||
|
||||
vec3 get_sky_light(vec3 dir, float time_of_day, bool with_stars) {
|
||||
// Add white dots for stars. Note these flicker and jump due to FXAA
|
||||
float star = 0.0;
|
||||
if (with_stars) {
|
||||
vec3 star_dir = normalize(sun_dir.xyz * dir.z + cross(sun_dir.xyz, vec3(0, 1, 0)) * dir.x + vec3(0, 1, 0) * dir.y);
|
||||
star = is_star_at(star_dir);
|
||||
}
|
||||
|
||||
vec3 sky_top = mix(
|
||||
mix(
|
||||
SKY_DUSK_TOP,
|
||||
SKY_NIGHT_TOP,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
) + star,
|
||||
SKY_DAY_TOP,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_mid = mix(
|
||||
mix( SKY_DUSK_MID,
|
||||
SKY_NIGHT_MID,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_MID,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_bot = mix(
|
||||
mix(
|
||||
SKY_DUSK_BOT,
|
||||
SKY_NIGHT_BOT,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_BOT,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_color = mix(
|
||||
mix(
|
||||
sky_mid,
|
||||
sky_bot,
|
||||
pow(max(-dir.z, 0), 0.4)
|
||||
),
|
||||
sky_top,
|
||||
max(dir.z, 0)
|
||||
);
|
||||
|
||||
return sky_color;
|
||||
}
|
||||
|
||||
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_features, float refractionIndex) {
|
||||
// Sky color
|
||||
/* vec3 sun_dir = get_sun_dir(time_of_day);
|
||||
@ -423,20 +473,13 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
|
||||
// sun_dir = sun_dir.z <= 0 ? refract(sun_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : sun_dir;
|
||||
// moon_dir = moon_dir.z <= 0 ? refract(moon_dir/*-view_dir*/, vec3(0.0, 0.0, 1.0), refractionIndex) : moon_dir;
|
||||
|
||||
// Add white dots for stars. Note these flicker and jump due to FXAA
|
||||
float star = 0.0;
|
||||
if (with_features) {
|
||||
vec3 star_dir = normalize(sun_dir * dir.z + cross(sun_dir, vec3(0, 1, 0)) * dir.x + vec3(0, 1, 0) * dir.y);
|
||||
star = is_star_at(star_dir);
|
||||
}
|
||||
|
||||
// Sun
|
||||
const vec3 SUN_SURF_COLOR = vec3(1.5, 0.9, 0.35) * 8.0;
|
||||
|
||||
vec3 sun_halo_color = mix(
|
||||
SUN_HALO_DUSK,
|
||||
SUN_HALO_DAY,
|
||||
max(-sun_dir.z, 0.0)
|
||||
pow(max(-sun_dir.z, 0.0), 0.5)
|
||||
);
|
||||
|
||||
vec3 sun_halo = sun_halo_color * 4 * pow(max(dot(dir, -sun_dir), 0), 20.0);
|
||||
@ -463,45 +506,10 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
|
||||
// Replaced all clamp(sun_dir, 0, 1) with max(sun_dir, 0) because sun_dir is calculated from sin and cos, which are never > 1
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
vec3 sky_top = mix(
|
||||
mix(
|
||||
SKY_DUSK_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
SKY_NIGHT_TOP + star / (1.0 + moon_surf * 100.0),
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_TOP,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_mid = mix(
|
||||
mix( SKY_DUSK_MID,
|
||||
SKY_NIGHT_MID,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_MID,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_bot = mix(
|
||||
mix(
|
||||
SKY_DUSK_BOT,
|
||||
SKY_NIGHT_BOT,
|
||||
max(pow(sun_dir.z, 0.2), 0)
|
||||
),
|
||||
SKY_DAY_BOT,
|
||||
max(-sun_dir.z, 0)
|
||||
);
|
||||
|
||||
vec3 sky_color = mix(
|
||||
mix(
|
||||
sky_mid,
|
||||
sky_bot,
|
||||
pow(max(-dir.z, 0), 0.4)
|
||||
),
|
||||
sky_top,
|
||||
max(dir.z, 0)
|
||||
);
|
||||
vec3 sky_color = get_sky_light(dir, time_of_day, true);
|
||||
#else
|
||||
vec3 star_dir = normalize(sun_dir.xyz * dir.z + cross(sun_dir.xyz, vec3(0, 1, 0)) * dir.x + vec3(0, 1, 0) * dir.y);
|
||||
float star = is_star_at(star_dir);
|
||||
vec3 sky_color = vec3(0) + star;
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user