forked from servo/servo
/
ps_image_clip.fs.glsl
32 lines (26 loc) · 1.29 KB
/
ps_image_clip.fs.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#line 1
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 1;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
// We clamp the texture coordinate calculation here to the local rectangle boundaries,
// which makes the edge of the texture stretch instead of repeat.
vec2 pos_for_texture =
clamp(pos, vLocalRect.xy, vLocalRect.xy + vLocalRect.zw) - vLocalRect.xy;
#else
float alpha = 1;
vec2 local_pos = vLocalPos;
vec2 relative_pos_in_rect = vLocalPos - vLocalRect.xy;
#endif
alpha = min(alpha, do_clip(local_pos, vClipRect, vClipRadius));
// We calculate the particular tile this fragment belongs to, taking into
// account the spacing in between tiles. We only paint if our fragment does
// not fall into that spacing.
vec2 position_in_tile = mod(relative_pos_in_rect, vStretchSize + vTileSpacing);
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize);
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));
oFragColor = texture(sDiffuse, st) * vec4(1, 1, 1, alpha);
}