mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Various fixes.
This commit is contained in:
parent
f7b497a0c2
commit
48a643955d
@ -6,8 +6,8 @@ in vec3 f_pos;
|
|||||||
in vec3 f_col;
|
in vec3 f_col;
|
||||||
in float f_ao;
|
in float f_ao;
|
||||||
flat in vec3 f_norm;
|
flat in vec3 f_norm;
|
||||||
in float f_alt;
|
// in float f_alt;
|
||||||
in vec4 f_shadow;
|
// in vec4 f_shadow;
|
||||||
|
|
||||||
layout (std140)
|
layout (std140)
|
||||||
uniform u_locals {
|
uniform u_locals {
|
||||||
@ -45,6 +45,8 @@ void main() {
|
|||||||
// float moon_light = get_moon_brightness(moon_dir);
|
// float moon_light = get_moon_brightness(moon_dir);
|
||||||
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
||||||
|
float f_alt = alt_at(f_pos.xy);
|
||||||
|
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
||||||
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
||||||
@ -58,7 +60,11 @@ void main() {
|
|||||||
vec3 surf_color = /*srgb_to_linear*/(model_col.rgb * f_col);
|
vec3 surf_color = /*srgb_to_linear*/(model_col.rgb * f_col);
|
||||||
float alpha = 1.0;
|
float alpha = 1.0;
|
||||||
const float n2 = 1.01;
|
const float n2 = 1.01;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||||
|
|
||||||
vec3 k_a = vec3(1.0);
|
vec3 k_a = vec3(1.0);
|
||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
|
@ -31,8 +31,8 @@ out vec3 f_pos;
|
|||||||
out vec3 f_col;
|
out vec3 f_col;
|
||||||
out float f_ao;
|
out float f_ao;
|
||||||
flat out vec3 f_norm;
|
flat out vec3 f_norm;
|
||||||
out float f_alt;
|
// out float f_alt;
|
||||||
out vec4 f_shadow;
|
// out vec4 f_shadow;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Pre-calculate bone matrix
|
// Pre-calculate bone matrix
|
||||||
@ -53,8 +53,8 @@ void main() {
|
|||||||
).xyz);
|
).xyz);
|
||||||
|
|
||||||
// Also precalculate shadow texture and estimated terrain altitude.
|
// Also precalculate shadow texture and estimated terrain altitude.
|
||||||
f_alt = alt_at(f_pos.xy);
|
// f_alt = alt_at(f_pos.xy);
|
||||||
f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
// f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
|
|
||||||
gl_Position = all_mat * vec4(f_pos, 1);
|
gl_Position = all_mat * vec4(f_pos, 1);
|
||||||
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
||||||
|
@ -8,6 +8,7 @@ flat in uint f_pos_norm;
|
|||||||
in vec3 f_col;
|
in vec3 f_col;
|
||||||
in float f_light;
|
in float f_light;
|
||||||
|
|
||||||
|
|
||||||
layout (std140)
|
layout (std140)
|
||||||
uniform u_locals {
|
uniform u_locals {
|
||||||
vec3 model_offs;
|
vec3 model_offs;
|
||||||
@ -42,13 +43,21 @@ void main() {
|
|||||||
|
|
||||||
vec3 sun_dir = get_sun_dir(time_of_day.x);
|
vec3 sun_dir = get_sun_dir(time_of_day.x);
|
||||||
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
||||||
float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
float f_alt = alt_at(f_pos.xy);
|
||||||
float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir);
|
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
|
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
||||||
|
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
||||||
|
// float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
||||||
|
// 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;
|
float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac;
|
||||||
|
|
||||||
const float alpha = 0.255/* / 4.0 / sqrt(2.0)*/;
|
const float alpha = 0.255/* / 4.0 / sqrt(2.0)*/;
|
||||||
const float n2 = 1.3325;
|
const float n2 = 1.3325;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||||
|
|
||||||
vec3 k_a = vec3(1.0);
|
vec3 k_a = vec3(1.0);
|
||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
|
@ -112,13 +112,21 @@ void main() {
|
|||||||
|
|
||||||
vec3 sun_dir = get_sun_dir(time_of_day.x);
|
vec3 sun_dir = get_sun_dir(time_of_day.x);
|
||||||
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
||||||
float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
float f_alt = alt_at(f_pos.xy);
|
||||||
float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir);
|
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
|
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
||||||
|
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
||||||
|
// float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
||||||
|
// 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;
|
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 n2 = 1.3325;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||||
|
|
||||||
vec3 k_a = vec3(1.0);
|
vec3 k_a = vec3(1.0);
|
||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
@ -143,7 +151,7 @@ void main() {
|
|||||||
lights_at(f_pos, norm, view_dir, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point);
|
lights_at(f_pos, norm, view_dir, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point);
|
||||||
diffuse_light_point -= specular_light_point;
|
diffuse_light_point -= specular_light_point;
|
||||||
|
|
||||||
float reflected_light_point = length(diffuse_light_point/*.r*/) + f_light * point_shadow;
|
float reflected_light_point = /*length*/(diffuse_light_point.r) + f_light * point_shadow;
|
||||||
reflected_light += reflect_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);
|
/* vec3 point_light = light_at(f_pos, norm);
|
||||||
emitted_light += point_light;
|
emitted_light += point_light;
|
||||||
|
@ -14,7 +14,6 @@ uniform u_locals {
|
|||||||
|
|
||||||
out vec3 f_pos;
|
out vec3 f_pos;
|
||||||
flat out uint f_pos_norm;
|
flat out uint f_pos_norm;
|
||||||
flat out vec3 f_norm;
|
|
||||||
out vec3 f_col;
|
out vec3 f_col;
|
||||||
out float f_light;
|
out float f_light;
|
||||||
|
|
||||||
|
@ -194,17 +194,23 @@ vec2 splay(vec2 pos) {
|
|||||||
vec3 lod_norm(vec2 pos) {
|
vec3 lod_norm(vec2 pos) {
|
||||||
const float SAMPLE_W = 32;
|
const float SAMPLE_W = 32;
|
||||||
|
|
||||||
float altx0 = alt_at(pos + vec2(-1, 0) * SAMPLE_W);
|
float altx0 = alt_at(pos + vec2(-1.0, 0) * SAMPLE_W);
|
||||||
float altx1 = alt_at(pos + vec2(1, 0) * SAMPLE_W);
|
float altx1 = alt_at(pos + vec2(1.0, 0) * SAMPLE_W);
|
||||||
float alty0 = alt_at(pos + vec2(0, -1) * SAMPLE_W);
|
float alty0 = alt_at(pos + vec2(0, -1.0) * SAMPLE_W);
|
||||||
float alty1 = alt_at(pos + vec2(0, 1) * SAMPLE_W);
|
float alty1 = alt_at(pos + vec2(0, 1.0) * SAMPLE_W);
|
||||||
float slope = abs(altx1 - altx0) + abs(alty0 - alty1);
|
float slope = abs(altx1 - altx0) + abs(alty0 - alty1);
|
||||||
|
|
||||||
return normalize(vec3(
|
vec3 norm = normalize(cross(
|
||||||
(altx0 - altx1) / SAMPLE_W,
|
vec3(2.0 * SAMPLE_W, 0.0, altx1 - altx0),
|
||||||
(alty0 - alty1) / SAMPLE_W,
|
vec3(0.0, 2.0 * SAMPLE_W, alty1 - alty0)
|
||||||
SAMPLE_W / (slope + 0.00001) // Avoid NaN
|
|
||||||
));
|
));
|
||||||
|
/* vec3 norm = normalize(vec3(
|
||||||
|
(altx0 - altx1) / (2.0 * SAMPLE_W),
|
||||||
|
(alty0 - alty1) / (2.0 * SAMPLE_W),
|
||||||
|
(2.0 * SAMPLE_W) / (slope + 0.00001) // Avoid NaN
|
||||||
|
)); */
|
||||||
|
|
||||||
|
return faceforward(norm, vec3(0.0, 0.0, -1.0), norm);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 lod_pos(vec2 v_pos, vec2 focus_pos) {
|
vec3 lod_pos(vec2 v_pos, vec2 focus_pos) {
|
||||||
|
@ -27,6 +27,7 @@ vec3 get_sun_dir(float time_of_day) {
|
|||||||
const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0);
|
const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0);
|
||||||
|
|
||||||
float sun_angle_rad = time_of_day * TIME_FACTOR;
|
float sun_angle_rad = time_of_day * TIME_FACTOR;
|
||||||
|
// return vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad));
|
||||||
return vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad));
|
return vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +35,13 @@ vec3 get_moon_dir(float time_of_day) {
|
|||||||
const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0);
|
const float TIME_FACTOR = (PI * 2.0) / (3600.0 * 24.0);
|
||||||
|
|
||||||
float moon_angle_rad = time_of_day * TIME_FACTOR;
|
float moon_angle_rad = time_of_day * TIME_FACTOR;
|
||||||
|
// -cos((60+60*4)/360*2*pi)-0.5 = 0
|
||||||
|
// -cos((60+60*5)/360*2*pi)-0.5 = -0.5
|
||||||
|
// -cos((60+60*6)/360*2*pi)-0.5 = 0
|
||||||
|
//
|
||||||
|
// i.e. moon out from (60*5)/360*24 = 20:00 to (60*7/360*24) = 28:00 = 04:00.
|
||||||
|
//
|
||||||
|
// Then sun out from 04:00 to 20:00.
|
||||||
return normalize(-vec3(sin(moon_angle_rad), 0.0, cos(moon_angle_rad) - 0.5));
|
return normalize(-vec3(sin(moon_angle_rad), 0.0, cos(moon_angle_rad) - 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,14 +138,93 @@ float get_sun_diffuse2(vec3 norm, vec3 sun_dir, vec3 moon_dir, vec3 dir, vec3 k_
|
|||||||
//
|
//
|
||||||
// HdRd radiation should come in at angle normal to us.
|
// HdRd radiation should come in at angle normal to us.
|
||||||
// const float H_d = 0.23;
|
// const float H_d = 0.23;
|
||||||
// Assuming we are on the equator:
|
//
|
||||||
// R_b = (cos(h)cos(-β) / cos(h)) = cos(-β), the angle from horizontal.
|
// Let β be the angle from horizontal
|
||||||
|
// (for objects exposed to the sky, where positive when sloping towards south and negative when sloping towards north):
|
||||||
|
//
|
||||||
|
// sin β = (north ⋅ norm) / |north||norm|
|
||||||
|
// = dot(vec3(0, 1, 0), norm)
|
||||||
|
//
|
||||||
|
// cos β = sqrt(1.0 - dot(vec3(0, 1, 0), norm))
|
||||||
|
//
|
||||||
|
// Let h be the hour angle (180/0.0 at midnight, 90/1.0 at dawn, 0/0.0 at noon, -90/-1.0 at dusk, -180 at midnight/0.0):
|
||||||
|
// cos h = (midnight ⋅ -light_dir) / |midnight||-light_dir|
|
||||||
|
// = (noon ⋅ light_dir) / |noon||light_dir|
|
||||||
|
// = dot(vec3(0, 0, 1), light_dir)
|
||||||
|
//
|
||||||
|
// Let φ be the latitude at this point. 0 at equator, -90 at south pole / 90 at north pole.
|
||||||
|
//
|
||||||
|
// Let δ be the solar declination (angular distance of the sun's rays north [or south[]
|
||||||
|
// of the equator), i.e. the angle made by the line joining the centers of the sun and Earth with its projection on the
|
||||||
|
// equatorial plane. Caused by axial tilt, and 0 at equinoxes. Normally varies between -23.45 and 23.45 degrees.
|
||||||
|
//
|
||||||
|
// Let α (the solar altitude / altitud3 angle) be the vertical angle between the projection of the sun's rays on the
|
||||||
|
// horizontal plane and the direction of the sun's rays (passing through a point).
|
||||||
|
//
|
||||||
|
// Let Θ_z be the vertical angle between sun's rays and a line perpendicular to the horizontal plane through a point,
|
||||||
|
// i.e.
|
||||||
|
//
|
||||||
|
// Θ_z = (π/2) - α
|
||||||
|
//
|
||||||
|
// i.e. cos Θ_z = sin α and
|
||||||
|
// cos α = sin Θ_z
|
||||||
|
//
|
||||||
|
// Let γ_s be the horizontal angle measured from north to the horizontal projection of the sun's rays (positive when
|
||||||
|
// measured westwise).
|
||||||
|
//
|
||||||
|
// cos Θ_z = cos φ cos h cos δ + sin φ sin δ
|
||||||
|
// cos γ_s = sec α (cos φ sin δ - cos δ sin φ cos h)
|
||||||
|
// = (1 / √(1 - cos² Θ_z)) (cos φ sin δ - cos δ sin φ cos h)
|
||||||
|
// sin γ_s = sec α cos δ sin h
|
||||||
|
// = (1 / cos α) cos δ sin h
|
||||||
|
// = (1 / sin Θ_z) cos δ sin h
|
||||||
|
// = (1 / √(1 - cos² Θ_z)) cos δ sin h
|
||||||
|
//
|
||||||
|
// R_b = (sin(δ)sin(φ - β) + cos(δ)cos(h)cos(φ - β))/(sin(δ)sin(φ) + cos(δ)cos(h)cos(φ))
|
||||||
|
//
|
||||||
|
// Assuming we are on the equator (i.e. φ = 0), and there is no axial tilt or we are at an equinox (i.e. δ = 0):
|
||||||
|
//
|
||||||
|
// cos Θ_z = 1 * cos h * 1 + 0 * 0 = cos h
|
||||||
|
// cos γ_s = (1 / √(1 - cos² h)) (1 * 0 - 1 * 0 * cos h)
|
||||||
|
// = (1 / √(1 - cos² h)) * 0
|
||||||
|
// = 0
|
||||||
|
// sin γ_s = (1 / √(1 - cos² h)) * sin h
|
||||||
|
// = sin h / sin h
|
||||||
|
// = 1
|
||||||
|
//
|
||||||
|
// R_b = (0 * sin(0 - β) + 1 * cos(h) * cos(0 - β))/(0 * 0 + 1 * cos(h) * 1)
|
||||||
|
// = (cos(h)cos(-β)) / cos(H)
|
||||||
|
// = cos(-β), the angle from horizontal.
|
||||||
|
//
|
||||||
// NOTE: cos(-β) = cos(β).
|
// NOTE: cos(-β) = cos(β).
|
||||||
float cos_sun = dot(norm, -sun_dir);
|
// float cos_sun = dot(norm, /*-sun_dir*/vec3(0, 0, 1));
|
||||||
float cos_moon = dot(norm, -moon_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) +
|
// Let ζ = diffuse reflectance of surrounding ground for solar radiation, then we have
|
||||||
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);
|
//
|
||||||
|
// R_d = (1 + cos β) / 2
|
||||||
|
// R_r = ζ (1 - cos β) / 2
|
||||||
|
//
|
||||||
|
// H_t = H_b R_b + H_d R_d + (H_b + H_d) R_r
|
||||||
|
float sin_beta = dot(vec3(0, 1, 0), norm);
|
||||||
|
float R_b = sqrt(1.0 - sin_beta * sin_beta);
|
||||||
|
// Rough estimate of diffuse reflectance of rest of ground.
|
||||||
|
// NOTE: zeta should be close to 0.7 with snow cover, 0.2 normally? Maybe?
|
||||||
|
vec3 zeta = max(vec3(0.2), k_d * (1.0 - k_s));//vec3(0.2);// k_d * (1.0 - k_s);
|
||||||
|
float R_d = (1 + R_b) * 0.5;
|
||||||
|
vec3 R_r = zeta * (1.0 - R_b) * 0.5;
|
||||||
|
//
|
||||||
|
// We can break this down into:
|
||||||
|
// H_t_b = H_b * (R_b + R_r) = light_intensity * (R_b + R_r)
|
||||||
|
// H_t_r = H_d * (R_d + R_r) = light_intensity * (R_d + R_r)
|
||||||
|
vec3 R_t_b = R_b + R_r;
|
||||||
|
vec3 R_t_r = R_d + R_r;
|
||||||
|
|
||||||
|
// vec3 half_vec = normalize(-norm + dir);
|
||||||
|
vec3 light_frac = R_t_b * (sun_chroma * SUN_AMBIANCE + moon_chroma * MOON_AMBIANCE) * light_reflection_factor(norm, norm, /*-norm*/-norm, /*k_d*/k_d * (1.0 - k_s), /*k_s*/vec3(0.0), alpha);
|
||||||
|
// 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 NLsun = max(dot(-norm, sun_dir), 0);
|
||||||
float NLmoon = max(dot(-norm, moon_dir), 0);
|
float NLmoon = max(dot(-norm, moon_dir), 0);
|
||||||
vec3 E = -dir; */
|
vec3 E = -dir; */
|
||||||
@ -149,15 +236,16 @@ 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);
|
||||||
// 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 * light_frac + 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;
|
// 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.
|
// TODO: Add shadows.
|
||||||
reflected_light =
|
reflected_light = R_t_r * (
|
||||||
(1.0 - SUN_AMBIANCE) * sun_chroma * (light_reflection_factor(norm, dir, sun_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) +
|
||||||
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);
|
(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;
|
/* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE;
|
||||||
diffuse_light =
|
diffuse_light =
|
||||||
@ -322,16 +410,17 @@ vec3 illuminate(/*vec3 max_light, */vec3 emitted, vec3 reflected) {
|
|||||||
|
|
||||||
// Tone mapped value.
|
// Tone mapped value.
|
||||||
// vec3 T = /*color*//*lum*/color;//normalize(color) * lum / (1.0 + lum);
|
// vec3 T = /*color*//*lum*/color;//normalize(color) * lum / (1.0 + lum);
|
||||||
float alpha = 2.0;// 2.0;
|
float alpha = 2.0;
|
||||||
float T = 1.0 - exp(-alpha * lum);//lum / (1.0 + lum);
|
float T = 1.0 - exp(-alpha * lum);//lum / (1.0 + lum);
|
||||||
// float T = lum;
|
// float T = lum;
|
||||||
|
|
||||||
// Heuristic desaturation
|
// Heuristic desaturation
|
||||||
// float s = 0.5;
|
const float s = 0.8;
|
||||||
vec3 col_adjusted = (color / lum);
|
vec3 col_adjusted = lum == 0.0 ? vec3(0.0) : color / lum;
|
||||||
// vec3 c = pow(color / lum, vec3(s)) * T;
|
// vec3 c = pow(col_adjusted, vec3(s)) * T;
|
||||||
|
// vec3 c = col_adjusted * T;
|
||||||
// vec3 c = sqrt(col_adjusted) * T;
|
// vec3 c = sqrt(col_adjusted) * T;
|
||||||
vec3 c = col_adjusted * col_adjusted * T;
|
vec3 c = /*col_adjusted * */col_adjusted * T;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
// float sum_col = color.r + color.g + color.b;
|
// float sum_col = color.r + color.g + color.b;
|
||||||
|
@ -53,11 +53,13 @@ void main() {
|
|||||||
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
||||||
// float sun_light = get_sun_brightness(sun_dir);
|
// float sun_light = get_sun_brightness(sun_dir);
|
||||||
// float moon_light = get_moon_brightness(moon_dir);
|
// float moon_light = get_moon_brightness(moon_dir);
|
||||||
/* float my_alt = alt_at(f_pos.xy);
|
float my_alt = f_pos.z;//alt_at(f_pos.xy);
|
||||||
|
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
|
// float my_alt = alt_at(f_pos.xy);
|
||||||
float sun_shade_frac = horizon_at2(f_shadow, my_alt, f_pos, sun_dir);
|
float sun_shade_frac = horizon_at2(f_shadow, my_alt, f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at2(f_shadow, my_alt, f_pos, moon_dir); */
|
float moon_shade_frac = horizon_at2(f_shadow, my_alt, f_pos, moon_dir);
|
||||||
float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
// float sun_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir);
|
// float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir);
|
||||||
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
||||||
// Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing).
|
// Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing).
|
||||||
// float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5);
|
// float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5);
|
||||||
@ -69,7 +71,11 @@ void main() {
|
|||||||
|
|
||||||
float alpha = 1.0;//sqrt(2.0);
|
float alpha = 1.0;//sqrt(2.0);
|
||||||
const float n2 = 1.01;
|
const float n2 = 1.01;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 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 emitted_light, reflected_light;
|
||||||
// Use f_norm here for better shadows.
|
// Use f_norm here for better shadows.
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
in vec3 f_pos;
|
in vec3 f_pos;
|
||||||
in vec3 f_col;
|
in vec3 f_col;
|
||||||
flat in vec3 f_norm;
|
flat in vec3 f_norm;
|
||||||
|
in float f_ao;
|
||||||
|
in float f_alt;
|
||||||
|
in vec4 f_shadow;
|
||||||
|
|
||||||
layout (std140)
|
layout (std140)
|
||||||
uniform u_locals {
|
uniform u_locals {
|
||||||
|
@ -27,8 +27,12 @@ void main() {
|
|||||||
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
vec3 moon_dir = get_moon_dir(time_of_day.x);
|
||||||
// float sun_light = get_sun_brightness(sun_dir);
|
// float sun_light = get_sun_brightness(sun_dir);
|
||||||
// float moon_light = get_moon_brightness(moon_dir);
|
// float moon_light = get_moon_brightness(moon_dir);
|
||||||
float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
float f_alt = alt_at(f_pos.xy);
|
||||||
float moon_shade_frac = horizon_at(f_pos, moon_dir);
|
vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
|
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
||||||
|
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
||||||
|
// float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
||||||
|
// float moon_shade_frac = horizon_at(f_pos, moon_dir);
|
||||||
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
||||||
// Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing).
|
// Will be attenuated by k_d, which is assumed to carry any additional ambient occlusion information (e.g. about shadowing).
|
||||||
// float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5);
|
// float ambient_sides = clamp(mix(0.5, 0.0, abs(dot(-f_norm, sun_dir)) * 10000.0), 0.0, 0.5);
|
||||||
@ -40,7 +44,11 @@ void main() {
|
|||||||
vec3 surf_color = /*srgb_to_linear*//*linear_to_srgb*/(f_col);
|
vec3 surf_color = /*srgb_to_linear*//*linear_to_srgb*/(f_col);
|
||||||
float alpha = 1.0;
|
float alpha = 1.0;
|
||||||
const float n2 = 1.01;
|
const float n2 = 1.01;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||||
|
|
||||||
vec3 k_a = vec3(1.0);
|
vec3 k_a = vec3(1.0);
|
||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
|
@ -41,6 +41,8 @@ void main() {
|
|||||||
// float moon_light = get_moon_brightness(moon_dir);
|
// float moon_light = get_moon_brightness(moon_dir);
|
||||||
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
/* float sun_shade_frac = horizon_at(f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
float moon_shade_frac = horizon_at(f_pos, moon_dir); */
|
||||||
|
// float f_alt = alt_at(f_pos.xy);
|
||||||
|
// vec4 f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
|
||||||
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
float sun_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, sun_dir);
|
||||||
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
float moon_shade_frac = horizon_at2(f_shadow, f_alt, f_pos, moon_dir);
|
||||||
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
// Globbal illumination "estimate" used to light the faces of voxels which are parallel to the sun or moon (which is a very common occurrence).
|
||||||
@ -53,8 +55,13 @@ void main() {
|
|||||||
|
|
||||||
vec3 surf_color = /*srgb_to_linear*/(f_col);
|
vec3 surf_color = /*srgb_to_linear*/(f_col);
|
||||||
float alpha = 1.0;
|
float alpha = 1.0;
|
||||||
|
// TODO: Possibly angle with water surface into account? Since we can basically assume it's horizontal.
|
||||||
const float n2 = 1.01;
|
const float n2 = 1.01;
|
||||||
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
|
const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2);
|
||||||
|
const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2);
|
||||||
|
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 R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x);
|
||||||
vec3 k_a = vec3(1.0);
|
vec3 k_a = vec3(1.0);
|
||||||
vec3 k_d = vec3(1.0);
|
vec3 k_d = vec3(1.0);
|
||||||
vec3 k_s = vec3(R_s);
|
vec3 k_s = vec3(R_s);
|
||||||
|
Loading…
Reference in New Issue
Block a user