mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'zesterer/underwater' into 'master'
Underwater shaders See merge request veloren/veloren!3127
This commit is contained in:
commit
bdb0fc9c16
@ -16,6 +16,9 @@
|
||||
|
||||
#define LIGHTING_DISTRIBUTION LIGHTING_DISTRIBUTION_BECKMANN
|
||||
|
||||
// Must come before includes
|
||||
#define IS_POSTPROCESS
|
||||
|
||||
#include <globals.glsl>
|
||||
// Note: The sampler uniform is declared here because it differs for MSAA
|
||||
#include <anti-aliasing.glsl>
|
||||
@ -67,10 +70,15 @@ 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 = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb, BLOOM_FACTOR);
|
||||
float cloud_blend = 1.0;
|
||||
if (color.a < 1.0) {
|
||||
cloud_blend = 1.0 - color.a;
|
||||
dist = DIST_CAP;
|
||||
}
|
||||
color.rgb = mix(color.rgb, get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0), cloud_blend);
|
||||
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb);
|
||||
#endif
|
||||
|
||||
tgt_color = vec4(color.rgb, 1);
|
||||
|
@ -8,7 +8,11 @@
|
||||
|
||||
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_GLOSSY
|
||||
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#elif (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
|
||||
#endif
|
||||
|
||||
#define LIGHTING_DISTRIBUTION_SCHEME LIGHTING_DISTRIBUTION_SCHEME_MICROFACET
|
||||
|
||||
@ -183,7 +187,6 @@ void main() {
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
//get_sun_diffuse(f_norm, time_of_day.x, view_dir, k_a * point_shadow * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
// reflected_light *= point_shadow * shade_frac;
|
||||
// emitted_light *= point_shadow * max(shade_frac, MIN_SHADOW);
|
||||
// max_light *= point_shadow * shade_frac;
|
||||
@ -191,7 +194,18 @@ void main() {
|
||||
// emitted_light *= point_shadow;
|
||||
// max_light *= point_shadow;
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
vec3 cam_attenuation = vec3(1);
|
||||
float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1));
|
||||
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
|
||||
#if (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
cam_attenuation =
|
||||
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
|
||||
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
|
||||
#endif
|
||||
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
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 ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
|
||||
|
||||
@ -206,7 +220,7 @@ void main() {
|
||||
* glow_light(f_pos)
|
||||
* (max(dot(f_norm, model_glow.xyz / glow_mag) * 0.5 + 0.5, 0.0) + max(1.0 - glow_mag, 0.0));
|
||||
|
||||
emitted_light += glow;
|
||||
emitted_light += glow * cam_attenuation;
|
||||
|
||||
reflected_light *= ao;
|
||||
emitted_light *= ao;
|
||||
|
@ -146,6 +146,7 @@ void main() {
|
||||
// vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0));
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, /*time_of_day.x*//*-cam_to_frag*/sun_view_dir/*view_dir*/, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, /*vec3(0.0)*/k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
emitted_light *= not_underground;
|
||||
reflected_light *= not_underground;
|
||||
|
||||
@ -185,8 +186,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 = max(dot(f_norm, -cam_to_frag), 0);
|
||||
float min_refl = 0.0;
|
||||
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)));
|
||||
|
@ -170,14 +170,20 @@ 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);
|
||||
// Squared to account for prior saturation.
|
||||
float f_light = 1.0;// pow(f_light, 1.5);
|
||||
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/beam_view_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
|
||||
reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, f_pos.xyz, time_of_day.x, 100000.0, 0.1);
|
||||
vec3 ray_dir;
|
||||
if (medium.x == MEDIUM_WATER) {
|
||||
ray_dir = refract(cam_to_frag, -norm, 1.33);
|
||||
} else {
|
||||
ray_dir = reflect_ray_dir;
|
||||
}
|
||||
|
||||
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
|
||||
reflect_color = get_cloud_color(reflect_color, ray_dir, f_pos.xyz, time_of_day.x, 100000.0, 0.2);
|
||||
reflect_color *= f_light;
|
||||
|
||||
// Prevent the sky affecting light when underground
|
||||
@ -254,7 +260,7 @@ void main() {
|
||||
// vec3 light, diffuse_light, ambient_light;
|
||||
// vec3 light_frac = /*vec3(1.0);*/light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha);
|
||||
// 0 = 100% reflection, 1 = translucent water
|
||||
float passthrough = /*pow(*/dot(faceforward(norm, norm, cam_to_frag/*view_dir*/), -cam_to_frag/*view_dir*/)/*, 0.5)*/;
|
||||
float passthrough = max(dot(norm, -cam_to_frag), 0);
|
||||
|
||||
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);
|
||||
@ -324,7 +330,10 @@ void main() {
|
||||
// vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point/* + point_light*//*reflected_light*/))), passthrough);
|
||||
|
||||
// float log_cam = log(min(cam_attenuation.r, min(cam_attenuation.g, cam_attenuation.b)));
|
||||
float min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
|
||||
float min_refl = 0.0;
|
||||
if (medium.x != MEDIUM_WATER) {
|
||||
min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));
|
||||
}
|
||||
vec4 color = vec4(surf_color, (1.0 - passthrough) * 1.0 / (1.0 + min_refl));// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam)));
|
||||
// vec4 color = vec4(surf_color, mix(1.0, 1.0 / (1.0 + /*0.25 * *//*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point)), passthrough));
|
||||
// vec4 color = vec4(surf_color, mix(1.0, length(cam_attenuation), passthrough));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -178,7 +178,6 @@ float atan2(in float y, in float x) {
|
||||
return mix(PI/2.0 - atan(x,y), atan(y,x), s);
|
||||
}
|
||||
|
||||
const float DIST_CAP = 50000;
|
||||
#if (CLOUD_MODE == CLOUD_MODE_ULTRA)
|
||||
const uint QUALITY = 200u;
|
||||
#elif (CLOUD_MODE == CLOUD_MODE_HIGH)
|
||||
@ -229,40 +228,50 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
|
||||
vec3 sun_color = get_sun_color();
|
||||
vec3 moon_color = get_moon_color();
|
||||
|
||||
float cdist = max_dist;
|
||||
float ldist = cdist;
|
||||
// i is an emergency brake
|
||||
float min_dist = clamp(max_dist / 4, 0.25, 24);
|
||||
int i;
|
||||
for (i = 0; cdist > min_dist && i < 250; i ++) {
|
||||
ldist = cdist;
|
||||
cdist = step_to_dist(trunc(dist_to_step(cdist - 0.25, quality)), quality);
|
||||
// Clouds aren't visible underwater
|
||||
#ifdef IS_POSTPROCESS
|
||||
if (medium.x != 1) {
|
||||
#endif
|
||||
float cdist = max_dist;
|
||||
float ldist = cdist;
|
||||
// i is an emergency brake
|
||||
float min_dist = clamp(max_dist / 4, 0.25, 24);
|
||||
int i;
|
||||
for (i = 0; cdist > min_dist && i < 250; i ++) {
|
||||
ldist = cdist;
|
||||
cdist = step_to_dist(trunc(dist_to_step(cdist - 0.25, quality)), quality);
|
||||
|
||||
vec3 emission;
|
||||
float not_underground; // Used to prevent sunlight leaking underground
|
||||
// `sample` is a reserved keyword
|
||||
vec4 sample_ = cloud_at(origin + dir * ldist * splay, ldist, emission, not_underground);
|
||||
vec3 emission;
|
||||
float not_underground; // Used to prevent sunlight leaking underground
|
||||
// `sample` is a reserved keyword
|
||||
vec4 sample_ = cloud_at(origin + dir * ldist * splay, ldist, emission, not_underground);
|
||||
|
||||
vec2 density_integrals = max(sample_.zw, vec2(0));
|
||||
vec2 density_integrals = max(sample_.zw, vec2(0));
|
||||
|
||||
float sun_access = max(sample_.x, 0);
|
||||
float moon_access = max(sample_.y, 0);
|
||||
float cloud_scatter_factor = density_integrals.x;
|
||||
float global_scatter_factor = density_integrals.y;
|
||||
float sun_access = max(sample_.x, 0);
|
||||
float moon_access = max(sample_.y, 0);
|
||||
float cloud_scatter_factor = density_integrals.x;
|
||||
float global_scatter_factor = density_integrals.y;
|
||||
|
||||
float step = (ldist - cdist) * 0.01;
|
||||
float cloud_darken = pow(1.0 / (1.0 + cloud_scatter_factor), step);
|
||||
float global_darken = pow(1.0 / (1.0 + global_scatter_factor), step);
|
||||
float step = (ldist - cdist) * 0.01;
|
||||
float cloud_darken = pow(1.0 / (1.0 + cloud_scatter_factor), step);
|
||||
float global_darken = pow(1.0 / (1.0 + global_scatter_factor), step);
|
||||
|
||||
surf_color =
|
||||
// Attenuate light passing through the clouds
|
||||
surf_color * cloud_darken * global_darken +
|
||||
// Add the directed light light scattered into the camera by the clouds and the atmosphere (global illumination)
|
||||
sun_color * sun_scatter * get_sun_brightness() * (sun_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) +
|
||||
moon_color * moon_scatter * get_moon_brightness() * (moon_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) +
|
||||
sky_light * (1.0 - global_darken) * not_underground +
|
||||
emission * density_integrals.y * step;
|
||||
}
|
||||
surf_color =
|
||||
// Attenuate light passing through the clouds
|
||||
surf_color * cloud_darken * global_darken +
|
||||
// Add the directed light light scattered into the camera by the clouds and the atmosphere (global illumination)
|
||||
sun_color * sun_scatter * get_sun_brightness() * (sun_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) +
|
||||
moon_color * moon_scatter * get_moon_brightness() * (moon_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) +
|
||||
sky_light * (1.0 - global_darken) * not_underground +
|
||||
emission * density_integrals.y * step;
|
||||
}
|
||||
#ifdef IS_POSTPROCESS
|
||||
}
|
||||
#endif
|
||||
|
||||
// Underwater light attenuation
|
||||
surf_color = water_diffuse(surf_color, dir, max_dist);
|
||||
|
||||
// Apply point glow
|
||||
surf_color = apply_point_glow(origin, dir, max_dist, surf_color);
|
||||
|
@ -44,6 +44,13 @@
|
||||
#define LIGHTING_DISTRIBUTION_BECKMANN 0
|
||||
#define LIGHTING_DISTRIBUTION_TROWBRIDGE 1
|
||||
|
||||
#define MEDIUM_AIR 0
|
||||
#define MEDIUM_WATER 1
|
||||
|
||||
// An arbitrary value that represents a very far distance (at least as far as the player should be able to see) without
|
||||
// being too far that we end up with precision issues (used in clouds and elsewhere).
|
||||
#define DIST_CAP 50000
|
||||
|
||||
/* Constants expected to be defined automatically by configuration: */
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
@ -418,14 +418,6 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve
|
||||
return rel_luminance(emitted_light + reflected_light);//rel_luminance(emitted_light + reflected_light);//sun_chroma + moon_chroma + PERSISTENT_AMBIANCE;
|
||||
}
|
||||
|
||||
float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, vec3 norm, vec3 dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, vec3 voxel_norm, float voxel_lighting, out vec3 emitted_light, out vec3 reflected_light) {
|
||||
return get_sun_diffuse2(sun_info, moon_info, norm, dir, vec3(0.0), vec3(0.0), vec3(1.0), 0.0, k_a, k_d, k_s, alpha, voxel_norm, voxel_lighting, emitted_light, reflected_light);
|
||||
}
|
||||
|
||||
float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, vec3 norm, vec3 dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, out vec3 emitted_light, out vec3 reflected_light) {
|
||||
return get_sun_diffuse2(sun_info, moon_info, norm, dir, vec3(0.0), vec3(0.0), vec3(1.0), 0.0, k_a, k_d, k_s, alpha, norm, 1.0, emitted_light, reflected_light);
|
||||
}
|
||||
|
||||
// This has been extracted into a function to allow quick exit when detecting a star.
|
||||
float is_star_at(vec3 dir) {
|
||||
|
||||
@ -559,9 +551,14 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
|
||||
#if (CLOUD_MODE == CLOUD_MODE_NONE)
|
||||
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;
|
||||
vec3 sky_color;
|
||||
if (medium.x == MEDIUM_WATER) {
|
||||
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);
|
||||
sky_color = vec3(0) + star;
|
||||
}
|
||||
#endif
|
||||
|
||||
return sky_color + sun_light + moon_light;
|
||||
@ -580,7 +577,7 @@ float fog(vec3 f_pos, vec3 focus_pos, uint medium) {
|
||||
// float min_fog = 0.5;
|
||||
// float max_fog = 1.0;
|
||||
|
||||
// if (medium == 1u) {
|
||||
// if (medium == MEDIUM_WATER) {
|
||||
// mist_radius = UNDERWATER_MIST_DIST;
|
||||
// min_fog = 0.0;
|
||||
// }
|
||||
|
@ -492,7 +492,7 @@ vec3 compute_attenuation(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_alt, ve
|
||||
return vec3(1.0);
|
||||
#elif (LIGHTING_TRANSPORT_MODE == LIGHTING_TRANSPORT_MODE_RADIANCE)
|
||||
#if (LIGHTING_TYPE & LIGHTING_TYPE_TRANSMISSION) != 0
|
||||
return vec3(1.0);
|
||||
return vec3(1.0);
|
||||
#else
|
||||
// return vec3(1.0);
|
||||
/*if (mu == vec3(0.0)) {
|
||||
@ -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
|
||||
|
@ -565,12 +565,12 @@ void main() {
|
||||
const float R_s2s1 = pow((1.0 - 1.3325) / (1.0 + 1.3325), 2);
|
||||
const float R_s1s2 = pow((1.3325 - 1.0) / (1.3325 + 1.0), 2);
|
||||
float cam_alt = alt_at(cam_pos.xy);
|
||||
float fluid_alt = medium.x == 1u ? max(cam_alt + 1, floor(shadow_alt)) : view_distance.w;
|
||||
float fluid_alt = medium.x == MEDIUM_WATER ? max(cam_alt + 1, floor(shadow_alt)) : view_distance.w;
|
||||
float R_s = (f_pos.z < my_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||
|
||||
vec3 emitted_light, reflected_light;
|
||||
|
||||
vec3 mu = medium.x == 1u/* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
|
||||
vec3 mu = medium.x == MEDIUM_WATER/* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
|
||||
// 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(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos);
|
||||
// Use f_norm here for better shadows.
|
||||
|
@ -6,7 +6,11 @@
|
||||
|
||||
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_GLOSSY
|
||||
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#elif (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
|
||||
#endif
|
||||
|
||||
#define LIGHTING_DISTRIBUTION_SCHEME LIGHTING_DISTRIBUTION_SCHEME_MICROFACET
|
||||
|
||||
@ -75,9 +79,19 @@ void main() {
|
||||
|
||||
// To account for prior saturation.
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
vec3 cam_attenuation = vec3(1);
|
||||
float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1));
|
||||
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
|
||||
#if (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
cam_attenuation =
|
||||
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
|
||||
: compute_attenuation_point(f_pos, -view_dir, vec3(0), fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
|
||||
#endif
|
||||
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, MU_WATER, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
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);
|
||||
|
||||
// Allow particles to glow at night
|
||||
// TODO: Not this
|
||||
|
@ -191,6 +191,13 @@ void main() {
|
||||
// return;
|
||||
// }
|
||||
|
||||
#ifdef EXPERIMENTAL_UNDERWARPER
|
||||
vec2 uv = uv;
|
||||
if (medium.x == MEDIUM_WATER) {
|
||||
uv += sin(uv.yx * 40 + tick.xx * 1.0) * 0.003;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 aa_color = aa_apply(t_src_color, s_src_color, uv * screen_res.xy, screen_res.xy);
|
||||
|
||||
// Bloom
|
||||
@ -248,7 +255,7 @@ void main() {
|
||||
vec4 final_color = aa_color;
|
||||
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
if (medium.x == 1u) {
|
||||
if (medium.x == MEDIUM_WATER) {
|
||||
final_color *= vec4(0.2, 0.2, 0.8, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
@ -32,9 +32,9 @@ void main() {
|
||||
|
||||
float cam_alt = alt_at(cam_pos.xy);
|
||||
// float f_alt = alt_at(f_pos.xy);
|
||||
float fluid_alt = medium.x == 1u ? floor(cam_alt + 1) : view_distance.w;
|
||||
float fluid_alt = medium.x == MEDIUM_WATER ? floor(cam_alt + 1) : view_distance.w;
|
||||
// float fluid_alt = max(f_pos.z + 1, floor(f_alt));
|
||||
vec3 mu = medium.x == 1u /* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
|
||||
vec3 mu = medium.x == MEDIUM_WATER /* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
|
||||
// vec3 sun_attenuation = compute_attenuation(wpos, -sun_dir, mu, surface_alt, wpos);
|
||||
vec3 cam_attenuation = compute_attenuation(cam_pos.xyz, -cam_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*//*f_pos*//*vec3(f_pos.xy, fluid_alt)*/cam_pos.xyz);
|
||||
// vec3 cam_attenuation = compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, cam_pos.xyz);
|
||||
@ -47,7 +47,7 @@ void main() {
|
||||
|
||||
float dist = 100000.0;
|
||||
|
||||
float refractionIndex = medium.x == 1u ? 1.0 / 1.3325 : 1.0;
|
||||
float refractionIndex = medium.x == MEDIUM_WATER ? 1.0 / 1.3325 : 1.0;
|
||||
/* if (medium.x == 1u) {
|
||||
dist = UNDERWATER_MIST_DIST;
|
||||
} */
|
||||
|
@ -6,7 +6,11 @@
|
||||
|
||||
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_GLOSSY
|
||||
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#elif (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
|
||||
#endif
|
||||
|
||||
#define LIGHTING_DISTRIBUTION_SCHEME LIGHTING_DISTRIBUTION_SCHEME_MICROFACET
|
||||
|
||||
@ -73,19 +77,33 @@ void main() {
|
||||
vec3 k_d = vec3(1.0);
|
||||
vec3 k_s = vec3(R_s);
|
||||
|
||||
vec3 emitted_light, reflected_light;
|
||||
vec3 emitted_light = vec3(1);
|
||||
vec3 reflected_light = vec3(1);
|
||||
|
||||
// Make voxel shadows block the sun and moon
|
||||
sun_info.block = f_inst_light.x;
|
||||
moon_info.block = f_inst_light.x;
|
||||
|
||||
float max_light = 0.0;
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
|
||||
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
|
||||
vec3 cam_attenuation = vec3(1);
|
||||
float fluid_alt = max(f_pos.z + 1, floor(f_alt + 1));
|
||||
vec3 mu = medium.x == MEDIUM_WATER ? MU_WATER : vec3(0.0);
|
||||
#if (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
cam_attenuation =
|
||||
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
|
||||
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
|
||||
#endif
|
||||
|
||||
max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
|
||||
emitted_light *= sun_info.block;
|
||||
reflected_light *= sun_info.block;
|
||||
|
||||
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);
|
||||
|
||||
vec3 glow = pow(f_inst_light.y, 3) * 4 * glow_light(f_pos);
|
||||
emitted_light += glow;
|
||||
emitted_light += glow * cam_attenuation;
|
||||
|
||||
float ao = f_ao;
|
||||
emitted_light *= ao;
|
||||
|
@ -8,9 +8,9 @@
|
||||
#define LIGHTING_REFLECTION_KIND LIGHTING_REFLECTION_KIND_GLOSSY
|
||||
|
||||
#if (FLUID_MODE == FLUID_MODE_CHEAP)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_IMPORTANCE
|
||||
#elif (FLUID_MODE == FLUID_MODE_SHINY)
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
|
||||
#define LIGHTING_TRANSPORT_MODE LIGHTING_TRANSPORT_MODE_RADIANCE
|
||||
#endif
|
||||
|
||||
#define LIGHTING_DISTRIBUTION_SCHEME LIGHTING_DISTRIBUTION_SCHEME_MICROFACET
|
||||
@ -260,12 +260,10 @@ void main() {
|
||||
// Compute attenuation due to water from the camera.
|
||||
vec3 mu = faces_fluid/* && f_pos.z <= fluid_alt*/ ? MU_WATER : vec3(0.0);
|
||||
// NOTE: Default intersection point is camera position, meaning if we fail to intersect we assume the whole camera is in water.
|
||||
vec3 cam_attenuation =
|
||||
medium.x == 1u ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
|
||||
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
|
||||
|
||||
// Computing light attenuation from water.
|
||||
vec3 emitted_light, reflected_light;
|
||||
vec3 cam_attenuation =
|
||||
medium.x == MEDIUM_WATER ? compute_attenuation_point(cam_pos.xyz, view_dir, MU_WATER, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/f_pos)
|
||||
: compute_attenuation_point(f_pos, -view_dir, mu, fluid_alt, /*cam_pos.z <= fluid_alt ? cam_pos.xyz : f_pos*/cam_pos.xyz);
|
||||
|
||||
// Prevent the sky affecting light when underground
|
||||
float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0);
|
||||
@ -273,9 +271,11 @@ void main() {
|
||||
// To account for prior saturation
|
||||
/*float */f_light = faces_fluid ? not_underground : f_light * sqrt(f_light);
|
||||
|
||||
emitted_light = vec3(1.0);
|
||||
reflected_light = vec3(1.0);
|
||||
max_light += get_sun_diffuse2(/*time_of_day.x, */sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
vec3 emitted_light = vec3(1.0);
|
||||
vec3 reflected_light = vec3(1.0);
|
||||
|
||||
float sun_diffuse = get_sun_diffuse2(/*time_of_day.x, */sun_info, moon_info, f_norm, view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light);
|
||||
max_light += sun_diffuse;
|
||||
|
||||
// emitted_light *= f_light * point_shadow * max(shade_frac, MIN_SHADOW);
|
||||
// reflected_light *= f_light * point_shadow * shade_frac;
|
||||
@ -285,11 +285,27 @@ void main() {
|
||||
max_light *= f_light;
|
||||
|
||||
// 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);
|
||||
vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2) * pow(max(dot(face_norm, f_norm), 0), 2);
|
||||
reflected_light += glow * cam_attenuation;
|
||||
|
||||
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 + vec3(focus_off.xy, 0);
|
||||
vec3 spos = (wpos + (fluid_alt - wpos.z) * vec3(sun_dir.xy, 0)) * 0.05;
|
||||
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)
|
||||
* 1000
|
||||
* cam_attenuation
|
||||
* max(dot(f_norm, -sun_dir.xyz), 0)
|
||||
* sun_diffuse
|
||||
* sun_info.shadow
|
||||
* f_light;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 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 {
|
||||
|
@ -427,4 +427,8 @@ pub enum ExperimentalShader {
|
||||
CurvedWorld,
|
||||
/// Adds extra detail to distant LoD (Level of Detail) terrain procedurally.
|
||||
ProceduralLodDetail,
|
||||
/// Add a warping effect when underwater.
|
||||
Underwarper,
|
||||
/// Remove caustics from underwater terrain when shiny water is enabled.
|
||||
NoCaustics,
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl FluidPipeline {
|
||||
},
|
||||
depth_stencil: Some(wgpu::DepthStencilState {
|
||||
format: wgpu::TextureFormat::Depth32Float,
|
||||
depth_write_enabled: false,
|
||||
depth_write_enabled: true,
|
||||
depth_compare: wgpu::CompareFunction::GreaterEqual,
|
||||
stencil: wgpu::StencilState {
|
||||
front: wgpu::StencilFaceState::IGNORE,
|
||||
|
@ -98,7 +98,14 @@ impl SkyboxPipeline {
|
||||
entry_point: "main",
|
||||
targets: &[wgpu::ColorTargetState {
|
||||
format: wgpu::TextureFormat::Rgba16Float,
|
||||
blend: None,
|
||||
blend: Some(wgpu::BlendState {
|
||||
color: wgpu::BlendComponent::REPLACE,
|
||||
alpha: wgpu::BlendComponent {
|
||||
src_factor: wgpu::BlendFactor::Zero,
|
||||
dst_factor: wgpu::BlendFactor::One,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
}),
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user