Various water-related lighting fixes

This commit is contained in:
Joshua Barretto 2022-09-24 14:08:32 +01:00
parent b45586902a
commit 81ac4f9125
7 changed files with 33 additions and 27 deletions

View File

@ -59,7 +59,7 @@ vec4 water_col(vec4 posx, vec4 posy) {
textureLod(sampler2D(t_noise, s_noise), vec2(posx.y, posy.y), 0).x,
textureLod(sampler2D(t_noise, s_noise), vec2(posx.z, posy.z), 0).x,
textureLod(sampler2D(t_noise, s_noise), vec2(posx.w, posy.w), 0).x
) - 0.5) * 0.5;
) - 0.5) * 1.3;
}
float water_col_vel(vec2 pos){
@ -107,10 +107,8 @@ void main() {
// vec3 view_dir = normalize(-vec3(vert_pos4)/* / vert_pos4.w*/);
vec3 view_dir = -cam_to_frag;
// vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0));
/*const */vec3 water_color = (1.0 - MU_WATER) * MU_SCATTER;//srgb_to_linear(vec3(0.2, 0.5, 1.0));
// /*const */vec3 water_color = srgb_to_linear(vec3(0.0, 0.25, 0.5));
water_color *= water_col_vel(f_pos.xy);
vec3 water_color = (1.0 - mix(MU_WATER, vec3(0.8, 0.24, 0.08), water_col_vel(f_pos.xy))) * MU_SCATTER;
/* vec3 sun_dir = get_sun_dir(time_of_day.x);
vec3 moon_dir = get_moon_dir(time_of_day.x); */
@ -217,11 +215,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 = max(dot(f_norm, -cam_to_frag), 0) * 0.25;
float passthrough = max(dot(f_norm, -cam_to_frag), 0) * 0.65;
float min_refl = 0.0;
if (medium.x != MEDIUM_WATER) {
min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
}
/* if (medium.x != MEDIUM_WATER) { */
/* 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)));

View File

@ -104,7 +104,7 @@ vec4 wave_height(vec4 posx, vec4 posy) {
phase *= 1.2;
speed += speed_per_iter;
}
return w / ws * 20.0;
return w / ws * 5.0;
}
float wave_height_vel(vec2 pos){
@ -267,10 +267,10 @@ void main() {
vec3 reflect_color;
#if (FLUID_MODE == FLUID_MODE_HIGH)
reflect_color = get_sky_color(ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, sun_shade_frac > 0.5);
reflect_color = get_sky_color(ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac);
reflect_color = get_cloud_color(reflect_color, ray_dir, f_pos.xyz, time_of_day.x, 100000.0, 0.1);
#else
reflect_color = get_sky_color(ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, sun_shade_frac > 0.5, 1.0, true);
reflect_color = get_sky_color(ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac);
#endif
// Sort of non-physical, but we try to balance the reflection intensity with the direct light from the sun,
// resulting in decent reflection of the ambient environment even after the sun has gone down.
@ -314,6 +314,7 @@ void main() {
vec3 mu = MU_WATER;
// NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water.
vec3 cam_attenuation = compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz);
//reflect_color *= cam_attenuation;
// float water_depth_to_vertical = max(/*f_alt - f_pos.z*/f_light, 0.0);
// For ambient color, we just take the distance to the surface out of laziness.
// See https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law.
@ -334,7 +335,7 @@ void main() {
float passthrough = max(dot(norm, -cam_to_frag), 0) * 0.75;
float max_light = 0.0;
max_light += get_sun_diffuse2(sun_info, moon_info, norm, /*time_of_day.x*/sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(k_d), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
max_light += get_sun_diffuse2(sun_info, moon_info, cam_norm, /*time_of_day.x*/sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(k_d), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
emitted_light *= not_underground;
reflected_light *= not_underground;

View File

@ -69,7 +69,7 @@ void main() {
#endif
float pull_down = pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0) * 0.7;
f_pos.z -= pull_down;
//f_pos.z -= pull_down;
#ifdef EXPERIMENTAL_CURVEDWORLD
f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2);

View File

@ -570,7 +570,7 @@ vec3 get_sky_light(vec3 dir, float time_of_day, bool with_stars) {
return sky_color * magnetosphere_tint;
}
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_features, float refractionIndex, bool fake_clouds) {
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_features, float refractionIndex, bool fake_clouds, float sun_shade_frac) {
// Sky color
/* vec3 sun_dir = get_sun_dir(time_of_day);
vec3 moon_dir = get_moon_dir(time_of_day); */
@ -595,15 +595,18 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
#else
if (fake_clouds || medium.x == MEDIUM_WATER) {
#endif
sun_halo_power = 50.0;
sun_halo_color *= 0.025;
sun_halo_power = 30.0;
sun_halo_color *= 0.01;
}
vec3 sun_halo = sun_halo_color * 25 * pow(max(dot(dir, -sun_dir), 0), sun_halo_power);
vec3 sun_surf = vec3(0);
if (with_features) {
float angle = 0.00035;
sun_surf = clamp((dot(dir, -sun_dir) - (1.0 - angle)) * 4 / angle, 0, 1) * SUN_SURF_COLOR * SUN_COLOR_FACTOR;
sun_surf = clamp((dot(dir, -sun_dir) - (1.0 - angle)) * 4 / angle, 0, 1)
* SUN_SURF_COLOR
* SUN_COLOR_FACTOR
* sun_shade_frac;
}
#if (CLOUD_MODE == CLOUD_MODE_NONE)
if (true) {
@ -626,8 +629,8 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
#else
if (fake_clouds || medium.x == MEDIUM_WATER) {
#endif
moon_halo_power = 2500.0;
moon_halo_color *= 0.1;
moon_halo_power = 50.0;
moon_halo_color *= 0.02;
}
vec3 moon_halo = moon_halo_color * pow(max(dot(dir, -moon_dir), 0), moon_halo_power);
@ -646,7 +649,7 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
#else
if (fake_clouds || medium.x == MEDIUM_WATER) {
#endif
sky_color = get_sky_light(dir, time_of_day, false);
sky_color = get_sky_light(dir, time_of_day, !fake_clouds);
} else {
if (medium.x == MEDIUM_WATER) {
sky_color = get_sky_light(dir, time_of_day, true);
@ -661,11 +664,11 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
}
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_features, float refractionIndex) {
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_features, refractionIndex, false);
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_features, refractionIndex, false, 1.0);
}
vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float quality, bool with_stars) {
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_stars, 1.0, false);
return get_sky_color(dir, time_of_day, origin, f_pos, quality, with_stars, 1.0, false, 1.0);
}
float fog(vec3 f_pos, vec3 focus_pos, uint medium) {

View File

@ -536,7 +536,7 @@ vec3 compute_attenuation(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, ve
// from the default point.
vec3 compute_attenuation_point(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, vec3 defaultpos) {
#if (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_IMPORTANCE)
return vec3(1.0);
return pow(1.0 - mu, vec3(3));
#elif (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_RADIANCE)
// return vec3(1.0);
/*if (mu == vec3(0.0)) {

View File

@ -658,14 +658,14 @@ void main() {
vec3 reflect_color;
#if (FLUID_MODE == FLUID_MODE_HIGH)
reflect_color = get_sky_color(reflect_ray, time_of_day.x, f_pos, vec3(-100000), 0.125, sun_shade_frac > 0.5);
reflect_color = get_sky_color(reflect_ray, time_of_day.x, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac);
reflect_color = get_cloud_color(reflect_color, reflect_ray, cam_pos.xyz, time_of_day.x, 100000.0, 0.1);
#else
reflect_color = get_sky_color(reflect_ray, time_of_day.x, f_pos, vec3(-100000), 0.125, sun_shade_frac > 0.5, 1.0, true);
reflect_color = get_sky_color(reflect_ray, time_of_day.x, f_pos, vec3(-100000), 0.125, true, 1.0, true, sun_shade_frac);
#endif
reflect_color *= sun_shade_frac * 0.75 + 0.25;
const float REFLECTANCE = 0.5;
const float REFLECTANCE = 1.0;
surf_color = illuminate(max_light, view_dir, f_col * emitted_light, reflect_color * REFLECTANCE + water_color * reflected_light);
const vec3 underwater_col = vec3(0.0);

View File

@ -369,7 +369,11 @@ void main() {
float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0);
// To account for prior saturation
/*float */f_light = faces_fluid ? not_underground : f_light * sqrt(f_light);
#if (FLUID_MODE == FLUID_MODE_CHEAP)
f_light = f_light * sqrt(f_light);
#else
f_light = faces_fluid ? not_underground : f_light * sqrt(f_light);
#endif
vec3 emitted_light = vec3(1.0);
vec3 reflected_light = vec3(1.0);