[gtk/matthiasc/color-profiles: 23/32] ngl: Refactor shaders a bit




commit ec1290432eb026b02195e36ab51ff0f39e3acc65
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 2 09:31:12 2021 -0400

    ngl: Refactor shaders a bit
    
    We want to add more shaders using the same bits, so move
    the functions to the preamble.

 gsk/ngl/resources/linearize.glsl      | 21 ---------------------
 gsk/ngl/resources/postprocessing.glsl | 20 --------------------
 gsk/ngl/resources/preamble.glsl       | 23 ++++++++++++++++++++++-
 3 files changed, 22 insertions(+), 42 deletions(-)
---
diff --git a/gsk/ngl/resources/linearize.glsl b/gsk/ngl/resources/linearize.glsl
index 73806e156a..7ae1e6998c 100644
--- a/gsk/ngl/resources/linearize.glsl
+++ b/gsk/ngl/resources/linearize.glsl
@@ -11,27 +11,6 @@ void main() {
 // FRAGMENT_SHADER:
 // linearize.glsl
 
-float u_gamma = 2.2;
-
-vec4 gsk_unpremultiply(vec4 c)
-{
-  if (c.a != 0)
-    return vec4(c.rgb / c.a, c.a);
-  else
-    return c;
-}
-
-vec4 gsk_srgb_to_linear(vec4 srgb)
-{
-  vec3 linear_rgb = pow(srgb.rgb, vec3(u_gamma));
-  return vec4(linear_rgb, srgb.a);
-}
-
-vec4 gsk_linear_to_srgb(vec4 linear_rgba)
-{
-  vec3 srgb = pow(linear_rgba.rgb , vec3(1/u_gamma));
-  return vec4(srgb, linear_rgba.a);
-}
 void main() {
   vec4 diffuse = GskTexture(u_source, vUv);
 
diff --git a/gsk/ngl/resources/postprocessing.glsl b/gsk/ngl/resources/postprocessing.glsl
index 904da6ef2b..c381beccef 100644
--- a/gsk/ngl/resources/postprocessing.glsl
+++ b/gsk/ngl/resources/postprocessing.glsl
@@ -10,27 +10,7 @@ void main() {
 
 // FRAGMENT_SHADER:
 // postprocessing.glsl
-float u_gamma = 2.2;
 
-vec4 gsk_unpremultiply(vec4 c)
-{
-  if (c.a != 0)
-    return vec4(c.rgb / c.a, c.a);
-  else
-    return c;
-}
-
-vec4 gsk_srgb_to_linear(vec4 srgb)
-{
-  vec3 linear_rgb = pow(srgb.rgb, vec3(u_gamma));
-  return vec4(linear_rgb, srgb.a);
-}
-
-vec4 gsk_linear_to_srgb(vec4 linear_rgba)
-{
-  vec3 srgb = pow(linear_rgba.rgb , vec3(1/u_gamma));
-  return vec4(srgb, linear_rgba.a);
-}
 void main() {
   vec4 diffuse = GskTexture(u_source, vUv);
 
diff --git a/gsk/ngl/resources/preamble.glsl b/gsk/ngl/resources/preamble.glsl
index 8bc007ba67..0e5ebffc9e 100644
--- a/gsk/ngl/resources/preamble.glsl
+++ b/gsk/ngl/resources/preamble.glsl
@@ -44,10 +44,31 @@ gsk_get_bounds(vec4[3] data)
   return vec4(data[0].xy, data[0].xy + data[0].zw);
 }
 
-vec4 gsk_premultiply(vec4 c) {
+vec4 gsk_premultiply(vec4 c)
+{
   return vec4(c.rgb * c.a, c.a);
 }
 
+vec4 gsk_unpremultiply(vec4 c)
+{
+  if (c.a != 0)
+    return vec4(c.rgb / c.a, c.a);
+  else
+    return c;
+}
+
+vec4 gsk_srgb_to_linear(vec4 srgb)
+{
+  vec3 linear_rgb = pow(srgb.rgb, vec3(2.2));
+  return vec4(linear_rgb, srgb.a);
+}
+
+vec4 gsk_linear_to_srgb(vec4 linear_rgba)
+{
+  vec3 srgb = pow(linear_rgba.rgb , vec3(1/2.2));
+  return vec4(srgb, linear_rgba.a);
+}
+
 vec4 gsk_scaled_premultiply(vec4 c, float s) {
   // Fast version of gsk_premultiply(c) * s
   // 4 muls instead of 7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]