From 82f00237af1cdcd0fa5980b521618aa046a06b76 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 13 Oct 2020 22:47:52 +1000 Subject: [PATCH] Data: Add simple-brightness and simple-gamma shaders --- data/shaders/simple-brightness.glsl | 36 +++++++++++++++++++++++++++++ data/shaders/simple-gamma.glsl | 33 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 data/shaders/simple-brightness.glsl create mode 100644 data/shaders/simple-gamma.glsl diff --git a/data/shaders/simple-brightness.glsl b/data/shaders/simple-brightness.glsl new file mode 100644 index 000000000..5451a0457 --- /dev/null +++ b/data/shaders/simple-brightness.glsl @@ -0,0 +1,36 @@ +/* +[configuration] + +[OptionRangeFloat] +GUIName = Brightness Scale +OptionName = BRIGHTNESS_SCALE +MinValue = 0.1 +MaxValue = 5.0 +StepAmount = 0.1 +DefaultValue = 1.0 + +[/configuration] +*/ + +void main() +{ + float4 color = Sample(); + float brightness_scale = GetOption(BRIGHTNESS_SCALE); + + // rgb->yuv + float3 yuv; + yuv.r = dot(color.rgb, float3(0.299f, 0.587f, 0.114f)); + yuv.g = dot(color.rgb, float3(-0.14713f, -0.28886f, 0.436f)); + yuv.b = dot(color.rgb, float3(0.615f, -0.51499f, -0.10001f)); + + // apply brightness to y + yuv.r = saturate(yuv.r * brightness_scale); + + // yuv->rgb + color.r = dot(yuv, float3(1.0f, 0.0f, 1.13983f)); + color.g = dot(yuv, float3(1.0f, -0.39465f, -0.58060f)); + color.b = dot(yuv, float3(1.0f, 2.03211f, 0.0f)); + color.rgb = saturate(color.rgb); + + SetOutput(saturate(color)); +} diff --git a/data/shaders/simple-gamma.glsl b/data/shaders/simple-gamma.glsl new file mode 100644 index 000000000..bb07fc63d --- /dev/null +++ b/data/shaders/simple-gamma.glsl @@ -0,0 +1,33 @@ +/* +[configuration] + +[OptionRangeFloat] +GUIName = Gamma In +OptionName = GAMMA_IN +MinValue = 0.1 +MaxValue = 10.0 +StepAmount = 0.1 +DefaultValue = 2.2 + +[OptionRangeFloat] +GUIName = Gamma Out +OptionName = GAMMA_OUT +MinValue = 0.1 +MaxValue = 10.0 +StepAmount = 0.1 +DefaultValue = 2.2 + +[/configuration] +*/ + +void main() +{ + float4 color = Sample(); + float gamma_in = GetOption(GAMMA_IN); + float gamma_out = 1.0f / GetOption(GAMMA_OUT); + + color.rgb = pow(color.rgb, float3(gamma_in, gamma_in, gamma_in)); + color.rgb = pow(color.rgb, float3(gamma_out, gamma_out, gamma_out)); + + SetOutput(saturate(color)); +}