mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-26 09:21:30 +11:00
65 lines
1.5 KiB
Plaintext
65 lines
1.5 KiB
Plaintext
#version 450
|
|
|
|
// license:BSD-3-Clause
|
|
// copyright-holders:W. M. Martinez
|
|
//-----------------------------------------------------------------------------
|
|
// Phosphor Chromaticity to sRGB Transform Effect
|
|
//-----------------------------------------------------------------------------
|
|
|
|
layout(push_constant) uniform Push
|
|
{
|
|
vec4 SourceSize;
|
|
vec4 OriginalSize;
|
|
vec4 OutputSize;
|
|
uint FrameCount;
|
|
} params;
|
|
|
|
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;
|
|
|
|
#define DiffuseSampler Source
|
|
#define mul(a,b) (b*a)
|
|
|
|
const vec3 YGain = vec3(0.2126, 0.7152, 0.0722);
|
|
const vec2 ChromaA = vec2(0.630, 0.340);
|
|
const vec2 ChromaB = vec2(0.310, 0.595);
|
|
const vec2 ChromaC = vec2(0.155, 0.070);
|
|
|
|
const mat3 XYZ_TO_sRGB = mat3(
|
|
3.2406, -1.5372, -0.4986,
|
|
-0.9689, 1.8758, 0.0415,
|
|
0.0557, -0.2040, 1.0570);
|
|
|
|
void main()
|
|
{
|
|
vec4 cin = texture(DiffuseSampler, vTexCoord);
|
|
vec4 cout = vec4(0.0, 0.0, 0.0, cin.a);
|
|
mat3x2 xy = { ChromaA, ChromaB, ChromaC };
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
float Y = YGain[i] * cin[i];
|
|
float X = xy[i].x * (Y / xy[i].y);
|
|
float Z = (1.0 - xy[i].x - xy[i].y) * (Y / xy[i].y);
|
|
cout.rgb += mul(XYZ_TO_sRGB, vec3(X, Y, Z));
|
|
}
|
|
FragColor = cout;
|
|
}
|