Merge pull request #48 from rz5/master

(glow) Enforce the R8G8B8A8_SRGB format from within the shaders
This commit is contained in:
hizzlekizzle 2016-12-08 19:43:54 -06:00 committed by GitHub
commit f029113ceb
8 changed files with 428 additions and 422 deletions

View file

@ -1,45 +1,46 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "blur_params.inc"
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
void main()
{
vec3 col = vec3(0.0);
float dx = 4.0 * global.SourceSize.z; // Mipmapped
float k_total = 0.0;
for (int i = -TAPS; i <= TAPS; i++)
{
float k = kernel(i);
k_total += k;
col += k * texture(Source, vTexCoord + vec2(float(i) * dx, 0.0)).rgb;
}
FragColor = vec4(col / k_total, 1.0);
}
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "blur_params.inc"
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
void main()
{
vec3 col = vec3(0.0);
float dx = 4.0 * global.SourceSize.z; // Mipmapped
float k_total = 0.0;
for (int i = -TAPS; i <= TAPS; i++)
{
float k = kernel(i);
k_total += k;
col += k * texture(Source, vTexCoord + vec2(float(i) * dx, 0.0)).rgb;
}
FragColor = vec4(col / k_total, 1.0);
}

View file

@ -1,45 +1,45 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "blur_params.inc"
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
void main()
{
vec3 col = vec3(0.0);
float dy = global.SourceSize.w;
float k_total = 0.0;
for (int i = -TAPS; i <= TAPS; i++)
{
float k = kernel(i);
k_total += k;
col += k * texture(Source, vTexCoord + vec2(0.0, float(i) * dy)).rgb;
}
FragColor = vec4(col / k_total, 1.0);
}
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "blur_params.inc"
#define kernel(x) exp(-GLOW_FALLOFF * (x) * (x))
void main()
{
vec3 col = vec3(0.0);
float dy = global.SourceSize.w;
float k_total = 0.0;
for (int i = -TAPS; i <= TAPS; i++)
{
float k = kernel(i);
k_total += k;
col += k * texture(Source, vTexCoord + vec2(0.0, float(i) * dy)).rgb;
}
FragColor = vec4(col / k_total, 1.0);
}

View file

@ -1,54 +1,55 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord.x * global.SourceSize.x;
data_one = global.SourceSize.z;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define INV_SQRT_2_PI 0.38 // Doesn't have to be accurate.
#define HORIZ_GAUSS_WIDTH 0.5
void main()
{
float texel = floor(data_pix_no);
float phase = data_pix_no - texel;
float base_phase = phase.x - 0.5;
vec2 tex = vec2((texel + 0.5) * global.SourceSize.z, vTexCoord.y);
vec3 col = vec3(0.0);
for (int i = -2; i <= 2; i++)
{
float phase = base_phase - float(i);
float g = INV_SQRT_2_PI * exp(-0.5 * phase * phase / (HORIZ_GAUSS_WIDTH * HORIZ_GAUSS_WIDTH)) / HORIZ_GAUSS_WIDTH;
col += texture(Source, tex + vec2(float(i) * data_one, 0.0)).rgb * g;
}
FragColor = vec4(col, 1.0);
}
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord.x * global.SourceSize.x;
data_one = global.SourceSize.z;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define INV_SQRT_2_PI 0.38 // Doesn't have to be accurate.
#define HORIZ_GAUSS_WIDTH 0.5
void main()
{
float texel = floor(data_pix_no);
float phase = data_pix_no - texel;
float base_phase = phase.x - 0.5;
vec2 tex = vec2((texel + 0.5) * global.SourceSize.z, vTexCoord.y);
vec3 col = vec3(0.0);
for (int i = -2; i <= 2; i++)
{
float phase = base_phase - float(i);
float g = INV_SQRT_2_PI * exp(-0.5 * phase * phase / (HORIZ_GAUSS_WIDTH * HORIZ_GAUSS_WIDTH)) / HORIZ_GAUSS_WIDTH;
col += texture(Source, tex + vec2(float(i) * data_one, 0.0)).rgb * g;
}
FragColor = vec4(col, 1.0);
}

View file

@ -1,77 +1,78 @@
#version 450
layout(push_constant) uniform Push
{
float BOOST;
} param;
#pragma parameter BOOST "Color Boost" 1.0 0.5 1.5 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec2 data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord * global.SourceSize.xy - vec2(0.0, 0.5);
data_one = global.SourceSize.w;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define CRT_GEOM_BEAM 1
vec3 beam(vec3 color, float dist)
{
#if CRT_GEOM_BEAM
vec3 wid = 2.0 + 2.0 * pow(color, vec3(4.0));
vec3 weights = vec3(abs(dist) * 3.333333333);
return 2.0 * color * exp(-pow(weights * inversesqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
#else
float reciprocal_width = 4.0;
vec3 x = dist * reciprocal_width;
return 2.0 * color * exp(-0.5 * x * x) * reciprocal_width;
#endif
}
void main()
{
vec2 texel = floor(data_pix_no);
float phase = data_pix_no.y - texel.y;
vec2 tex = vec2(texel + 0.5) * global.SourceSize.zw;
vec3 top = texture(Source, tex + vec2(0.0, 0 * data_one)).rgb;
vec3 bottom = texture(Source, tex + vec2(0.0, 1 * data_one)).rgb;
float dist0 = phase;
float dist1 = 1.0 - phase;
vec3 scanline = vec3(0.0);
scanline += beam(top, dist0);
scanline += beam(bottom, dist1);
FragColor = vec4(param.BOOST * scanline * 0.869565217391304, 1.0);
}
#version 450
layout(push_constant) uniform Push
{
float BOOST;
} param;
#pragma parameter BOOST "Color Boost" 1.0 0.5 1.5 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec2 data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord * global.SourceSize.xy - vec2(0.0, 0.5);
data_one = global.SourceSize.w;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define CRT_GEOM_BEAM 1
vec3 beam(vec3 color, float dist)
{
#if CRT_GEOM_BEAM
vec3 wid = 2.0 + 2.0 * pow(color, vec3(4.0));
vec3 weights = vec3(abs(dist) * 3.333333333);
return 2.0 * color * exp(-pow(weights * inversesqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
#else
float reciprocal_width = 4.0;
vec3 x = dist * reciprocal_width;
return 2.0 * color * exp(-0.5 * x * x) * reciprocal_width;
#endif
}
void main()
{
vec2 texel = floor(data_pix_no);
float phase = data_pix_no.y - texel.y;
vec2 tex = vec2(texel + 0.5) * global.SourceSize.zw;
vec3 top = texture(Source, tex + vec2(0.0, 0 * data_one)).rgb;
vec3 bottom = texture(Source, tex + vec2(0.0, 1 * data_one)).rgb;
float dist0 = phase;
float dist1 = 1.0 - phase;
vec3 scanline = vec3(0.0);
scanline += beam(top, dist0);
scanline += beam(bottom, dist1);
FragColor = vec4(param.BOOST * scanline * 0.869565217391304, 1.0);
}

View file

@ -1,66 +1,67 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord.x * global.SourceSize.x;
data_one = global.SourceSize.z;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define PI 3.14159265359
float sinc(float x)
{
if (abs(x) < 0.001)
return 1.0;
x *= PI;
return sin(x) / x;
}
#define BOOST 1.0
void main()
{
float texel = floor(data_pix_no);
float phase = data_pix_no - texel;
float base_phase = phase - 0.5;
vec2 tex = vec2((texel + 0.5) * global.SourceSize.z, vTexCoord.y);
vec3 col = vec3(0.0);
for (int i = -2; i <= 2; i++)
{
float phase = base_phase - float(i);
if (abs(phase) < 2.0)
{
float g = BOOST * sinc(phase) * sinc(0.5 * phase);
col += texture(Source, tex + vec2(float(i) * data_one, 0.0)).rgb * g;
}
}
FragColor = vec4(col, 1.0);
}
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float data_pix_no;
layout(location = 2) out float data_one;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
data_pix_no = vTexCoord.x * global.SourceSize.x;
data_one = global.SourceSize.z;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float data_pix_no;
layout(location = 2) in float data_one;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define PI 3.14159265359
float sinc(float x)
{
if (abs(x) < 0.001)
return 1.0;
x *= PI;
return sin(x) / x;
}
#define BOOST 1.0
void main()
{
float texel = floor(data_pix_no);
float phase = data_pix_no - texel;
float base_phase = phase - 0.5;
vec2 tex = vec2((texel + 0.5) * global.SourceSize.z, vTexCoord.y);
vec3 col = vec3(0.0);
for (int i = -2; i <= 2; i++)
{
float phase = base_phase - float(i);
if (abs(phase) < 2.0)
{
float g = BOOST * sinc(phase) * sinc(0.5 * phase);
col += texture(Source, tex + vec2(float(i) * data_one, 0.0)).rgb * g;
}
}
FragColor = vec4(col, 1.0);
}

View file

@ -1,39 +1,40 @@
#version 450
layout(push_constant) uniform Push
{
float INPUT_GAMMA;
} param;
#pragma parameter INPUT_GAMMA "Input Gamma" 2.4 2.0 2.6 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 color = texture(Source, vTexCoord).rgb;
FragColor = vec4(pow(color, vec3(param.INPUT_GAMMA)), 1.0);
}
#version 450
layout(push_constant) uniform Push
{
float INPUT_GAMMA;
} param;
#pragma parameter INPUT_GAMMA "Input Gamma" 2.4 2.0 2.6 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 color = texture(Source, vTexCoord).rgb;
FragColor = vec4(pow(color, vec3(param.INPUT_GAMMA)), 1.0);
}

View file

@ -1,54 +1,54 @@
#version 450
layout(push_constant) uniform Push
{
float BLOOM_STRENGTH;
float OUTPUT_GAMMA;
} param;
#pragma parameter BLOOM_STRENGTH "Glow Strength" 0.45 0.0 0.8 0.05
#pragma parameter OUTPUT_GAMMA "Monitor Gamma" 2.2 1.8 2.6 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 CRTPassSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source;
layout(set = 0, binding = 2) uniform sampler2D CRTPass;
// For debugging
#define BLOOM_ONLY 0
#define CRT_PASS CRTPass
void main()
{
#if BLOOM_ONLY
vec3 source = BLOOM_STRENGTH * texture(Source, vTexCoord).rgb;
#else
vec3 source = 1.15 * texture(CRT_PASS, vTexCoord).rgb;
vec3 bloom = texture(Source, vTexCoord).rgb;
source += param.BLOOM_STRENGTH * bloom;
#endif
FragColor = vec4(pow(clamp(source, 0.0, 1.0), vec3(1.0 / param.OUTPUT_GAMMA)), 1.0);
}
#version 450
layout(push_constant) uniform Push
{
float BLOOM_STRENGTH;
float OUTPUT_GAMMA;
} param;
#pragma parameter BLOOM_STRENGTH "Glow Strength" 0.45 0.0 0.8 0.05
#pragma parameter OUTPUT_GAMMA "Monitor Gamma" 2.2 1.8 2.6 0.02
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
vec4 CRTPassSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source;
layout(set = 0, binding = 2) uniform sampler2D CRTPass;
// For debugging
#define BLOOM_ONLY 0
#define CRT_PASS CRTPass
void main()
{
#if BLOOM_ONLY
vec3 source = BLOOM_STRENGTH * texture(Source, vTexCoord).rgb;
#else
vec3 source = 1.15 * texture(CRT_PASS, vTexCoord).rgb;
vec3 bloom = texture(Source, vTexCoord).rgb;
source += param.BLOOM_STRENGTH * bloom;
#endif
FragColor = vec4(pow(clamp(source, 0.0, 1.0), vec3(1.0 / param.OUTPUT_GAMMA)), 1.0);
}

View file

@ -1,42 +1,43 @@
#version 450
layout(push_constant) uniform Push
{
float GLOW_WHITEPOINT;
float GLOW_ROLLOFF;
} param;
#pragma parameter GLOW_WHITEPOINT "Glow Whitepoint" 1.0 0.5 1.1 0.02
#pragma parameter GLOW_ROLLOFF "Glow Rolloff" 3.0 1.2 6.0 0.1
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 color = 1.15 * texture(Source, vTexCoord).rgb;
vec3 factor = clamp(color / param.GLOW_WHITEPOINT, 0.0, 1.0);
FragColor = vec4(pow(factor, vec3(param.GLOW_ROLLOFF)), 1.0);
}
#version 450
layout(push_constant) uniform Push
{
float GLOW_WHITEPOINT;
float GLOW_ROLLOFF;
} param;
#pragma parameter GLOW_WHITEPOINT "Glow Whitepoint" 1.0 0.5 1.1 0.02
#pragma parameter GLOW_ROLLOFF "Glow Rolloff" 3.0 1.2 6.0 0.1
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
#pragma format R8G8B8A8_SRGB
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 color = 1.15 * texture(Source, vTexCoord).rgb;
vec3 factor = clamp(color / param.GLOW_WHITEPOINT, 0.0, 1.0);
FragColor = vec4(pow(factor, vec3(param.GLOW_ROLLOFF)), 1.0);
}