16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 03:09:18 +02:00

fixes, configurable framebuffers quality

This commit is contained in:
milek7
2018-10-14 21:52:37 +02:00
parent d8b902a364
commit dd0a9b1d77
24 changed files with 289 additions and 141 deletions

View File

@@ -7,11 +7,16 @@ in vec2 f_coord;
uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(tex1, f_coord);
#if POSTFX_ENABLED
gl_FragData[0] = tex_color * param[0];
#else
gl_FragData[0] = tonemap(tex_color * param[0]);
#endif
#if MOTIONBLUR_ENABLED
gl_FragData[1] = vec4(0.0f);
#endif

View File

@@ -3,10 +3,15 @@
in vec3 f_color;
#include <common>
#include <tonemapping.glsl>
void main()
{
#if POSTFX_ENABLED
gl_FragData[0] = vec4(f_color, 1.0f);
#else
gl_FragData[0] = tonemap(vec4(f_color, 1.0f));
#endif
#if MOTIONBLUR_ENABLED
gl_FragData[1] = vec4(0.0f);
#endif

View File

@@ -1,6 +1,7 @@
#version 330
#include <common>
#include <tonemapping.glsl>
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
@@ -12,7 +13,12 @@ void main()
float dist = sqrt(x * x + y * y);
if (dist > 0.5f)
discard;
gl_FragData[0] = vec4(param[0].rgb * emission, mix(param[0].a, 0.0f, dist * 2.0f));
vec4 color = vec4(param[0].rgb * emission, mix(param[0].a, 0.0f, dist * 2.0f));
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;

View File

@@ -8,11 +8,16 @@ in vec4 f_pos;
uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(tex1, f_coord);
#if POSTFX_ENABLED
gl_FragData[0] = tex_color * param[0];
#else
gl_FragData[0] = tonemap(tex_color * param[0]);
#endif
#if MOTIONBLUR_ENABLED
gl_FragData[1] = vec4(0.0f);
#endif

View File

@@ -24,6 +24,7 @@ uniform samplerCube envmap;
#endif
#include <light_common.glsl>
#include <tonemapping.glsl>
void main()
{
@@ -61,7 +62,12 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
vec4 color = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;

View File

@@ -27,6 +27,7 @@ uniform samplerCube envmap;
#endif
#include <light_common.glsl>
#include <tonemapping.glsl>
void main()
{
@@ -67,7 +68,12 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
vec4 color = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{

View File

@@ -1,10 +1,16 @@
#version 330
#include <common>
#include <tonemapping.glsl>
void main()
{
gl_FragData[0] = vec4(1.0, 0.0, 1.0, 1.0);
vec4 color = vec4(1.0, 0.0, 1.0, 1.0);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
gl_FragData[1] = vec4(0.0f);
#endif

View File

@@ -32,6 +32,7 @@ uniform samplerCube envmap;
#define NORMALMAP
#include <light_common.glsl>
#include <tonemapping.glsl>
void main()
{
@@ -72,8 +73,12 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
vec4 color = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;

View File

@@ -30,6 +30,7 @@ uniform samplerCube envmap;
#endif
#include <light_common.glsl>
#include <tonemapping.glsl>
void main()
{
@@ -70,8 +71,12 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
vec4 color = vec4(apply_fog(result * tex_color.rgb), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;

View File

@@ -1,6 +1,7 @@
#version 330
#include <common>
#include <tonemapping.glsl>
flat in vec3 f_normal_raw;
@@ -12,8 +13,13 @@ void main()
if (dist2 > 0.5f * 0.5f)
discard;
// color data is shared with normals, ugh
gl_FragData[0] = vec4(f_normal_raw.bgr, 1.0f);
// color data space is shared with normals, ugh
vec4 color = vec4(pow(f_normal_raw.bgr, vec3(2.2)), 1.0f);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
gl_FragData[1] = vec4(0.0f);
#endif

View File

@@ -6,44 +6,13 @@ in vec2 f_coords;
#texture (tex1, 0, RGB)
uniform sampler2D tex1;
vec3 reinhard(vec3 x)
{
return x / (x + vec3(1.0));
}
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x)
{
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return (x*(a*x+b))/(x*(c*x+d)+e);
}
// https://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting
vec3 filmicF(vec3 x)
{
float A = 0.22f;
float B = 0.30f;
float C = 0.10f;
float D = 0.20f;
float E = 0.01f;
float F = 0.30f;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F)) - E/F;
}
vec3 filmic(vec3 x)
{
return filmicF(x) / filmicF(vec3(11.2f));
}
#include <tonemapping.glsl>
void main()
{
vec2 texcoord = f_coords;
vec3 hdr_color = texture(tex1, texcoord).xyz;
vec3 mapped = ACESFilm(hdr_color);
vec3 mapped = tonemap(hdr_color);
gl_FragColor = vec4(mapped, 1.0);
}

View File

@@ -10,10 +10,17 @@ uniform sampler2D tex1;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(tex1, vec2(f_coord.x, f_coord.y + param[1].x));
gl_FragData[0] = tex_color * param[0];
vec4 color = tex_color * param[0];
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;

42
shaders/tonemapping.glsl Normal file
View File

@@ -0,0 +1,42 @@
vec3 reinhard(vec3 x)
{
return x / (x + vec3(1.0));
}
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x)
{
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return (x*(a*x+b))/(x*(c*x+d)+e);
}
// https://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting
vec3 filmicF(vec3 x)
{
float A = 0.22f;
float B = 0.30f;
float C = 0.10f;
float D = 0.20f;
float E = 0.01f;
float F = 0.30f;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F)) - E/F;
}
vec3 filmic(vec3 x)
{
return filmicF(x) / filmicF(vec3(11.2f));
}
vec3 tonemap(vec3 x)
{
return ACESFilm(x);
}
vec4 tonemap(vec4 x)
{
return vec4(tonemap(x.rgb), x.a);
}

View File

@@ -5,9 +5,17 @@
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <tonemapping.glsl>
void main()
{
gl_FragData[0] = param[0];
vec4 color = vec4(pow(param[0].rgb, vec3(2.2)), param[0].a);
#if POSTFX_ENABLED
gl_FragData[0] = color;
#else
gl_FragData[0] = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;