polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit c35a0b9e52d0cc84bfedaf75c1c3c9c9348288a7
parent 871f56ef81427b53c60097e49faaa210fb7f4054
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  9 Nov 2018 11:59:58 -0800

test some gamma correction/tonemapping

Diffstat:
Metc/shaders/lighting.glsl | 13++++++++++++-
Metc/shaders/test.f.glsl | 2+-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/etc/shaders/lighting.glsl b/etc/shaders/lighting.glsl @@ -19,11 +19,21 @@ vec3 gamma_correct(vec3 color) { return pow(color, vec3(1.0/2.2)); } +vec3 uncharted_tonemap(const vec3 x) { + const float A = 0.15; + const float B = 0.50; + const float C = 0.10; + const float D = 0.20; + const float E = 0.02; + const float F = 0.30; + return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F; +} + vec3 standard_light(vec3 color, vec4 position, vec4 normal) { // vec3 light_dir = vec3() const float pi = 3.14159265; const float shiny = 14.0; - const float exposure = 0.2; + const float exposure = 0.3; float ambient_str = 0.2; float spec_str = 0.8 * light_intensity; @@ -70,6 +80,7 @@ vec3 standard_light(vec3 color, vec4 position, vec4 normal) { // tone mapping // final = final / (vec3(1.0) - final * exposure); // final = final / (vec3(1.0) + color); + final = uncharted_tonemap(final); return final; } diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl @@ -31,5 +31,5 @@ void main() { color *= shadow_strength(v4_pos, v4_normal, vertex.shadow_coord); - frag_color = vec4(color, 1.0); + frag_color = vec4(gamma_correct(color), 1.0); }