commit 9c88e0889ab92786cf81d7b85960430b3278ef70
parent b4765bfc0564a78c20ac18e9615dd9fb2839ce6f
Author: William Casarin <jb55@jb55.com>
Date: Thu, 1 Nov 2018 14:52:23 -0700
looking a bit better
Diffstat:
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/etc/shaders/lighting.glsl b/etc/shaders/lighting.glsl
@@ -15,6 +15,9 @@
// return clouds;
// }
+vec3 gamma_correct(vec3 color) {
+ return pow(color, vec3(1.0/2.2));
+}
vec3 standard_light(vec3 color, vec3 position) {
vec4 v4_normal = vec4(v_normal , 1);
@@ -22,8 +25,10 @@ vec3 standard_light(vec3 color, vec3 position) {
const float pi = 3.14159265;
const float shiny = 12.0;
- float ambient_str = 0.2;
- float spec_str = 0.2 * light_intensity;
+ const float exposure = 10.0;
+
+ float ambient_str = 0.3;
+ float spec_str = 0.8 * light_intensity;
// too much ambient during daytime is making things look weird
// ambient_str =- light_intensity * ambient_str;
@@ -45,7 +50,7 @@ vec3 standard_light(vec3 color, vec3 position) {
vec3 ambient = ambient_str * sun_color;
float spec;
- bool blinn = false;
+ bool blinn = true;
if (blinn) {
const float energy_conservation = ( 8.0 + shiny ) / ( 8.0 * pi );
vec3 halfway_dir = normalize(light_dir + view_dir); // blinn-phong
@@ -62,10 +67,10 @@ vec3 standard_light(vec3 color, vec3 position) {
vec3 specular = spec_str * spec * sun_color;
vec3 final = (ambient + diffuse + specular) * color;
- return final / (final + vec3(1.0));
+ // tone mappink
+ final = final / (vec3(1.0) - exp(-final * exposure));
+
+ return final;
}
-vec3 gamma_correct(vec3 color) {
- return pow(color, vec3(1.0/2.2));
-}
diff --git a/src/update.c b/src/update.c
@@ -160,7 +160,7 @@ static void player_terrain_collision(struct terrain *terrain, struct entity *pla
if (!vec3_eq(player->node.pos, last_pos, 0.0001)) {
float player_z = player->node.pos[2];
- float terrain_z =
+ float terrain_z =
terrain->fn(terrain, player->node.pos[0], player->node.pos[1]) + 5.0;
float inset =
@@ -239,7 +239,7 @@ void resize_fbos(struct game *game, int width, int height) {
// TODO: match based on some real concept of time
static void day_night_cycle(float time, struct resources *res) {
- float val = time * 0.0005;
+ float val = time * 0.0001;
float intensity = max(0.0, vec3_dot(res->light_dir, V3(0.0, 0.0, 0.8)));
float light_pos[3];
@@ -263,8 +263,8 @@ static void day_night_cycle(float time, struct resources *res) {
/* vec3_normalize(res->light_intensity, res->light_intensity); */
res->light_dir[0] = 0.0;
- res->light_dir[1] = -sin(val);
- res->light_dir[2] = -cos(val);
+ res->light_dir[1] = sin(val);
+ res->light_dir[2] = cos(val) + 1.0;
vec3_normalize(res->light_dir, res->light_dir);