medfall

A super great game engine
Log | Files | Refs

commit e576908af859079ca534144a7840c5213a58dc96
parent 52fbce5867030fe382f7fc4ecda3ae465f8c80b5
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 29 Oct 2017 09:36:55 +0200

Explicit linear -> sRGB in shaders. No more GL_FRAMEBUFFER_SRGB

Diffstat:
gl.cc | 4----
shaders/common.glsl | 14++++++++++++++
shaders/flat_vertex_colours.glsl | 2+-
shaders/shadowed_vertex_colours.glsl | 2+-
shaders/skybox.glsl | 2+-
shaders/terrain.glsl | 2+-
shaders/tree.glsl | 2+-
7 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gl.cc b/gl.cc @@ -246,10 +246,6 @@ GLFWwindow * gl_init( WindowType window_type ) { glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); - if( window_type == WINDOW_GAME ) { - glEnable( GL_FRAMEBUFFER_SRGB ); - } - return window; } diff --git a/shaders/common.glsl b/shaders/common.glsl @@ -29,3 +29,17 @@ float dot_sat( vec3 a, vec3 b ) { vec3 reinhard_tonemap( vec3 c ) { return c / ( c + vec3( 1.0 ) ); } + +float linear_to_srgb( float linear ) { + if( linear <= 0.0031308 ) + return 12.92 * linear; + return 1.055 * pow( linear, 1.0 / 2.4 ) - 0.055; +} + +vec3 linear_to_srgb( vec3 linear ) { + return vec3( linear_to_srgb( linear.r ), linear_to_srgb( linear.g ), linear_to_srgb( linear.b ) ); +} + +vec4 linear_to_srgb( vec4 linear ) { + return vec4( linear_to_srgb( linear.rgb ), linear.a ); +} diff --git a/shaders/flat_vertex_colours.glsl b/shaders/flat_vertex_colours.glsl @@ -22,7 +22,7 @@ in vec3 frag_colour; out vec4 screen_colour; void main() { - screen_colour = vec4( frag_colour, 1.0 ); + screen_colour = vec4( linear_to_srgb( frag_colour ), 1.0 ); } #endif diff --git a/shaders/shadowed_vertex_colours.glsl b/shaders/shadowed_vertex_colours.glsl @@ -87,7 +87,7 @@ void main() { vec3 ambient = vec3( 0.03 ) * v2f.colour; vec3 Lo = cook_torrance_brdf( to_camera, v2f.position, v2f.normal, light_pos, light_colour, v2f.colour, 0.75, 0.0 ); - screen_colour = vec4( reinhard_tonemap( ambient + Lo * shadow + noise ), 1.0 ); + screen_colour = vec4( linear_to_srgb( reinhard_tonemap( ambient + Lo * shadow + noise ) ), 1.0 ); } #endif diff --git a/shaders/skybox.glsl b/shaders/skybox.glsl @@ -43,7 +43,7 @@ void main() { vec3 dither_noise = texture( blue_noise, gl_FragCoord.xy / textureSize( blue_noise, 0 ) ).xxx; dither_noise = ( dither_noise - vec3( 0.5 ) ) / 128.0; - colour = vec4( saturate( R + dither_noise ), 1.0 ); + colour = vec4( linear_to_srgb( saturate( R + dither_noise ) ), 1.0 ); } #endif diff --git a/shaders/terrain.glsl b/shaders/terrain.glsl @@ -97,7 +97,7 @@ void main() { vec3 dither_noise = texture( blue_noise, gl_FragCoord.xy / textureSize( blue_noise, 0 ) ).xxx; dither_noise = ( dither_noise - vec3( 0.5 ) ) / 128.0; - colour = vec4( mix( c, fog_colour, fog_t ) + dither_noise, 1.0 ); + colour = vec4( linear_to_srgb( mix( c, fog_colour, fog_t ) + dither_noise ), 1.0 ); } #endif diff --git a/shaders/tree.glsl b/shaders/tree.glsl @@ -50,7 +50,7 @@ void main() { float fog_distance_bias = 100.0; float fog_t = 1.0 - exp( -fog_strength * max( ( length( v2f.view_position ) - fog_distance_bias ), 0.0 ) ); - screen_colour = vec4( mix( c, fog_colour, fog_t ), 1.0 ); + screen_colour = vec4( linear_to_srgb( mix( c, fog_colour, fog_t ) ), 1.0 ); } #endif