mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Update shaders for sampler names, copy new text-shadow shaders.
This commit is contained in:
parent
db357b0334
commit
9991e0674b
18 changed files with 219 additions and 10 deletions
40
resources/shaders/cs_blur.fs.glsl
Normal file
40
resources/shaders/cs_blur.fs.glsl
Normal file
|
@ -0,0 +1,40 @@
|
|||
#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/. */
|
||||
|
||||
// TODO(gw): Write a fast path blur that handles smaller blur radii
|
||||
// with a offset / weight uniform table and a constant
|
||||
// loop iteration count!
|
||||
|
||||
// TODO(gw): Make use of the bilinear sampling trick to reduce
|
||||
// the number of texture fetches needed for a gaussian blur.
|
||||
|
||||
float gauss(float x, float sigma) {
|
||||
return (1.0 / sqrt(6.283185307179586 * sigma * sigma)) * exp(-(x * x) / (2.0 * sigma * sigma));
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
vec4 sample = texture(sCache, vUv);
|
||||
vec4 color = vec4(sample.rgb * sample.a, sample.a) * gauss(0.0, vSigma);
|
||||
|
||||
for (int i=1 ; i < vBlurRadius ; ++i) {
|
||||
vec2 offset = vec2(float(i)) * vOffsetScale;
|
||||
|
||||
vec2 st0 = clamp(vUv.xy + offset, vUvRect.xy, vUvRect.zw);
|
||||
vec4 color0 = texture(sCache, vec3(st0, vUv.z));
|
||||
|
||||
vec2 st1 = clamp(vUv.xy - offset, vUvRect.xy, vUvRect.zw);
|
||||
vec4 color1 = texture(sCache, vec3(st1, vUv.z));
|
||||
|
||||
// Alpha must be premultiplied in order to properly blur the alpha channel.
|
||||
float weight = gauss(float(i), vSigma);
|
||||
color += vec4(color0.rgb * color0.a, color0.a) * weight;
|
||||
color += vec4(color1.rgb * color1.a, color1.a) * weight;
|
||||
}
|
||||
|
||||
// Unpremultiply the alpha.
|
||||
color.rgb /= color.a;
|
||||
|
||||
oFragColor = color;
|
||||
}
|
10
resources/shaders/cs_blur.glsl
Normal file
10
resources/shaders/cs_blur.glsl
Normal file
|
@ -0,0 +1,10 @@
|
|||
#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/. */
|
||||
|
||||
varying vec3 vUv;
|
||||
flat varying vec4 vUvRect;
|
||||
flat varying vec2 vOffsetScale;
|
||||
flat varying float vSigma;
|
||||
flat varying int vBlurRadius;
|
45
resources/shaders/cs_blur.vs.glsl
Normal file
45
resources/shaders/cs_blur.vs.glsl
Normal file
|
@ -0,0 +1,45 @@
|
|||
#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/. */
|
||||
|
||||
// Applies a separable gaussian blur in one direction, as specified
|
||||
// by the dir field in the blur command.
|
||||
|
||||
#define DIR_HORIZONTAL 0
|
||||
#define DIR_VERTICAL 1
|
||||
|
||||
void main(void) {
|
||||
BlurCommand cmd = fetch_blur(gl_InstanceID);
|
||||
RenderTaskData task = fetch_render_task(cmd.task_id);
|
||||
RenderTaskData src_task = fetch_render_task(cmd.src_task_id);
|
||||
|
||||
vec4 local_rect = task.data0;
|
||||
|
||||
vec2 pos = mix(local_rect.xy,
|
||||
local_rect.xy + local_rect.zw,
|
||||
aPosition.xy);
|
||||
|
||||
vec2 texture_size = textureSize(sCache, 0).xy;
|
||||
vUv.z = src_task.data1.x;
|
||||
vBlurRadius = int(task.data1.y);
|
||||
vSigma = task.data1.y * 0.5;
|
||||
|
||||
switch (cmd.dir) {
|
||||
case DIR_HORIZONTAL:
|
||||
vOffsetScale = vec2(1.0 / texture_size.x, 0.0);
|
||||
break;
|
||||
case DIR_VERTICAL:
|
||||
vOffsetScale = vec2(0.0, 1.0 / texture_size.y);
|
||||
break;
|
||||
}
|
||||
|
||||
vUvRect = vec4(src_task.data0.xy, src_task.data0.xy + src_task.data0.zw);
|
||||
vUvRect /= texture_size.xyxy;
|
||||
|
||||
vec2 uv0 = src_task.data0.xy / texture_size;
|
||||
vec2 uv1 = (src_task.data0.xy + src_task.data0.zw) / texture_size;
|
||||
vUv.xy = mix(uv0, uv1, aPosition.xy);
|
||||
|
||||
gl_Position = uTransform * vec4(pos, 0.0, 1.0);
|
||||
}
|
9
resources/shaders/cs_text_run.fs.glsl
Normal file
9
resources/shaders/cs_text_run.fs.glsl
Normal file
|
@ -0,0 +1,9 @@
|
|||
#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) {
|
||||
float a = texture(sColor0, vUv).a;
|
||||
oFragColor = vec4(vColor.rgb, vColor.a * a);
|
||||
}
|
7
resources/shaders/cs_text_run.glsl
Normal file
7
resources/shaders/cs_text_run.glsl
Normal file
|
@ -0,0 +1,7 @@
|
|||
#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/. */
|
||||
|
||||
varying vec2 vUv;
|
||||
flat varying vec4 vColor;
|
35
resources/shaders/cs_text_run.vs.glsl
Normal file
35
resources/shaders/cs_text_run.vs.glsl
Normal file
|
@ -0,0 +1,35 @@
|
|||
#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/. */
|
||||
|
||||
// Draw a text run to a cache target. These are always
|
||||
// drawn un-transformed. These are used for effects such
|
||||
// as text-shadow.
|
||||
|
||||
void main(void) {
|
||||
CachePrimitiveInstance cpi = fetch_cache_instance(gl_InstanceID);
|
||||
RenderTaskData task = fetch_render_task(cpi.render_task_index);
|
||||
TextRun text = fetch_text_run(cpi.specific_prim_index);
|
||||
Glyph glyph = fetch_glyph(cpi.sub_index);
|
||||
PrimitiveGeometry pg = fetch_prim_geometry(cpi.global_prim_index);
|
||||
|
||||
// Glyphs size is already in device-pixels.
|
||||
// The render task origin is in device-pixels. Offset that by
|
||||
// the glyph offset, relative to its primitive bounding rect.
|
||||
vec2 size = glyph.uv_rect.zw - glyph.uv_rect.xy;
|
||||
vec2 origin = task.data0.xy + uDevicePixelRatio * (glyph.offset.xy - pg.local_rect.xy);
|
||||
vec4 local_rect = vec4(origin, size);
|
||||
|
||||
vec2 texture_size = vec2(textureSize(sColor0, 0));
|
||||
vec2 st0 = glyph.uv_rect.xy / texture_size;
|
||||
vec2 st1 = glyph.uv_rect.zw / texture_size;
|
||||
|
||||
vec2 pos = mix(local_rect.xy,
|
||||
local_rect.xy + local_rect.zw,
|
||||
aPosition.xy);
|
||||
vUv = mix(st0, st1, aPosition.xy);
|
||||
vColor = text.color;
|
||||
|
||||
gl_Position = uTransform * vec4(pos, 0.0, 1.0);
|
||||
}
|
|
@ -5,9 +5,9 @@
|
|||
void main(void)
|
||||
{
|
||||
#ifdef SERVO_ES2
|
||||
float alpha = texture(sDiffuse, vColorTexCoord.xy).a;
|
||||
float alpha = texture(sColor0, vColorTexCoord.xy).a;
|
||||
#else
|
||||
float alpha = texture(sDiffuse, vColorTexCoord.xy).r;
|
||||
float alpha = texture(sColor0, vColorTexCoord.xy).r;
|
||||
#endif
|
||||
oFragColor = vec4(vColor.xyz, vColor.w * alpha);
|
||||
}
|
||||
|
|
|
@ -277,10 +277,31 @@ PrimitiveInstance fetch_instance(int index) {
|
|||
return pi;
|
||||
}
|
||||
|
||||
struct BlurCommand {
|
||||
int task_id;
|
||||
int src_task_id;
|
||||
int dir;
|
||||
};
|
||||
|
||||
BlurCommand fetch_blur(int index) {
|
||||
BlurCommand blur;
|
||||
|
||||
int offset = index * 1;
|
||||
|
||||
ivec4 data0 = int_data[offset + 0];
|
||||
|
||||
blur.task_id = data0.x;
|
||||
blur.src_task_id = data0.y;
|
||||
blur.dir = data0.z;
|
||||
|
||||
return blur;
|
||||
}
|
||||
|
||||
struct CachePrimitiveInstance {
|
||||
int global_prim_index;
|
||||
int specific_prim_index;
|
||||
int render_task_index;
|
||||
int sub_index;
|
||||
};
|
||||
|
||||
CachePrimitiveInstance fetch_cache_instance(int index) {
|
||||
|
@ -293,6 +314,7 @@ CachePrimitiveInstance fetch_cache_instance(int index) {
|
|||
cpi.global_prim_index = data0.x;
|
||||
cpi.specific_prim_index = data0.y;
|
||||
cpi.render_task_index = data0.z;
|
||||
cpi.sub_index = data0.w;
|
||||
|
||||
return cpi;
|
||||
}
|
||||
|
|
7
resources/shaders/ps_cache_image.fs.glsl
Normal file
7
resources/shaders/ps_cache_image.fs.glsl
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* 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) {
|
||||
oFragColor = texture(sCache, vUv);
|
||||
}
|
5
resources/shaders/ps_cache_image.glsl
Normal file
5
resources/shaders/ps_cache_image.glsl
Normal file
|
@ -0,0 +1,5 @@
|
|||
/* 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/. */
|
||||
|
||||
varying vec3 vUv;
|
27
resources/shaders/ps_cache_image.vs.glsl
Normal file
27
resources/shaders/ps_cache_image.vs.glsl
Normal file
|
@ -0,0 +1,27 @@
|
|||
#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/. */
|
||||
|
||||
// Draw a cached primitive (e.g. a blurred text run) from the
|
||||
// target cache to the framebuffer, applying tile clip boundaries.
|
||||
|
||||
void main(void) {
|
||||
Primitive prim = load_primitive(gl_InstanceID);
|
||||
|
||||
VertexInfo vi = write_vertex(prim.local_rect,
|
||||
prim.local_clip_rect,
|
||||
prim.layer,
|
||||
prim.tile);
|
||||
|
||||
RenderTaskData child_task = fetch_render_task(prim.user_data.x);
|
||||
vUv.z = child_task.data1.x;
|
||||
|
||||
vec2 texture_size = vec2(textureSize(sCache, 0));
|
||||
vec2 uv0 = child_task.data0.xy / texture_size;
|
||||
vec2 uv1 = (child_task.data0.xy + child_task.data0.zw) / texture_size;
|
||||
|
||||
vec2 f = (vi.local_clamped_pos - prim.local_rect.xy) / prim.local_rect.zw;
|
||||
|
||||
vUv.xy = mix(uv0, uv1, f);
|
||||
}
|
|
@ -25,5 +25,5 @@ void main(void) {
|
|||
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize);
|
||||
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));
|
||||
|
||||
oFragColor = vec4(1, 1, 1, alpha) * texture(sDiffuse, st);
|
||||
oFragColor = vec4(1, 1, 1, alpha) * texture(sColor0, st);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ void main(void) {
|
|||
#endif
|
||||
|
||||
// vUv will contain how many times this image has wrapped around the image size.
|
||||
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
|
||||
vec2 texture_size = vec2(textureSize(sColor0, 0));
|
||||
vec2 st0 = image.st_rect.xy / texture_size;
|
||||
vec2 st1 = image.st_rect.zw / texture_size;
|
||||
|
||||
|
|
|
@ -28,5 +28,5 @@ void main(void) {
|
|||
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);
|
||||
oFragColor = texture(sColor0, st) * vec4(1, 1, 1, alpha);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ void main(void) {
|
|||
write_clip(clip);
|
||||
|
||||
// vUv will contain how many times this image has wrapped around the image size.
|
||||
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
|
||||
vec2 texture_size = vec2(textureSize(sColor0, 0));
|
||||
vec2 st0 = image.st_rect.xy / texture_size;
|
||||
vec2 st1 = image.st_rect.zw / texture_size;
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
void main(void) {
|
||||
#ifdef WR_FEATURE_SUBPIXEL_AA
|
||||
oFragColor = texture(sDiffuse, vUv);
|
||||
oFragColor = texture(sColor0, vUv);
|
||||
#else
|
||||
float a = texture(sDiffuse, vUv).a;
|
||||
float a = texture(sColor0, vUv).a;
|
||||
#ifdef WR_FEATURE_TRANSFORM
|
||||
float alpha = 0.0;
|
||||
init_transform_fs(vLocalPos, vLocalRect, alpha);
|
||||
|
|
|
@ -25,7 +25,7 @@ void main(void) {
|
|||
vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);
|
||||
#endif
|
||||
|
||||
vec2 texture_size = vec2(textureSize(sDiffuse, 0));
|
||||
vec2 texture_size = vec2(textureSize(sColor0, 0));
|
||||
vec2 st0 = glyph.uv_rect.xy / texture_size;
|
||||
vec2 st1 = glyph.uv_rect.zw / texture_size;
|
||||
|
||||
|
|
|
@ -33,7 +33,9 @@
|
|||
//======================================================================================
|
||||
// Shared shader uniforms
|
||||
//======================================================================================
|
||||
uniform sampler2D sDiffuse;
|
||||
uniform sampler2D sColor0;
|
||||
uniform sampler2D sColor1;
|
||||
uniform sampler2D sColor2;
|
||||
uniform sampler2D sMask;
|
||||
|
||||
//======================================================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue