mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Copy updated WR shaders.
This commit is contained in:
parent
a22913569c
commit
3543cc6098
7 changed files with 58 additions and 12 deletions
|
@ -218,18 +218,19 @@ void do_clip(vec2 pos, vec4 clip_rect, vec4 radius) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool point_in_rect(vec2 p, vec2 p0, vec2 p1) {
|
float squared_distance_from_rect(vec2 p, vec2 origin, vec2 size) {
|
||||||
return p.x >= p0.x &&
|
vec2 clamped = clamp(p, origin, origin + size);
|
||||||
p.y >= p0.y &&
|
return distance(clamped, p);
|
||||||
p.x <= p1.x &&
|
|
||||||
p.y <= p1.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 init_transform_fs(vec3 local_pos, vec4 local_rect) {
|
vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha) {
|
||||||
|
fragment_alpha = 1.0;
|
||||||
vec2 pos = local_pos.xy / local_pos.z;
|
vec2 pos = local_pos.xy / local_pos.z;
|
||||||
|
|
||||||
if (!point_in_rect(pos, local_rect.xy, local_rect.xy + local_rect.zw)) {
|
float squared_distance = squared_distance_from_rect(pos, local_rect.xy, local_rect.zw);
|
||||||
discard;
|
if (squared_distance != 0) {
|
||||||
|
float delta = length(fwidth(local_pos.xy));
|
||||||
|
fragment_alpha = smoothstep(1.0, 0.0, squared_distance / delta * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
|
|
|
@ -1,8 +1,21 @@
|
||||||
|
#line 1
|
||||||
|
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
vec2 st = vTextureOffset + vTextureSize * fract(vUv);
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
float alpha = 0;
|
||||||
|
vec2 pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
|
||||||
|
vec2 uv = (pos - vLocalRect.xy) / vStretchSize;
|
||||||
|
#else
|
||||||
|
vec2 uv = vUv;
|
||||||
|
#endif
|
||||||
|
vec2 st = vTextureOffset + vTextureSize * fract(uv);
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
oFragColor = vec4(1, 1, 1, alpha) * texture(sDiffuse, st);
|
||||||
|
#else
|
||||||
oFragColor = texture(sDiffuse, st);
|
oFragColor = texture(sDiffuse, st);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
varying vec2 vUv; // Location within the CSS box to draw.
|
|
||||||
flat varying vec2 vTextureOffset; // Offset of this image into the texture atlas.
|
flat varying vec2 vTextureOffset; // Offset of this image into the texture atlas.
|
||||||
flat varying vec2 vTextureSize; // Size of the image in the texture atlas.
|
flat varying vec2 vTextureSize; // Size of the image in the texture atlas.
|
||||||
|
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
varying vec3 vLocalPos;
|
||||||
|
flat varying vec4 vLocalRect;
|
||||||
|
flat varying vec2 vStretchSize;
|
||||||
|
#else
|
||||||
|
varying vec2 vUv; // Location within the CSS box to draw.
|
||||||
|
#endif
|
||||||
|
|
|
@ -15,10 +15,18 @@ layout(std140) uniform Items {
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
Image image = images[gl_InstanceID];
|
Image image = images[gl_InstanceID];
|
||||||
|
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
TransformVertexInfo vi = write_transform_vertex(image.info);
|
||||||
|
vLocalRect = image.info.local_rect;
|
||||||
|
vLocalPos = vi.local_pos;
|
||||||
|
vStretchSize = image.stretch_size.xy;
|
||||||
|
#else
|
||||||
VertexInfo vi = write_vertex(image.info);
|
VertexInfo vi = write_vertex(image.info);
|
||||||
|
vUv = (vi.local_clamped_pos - vi.local_rect.p0) / image.stretch_size.xy;
|
||||||
|
#endif
|
||||||
|
|
||||||
// vUv will contain how many times this image has wrapped around the image size.
|
// vUv will contain how many times this image has wrapped around the image size.
|
||||||
vUv = (vi.local_clamped_pos - vi.local_rect.p0) / image.stretch_size.xy;
|
|
||||||
vTextureSize = image.st_rect.zw - image.st_rect.xy;
|
vTextureSize = image.st_rect.zw - image.st_rect.xy;
|
||||||
vTextureOffset = image.st_rect.xy;
|
vTextureOffset = image.st_rect.xy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,11 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
float alpha = 0;
|
||||||
|
init_transform_fs(vLocalPos, vLocalRect, alpha);
|
||||||
|
oFragColor = vec4(1, 1, 1, alpha) * vColor;
|
||||||
|
#else
|
||||||
oFragColor = vColor;
|
oFragColor = vColor;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,8 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
varying vec4 vColor;
|
varying vec4 vColor;
|
||||||
|
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
varying vec3 vLocalPos;
|
||||||
|
flat varying vec4 vLocalRect;
|
||||||
|
#endif
|
||||||
|
|
|
@ -14,6 +14,12 @@ layout(std140) uniform Items {
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
Rectangle rect = rects[gl_InstanceID];
|
Rectangle rect = rects[gl_InstanceID];
|
||||||
write_vertex(rect.info);
|
|
||||||
vColor = rect.color;
|
vColor = rect.color;
|
||||||
|
#ifdef WR_FEATURE_TRANSFORM
|
||||||
|
TransformVertexInfo vi = write_transform_vertex(rect.info);
|
||||||
|
vLocalRect = rect.info.local_rect;
|
||||||
|
vLocalPos = vi.local_pos;
|
||||||
|
#else
|
||||||
|
write_vertex(rect.info);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue