slang-shaders/crt/shaders/guest/d65-d50.slang

88 lines
2 KiB
Plaintext
Raw Normal View History

#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
2019-05-04 03:31:31 +10:00
float WP;
2019-05-07 23:16:43 +10:00
float wp_saturation;
} params;
2019-05-04 03:31:31 +10:00
#pragma parameter WP "Color Temperature %" 0.0 -100.0 100.0 5.0
2019-05-07 23:16:43 +10:00
#pragma parameter wp_saturation "Saturation Adjustment" 1.0 0.0 2.0 0.05
2019-05-04 03:31:31 +10:00
#define WP params.WP
2019-05-07 23:16:43 +10:00
#define wp_saturation params.wp_saturation
2019-05-04 03:31:31 +10:00
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define TEX0 vTexCoord
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} 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;
2019-05-04 03:31:31 +10:00
const mat3 D65_to_XYZ = mat3 (
0.4306190, 0.2220379, 0.0201853,
0.3415419, 0.7066384, 0.1295504,
0.1783091, 0.0713236, 0.9390944);
2019-05-04 03:31:31 +10:00
const mat3 XYZ_to_D65 = mat3 (
3.0628971, -0.9692660, 0.0678775,
-1.3931791, 1.8760108, -0.2288548,
-0.4757517, 0.0415560, 1.0693490);
const mat3 D50_to_XYZ = mat3 (
0.4552773, 0.2323025, 0.0145457,
0.3675500, 0.7077956, 0.1049154,
0.1413926, 0.0599019, 0.7057489);
const mat3 XYZ_to_D50 = mat3 (
2.9603944, -0.9787684, 0.0844874,
-1.4678519, 1.9161415, -0.2545973,
-0.4685105, 0.0334540, 1.4216174);
void main()
{
2019-05-04 03:31:31 +10:00
vec3 color = COMPAT_TEXTURE(Source, TEX0.xy).rgb;
2019-05-07 23:16:43 +10:00
color = normalize(pow(color + 1e-4, vec3(wp_saturation)))*length(color);
2019-05-04 03:31:31 +10:00
float p = 2.4;
color = pow(color, vec3(p));
2019-05-04 03:31:31 +10:00
vec3 warmer = D50_to_XYZ*color;
warmer = XYZ_to_D65*warmer;
2019-05-04 03:31:31 +10:00
vec3 cooler = D65_to_XYZ*color;
cooler = XYZ_to_D50*cooler;
2019-05-04 03:31:31 +10:00
float m = abs(WP)/100.0;
vec3 comp = (WP < 0.0) ? cooler : warmer;
color = mix(color, comp, m);
color = pow(color, vec3(1.0/p));
FragColor = vec4(color,1.0);
}