mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'sharp/new-lighting' into sharp/small-fixes
This commit is contained in:
commit
9cd2b3fb0d
@ -28,19 +28,37 @@ uniform u_bones {
|
|||||||
out vec4 tgt_color;
|
out vec4 tgt_color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
vec3 surf_color = /*srgb_to_linear*/(model_col.rgb * f_col);
|
||||||
|
|
||||||
|
vec3 k_a = surf_color;
|
||||||
|
vec3 k_d = 0.5 * surf_color;
|
||||||
|
vec3 k_s = 0.5 * surf_color;
|
||||||
|
float alpha = 2.0;
|
||||||
|
|
||||||
|
vec3 emitted_light, reflected_light;
|
||||||
|
|
||||||
float point_shadow = shadow_at(f_pos, f_norm);
|
float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
diffuse_light *= point_shadow;
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
ambient_light *= point_shadow;
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
vec3 point_light = light_at(f_pos, f_norm);
|
get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * point_shadow, k_d * point_shadow, k_s * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
light += point_light;
|
|
||||||
diffuse_light += point_light;
|
lights_at(f_pos, f_norm, cam_to_frag, k_a * point_shadow, k_d * point_shadow, k_s * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
vec3 surf_color = illuminate(srgb_to_linear(model_col.rgb * f_col), light, diffuse_light, ambient_light);
|
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 0.5 * surf_color * f_light * point_shadow, 2.0, emitted_light, reflected_light);
|
||||||
|
|
||||||
|
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||||
|
// diffuse_light *= point_shadow;
|
||||||
|
// ambient_light *= point_shadow;
|
||||||
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
|
// light += point_light;
|
||||||
|
// diffuse_light += point_light;
|
||||||
|
// reflected_light += point_light;
|
||||||
|
// vec3 surf_color = illuminate(srgb_to_linear(model_col.rgb * f_col), light, diffuse_light, ambient_light);
|
||||||
|
surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds);
|
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds);
|
||||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||||
|
|
||||||
tgt_color = vec4(color, 1.0);
|
tgt_color = vec4(color, 1.0);
|
||||||
|
@ -33,16 +33,31 @@ void main() {
|
|||||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
vec3 f_norm = normals[norm_axis + norm_dir];
|
||||||
|
|
||||||
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
|
vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0));
|
||||||
|
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 k_a = 0.5 * surf_color;
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
vec3 k_d = vec3(1.0);
|
||||||
|
vec3 k_s = 0.5 * vec3(1.0);
|
||||||
|
float alpha = 0.255;
|
||||||
|
|
||||||
|
vec3 emitted_light, reflected_light;
|
||||||
|
|
||||||
|
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
|
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
|
// vec3 emitted_light, reflected_light;
|
||||||
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
float point_shadow = shadow_at(f_pos,f_norm);
|
float point_shadow = shadow_at(f_pos,f_norm);
|
||||||
diffuse_light *= f_light * point_shadow;
|
// vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0));
|
||||||
ambient_light *= f_light, point_shadow;
|
get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light * point_shadow, vec3(0.0), k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
vec3 point_light = light_at(f_pos, f_norm);
|
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
||||||
light += point_light;
|
// diffuse_light *= f_light * point_shadow;
|
||||||
diffuse_light += point_light;
|
// ambient_light *= f_light, point_shadow;
|
||||||
vec3 surf_color = srgb_to_linear(vec3(0.4, 0.7, 2.0)) * light * diffuse_light * ambient_light;
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
|
// light += point_light;
|
||||||
|
// diffuse_light += point_light;
|
||||||
|
// reflected_light += point_light;
|
||||||
|
// vec3 surf_color = srgb_to_linear(vec3(0.4, 0.7, 2.0)) * light * diffuse_light * ambient_light;
|
||||||
|
lights_at(f_pos, f_norm, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
@ -50,7 +65,8 @@ void main() {
|
|||||||
|
|
||||||
float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5);
|
float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5);
|
||||||
|
|
||||||
vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 1.0 / (1.0 + diffuse_light * 0.25)), passthrough);
|
surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*//*(f_light * point_shadow + point_light)*/reflected_light * 0.25)), passthrough);
|
||||||
|
|
||||||
tgt_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
tgt_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
||||||
}
|
}
|
||||||
|
@ -93,32 +93,51 @@ void main() {
|
|||||||
|
|
||||||
vec3 norm = f_norm * nmap.z + b_norm * nmap.x + c_norm * nmap.y;
|
vec3 norm = f_norm * nmap.z + b_norm * nmap.x + c_norm * nmap.y;
|
||||||
|
|
||||||
vec3 light, diffuse_light, ambient_light;
|
|
||||||
get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
vec4 _clouds;
|
||||||
float point_shadow = shadow_at(f_pos, norm);
|
vec3 reflect_ray_dir = reflect(cam_to_frag, norm);
|
||||||
diffuse_light *= f_light * point_shadow;
|
vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light;
|
||||||
ambient_light *= f_light, point_shadow;
|
vec3 surf_color = /*srgb_to_linear*/(vec3(0.2, 0.5, 1.0));
|
||||||
vec3 point_light = light_at(f_pos, norm);
|
|
||||||
light += point_light;
|
vec3 k_a = surf_color;
|
||||||
diffuse_light += point_light;
|
vec3 k_d = vec3(1.0);
|
||||||
vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light;
|
vec3 k_s = reflect_color;
|
||||||
|
float alpha = 0.255;
|
||||||
|
|
||||||
|
vec3 emitted_light, reflected_light;
|
||||||
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
|
float point_shadow = shadow_at(f_pos,f_norm);
|
||||||
|
// 0 = 100% reflection, 1 = translucent water
|
||||||
|
float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5);
|
||||||
|
get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light * point_shadow, vec3(0.0), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
|
lights_at(f_pos, f_norm, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
|
// get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
|
||||||
|
// diffuse_light *= f_light * point_shadow;
|
||||||
|
// ambient_light *= f_light * point_shadow;
|
||||||
|
// vec3 point_light = light_at(f_pos, norm);
|
||||||
|
// light += point_light;
|
||||||
|
// 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;
|
||||||
|
surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 0.25, true, clouds);
|
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 0.25, true, clouds);
|
||||||
|
|
||||||
vec3 reflect_ray_dir = reflect(cam_to_frag, norm);
|
// vec3 reflect_ray_dir = reflect(cam_to_frag, norm);
|
||||||
// Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water
|
// Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water
|
||||||
reflect_ray_dir.z = max(reflect_ray_dir.z, 0.01);
|
// reflect_ray_dir.z = max(reflect_ray_dir.z, 0.01);
|
||||||
|
|
||||||
vec4 _clouds;
|
// vec4 _clouds;
|
||||||
vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light;
|
// vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.25, false, _clouds) * f_light;
|
||||||
// Tint
|
// Tint
|
||||||
reflect_color = mix(reflect_color, surf_color, 0.6);
|
// reflect_color = mix(reflect_color, surf_color, 0.6);
|
||||||
// 0 = 100% reflection, 1 = translucent water
|
|
||||||
float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5);
|
|
||||||
|
|
||||||
vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + diffuse_light * 0.25)), passthrough);
|
|
||||||
|
|
||||||
tgt_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(f_light * point_shadow + point_light) * 0.25)), passthrough);
|
||||||
|
vec4 color = vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow + point_light*/reflected_light) * 0.25));
|
||||||
|
// vec4 color = surf_color;
|
||||||
|
|
||||||
|
tgt_color = color; // mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);
|
||||||
}
|
}
|
||||||
|
@ -70,3 +70,56 @@ float shadow_at(vec3 wpos, vec3 wnorm) {
|
|||||||
}
|
}
|
||||||
return min(shadow, 1.0);
|
return min(shadow, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lights_at(vec3 wpos, vec3 wnorm, vec3 cam_to_frag, vec3 k_a, vec3 k_d, vec3 k_s, float alpha, inout vec3 emitted_light, inout vec3 reflected_light/*, out float shadow*/) {
|
||||||
|
// shadow = 0.0;
|
||||||
|
vec3 ambient_light = vec3(0.0);
|
||||||
|
|
||||||
|
const float LIGHT_AMBIENCE = 0.025;
|
||||||
|
|
||||||
|
for (uint i = 0u; i < light_shadow_count.x; i ++) {
|
||||||
|
|
||||||
|
// Only access the array once
|
||||||
|
Light L = lights[i];
|
||||||
|
|
||||||
|
vec3 light_pos = L.light_pos.xyz;
|
||||||
|
|
||||||
|
// Pre-calculate difference between light and fragment
|
||||||
|
vec3 difference = light_pos - wpos;
|
||||||
|
|
||||||
|
float strength = pow(attenuation_strength(difference), 0.6);
|
||||||
|
|
||||||
|
// Multiply the vec3 only once
|
||||||
|
vec3 color = /*srgb_to_linear*/(L.light_col.rgb) * (strength * L.light_col.a);
|
||||||
|
|
||||||
|
// // Only access the array once
|
||||||
|
// Shadow S = shadows[i];
|
||||||
|
|
||||||
|
// vec3 shadow_pos = S.shadow_pos_radius.xyz;
|
||||||
|
// float radius = S.shadow_pos_radius.w;
|
||||||
|
|
||||||
|
// vec3 diff = shadow_pos - wpos;
|
||||||
|
// if (diff.z >= 0.0) {
|
||||||
|
// diff.z = -sign(diff.z) * diff.z * 0.1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// float shade = max(pow(diff.x * diff.x + diff.y * diff.y + diff.z * diff.z, 0.25) / pow(radius * radius * 0.5, 0.25), /*0.5*/0.0);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
@ -7,6 +7,50 @@ vec2 pos_to_uv(vec2 pos) {
|
|||||||
return vec2(uv_pos.x, 1.0 - uv_pos.y);
|
return vec2(uv_pos.x, 1.0 - 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;
|
||||||
|
vec4 s = n * n * n;
|
||||||
|
float x = s.x;
|
||||||
|
float y = s.y - 4.0 * s.x;
|
||||||
|
float z = s.z - 4.0 * s.y + 6.0 * s.x;
|
||||||
|
float w = 6.0 - x - y - z;
|
||||||
|
return vec4(x, y, z, w) * (1.0/6.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 textureBicubic(sampler2D sampler, vec2 texCoords) {
|
||||||
|
vec2 texSize = textureSize(sampler, 0);
|
||||||
|
vec2 invTexSize = 1.0 / texSize;
|
||||||
|
|
||||||
|
texCoords = texCoords * texSize - 0.5;
|
||||||
|
|
||||||
|
|
||||||
|
vec2 fxy = fract(texCoords);
|
||||||
|
texCoords -= fxy;
|
||||||
|
|
||||||
|
vec4 xcubic = cubic(fxy.x);
|
||||||
|
vec4 ycubic = cubic(fxy.y);
|
||||||
|
|
||||||
|
vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy;
|
||||||
|
|
||||||
|
vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);
|
||||||
|
vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s;
|
||||||
|
|
||||||
|
offset *= invTexSize.xxyy;
|
||||||
|
|
||||||
|
vec4 sample0 = texture(sampler, offset.xz);
|
||||||
|
vec4 sample1 = texture(sampler, offset.yz);
|
||||||
|
vec4 sample2 = texture(sampler, offset.xw);
|
||||||
|
vec4 sample3 = texture(sampler, offset.yw);
|
||||||
|
|
||||||
|
float sx = s.x / (s.x + s.y);
|
||||||
|
float sy = s.z / (s.z + s.w);
|
||||||
|
|
||||||
|
return mix(
|
||||||
|
mix(sample3, sample2, sx), mix(sample1, sample0, sx)
|
||||||
|
, sy);
|
||||||
|
}
|
||||||
|
|
||||||
float alt_at(vec2 pos) {
|
float alt_at(vec2 pos) {
|
||||||
return texture(t_map, pos_to_uv(pos)).a * (1300.0) + 140.0;
|
return texture(t_map, pos_to_uv(pos)).a * (1300.0) + 140.0;
|
||||||
//+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0;
|
//+ (texture(t_noise, pos * 0.002).x - 0.5) * 64.0;
|
||||||
@ -52,6 +96,6 @@ vec3 lod_pos(vec2 v_pos, vec2 focus_pos) {
|
|||||||
|
|
||||||
vec3 lod_col(vec2 pos) {
|
vec3 lod_col(vec2 pos) {
|
||||||
//return vec3(0, 0.5, 0);
|
//return vec3(0, 0.5, 0);
|
||||||
return texture(t_map, pos_to_uv(pos)).rgb;
|
return textureBicubic(t_map, pos_to_uv(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;
|
//+ (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;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <random.glsl>
|
#include <random.glsl>
|
||||||
|
#include <srgb.glsl>
|
||||||
#include <cloud.glsl>
|
#include <cloud.glsl>
|
||||||
|
|
||||||
const float PI = 3.141592;
|
const float PI = 3.141592;
|
||||||
@ -36,7 +37,7 @@ vec3 get_moon_dir(float time_of_day) {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
const float PERSISTENT_AMBIANCE = 0.1;
|
const float PERSISTENT_AMBIANCE = 0.025; // 0.1;
|
||||||
|
|
||||||
float get_sun_brightness(vec3 sun_dir) {
|
float get_sun_brightness(vec3 sun_dir) {
|
||||||
return max(-sun_dir.z + 0.6, 0.0) * 0.9;
|
return max(-sun_dir.z + 0.6, 0.0) * 0.9;
|
||||||
@ -62,7 +63,18 @@ vec3 get_moon_color(vec3 moon_dir) {
|
|||||||
return vec3(0.05, 0.05, 0.6);
|
return vec3(0.05, 0.05, 0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diffuse_light, out vec3 ambient_light, float diffusion) {
|
// Calculates extra emission and reflectance (due to sunlight / moonlight).
|
||||||
|
//
|
||||||
|
// reflectence = k_a * i_a + i_a,persistent
|
||||||
|
// emittence = Σ { m ∈ lights } i_m * shadow_m * get_light_reflected(light_m)
|
||||||
|
//
|
||||||
|
// Note that any shadowing to be done that would block the sun and moon, aside from heightmap shadowing (that will be
|
||||||
|
// implemented sooon), should be implicitly provided via k_a, k_d, and k_s. For instance, shadowing via ambient occlusion.
|
||||||
|
//
|
||||||
|
// Also note that the emitted light calculation is kind of lame... we probabbly need something a bit nicer if we ever want to do
|
||||||
|
// 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;
|
const float SUN_AMBIANCE = 0.1;
|
||||||
|
|
||||||
vec3 sun_dir = get_sun_dir(time_of_day);
|
vec3 sun_dir = get_sun_dir(time_of_day);
|
||||||
@ -77,12 +89,26 @@ void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 light, out vec3 diff
|
|||||||
vec3 sun_chroma = sun_color * sun_light;
|
vec3 sun_chroma = sun_color * sun_light;
|
||||||
vec3 moon_chroma = moon_color * moon_light;
|
vec3 moon_chroma = moon_color * moon_light;
|
||||||
|
|
||||||
light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE;
|
/* float NLsun = max(dot(-norm, sun_dir), 0);
|
||||||
|
float NLmoon = max(dot(-norm, moon_dir), 0);
|
||||||
|
vec3 E = -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).
|
||||||
|
// 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(-norm, sun_dir)) * 10000.0), 0.0, 0.5);
|
||||||
|
|
||||||
|
emitted_light = k_a * (ambient_sides + vec3(SUN_AMBIANCE * sun_light + moon_light)) + PERSISTENT_AMBIANCE;
|
||||||
|
// TODO: Add shadows.
|
||||||
|
reflected_light =
|
||||||
|
sun_chroma * light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha) +
|
||||||
|
moon_chroma * 0.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha);
|
||||||
|
|
||||||
|
/* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE;
|
||||||
diffuse_light =
|
diffuse_light =
|
||||||
sun_chroma * mix(1.0, max(dot(-norm, sun_dir) * 0.5 + 0.5, 0.0), diffusion) +
|
sun_chroma * mix(1.0, max(dot(-norm, sun_dir) * 0.5 + 0.5, 0.0), diffusion) +
|
||||||
moon_chroma * mix(1.0, pow(dot(-norm, moon_dir) * 2.0, 2.0), diffusion) +
|
moon_chroma * mix(1.0, pow(dot(-norm, moon_dir) * 2.0, 2.0), diffusion) +
|
||||||
PERSISTENT_AMBIANCE;
|
PERSISTENT_AMBIANCE;
|
||||||
ambient_light = vec3(SUN_AMBIANCE * sun_light + moon_light);
|
ambient_light = vec3(SUN_AMBIANCE * sun_light + moon_light); */
|
||||||
}
|
}
|
||||||
|
|
||||||
// This has been extracted into a function to allow quick exit when detecting a star.
|
// This has been extracted into a function to allow quick exit when detecting a star.
|
||||||
@ -215,7 +241,12 @@ float fog(vec3 f_pos, vec3 focus_pos, uint medium) {
|
|||||||
return pow(clamp((max(fog, mist) - min_fog) / (max_fog - min_fog), 0.0, 1.0), 1.7);
|
return pow(clamp((max(fog, mist) - min_fog) / (max_fog - min_fog), 0.0, 1.0), 1.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 illuminate(vec3 color, vec3 light, vec3 diffuse, vec3 ambience) {
|
/* vec3 illuminate(vec3 color, vec3 light, vec3 diffuse, vec3 ambience) {
|
||||||
float avg_col = (color.r + color.g + color.b) / 3.0;
|
float avg_col = (color.r + color.g + color.b) / 3.0;
|
||||||
return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * (diffuse + ambience);
|
return ((color - avg_col) * light + (diffuse + ambience) * avg_col) * (diffuse + ambience);
|
||||||
|
} */
|
||||||
|
vec3 illuminate(vec3 emitted, vec3 reflected) {
|
||||||
|
const float gamma = /*0.5*/1.0;//1.0;
|
||||||
|
vec3 color = emitted + reflected;
|
||||||
|
return srgb_to_linear(/*0.5*//*0.125 * */vec3(pow(color.x, gamma), pow(color.y, gamma), pow(color.z, gamma)));
|
||||||
}
|
}
|
||||||
|
@ -6,3 +6,16 @@ vec3 srgb_to_linear(vec3 srgb) {
|
|||||||
|
|
||||||
return mix(higher, lower, cutoff);
|
return mix(higher, lower, cutoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Phong reflection.
|
||||||
|
//
|
||||||
|
// Note: norm, dir, light_dir must all be normalizd.
|
||||||
|
vec3 light_reflection_factor(vec3 norm, vec3 dir, vec3 light_dir, vec3 k_d, vec3 k_s, float alpha) {
|
||||||
|
float ndotL = max(dot(-norm, light_dir), 0.0);
|
||||||
|
if (ndotL > 0.0) {
|
||||||
|
vec3 H = normalize(-light_dir + dir);
|
||||||
|
// (k_d * (L ⋅ N) + k_s * (R ⋅ V)^α)
|
||||||
|
return k_d * ndotL + k_s * pow(max(dot(norm, H), 0.0), alpha * 4.0);
|
||||||
|
}
|
||||||
|
return vec3(0.0);
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <globals.glsl>
|
#include <globals.glsl>
|
||||||
#include <sky.glsl>
|
#include <sky.glsl>
|
||||||
#include <srgb.glsl>
|
|
||||||
#include <lod.glsl>
|
#include <lod.glsl>
|
||||||
|
|
||||||
in vec3 f_pos;
|
in vec3 f_pos;
|
||||||
@ -17,19 +16,24 @@ void main() {
|
|||||||
|
|
||||||
vec3 f_col = lod_col(f_pos.xy);
|
vec3 f_col = lod_col(f_pos.xy);
|
||||||
|
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 emitted_light, reflected_light;
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
|
get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, f_col, 0.5 * f_col, 0.5 * vec3(1.0), 2.0, emitted_light, reflected_light);
|
||||||
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
|
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||||
|
// vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||||
|
vec3 surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
|
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
|
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
|
||||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||||
|
|
||||||
float mist_factor = max(1 - (f_pos.z + (texture(t_noise, f_pos.xy * 0.0005 + time_of_day.x * 0.001).x - 0.5) * 128.0) / 400.0, 0.0);
|
float mist_factor = max(1 - (f_pos.z + (texture(t_noise, f_pos.xy * 0.0005 + time_of_day.x * 0.0003).x - 0.5) * 128.0) / 400.0, 0.0);
|
||||||
//float mist_factor = f_norm.z * 2.0;
|
//float mist_factor = f_norm.z * 2.0;
|
||||||
color = mix(color, vec3(1.0) * diffuse_light, clamp(mist_factor * 0.00005 * distance(f_pos.xy, focus_pos.xy), 0, 0.3));
|
color = mix(color, vec3(1.0) * /*diffuse_light*/reflected_light, clamp(mist_factor * 0.00005 * distance(f_pos.xy, focus_pos.xy), 0, 0.3));
|
||||||
|
|
||||||
tgt_color = vec4(color, 1.0);
|
tgt_color = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -16,19 +16,39 @@ const float RENDER_DIST = 112.0;
|
|||||||
const float FADE_DIST = 32.0;
|
const float FADE_DIST = 32.0;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
vec3 surf_color = /*srgb_to_linear*/(f_col);
|
||||||
|
|
||||||
|
vec3 k_a = surf_color;
|
||||||
|
vec3 k_d = 0.5 * surf_color;
|
||||||
|
vec3 k_s = 0.5 * surf_color;
|
||||||
|
float alpha = 2.0;
|
||||||
|
|
||||||
|
vec3 emitted_light, reflected_light;
|
||||||
|
|
||||||
float point_shadow = shadow_at(f_pos, f_norm);
|
float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
diffuse_light *= f_light * point_shadow;
|
|
||||||
ambient_light *= f_light, point_shadow;
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
vec3 point_light = light_at(f_pos, f_norm);
|
// vec3 emitted_light, reflected_light;
|
||||||
light += point_light;
|
// float point_shadow = shadow_at(f_pos,f_norm);
|
||||||
diffuse_light += point_light;
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
// 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_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, 2.0, emitted_light, reflected_light);
|
||||||
|
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||||
|
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
|
// diffuse_light *= f_light * point_shadow;
|
||||||
|
// ambient_light *= f_light * point_shadow;
|
||||||
|
// light += point_light;
|
||||||
|
// diffuse_light += point_light;
|
||||||
|
// reflected_light += point_light;
|
||||||
|
lights_at(f_pos, f_norm, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
|
surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
// vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds);
|
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds);
|
||||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||||
|
|
||||||
tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (RENDER_DIST - FADE_DIST)) / FADE_DIST, 0, 1));
|
tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (RENDER_DIST - FADE_DIST)) / FADE_DIST, 0, 1));
|
||||||
|
@ -23,20 +23,46 @@ void main() {
|
|||||||
// Use an array to avoid conditional branching
|
// Use an array to avoid conditional branching
|
||||||
vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
|
vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
|
||||||
|
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
|
||||||
|
vec3 surf_color = /*srgb_to_linear*/(f_col);
|
||||||
|
vec3 k_a = 0.5 * surf_color;
|
||||||
|
vec3 k_d = 0.5 * surf_color;
|
||||||
|
vec3 k_s = 0.5 * surf_color;
|
||||||
|
float alpha = 2.0;
|
||||||
|
|
||||||
|
vec3 emitted_light, reflected_light;
|
||||||
float point_shadow = shadow_at(f_pos, f_norm);
|
float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
diffuse_light *= f_light * point_shadow;
|
|
||||||
ambient_light *= f_light * point_shadow;
|
get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
vec3 point_light = light_at(f_pos, f_norm);
|
|
||||||
light += point_light;
|
lights_at(f_pos, f_norm, cam_to_frag, k_a * f_light * point_shadow, k_d * f_light * point_shadow, k_s * f_light * point_shadow, alpha, emitted_light, reflected_light);
|
||||||
diffuse_light += point_light;
|
|
||||||
vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
|
// vec3 light, diffuse_light, ambient_light;
|
||||||
|
|
||||||
|
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, k_a * f_light, k_d * f_light, k_s * f_light, alpha, emitted_light, reflected_light);
|
||||||
|
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||||
|
// float point_shadow = shadow_at(f_pos, f_norm);
|
||||||
|
// diffuse_light *= f_light * point_shadow;
|
||||||
|
// ambient_light *= f_light * point_shadow;
|
||||||
|
// vec3 point_light = light_at(f_pos, f_norm);
|
||||||
|
// light += point_light;
|
||||||
|
// diffuse_light += point_light;
|
||||||
|
// reflected_light += point_light;
|
||||||
|
// reflected_light += light_reflection_factor(norm, cam_to_frag, , vec3 k_d, vec3 k_s, float alpha) {
|
||||||
|
|
||||||
|
// light_reflection_factorplight_reflection_factor
|
||||||
|
|
||||||
|
// vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
||||||
|
surf_color = illuminate(emitted_light, reflected_light);
|
||||||
|
|
||||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||||
vec4 clouds;
|
vec4 clouds;
|
||||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
|
vec3 fog_color = get_sky_color(cam_to_frag, time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
|
||||||
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
vec3 color = surf_color;
|
||||||
|
// vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
|
||||||
|
|
||||||
tgt_color = vec4(color, 1.0);
|
tgt_color = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user