mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improved underwater lighting on low shader settings
This commit is contained in:
parent
2263bcbf7c
commit
3b347a2aa3
@ -70,9 +70,8 @@ void main() {
|
||||
vec3 dir = (wpos - cam_pos.xyz) / dist;
|
||||
|
||||
// Apply clouds
|
||||
#if (CLOUD_MODE != CLOUD_MODE_NONE)
|
||||
color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0);
|
||||
#else
|
||||
color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0);
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb);
|
||||
#endif
|
||||
|
||||
|
@ -185,8 +185,11 @@ void main() {
|
||||
// float reflected_light_point = /*length*/(diffuse_light_point.r) + f_light * point_shadow;
|
||||
// reflected_light += k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + specular_light_point;
|
||||
|
||||
float passthrough = clamp(dot(cam_norm, -cam_to_frag) * 1.0 - 0.2, 0, 1);
|
||||
float min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
|
||||
float passthrough = clamp(dot(f_norm, -cam_to_frag), 0, 1);
|
||||
float min_refl = 0.0;
|
||||
if (medium.x != 1) {
|
||||
min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
|
||||
}
|
||||
|
||||
vec3 surf_color = illuminate(max_light, view_dir, water_color * /* fog_color * */emitted_light, /*surf_color * */water_color * reflected_light);
|
||||
// vec4 color = vec4(surf_color, passthrough * 1.0 / (1.0 + min_refl));// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam)));
|
||||
|
@ -170,7 +170,6 @@ void main() {
|
||||
vec3 refract_ray_dir = refract(cam_to_frag/*-view_dir*/, norm, 1.0 / n2);
|
||||
vec3 sun_view_dir = view_dir;///*sign(cam_pos.z - fluid_alt) * view_dir;*/cam_pos.z <= fluid_alt ? -view_dir : view_dir;
|
||||
// vec3 sun_view_dir = cam_pos.z <= fluid_alt ? -view_dir : view_dir;
|
||||
vec3 beam_view_dir = reflect_ray_dir;//cam_pos.z <= fluid_alt ? -refract_ray_dir : reflect_ray_dir;
|
||||
/* vec4 reflect_ray_dir4 = view_mat * vec4(reflect_ray_dir, 1.0);
|
||||
reflect_ray_dir = normalize(vec3(reflect_ray_dir4) / reflect_ray_dir4.w); */
|
||||
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||
|
@ -1,3 +1,8 @@
|
||||
#include <lod.glsl>
|
||||
|
||||
vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) {
|
||||
// Underwater light attenuation
|
||||
surf_color = water_diffuse(surf_color, dir, max_dist);
|
||||
|
||||
return surf_color;
|
||||
}
|
||||
|
@ -272,19 +272,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
#endif
|
||||
|
||||
// Underwater light attenuation
|
||||
if (medium.x == 1) {
|
||||
float f_alt = alt_at(cam_pos.xy);
|
||||
float fluid_alt = max(cam_pos.z + 1, floor(f_alt + 1));
|
||||
|
||||
float water_dist = clamp((fluid_alt - cam_pos.z) / pow(max(dir.z, 0), 10), 0, max_dist);
|
||||
|
||||
//float fade = 1.0 - clamp(water_dist * 0.01, 0, 1);//pow(0.97, water_dist);
|
||||
float fade = pow(0.98, water_dist);
|
||||
|
||||
surf_color.rgb = mix(vec3(0, 0.5, 1)
|
||||
* (get_sun_brightness() * get_sun_color() + get_moon_brightness() * get_moon_color())
|
||||
/ max(1.0, (fluid_alt - cam_pos.z) * 0.5 - dir.z * 5), surf_color.rgb, fade/*pow(fade, 4)*/);
|
||||
}
|
||||
surf_color.rgb = water_diffuse(surf_color.rgb, dir, max_dist);
|
||||
|
||||
// Apply point glow
|
||||
surf_color = apply_point_glow(origin, dir, max_dist, surf_color);
|
||||
|
@ -382,4 +382,21 @@ vec3 lod_col(vec2 pos) {
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 water_diffuse(vec3 color, vec3 dir, float max_dist) {
|
||||
if (medium.x == 1) {
|
||||
float f_alt = alt_at(cam_pos.xy);
|
||||
float fluid_alt = max(cam_pos.z + 1, floor(f_alt + 1));
|
||||
|
||||
float water_dist = clamp((fluid_alt - cam_pos.z) / pow(max(dir.z, 0), 5), 0, max_dist);
|
||||
|
||||
float fade = pow(0.97, water_dist);
|
||||
|
||||
return mix(vec3(0.0, 0.2, 0.5)
|
||||
* (get_sun_brightness() * get_sun_color() + get_moon_brightness() * get_moon_color())
|
||||
* pow(0.99, max((fluid_alt - cam_pos.z) * 12.0 - dir.z * 200, 0)), color.rgb, fade);
|
||||
} else {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -650,4 +650,5 @@ vec3 greedy_extract_col_light_glow(texture2D t_col_light, sampler s_col_light, v
|
||||
uint f_attr;
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_attr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -194,7 +194,7 @@ void main() {
|
||||
#ifdef EXPERIMENTAL_UNDERWARPER
|
||||
vec2 uv = uv;
|
||||
if (medium.x == 1) {
|
||||
uv += sin(uv.yx * 30 + tick.xx * 1.0) * 0.005;
|
||||
uv += sin(uv.yx * 40 + tick.xx * 1.0) * 0.003;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -286,7 +286,13 @@ void main() {
|
||||
reflected_light *= f_light;
|
||||
max_light *= f_light;
|
||||
|
||||
#ifdef EXPERIMENTAL_CAUSTICS
|
||||
// TODO: Apply AO after this
|
||||
vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2);
|
||||
reflected_light += glow * pow(max(dot(face_norm, f_norm), 0), 2);
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
#ifndef EXPERIMENTAL_NOCAUSTICS
|
||||
#if (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
if (faces_fluid) {
|
||||
vec3 wpos = f_pos + focus_off.xyz;
|
||||
@ -294,17 +300,13 @@ void main() {
|
||||
reflected_light += max(1.0 - pow(abs(noise_3d(vec3(spos.xy, tick.x * 0.1 + dot(sin(wpos.xy * 0.8), vec2(1)) * 0.05)) - 0.5) * 10, 0.001), 0)
|
||||
* 500
|
||||
* cam_attenuation
|
||||
* sun_diffuse;
|
||||
* max(dot(f_norm, -sun_dir.xyz), 0)
|
||||
* sun_diffuse
|
||||
* sun_info.shadow;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TODO: Apply AO after this
|
||||
vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2);
|
||||
reflected_light += glow * pow(max(dot(face_norm, f_norm), 0), 2);
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
// float f_ao = 1.0;
|
||||
|
||||
// float ao = /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1;
|
||||
|
@ -223,15 +223,15 @@ impl Block {
|
||||
|
||||
// minimum block, attenuation
|
||||
#[inline]
|
||||
pub fn get_max_sunlight(&self) -> (u8, u8) {
|
||||
pub fn get_max_sunlight(&self) -> (u8, f32) {
|
||||
match self.kind() {
|
||||
BlockKind::Water => (1, 1),
|
||||
BlockKind::Leaves => (9, 255),
|
||||
BlockKind::Wood => (6, 2),
|
||||
BlockKind::Snow => (6, 2),
|
||||
BlockKind::Ice => (4, 2),
|
||||
_ if self.is_opaque() => (0, 255),
|
||||
_ => (0, 0),
|
||||
BlockKind::Water => (0, 0.4),
|
||||
BlockKind::Leaves => (9, 255.0),
|
||||
BlockKind::Wood => (6, 2.0),
|
||||
BlockKind::Snow => (6, 2.0),
|
||||
BlockKind::Ice => (4, 2.0),
|
||||
_ if self.is_opaque() => (0, 255.0),
|
||||
_ => (0, 0.0),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,19 +68,19 @@ fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
|
||||
if is_sunlight {
|
||||
for x in 0..outer.size().w {
|
||||
for y in 0..outer.size().h {
|
||||
let mut light = SUNLIGHT;
|
||||
let mut light = SUNLIGHT as f32;
|
||||
for z in (0..outer.size().d).rev() {
|
||||
let (min_light, attenuation) = vol_cached
|
||||
.get(outer.min + Vec3::new(x, y, z))
|
||||
.map_or((0, 0), |b| b.get_max_sunlight());
|
||||
.map_or((0, 0.0), |b| b.get_max_sunlight());
|
||||
|
||||
if light > min_light {
|
||||
light = light.saturating_sub(attenuation).max(min_light);
|
||||
if light > min_light as f32 {
|
||||
light = (light - attenuation).max(min_light as f32);
|
||||
}
|
||||
|
||||
light_map[lm_idx(x, y, z)] = light;
|
||||
light_map[lm_idx(x, y, z)] = light.floor() as u8;
|
||||
|
||||
if light == 0 {
|
||||
if light <= 0.0 {
|
||||
break;
|
||||
} else {
|
||||
prop_que.push_back((x as u8, y as u8, z as u16));
|
||||
@ -103,7 +103,7 @@ fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
|
||||
.ok()
|
||||
.map_or(false, |b| b.is_fluid())
|
||||
{
|
||||
*dest = src - 1;
|
||||
*dest = src.saturating_sub(1);
|
||||
// Can't propagate further
|
||||
if *dest > 1 {
|
||||
prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16));
|
||||
@ -111,7 +111,7 @@ fn calc_light<V: RectRasterableVol<Vox = Block> + ReadVol + Debug>(
|
||||
} else {
|
||||
*dest = OPAQUE;
|
||||
}
|
||||
} else if *dest < src - 1 {
|
||||
} else if *dest < src.saturating_sub(1) {
|
||||
*dest = src - 1;
|
||||
// Can't propagate further
|
||||
if *dest > 1 {
|
||||
|
@ -429,6 +429,6 @@ pub enum ExperimentalShader {
|
||||
ProceduralLodDetail,
|
||||
/// Add a warping effect when underwater.
|
||||
Underwarper,
|
||||
/// Add caustics to underwater terrain.
|
||||
Caustics,
|
||||
/// Remove caustics from underwater terrain when shiny water is enabled.
|
||||
NoCaustics,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user