From e6f0a5a981a82533ba188fff0a54ce98577bb152 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Fri, 24 Apr 2020 16:12:20 +0200 Subject: [PATCH] Add atmospheric scattering. --- assets/voxygen/shaders/figure-frag.glsl | 4 +- assets/voxygen/shaders/figure-vert.glsl | 2 +- assets/voxygen/shaders/fluid-frag/cheap.glsl | 4 +- assets/voxygen/shaders/fluid-frag/shiny.glsl | 10 ++-- assets/voxygen/shaders/include/light.glsl | 21 +++++--- assets/voxygen/shaders/include/lod.glsl | 51 +++++++++++++++----- assets/voxygen/shaders/include/sky.glsl | 31 +++++++++--- assets/voxygen/shaders/include/srgb.glsl | 10 ++-- assets/voxygen/shaders/lod-terrain-frag.glsl | 4 +- assets/voxygen/shaders/lod-terrain-vert.glsl | 2 +- assets/voxygen/shaders/sprite-frag.glsl | 4 +- assets/voxygen/shaders/terrain-frag.glsl | 4 +- assets/voxygen/shaders/terrain-vert.glsl | 2 +- 13 files changed, 99 insertions(+), 50 deletions(-) diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 0fbeac444f..ace255e3d5 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -63,11 +63,11 @@ void main() { vec3 emitted_light, reflected_light; float point_shadow = shadow_at(f_pos, f_norm); - vec3 light_frac = /*vec3(1.0);*//*vec3(max(dot(f_norm, -sun_dir) * 0.5 + 0.5, 0.0));*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); + // vec3 light_frac = /*vec3(1.0);*//*vec3(max(dot(f_norm, -sun_dir) * 0.5 + 0.5, 0.0));*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); // vec3 point_light = light_at(f_pos, f_norm); // 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); - get_sun_diffuse2(f_norm, sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light); + get_sun_diffuse2(f_norm, sun_dir, moon_dir, 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; diff --git a/assets/voxygen/shaders/figure-vert.glsl b/assets/voxygen/shaders/figure-vert.glsl index 4d84d7df8e..29ebec2b99 100644 --- a/assets/voxygen/shaders/figure-vert.glsl +++ b/assets/voxygen/shaders/figure-vert.glsl @@ -47,7 +47,7 @@ void main() { // Also precalculate shadow texture and estimated terrain altitude. f_alt = alt_at(f_pos.xy); - f_shadow = textureBicubic(t_horizon, pos_to_uv(f_pos.xy)); + f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy)); gl_Position = all_mat * vec4(f_pos, 1); gl_Position.z = -1000.0 / (gl_Position.z + 10000.0); diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index 677b208ea7..410c8abab8 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -62,10 +62,10 @@ void main() { // vec3 light, diffuse_light, ambient_light; float point_shadow = shadow_at(f_pos,f_norm); // float vert_light = f_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); + // 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); // vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0)); - get_sun_diffuse2(f_norm, /*time_of_day.x*/sun_dir, moon_dir, /*-cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), k_s, alpha, emitted_light, reflected_light); + get_sun_diffuse2(f_norm, /*time_of_day.x*/sun_dir, moon_dir, /*-cam_to_frag*/view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(0.0), k_s, alpha, emitted_light, reflected_light); reflected_light *= f_light * point_shadow * shade_frac; emitted_light *= f_light * point_shadow; // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0); diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index a46976bced..c4f2f300ee 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -114,7 +114,7 @@ void main() { float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir); float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac; - const float alpha = 0.255 / 4.0/* / 4.0 / sqrt(2.0)*/; + const float alpha = 0.255/*/ / 4.0*//* / 4.0 / sqrt(2.0)*/; const float n2 = 1.3325; const float R_s = pow((1.0 - n2) / (1.0 + n2), 2); @@ -125,11 +125,11 @@ void main() { vec3 emitted_light, reflected_light; // vec3 light, diffuse_light, ambient_light; float point_shadow = shadow_at(f_pos, f_norm); - 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); + // 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(f_norm, f_norm, cam_to_frag/*view_dir*/), -cam_to_frag/*view_dir*/), 0.5); - get_sun_diffuse2(norm, /*time_of_day.x*/sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, emitted_light, reflected_light); + get_sun_diffuse2(norm, /*time_of_day.x*/sun_dir, moon_dir, view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(0.0), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, emitted_light, reflected_light); reflected_light *= reflect_color * f_light * point_shadow * shade_frac; emitted_light *= f_light * point_shadow; @@ -142,7 +142,7 @@ void main() { diffuse_light_point -= specular_light_point; float reflected_light_point = length(diffuse_light_point/*.r*/) + f_light * point_shadow; - reflected_light += water_color * k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + reflect_color * specular_light_point; + reflected_light += reflect_color * k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + reflect_color * specular_light_point; /* vec3 point_light = light_at(f_pos, norm); emitted_light += point_light; reflected_light += point_light; */ @@ -155,7 +155,7 @@ void main() { // diffuse_light += point_light; // reflected_light += point_light; // vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light; - vec3 surf_color = illuminate(/*water_color * */emitted_light, reflected_light); + vec3 surf_color = illuminate(water_color * emitted_light, reflected_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec4 clouds; diff --git a/assets/voxygen/shaders/include/light.glsl b/assets/voxygen/shaders/include/light.glsl index a5421654fc..39f3f16801 100644 --- a/assets/voxygen/shaders/include/light.glsl +++ b/assets/voxygen/shaders/include/light.glsl @@ -20,7 +20,9 @@ uniform u_shadows { }; float attenuation_strength(vec3 rpos) { - return 1.0 / pow(rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z, 0.6); + // Idea: we start off with attenuation strength equal to 1 at the source of the point light. + // return 1.0 / (1.0 + /*pow*/(rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z/*, 0.6*/)); + return 1.0 / (/*pow*/(rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z/*, 0.6*/)); } vec3 light_at(vec3 wpos, vec3 wnorm) { @@ -87,11 +89,15 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 cam_to_frag, vec3 k_a, vec3 k_d, vec // Pre-calculate difference between light and fragment vec3 difference = light_pos - wpos; + float distance_2 = dot(difference, difference); - float strength = pow(attenuation_strength(difference), 0.6); + // float strength = attenuation_strength(difference);// pow(attenuation_strength(difference), 0.6); + // // NOTE: This normalizes strength to 1.0 at the center of the point source. + // float strength = 1.0 / (1.0 + distance_2); + float strength = 1.0 / distance_2; // Multiply the vec3 only once - vec3 color = /*srgb_to_linear*/(L.light_col.rgb) * (strength * L.light_col.a); + vec3 color = /*srgb_to_linear*/(L.light_col.rgb) * (13.0 * strength * L.light_col.a * L.light_col.a/* * L.light_col.a*/); // // Only access the array once // Shadow S = shadows[i]; @@ -109,19 +115,20 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 cam_to_frag, vec3 k_a, vec3 k_d, vec // shadow = min(shadow, shade); // Compute reflectance. - vec3 light_dir = normalize(-difference); - reflected_light += color * light_reflection_factor(wnorm, cam_to_frag, light_dir, k_d, k_s, alpha); + vec3 light_dir = -difference / sqrt(distance_2); // normalize(-difference); + // light_dir = faceforward(light_dir, wnorm, light_dir); + reflected_light += color * (strength == 0.0 ? vec3(1.0) : light_reflection_factor(wnorm, cam_to_frag, light_dir, k_d, k_s, alpha)); // light += color * (max(0, max(dot(normalize(difference), wnorm), 0.15)) + LIGHT_AMBIENCE); // Compute emiittance. // float ambient_sides = clamp(mix(0.15, 0.0, abs(dot(wnorm, light_dir)) * 10000.0), 0.0, 0.15); - float ambient_sides = max(dot(wnorm, light_dir) - 0.15, 0.15); + float ambient_sides = 0.0;// max(dot(wnorm, light_dir) - 0.15, 0.15); // float ambient_sides = 0.0; ambient_light += color * (ambient_sides + LIGHT_AMBIENCE); } // shadow = shadow_at(wpos, wnorm); // float shadow = shadow_at(wpos, wnorm); - emitted_light += k_a * ambient_light/* * shadow*/;// min(shadow, 1.0); + // emitted_light += k_a * ambient_light/* * shadow*/;// min(shadow, 1.0); return 1.0;//ambient_light; } diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index f698890d44..fd8be54b35 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -5,11 +5,19 @@ uniform sampler2D t_map; uniform sampler2D t_horizon; -vec2 pos_to_uv(vec2 pos) { - vec2 uv_pos = (pos + 16) / 32768.0; +vec2 pos_to_uv(sampler2D sampler, vec2 pos) { + // Want: (pixel + 0.5) / W + vec2 texSize = textureSize(sampler, 0); + vec2 uv_pos = (pos + 16) / (32.0 * texSize); return vec2(uv_pos.x, 1.0 - uv_pos.y); } +vec2 pos_to_tex(vec2 pos) { + // Want: (pixel + 0.5) + vec2 uv_pos = (pos + 16) / 32.0; + return vec2(uv_pos.x, uv_pos.y); +} + // textureBicubic from https://stackoverflow.com/a/42179924 vec4 cubic(float v) { vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v; @@ -21,11 +29,12 @@ vec4 cubic(float v) { return vec4(x, y, z, w) * (1.0/6.0); } +// NOTE: We assume the sampled coordinates are already in "texture pixels". vec4 textureBicubic(sampler2D sampler, vec2 texCoords) { vec2 texSize = textureSize(sampler, 0); vec2 invTexSize = 1.0 / texSize; - texCoords = texCoords * texSize - 0.5; + texCoords = texCoords/* * texSize */ - 0.5; vec2 fxy = fract(texCoords); @@ -35,16 +44,23 @@ vec4 textureBicubic(sampler2D sampler, vec2 texCoords) { vec4 ycubic = cubic(fxy.y); vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy; + // vec4 c = texCoords.xxyy + vec2 (-1, +1).xyxy; vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw); vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s; offset *= invTexSize.xxyy; + // Correct for map rotaton. + offset.zw = 1.0 - offset.zw; vec4 sample0 = texture(sampler, offset.xz); vec4 sample1 = texture(sampler, offset.yz); vec4 sample2 = texture(sampler, offset.xw); vec4 sample3 = texture(sampler, offset.yw); + // vec4 sample0 = texelFetch(sampler, offset.xz, 0); + // vec4 sample1 = texelFetch(sampler, offset.yz, 0); + // vec4 sample2 = texelFetch(sampler, offset.xw, 0); + // vec4 sample3 = texelFetch(sampler, offset.yw, 0); float sx = s.x / (s.x + s.y); float sy = s.z / (s.z + s.w); @@ -55,15 +71,26 @@ vec4 textureBicubic(sampler2D sampler, vec2 texCoords) { } float alt_at(vec2 pos) { - return texture/*textureBicubic*/(t_map, pos_to_uv(pos)).a * (/*1300.0*//*1278.7266845703125*/view_distance.w) + /*140.0*/view_distance.z; + return texture/*textureBicubic*/(t_map, pos_to_uv(t_map, pos)).a * (/*1300.0*//*1278.7266845703125*/view_distance.w) + /*140.0*/view_distance.z; //+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0; - return 0.0 - + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0 - + texture(t_noise, pos * 0.001).x * 100.0 - + texture(t_noise, pos * 0.003).x * 30.0; + // return 0.0 + // + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0 + // + texture(t_noise, pos * 0.001).x * 100.0 + // + texture(t_noise, pos * 0.003).x * 30.0; } +float alt_at_real(vec2 pos) { + return textureBicubic(t_map, pos_to_tex(pos)).a * (/*1300.0*//*1278.7266845703125*/view_distance.w) + /*140.0*/view_distance.z; + //+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0; + + // return 0.0 + // + pow(texture(t_noise, pos * 0.00005).x * 1.4, 3.0) * 1000.0 + // + texture(t_noise, pos * 0.001).x * 100.0 + // + texture(t_noise, pos * 0.003).x * 30.0; +} + + float horizon_at2(vec4 f_horizons, float alt, vec3 pos, /*float time_of_day*/vec3 light_dir) { // vec3 sun_dir = get_sun_dir(time_of_day); const float PI_2 = 3.1415926535897932384626433832795 / 2.0; @@ -154,9 +181,9 @@ float horizon_at2(vec4 f_horizons, float alt, vec3 pos, /*float time_of_day*/vec } float horizon_at(vec3 pos, /*float time_of_day*/vec3 light_dir) { - vec4 f_horizons = textureBicubic(t_horizon, pos_to_uv(pos.xy)); + vec4 f_horizons = textureBicubic(t_horizon, pos_to_tex(pos.xy)); f_horizons.xyz = /*linear_to_srgb*/(f_horizons.xyz); - float alt = alt_at(pos.xy); + float alt = alt_at_real(pos.xy); return horizon_at2(f_horizons, alt, pos, light_dir); } @@ -190,11 +217,11 @@ vec3 lod_pos(vec2 v_pos, vec2 focus_pos) { } hpos = hpos + normalize(nhpos - hpos + 0.001) * min(length(nhpos - hpos), 32); - return vec3(hpos, alt_at(hpos)); + return vec3(hpos, alt_at_real(hpos)); } vec3 lod_col(vec2 pos) { //return vec3(0, 0.5, 0); - return /*linear_to_srgb*/(textureBicubic(t_map, pos_to_uv(pos)).rgb); + return /*linear_to_srgb*/(textureBicubic(t_map, pos_to_tex(pos)).rgb); //+ (texture(t_noise, pos * 0.04 + texture(t_noise, pos * 0.005).xy * 2.0 + texture(t_noise, pos * 0.06).xy * 0.6).x - 0.5) * 0.1; } diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index da3995fec7..ac92f1cff4 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -7,7 +7,7 @@ const float PI = 3.141592; const vec3 SKY_DAY_TOP = vec3(0.1, 0.2, 0.9); const vec3 SKY_DAY_MID = vec3(0.02, 0.08, 0.8); const vec3 SKY_DAY_BOT = vec3(0.1, 0.2, 0.3); -const vec3 DAY_LIGHT = vec3(1.2, 1.0, 1.0) * 3.0; +const vec3 DAY_LIGHT = vec3(1.2, 1.0, 1.0) * 1.8;//3.0; const vec3 SUN_HALO_DAY = vec3(0.35, 0.35, 0.0); const vec3 SKY_DUSK_TOP = vec3(0.06, 0.1, 0.20); @@ -75,7 +75,7 @@ vec3 get_moon_color(vec3 moon_dir) { // anything interesting here. // void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diffuse_light, out vec3 ambient_light, float diffusion void get_sun_diffuse(vec3 norm, float time_of_day, vec3 dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, out vec3 emitted_light, out vec3 reflected_light) { - const float SUN_AMBIANCE = 0.1 / 3.0; + const float SUN_AMBIANCE = 0.1 / 2.0;// 0.1 / 3.0; vec3 sun_dir = get_sun_dir(time_of_day); vec3 moon_dir = get_moon_dir(time_of_day); @@ -114,8 +114,8 @@ void get_sun_diffuse(vec3 norm, float time_of_day, vec3 dir, vec3 k_a, vec3 k_d, // Returns computed maximum intensity. float get_sun_diffuse2(vec3 norm, vec3 sun_dir, vec3 moon_dir, vec3 dir, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, out vec3 emitted_light, out vec3 reflected_light) { - const float SUN_AMBIANCE = 0.1 / 3.0; - const float MOON_AMBIANCE = 0.1; + const float SUN_AMBIANCE = 0.23 / 1.8;// 0.1 / 3.0; + const float MOON_AMBIANCE = 0.23;//0.1; float sun_light = get_sun_brightness(sun_dir); float moon_light = get_moon_brightness(moon_dir); @@ -126,6 +126,18 @@ float get_sun_diffuse2(vec3 norm, vec3 sun_dir, vec3 moon_dir, vec3 dir, vec3 k_ vec3 sun_chroma = sun_color * sun_light; vec3 moon_chroma = moon_color * moon_light; + // https://en.m.wikipedia.org/wiki/Diffuse_sky_radiation + // + // HdRd radiation should come in at angle normal to us. + // const float H_d = 0.23; + // Assuming we are on the equator: + // R_b = (cos(h)cos(-β) / cos(h)) = cos(-β), the angle from horizontal. + // NOTE: cos(-β) = cos(β). + float cos_sun = dot(norm, -sun_dir); + float cos_moon = dot(norm, -moon_dir); + vec3 light_frac = /*vec3(1.0)*//*H_d * */ + SUN_AMBIANCE * /*sun_light*/sun_chroma * light_reflection_factor(norm, dir, /*vec3(0, 0, -1.0)*/-norm, vec3((1.0 + cos_sun) * 0.5), vec3(k_s * (1.0 - cos_sun) * 0.5), alpha) + + MOON_AMBIANCE * /*sun_light*/moon_chroma * light_reflection_factor(norm, dir, /*vec3(0, 0, -1.0)*/-norm, vec3((1.0 + cos_moon) * 0.5), vec3(k_s * (1.0 - cos_moon) * 0.5), alpha); /* float NLsun = max(dot(-norm, sun_dir), 0); float NLmoon = max(dot(-norm, moon_dir), 0); vec3 E = -dir; */ @@ -137,12 +149,15 @@ float get_sun_diffuse2(vec3 norm, vec3 sun_dir, vec3 moon_dir, vec3 dir, vec3 k_ // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-norm, sun_dir)) * mix(0.0, 1.0, abs(sun_dir.z) * 10000.0) * 10000.0), 0.0, 0.5); // float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-norm, sun_dir)) * mix(0.0, 1.0, abs(sun_dir.z) * 10000.0) * 10000.0), 0.0, 0.5); - emitted_light = k_a * (/*ambient_sides + */SUN_AMBIANCE * /*sun_light*/sun_chroma + /*vec3(moon_light)*/MOON_AMBIANCE * moon_chroma) + PERSISTENT_AMBIANCE; + + emitted_light = k_a * light_frac * (/*ambient_sides + */SUN_AMBIANCE * /*sun_light*/sun_chroma + /*vec3(moon_light)*/MOON_AMBIANCE * moon_chroma) + PERSISTENT_AMBIANCE; // TODO: Add shadows. reflected_light = - sun_chroma * light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha) + - moon_chroma * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha); + (1.0 - SUN_AMBIANCE) * sun_chroma * (light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha) /*+ + light_reflection_factor(norm, dir, normalize(sun_dir + vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha) + + light_reflection_factor(norm, dir, normalize(sun_dir - vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha)*/) + + (1.0 - MOON_AMBIANCE) * moon_chroma * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha); /* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; diffuse_light = @@ -296,7 +311,7 @@ float rel_luminance(vec3 rgb) return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * (diffuse + ambience); } */ vec3 illuminate(/*vec3 max_light, */vec3 emitted, vec3 reflected) { - const float gamma = /*0.5*/1.0;//1.0; + const float gamma = /*0.5*//*1.*0*/1.0;//1.0; /* float light = length(emitted + reflected); float color = srgb_to_linear(emitted + reflected); float avg_col = (color.r + color.g + color.b) / 3.0; diff --git a/assets/voxygen/shaders/include/srgb.glsl b/assets/voxygen/shaders/include/srgb.glsl index ed4215679d..1d679fe14e 100644 --- a/assets/voxygen/shaders/include/srgb.glsl +++ b/assets/voxygen/shaders/include/srgb.glsl @@ -25,6 +25,8 @@ float pow5(float x) { return x2 * x2 * x; } +// Fresnel angle for perfectly specular dialectric materials. + // Schlick approximation vec3 schlick_fresnel(vec3 Rs, float cosTheta) { // auto pow5 = [](Float v) { return (v * v) * (v * v) * v; }; @@ -94,8 +96,8 @@ float BeckmannDistribution_G(vec3 norm, vec3 dir, vec3 light_dir, float alpha) { vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, float alpha) { const float PI = 3.1415926535897932384626433832795; alpha = alpha * sqrt(2.0); - float cos_wi = max(dot(-light_dir, norm), 0.0); - float cos_wo = max(dot(dir, norm), 0.0); + float cos_wi = /*max(*/dot(-light_dir, norm)/*, 0.0)*/; + float cos_wo = /*max(*/dot(dir, norm)/*, 0.0)*/; vec3 diffuse = (28.0 / (23.0 * PI)) * R_d * (1.0 - R_s) * (1.0 - pow5(1.0 - 0.5 * abs(cos_wi))) * @@ -106,7 +108,7 @@ vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, flo (1 - pow5(1 - .5f * AbsCosTheta(wo))); */ // Vector3f wh = wi + wo; vec3 wh = -light_dir + dir; - if (cos_wi == 0.0 || cos_wo == 0.0) { + if (cos_wi <= 0.0 || cos_wo <= 0.0) { return vec3(0.0); } /* if (cos_wi == 0.0 || cos_wo == 0.0) { @@ -120,7 +122,7 @@ vec3 FresnelBlend_f(vec3 norm, vec3 dir, vec3 light_dir, vec3 R_d, vec3 R_s, flo float dot_wi_wh = dot(-light_dir, wh); vec3 specular = BeckmannDistribution_D(dot(wh, norm), alpha) / (4 * abs(dot_wi_wh)) * - max(/*abs*/(cos_wi), /*abs*/(cos_wo)) * + max(abs(cos_wi), abs(cos_wo)) * schlick_fresnel(R_s, dot_wi_wh); // Spectrum specular = distribution->D(wh) / // (4 * AbsDot(wi, wh) * diff --git a/assets/voxygen/shaders/lod-terrain-frag.glsl b/assets/voxygen/shaders/lod-terrain-frag.glsl index 3873f51fa4..6b0abc4c6a 100644 --- a/assets/voxygen/shaders/lod-terrain-frag.glsl +++ b/assets/voxygen/shaders/lod-terrain-frag.glsl @@ -73,11 +73,11 @@ void main() { vec3 emitted_light, reflected_light; // Use f_norm here for better shadows. - vec3 light_frac = light_reflection_factor(f_norm/*l_norm*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(/*1.0*/R_s), alpha); + // vec3 light_frac = light_reflection_factor(f_norm/*l_norm*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(/*1.0*/R_s), alpha); // vec3 light, diffuse_light, ambient_light; // get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, (0.25 * shade_frac + 0.25 * light_frac) * f_col, 0.5 * shade_frac * f_col, 0.5 * shade_frac * /*vec3(1.0)*/f_col, 2.0, emitted_light, reflected_light); - get_sun_diffuse2(f_norm/*l_norm*/, sun_dir, moon_dir, view_dir, 1.0 * (0.5 * light_frac + vec3(0.5 * shade_frac)), vec3(1.0), /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, emitted_light, reflected_light); + get_sun_diffuse2(f_norm/*l_norm*/, sun_dir, moon_dir, view_dir, vec3(1.0)/* * (0.5 * light_frac + vec3(0.5 * shade_frac))*/, vec3(1.0), /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, emitted_light, reflected_light); // emitted_light = vec3(1.0); reflected_light *= shade_frac; // reflected_light = vec3(0.0); diff --git a/assets/voxygen/shaders/lod-terrain-vert.glsl b/assets/voxygen/shaders/lod-terrain-vert.glsl index 3a895e9b05..12306c777d 100644 --- a/assets/voxygen/shaders/lod-terrain-vert.glsl +++ b/assets/voxygen/shaders/lod-terrain-vert.glsl @@ -21,7 +21,7 @@ void main() { // f_norm = lod_norm(f_pos.xy); - // f_shadow = textureBicubic(t_horizon, pos_to_uv(f_pos.xy)); + // f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy)); //f_pos.z -= 1.0 / pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0); diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 177e01bea0..ccd0821bda 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -49,7 +49,7 @@ void main() { float point_shadow = shadow_at(f_pos, f_norm); float vert_light = f_light; - vec3 light_frac = light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); + // vec3 light_frac = light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); /* light_frac += light_reflection_factor(f_norm, view_dir, vec3(1.0, 0, 0.0), vec3(1.0), vec3(1.0), 2.0); light_frac += light_reflection_factor(f_norm, view_dir, vec3(-1.0, 0, 0.0), vec3(1.0), vec3(1.0), 2.0); light_frac += light_reflection_factor(f_norm, view_dir, vec3(0.0, -1.0, 0.0), vec3(1.0), vec3(1.0), 2.0); @@ -61,7 +61,7 @@ void main() { // vec3 point_light = light_at(f_pos, f_norm); // vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)); // vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, /*cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light); + get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, /*cam_to_frag*/view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, emitted_light, reflected_light); reflected_light *= vert_light * point_shadow * shade_frac; emitted_light *= vert_light * point_shadow; // get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 505c24f4c7..8817944b8e 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -59,9 +59,7 @@ void main() { vec3 emitted_light, reflected_light; float point_shadow = shadow_at(f_pos, f_norm); - vec3 light_frac = /*vec3(1.0)*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha); - - max_light += get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light); + max_light += get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, view_dir, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, k_d, k_s, alpha, emitted_light, reflected_light); emitted_light *= f_light * point_shadow; reflected_light *= f_light * point_shadow * shade_frac; diff --git a/assets/voxygen/shaders/terrain-vert.glsl b/assets/voxygen/shaders/terrain-vert.glsl index d79ff62c9e..c210788c03 100644 --- a/assets/voxygen/shaders/terrain-vert.glsl +++ b/assets/voxygen/shaders/terrain-vert.glsl @@ -34,7 +34,7 @@ void main() { // Also precalculate shadow texture and estimated terrain altitude. f_alt = alt_at(f_pos.xy); - f_shadow = textureBicubic(t_horizon, pos_to_uv(f_pos.xy)); + f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy)); gl_Position = all_mat *