summaryrefslogtreecommitdiff
path: root/gsk/resources
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2018-01-08 18:59:01 +0100
committerTimm Bäder <mail@baedert.org>2018-01-08 19:23:06 +0100
commitbbf6e81c1f55d534ef20a2994a722fe4e0766d2f (patch)
treebd3671a31c37b69379c2a3cda8b8592cc90d447a /gsk/resources
parentcd2a53851b39fc1a97196aff031e6e6968abd885 (diff)
downloadgtk+-bbf6e81c1f55d534ef20a2994a722fe4e0766d2f.tar.gz
gl renderer: Fix shaders for gles
Remove uniform initializers, add casts to float, etc.
Diffstat (limited to 'gsk/resources')
-rw-r--r--gsk/resources/glsl/blur.fs.glsl8
-rw-r--r--gsk/resources/glsl/border.fs.glsl2
-rw-r--r--gsk/resources/glsl/cross_fade.fs.glsl2
-rw-r--r--gsk/resources/glsl/es2_common.fs.glsl98
-rw-r--r--gsk/resources/glsl/es2_common.vs.glsl5
-rw-r--r--gsk/resources/glsl/outset_shadow.fs.glsl6
6 files changed, 106 insertions, 15 deletions
diff --git a/gsk/resources/glsl/blur.fs.glsl b/gsk/resources/glsl/blur.fs.glsl
index 78107aa78b..19be916db1 100644
--- a/gsk/resources/glsl/blur.fs.glsl
+++ b/gsk/resources/glsl/blur.fs.glsl
@@ -1,5 +1,5 @@
-uniform float u_blur_radius = 40.0;
-uniform vec2 u_blur_size = vec2(393, 393);
+uniform float u_blur_radius;// = 40.0;
+uniform vec2 u_blur_size;// = vec2(393, 393);
float Gaussian (float sigma, float x) {
return exp ( - (x * x) / (2.0 * sigma * sigma));
@@ -18,11 +18,11 @@ vec4 blur_pixel (in vec2 uv) {
for (int y = -half_radius; y < half_radius; y ++) {
float fy = Gaussian (radius / 2.0, float(y));
- float offset_y = y * pixel_size_y;
+ float offset_y = float(y) * pixel_size_y;
for (int x = -half_radius; x < half_radius; x ++) {
float fx = Gaussian (radius / 2.0, float(x));
- float offset_x = x * pixel_size_x;
+ float offset_x = float(x) * pixel_size_x;
vec4 c = Texture(u_source, uv + vec2(offset_x, offset_y));
total += fx * fy;
diff --git a/gsk/resources/glsl/border.fs.glsl b/gsk/resources/glsl/border.fs.glsl
index 409c362737..59b1b816e5 100644
--- a/gsk/resources/glsl/border.fs.glsl
+++ b/gsk/resources/glsl/border.fs.glsl
@@ -1,4 +1,4 @@
-uniform vec4 u_color = vec4(1, 0, 1, 1);
+uniform vec4 u_color;// = vec4(1, 0, 1, 1);
uniform vec4 u_widths;
// For border we abuse, ehm, re-use, the global clip
diff --git a/gsk/resources/glsl/cross_fade.fs.glsl b/gsk/resources/glsl/cross_fade.fs.glsl
index a38b504a6c..8f0f4115f4 100644
--- a/gsk/resources/glsl/cross_fade.fs.glsl
+++ b/gsk/resources/glsl/cross_fade.fs.glsl
@@ -7,6 +7,6 @@ void main() {
vec4 source2 = Texture(u_source2, vUv); // end child
float p = u_progress;
- vec4 color = ((1 - p) * source1) + (p * source2);
+ vec4 color = ((1.0 - p) * source1) + (p * source2);
setOutputColor(color);
}
diff --git a/gsk/resources/glsl/es2_common.fs.glsl b/gsk/resources/glsl/es2_common.fs.glsl
index 4cbe57783c..0ed8df8692 100644
--- a/gsk/resources/glsl/es2_common.fs.glsl
+++ b/gsk/resources/glsl/es2_common.fs.glsl
@@ -1,17 +1,105 @@
precision mediump float;
-uniform mat4 uMVP;
-uniform sampler2D uSource;
-uniform sampler2D uMask;
-uniform float uAlpha;
+uniform sampler2D u_source;
+uniform sampler2D u_mask;
+uniform mat4 u_projection;
+uniform mat4 u_modelview;
+uniform float u_alpha;
uniform int uBlendMode;
+uniform vec4 u_viewport;
+
+// In GtkSnapshot coordinates
+uniform vec4 u_clip;
+uniform vec4 u_clip_corner_widths;
+uniform vec4 u_clip_corner_heights;
varying vec2 vUv;
+
+struct RoundedRect
+{
+ vec4 bounds;
+ vec4 corner_widths;
+ vec4 corner_heights;
+};
+
+float
+ellipsis_dist (vec2 p, vec2 radius)
+{
+ if (radius == vec2(0, 0))
+ return 0.0;
+
+ vec2 p0 = p / radius;
+ vec2 p1 = 2.0 * p0 / radius;
+
+ return (dot(p0, p0) - 1.0) / length (p1);
+}
+
+float
+ellipsis_coverage (vec2 point, vec2 center, vec2 radius)
+{
+ float d = ellipsis_dist (point - center, radius);
+ return clamp (0.5 - d, 0.0, 1.0);
+}
+
+float
+rounded_rect_coverage (RoundedRect r, vec2 p)
+{
+ if (p.x < r.bounds.x || p.y < r.bounds.y ||
+ p.x >= r.bounds.z || p.y >= r.bounds.w)
+ return 0.0;
+
+ vec2 rad_tl = vec2(r.corner_widths.x, r.corner_heights.x);
+ vec2 rad_tr = vec2(r.corner_widths.y, r.corner_heights.y);
+ vec2 rad_br = vec2(r.corner_widths.z, r.corner_heights.z);
+ vec2 rad_bl = vec2(r.corner_widths.w, r.corner_heights.w);
+
+ vec2 ref_tl = r.bounds.xy + vec2( r.corner_widths.x, r.corner_heights.x);
+ vec2 ref_tr = r.bounds.zy + vec2(-r.corner_widths.y, r.corner_heights.y);
+ vec2 ref_br = r.bounds.zw + vec2(-r.corner_widths.z, -r.corner_heights.z);
+ vec2 ref_bl = r.bounds.xw + vec2( r.corner_widths.w, -r.corner_heights.w);
+
+ float d_tl = ellipsis_coverage(p, ref_tl, rad_tl);
+ float d_tr = ellipsis_coverage(p, ref_tr, rad_tr);
+ float d_br = ellipsis_coverage(p, ref_br, rad_br);
+ float d_bl = ellipsis_coverage(p, ref_bl, rad_bl);
+
+ vec4 corner_coverages = 1.0 - vec4(d_tl, d_tr, d_br, d_bl);
+
+ bvec4 is_out = bvec4(p.x < ref_tl.x && p.y < ref_tl.y,
+ p.x > ref_tr.x && p.y < ref_tr.y,
+ p.x > ref_br.x && p.y > ref_br.y,
+ p.x < ref_bl.x && p.y > ref_bl.y);
+
+ return 1.0 - dot(vec4(is_out), corner_coverages);
+}
+
+RoundedRect
+rounded_rect_shrink (RoundedRect r, vec4 amount)
+{
+ vec4 new_bounds = r.bounds + vec4(1.0,1.0,-1.0,-1.0) * amount.wxyz;
+ vec4 new_widths = max (r.corner_widths - amount.wyyw, 0.0);
+ vec4 new_heights = max (r.corner_heights - amount.xxzz, 0.0);
+
+ return RoundedRect (new_bounds, new_widths, new_heights);
+}
+
vec4 Texture(sampler2D sampler, vec2 texCoords) {
return texture2D(sampler, texCoords);
}
void setOutputColor(vec4 color) {
- gl_FragColor = color;
+ vec4 clipBounds = u_clip;
+ vec4 f = gl_FragCoord;
+
+ f.x += u_viewport.x;
+ f.y = (u_viewport.y + u_viewport.w) - f.y;
+
+ clipBounds.z = clipBounds.x + clipBounds.z;
+ clipBounds.w = clipBounds.y + clipBounds.w;
+
+ RoundedRect r = RoundedRect(clipBounds, u_clip_corner_widths, u_clip_corner_heights);
+
+ gl_FragColor = color * rounded_rect_coverage(r, f.xy);
+ /*gl_FragColor = color;*/
}
diff --git a/gsk/resources/glsl/es2_common.vs.glsl b/gsk/resources/glsl/es2_common.vs.glsl
index 3db2e4dc07..c39fc444d9 100644
--- a/gsk/resources/glsl/es2_common.vs.glsl
+++ b/gsk/resources/glsl/es2_common.vs.glsl
@@ -1,4 +1,7 @@
-uniform mat4 uMVP;
+precision mediump float;
+
+uniform mat4 u_projection;
+uniform mat4 u_modelview;
attribute vec2 aPosition;
attribute vec2 aUv;
diff --git a/gsk/resources/glsl/outset_shadow.fs.glsl b/gsk/resources/glsl/outset_shadow.fs.glsl
index 63351b06d7..9a97c34e1b 100644
--- a/gsk/resources/glsl/outset_shadow.fs.glsl
+++ b/gsk/resources/glsl/outset_shadow.fs.glsl
@@ -1,6 +1,6 @@
uniform vec4 u_outline;
-uniform vec4 u_corner_widths = vec4(0, 0, 0, 0);
-uniform vec4 u_corner_heights = vec4(0, 0, 0, 0);
+uniform vec4 u_corner_widths;//= vec4(0, 0, 0, 0);
+uniform vec4 u_corner_heights;// = vec4(0, 0, 0, 0);
void main() {
vec4 f = gl_FragCoord;
@@ -11,6 +11,6 @@ void main() {
RoundedRect outline = RoundedRect(vec4(u_outline.xy, u_outline.xy + u_outline.zw), u_corner_widths, u_corner_heights);
vec4 color = Texture(u_source, vUv);
- color = color * (1 - clamp(rounded_rect_coverage (outline, f.xy), 0, 1));
+ color = color * (1.0 - clamp(rounded_rect_coverage (outline, f.xy), 0.0, 1.0));
setOutputColor(color * u_alpha);
}