Merge branch 'zesterer/mini-fixes' into 'master'

Improved water shaders

See merge request veloren/veloren!3636
This commit is contained in:
Joshua Barretto 2022-09-23 00:32:52 +00:00
commit 963d5a84b5
7 changed files with 75 additions and 44 deletions

View File

@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Present mode options renamed for clarity: Fifo -> 'Vsync capped', Mailbox -> 'Vsync uncapped',
Immediate -> 'Vsync off'.
- Item pickup UI now displays items that members of your group pick up.
- Improved shiny water shaders
### Removed

View File

@ -191,7 +191,7 @@ 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);
float passthrough = max(dot(f_norm, -cam_to_frag), 0) * 0.75;
float min_refl = 0.0;
if (medium.x != MEDIUM_WATER) {
min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b));

View File

@ -52,40 +52,35 @@ layout(location = 0) out vec4 tgt_color;
#include <light.glsl>
#include <lod.glsl>
vec3 warp_normal(vec3 norm, vec3 pos, float time) {
return normalize(norm
+ smooth_rand(pos * 1.0, time * 1.0) * 0.05
+ smooth_rand(pos * 0.25, time * 0.25) * 0.1);
vec2 wavedx(vec2 position, vec2 direction, float speed, float frequency, float timeshift) {
float x = dot(direction, position) * frequency + timeshift * speed;
float wave = pow(sin(x) + 0.5, 2);
float dx = wave * cos(x);
return vec2(wave, -dx);
}
float wave_height(vec3 pos) {
float timer = tick.x * 0.75;
pos *= 0.5;
vec3 big_warp = (
texture(sampler2D(t_noise, s_noise), fract(pos.xy * 0.03 + timer * 0.01)).xyz * 0.5 +
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.03 - timer * 0.01)).xyz * 0.5 +
vec3(0)
);
vec3 warp = (
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.1 + timer * 0.02)).xyz * 0.3 +
texture(sampler2D(t_noise, s_noise), fract(pos.yx * 0.1 - timer * 0.02)).xyz * 0.3 +
vec3(0)
);
float height = (
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.03 + big_warp.xy + timer * 0.05).y - 0.5) * 1.0 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.03 + big_warp.yx - timer * 0.05).y - 0.5) * 1.0 +
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.1 + warp.xy + timer * 0.1).x - 0.5) * 0.5 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.1 + warp.yx - timer * 0.1).x - 0.5) * 0.5 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 0.3 + warp.xy * 0.5 + timer * 0.1).x - 0.5) * 0.2 +
(texture(sampler2D(t_noise, s_noise), (pos.xy + pos.z) * 0.3 + warp.yx * 0.5 - timer * 0.1).x - 0.5) * 0.2 +
(texture(sampler2D(t_noise, s_noise), (pos.yx + pos.z) * 1.0 + warp.yx * 0.0 - timer * 0.1).x - 0.5) * 0.05 +
0.0
);
return pow(abs(height), 0.5) * sign(height) * 15.0;
// Based on https://www.shadertoy.com/view/MdXyzX
float wave_height(vec3 pos){
pos *= 0.3;
float iter = 0.0;
float phase = 6.0;
float speed = 2.0;
float weight = 1.0;
float w = 0.0;
float ws = 0.0;
const float drag_factor = 0.048;
for(int i = 0; i < 11; i ++){
vec2 p = vec2(sin(iter), cos(iter));
vec2 res = wavedx(pos.xy, p, speed, phase, tick.x);
pos.xy += p * res.y * weight * drag_factor;
w += res.x * weight;
iter += 10.0;
ws += weight;
weight = mix(weight, 0.0, 0.15);
phase *= 1.18;
speed *= 1.07;
}
return w / ws * 10.0;
}
void main() {
@ -132,7 +127,7 @@ void main() {
}
vec3 c_norm = cross(f_norm, b_norm);
vec3 wave_pos = mod(f_pos + focus_off.xyz, vec3(100.0));
vec3 wave_pos = mod(f_pos + focus_off.xyz, vec3(3000.0));
float wave_sample_dist = 0.025;
float wave00 = wave_height(wave_pos);
float wave10 = wave_height(wave_pos + vec3(wave_sample_dist, 0, 0));
@ -210,7 +205,9 @@ void main() {
if (medium.x == MEDIUM_WATER) {
ray_dir = refract(cam_to_frag, -norm, 1.33);
} else {
ray_dir = reflect_ray_dir;
// Ensure the ray doesn't accidentally point underwater
// TODO: Make this more efficient?
ray_dir = normalize(max(reflect_ray_dir, vec3(-1.0, -1.0, 0.0)));
}
vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
@ -284,14 +281,14 @@ void main() {
vec3 k_a = vec3(1.0);
// Oxygen is light blue.
vec3 k_d = vec3(/*vec3(0.2, 0.9, 0.99)*/1.0);
vec3 k_s = vec3(R_s);//2.0 * reflect_color;
vec3 k_d = vec3(1.0);
vec3 k_s = vec3(0.0);//2.0 * reflect_color;
vec3 emitted_light, reflected_light;
// 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 = max(dot(norm, -cam_to_frag), 0);
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);

View File

@ -282,7 +282,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
moon_color * moon_scatter * get_moon_brightness() * (moon_access * (1.0 - cloud_darken) * cloud_diffuse /*+ sky_color * global_scatter_factor*/) +
sky_light * (1.0 - global_darken) * not_underground +
// A small amount fake ambient light underground
(1.0 - not_underground) * vec3(0.2, 0.35, 0.5) * (1.0 - global_darken) +
(1.0 - not_underground) * vec3(0.2, 0.35, 0.5) * (1.0 - global_darken) / (1.0 + max_dist * 0.003) +
emission * density_integrals.y * step;
// Rainbow

View File

@ -119,4 +119,36 @@ float norm2tri(float n) {
n = flip ? 1.0 - n : n;
return n;
}
// Caustics, ported and modified from https://www.shadertoy.com/view/3tlfR7, originally David Hoskins.
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License: https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode.
// Modifying these three functions mean that you agree to release your changes under the above license, *not* under GPL 3 as with the rest of the project.
float hashvec2(vec2 p) {return fract(sin(p.x * 1e2 + p.y) * 1e5 + sin(p.y * 1e3) * 1e3 + sin(p.x * 735. + p.y * 11.1) * 1.5e2); }
float n12(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f *= f * (3.-2.*f);
return mix(
mix(hashvec2(i+vec2(0.,0.)),hashvec2(i+vec2(1.,0.)),f.x),
mix(hashvec2(i+vec2(0.,1.)),hashvec2(i+vec2(1.,1.)),f.x),
f.y
);
}
float caustics(vec2 p, float t) {
vec3 k = vec3(p,t);
float l;
mat3 m = mat3(-2.,-1.,2.,3.,-2.,1.,1.,2.,2.);
float n = n12(p);
k = k*m*.5;
l = length(.5 - fract(k+n));
k = k*m*.4;
l = min(l, length(.5-fract(k+n)));
k = k*m*.3;
l = min(l, length(.5-fract(k+n)));
return pow(l,3.)*5.5;
}
#endif

View File

@ -226,10 +226,10 @@ vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, flo
} */
wh = normalize(wh);//mix(normalize(wh), vec3(0.0), equal(light_dir, dir));
float dot_wi_wh = dot(-light_dir, wh);
vec3 specular = BeckmannDistribution_D(dot(wh, norm), alpha) /
vec3 specular = dot(norm, dir) > 0.0 ? vec3(0.0) : (BeckmannDistribution_D(dot(wh, norm), alpha) /
(4 * abs(dot_wi_wh) *
max(abs(cos_wi), abs(cos_wo))) *
schlick_fresnel(R_s, dot_wi_wh);
schlick_fresnel(R_s, dot_wi_wh));
// Spectrum specular = distribution->D(wh) /
// (4 * AbsDot(wi, wh) *
// std::max(AbsCosTheta(wi), AbsCosTheta(wo))) *

View File

@ -399,9 +399,10 @@ void main() {
#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
vec3 spos = (wpos + (fluid_alt - wpos.z) * vec3(sun_dir.xy, 0)) * 0.25;
reflected_light += caustics(spos.xy * 1.0, tick.x * 0.5)
* 3
/ (1.0 + pow(abs(fluid_alt - wpos.z) * 0.075, 2))
* cam_attenuation
* max(dot(f_norm, -sun_dir.xyz), 0)
* sun_diffuse