slang-shaders/misc/shaders/yiq-hue-adjustment.slang

54 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2017-04-09 06:54:27 +10:00
#version 450
/*
2017-04-09 07:01:17 +10:00
YIQ Hue Adjustment Shader
Ported from https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Shaders/Builtin/Functions/hue.glsl
2017-04-09 06:54:27 +10:00
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
2017-04-09 07:01:17 +10:00
float hue_degrees;
2017-04-09 06:54:27 +10:00
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma parameter hue_degrees "Hue" 0.0 -360.0 360.0 1.0
#define M_PI 3.1415926535897932384626433832795
#include "../../include/colorspace-tools.h"
2017-04-09 06:54:27 +10:00
#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 rgb = texture(Source, vTexCoord).rgb;
vec3 yiq = RGBtoYIQ(rgb);
float hue_radians = params.hue_degrees * (M_PI / 180.0);
float hue = atan(yiq.z, yiq.y) + hue_radians;
float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);
vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));
FragColor = vec4(YIQtoRGB(color).rgb, 1.0);
}