Better colour correction

This commit is contained in:
Joshua Barretto 2019-09-23 20:37:50 +01:00
parent 22af0ab016
commit a432cef263
8 changed files with 39 additions and 30 deletions

View File

@ -28,8 +28,10 @@ uniform u_bones {
out vec4 tgt_color;
void main() {
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) + light_at(f_pos, f_norm);
vec3 surf_color = srgb_to_linear(model_col.rgb * f_col) * 4.0 * light;
vec3 diffuse_light, ambient_light;
get_sun_diffuse(f_norm, time_of_day.x, diffuse_light, ambient_light);
diffuse_light += light_at(f_pos, f_norm);
vec3 surf_color = illuminate(srgb_to_linear(model_col.rgb * f_col) * 2.0, diffuse_light, ambient_light);
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);

View File

@ -37,8 +37,12 @@ void main() {
vec3 norm = warp_normal(f_norm, f_pos, tick.x);
vec3 light = get_sun_diffuse(norm, time_of_day.x) * f_light + light_at(f_pos, norm);
vec3 surf_color = f_col * light;
vec3 diffuse_light, ambient_light;
get_sun_diffuse(f_norm, time_of_day.x, diffuse_light, ambient_light);
diffuse_light *= f_light;
ambient_light *= f_light;
diffuse_light += light_at(f_pos, f_norm);
vec3 surf_color = illuminate(f_col, diffuse_light, ambient_light);
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);
@ -52,7 +56,7 @@ void main() {
// 0 = 100% reflection, 1 = translucent water
float passthrough = pow(dot(faceforward(norm, norm, cam_to_frag), -cam_to_frag), 1.0);
vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 0.5 / (1.0 + light * 2.0)), passthrough);
vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 0.5 / (1.0 + diffuse_light * 2.0)), passthrough);
tgt_color = mix(color, vec4(fog_color, 0.0), fog_level);
}

View File

@ -10,6 +10,11 @@ uniform u_lights {
#include <srgb.glsl>
vec3 illuminate(vec3 color, vec3 diffuse, vec3 ambience) {
float avg_col = (color.r + color.g + color.b) / 3.0;
return ((color - avg_col) * ambience * 2.0 + (diffuse + ambience) * avg_col) * (diffuse + ambience);
}
float attenuation_strength(vec3 rpos) {
return 1.0 / (rpos.x * rpos.x + rpos.y * rpos.y + rpos.z * rpos.z);
}
@ -46,4 +51,4 @@ vec3 light_at(vec3 wpos, vec3 wnorm) {
light += color * (max(0, dot(normalize(difference), wnorm)) + LIGHT_AMBIENCE);
}
return light;
}
}

View File

@ -5,12 +5,12 @@ 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.02, 0.01, 0.3);
const vec3 DAY_LIGHT = vec3(1.3, 0.9, 1.1);
const vec3 DAY_LIGHT = vec3(1.0, 1.0, 1.0);
const vec3 SKY_DUSK_TOP = vec3(0.06, 0.1, 0.20);
const vec3 SKY_DUSK_MID = vec3(0.35, 0.1, 0.15);
const vec3 SKY_DUSK_BOT = vec3(0.0, 0.1, 0.13);
const vec3 DUSK_LIGHT = vec3(3.0, 0.65, 0.3);
const vec3 DUSK_LIGHT = vec3(3.0, 1.0, 0.3);
const vec3 SKY_NIGHT_TOP = vec3(0.001, 0.001, 0.0025);
const vec3 SKY_NIGHT_MID = vec3(0.001, 0.005, 0.02);
@ -27,13 +27,13 @@ vec3 get_sun_dir(float time_of_day) {
}
float get_sun_brightness(vec3 sun_dir) {
return max(-sun_dir.z + 0.6, 0.0);
return max(-sun_dir.z + 0.6, 0.0) / 1.6;
}
const float PERSISTENT_AMBIANCE = 0.008;
vec3 get_sun_diffuse(vec3 norm, float time_of_day) {
const float SUN_AMBIANCE = 0.15;
void get_sun_diffuse(vec3 norm, float time_of_day, out vec3 diffuse_light, out vec3 ambient_light) {
const float SUN_AMBIANCE = 0.8;
vec3 sun_dir = get_sun_dir(time_of_day);
@ -51,9 +51,8 @@ vec3 get_sun_diffuse(vec3 norm, float time_of_day) {
max(-sun_dir.z, 0)
);
vec3 diffuse_light = (SUN_AMBIANCE + max(dot(-norm, sun_dir), 0.0) * sun_color) * sun_light + PERSISTENT_AMBIANCE;
return diffuse_light;
diffuse_light = vec3(max(dot(-norm, sun_dir), 0.0) * sun_color * sun_light);
ambient_light = vec3((SUN_AMBIANCE + PERSISTENT_AMBIANCE) * sun_light);
}
// This has been extracted into a function to allow quick exit when detecting a star.
@ -137,7 +136,7 @@ vec3 get_sky_color(vec3 dir, float time_of_day, bool with_stars) {
// Sun
const vec3 SUN_HALO_COLOR = vec3(1.5, 0.35, 0.0) * 0.3;
const vec3 SUN_HALO_COLOR = vec3(1.5, 0.65, 0.0) * 0.3;
const vec3 SUN_SURF_COLOR = vec3(1.5, 0.9, 0.35) * 200.0;
vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * SUN_HALO_COLOR;

View File

@ -16,8 +16,12 @@ const float RENDER_DIST = 112.0;
const float FADE_DIST = 32.0;
void main() {
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) * f_light + light_at(f_pos, f_norm);
vec3 surf_color = f_col * light;
vec3 diffuse_light, ambient_light;
get_sun_diffuse(f_norm, time_of_day.x, diffuse_light, ambient_light);
diffuse_light *= f_light;
ambient_light *= f_light;
diffuse_light += light_at(f_pos, f_norm);
vec3 surf_color = illuminate(f_col, diffuse_light, ambient_light);
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);

View File

@ -18,8 +18,12 @@ out vec4 tgt_color;
#include <light.glsl>
void main() {
vec3 light = get_sun_diffuse(f_norm, time_of_day.x) * f_light + light_at(f_pos, f_norm);
vec3 surf_color = f_col * light;
vec3 diffuse_light, ambient_light;
get_sun_diffuse(f_norm, time_of_day.x, diffuse_light, ambient_light);
diffuse_light *= f_light;
ambient_light *= f_light;
diffuse_light += light_at(f_pos, f_norm);
vec3 surf_color = illuminate(f_col, diffuse_light, ambient_light);
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);

View File

@ -382,16 +382,6 @@ impl<'a> BlockGen<'a> {
})
.or(block);
// Water
let block = block.or_else(|| {
if (wposf.z as f32) < water_height {
// Ocean
Some(water)
} else {
None
}
});
Some(block.unwrap_or(Block::empty()))
}
}

View File

@ -219,7 +219,8 @@ impl WorldSim {
.mul(alt_main.max(0.25))
.mul(0.3)
.add(1.0)
.mul(0.5))
.mul(0.5)
+ alt_main.mul(100.0).sin().mul(0.025))
};
// Now we can compute the final altitude using chaos.