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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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