1struct GlobalParams {
2 viewport_size: vec2<f32>,
3 pad: vec2<u32>,
4}
5
6var<uniform> globals: GlobalParams;
7var t_sprite: texture_2d<f32>;
8var s_sprite: sampler;
9
10const M_PI_F: f32 = 3.1415926;
11const GRAYSCALE_FACTORS: vec3<f32> = vec3<f32>(0.2126, 0.7152, 0.0722);
12
13struct ViewId {
14 lo: u32,
15 hi: u32,
16}
17
18struct Bounds {
19 origin: vec2<f32>,
20 size: vec2<f32>,
21}
22struct Corners {
23 top_left: f32,
24 top_right: f32,
25 bottom_right: f32,
26 bottom_left: f32,
27}
28struct Edges {
29 top: f32,
30 right: f32,
31 bottom: f32,
32 left: f32,
33}
34struct Hsla {
35 h: f32,
36 s: f32,
37 l: f32,
38 a: f32,
39}
40
41struct AtlasTextureId {
42 index: u32,
43 kind: u32,
44}
45
46struct AtlasBounds {
47 origin: vec2<i32>,
48 size: vec2<i32>,
49}
50struct AtlasTile {
51 texture_id: AtlasTextureId,
52 tile_id: u32,
53 padding: u32,
54 bounds: AtlasBounds,
55}
56
57fn to_device_position_impl(position: vec2<f32>) -> vec4<f32> {
58 let device_position = position / globals.viewport_size * vec2<f32>(2.0, -2.0) + vec2<f32>(-1.0, 1.0);
59 return vec4<f32>(device_position, 0.0, 1.0);
60}
61
62fn to_device_position(unit_vertex: vec2<f32>, bounds: Bounds) -> vec4<f32> {
63 let position = unit_vertex * vec2<f32>(bounds.size) + bounds.origin;
64 return to_device_position_impl(position);
65}
66
67fn to_tile_position(unit_vertex: vec2<f32>, tile: AtlasTile) -> vec2<f32> {
68 let atlas_size = vec2<f32>(textureDimensions(t_sprite, 0));
69 return (vec2<f32>(tile.bounds.origin) + unit_vertex * vec2<f32>(tile.bounds.size)) / atlas_size;
70}
71
72fn distance_from_clip_rect_impl(position: vec2<f32>, clip_bounds: Bounds) -> vec4<f32> {
73 let tl = position - clip_bounds.origin;
74 let br = clip_bounds.origin + clip_bounds.size - position;
75 return vec4<f32>(tl.x, br.x, tl.y, br.y);
76}
77
78fn distance_from_clip_rect(unit_vertex: vec2<f32>, bounds: Bounds, clip_bounds: Bounds) -> vec4<f32> {
79 let position = unit_vertex * vec2<f32>(bounds.size) + bounds.origin;
80 return distance_from_clip_rect_impl(position, clip_bounds);
81}
82
83fn hsla_to_rgba(hsla: Hsla) -> vec4<f32> {
84 let h = hsla.h * 6.0; // Now, it's an angle but scaled in [0, 6) range
85 let s = hsla.s;
86 let l = hsla.l;
87 let a = hsla.a;
88
89 let c = (1.0 - abs(2.0 * l - 1.0)) * s;
90 let x = c * (1.0 - abs(h % 2.0 - 1.0));
91 let m = l - c / 2.0;
92
93 var color = vec4<f32>(m, m, m, a);
94
95 if (h >= 0.0 && h < 1.0) {
96 color.r += c;
97 color.g += x;
98 } else if (h >= 1.0 && h < 2.0) {
99 color.r += x;
100 color.g += c;
101 } else if (h >= 2.0 && h < 3.0) {
102 color.g += c;
103 color.b += x;
104 } else if (h >= 3.0 && h < 4.0) {
105 color.g += x;
106 color.b += c;
107 } else if (h >= 4.0 && h < 5.0) {
108 color.r += x;
109 color.b += c;
110 } else {
111 color.r += c;
112 color.b += x;
113 }
114
115 return color;
116}
117
118fn over(below: vec4<f32>, above: vec4<f32>) -> vec4<f32> {
119 let alpha = above.a + below.a * (1.0 - above.a);
120 let color = (above.rgb * above.a + below.rgb * below.a * (1.0 - above.a)) / alpha;
121 return vec4<f32>(color, alpha);
122}
123
124// A standard gaussian function, used for weighting samples
125fn gaussian(x: f32, sigma: f32) -> f32{
126 return exp(-(x * x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * M_PI_F) * sigma);
127}
128
129// This approximates the error function, needed for the gaussian integral
130fn erf(v: vec2<f32>) -> vec2<f32> {
131 let s = sign(v);
132 let a = abs(v);
133 let r1 = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a;
134 let r2 = r1 * r1;
135 return s - s / (r2 * r2);
136}
137
138fn blur_along_x(x: f32, y: f32, sigma: f32, corner: f32, half_size: vec2<f32>) -> f32 {
139 let delta = min(half_size.y - corner - abs(y), 0.0);
140 let curved = half_size.x - corner + sqrt(max(0.0, corner * corner - delta * delta));
141 let integral = 0.5 + 0.5 * erf((x + vec2<f32>(-curved, curved)) * (sqrt(0.5) / sigma));
142 return integral.y - integral.x;
143}
144
145fn pick_corner_radius(point: vec2<f32>, radii: Corners) -> f32 {
146 if (point.x < 0.0) {
147 if (point.y < 0.0) {
148 return radii.top_left;
149 } else {
150 return radii.bottom_left;
151 }
152 } else {
153 if (point.y < 0.0) {
154 return radii.top_right;
155 } else {
156 return radii.bottom_right;
157 }
158 }
159}
160
161fn quad_sdf(point: vec2<f32>, bounds: Bounds, corner_radii: Corners) -> f32 {
162 let half_size = bounds.size / 2.0;
163 let center = bounds.origin + half_size;
164 let center_to_point = point - center;
165 let corner_radius = pick_corner_radius(center_to_point, corner_radii);
166 let rounded_edge_to_point = abs(center_to_point) - half_size + corner_radius;
167 return length(max(vec2<f32>(0.0), rounded_edge_to_point)) +
168 min(0.0, max(rounded_edge_to_point.x, rounded_edge_to_point.y)) -
169 corner_radius;
170}
171
172// --- quads --- //
173
174struct Quad {
175 view_id: ViewId,
176 layer_id: u32,
177 order: u32,
178 bounds: Bounds,
179 content_mask: Bounds,
180 background: Hsla,
181 border_color: Hsla,
182 corner_radii: Corners,
183 border_widths: Edges,
184}
185var<storage, read> b_quads: array<Quad>;
186
187struct QuadVarying {
188 @builtin(position) position: vec4<f32>,
189 @location(0) @interpolate(flat) background_color: vec4<f32>,
190 @location(1) @interpolate(flat) border_color: vec4<f32>,
191 @location(2) @interpolate(flat) quad_id: u32,
192 //TODO: use `clip_distance` once Naga supports it
193 @location(3) clip_distances: vec4<f32>,
194}
195
196@vertex
197fn vs_quad(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> QuadVarying {
198 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
199 let quad = b_quads[instance_id];
200
201 var out = QuadVarying();
202 out.position = to_device_position(unit_vertex, quad.bounds);
203 out.background_color = hsla_to_rgba(quad.background);
204 out.border_color = hsla_to_rgba(quad.border_color);
205 out.quad_id = instance_id;
206 out.clip_distances = distance_from_clip_rect(unit_vertex, quad.bounds, quad.content_mask);
207 return out;
208}
209
210@fragment
211fn fs_quad(input: QuadVarying) -> @location(0) vec4<f32> {
212 // Alpha clip first, since we don't have `clip_distance`.
213 if (any(input.clip_distances < vec4<f32>(0.0))) {
214 return vec4<f32>(0.0);
215 }
216
217 let quad = b_quads[input.quad_id];
218 // Fast path when the quad is not rounded and doesn't have any border.
219 if (quad.corner_radii.top_left == 0.0 && quad.corner_radii.bottom_left == 0.0 &&
220 quad.corner_radii.top_right == 0.0 &&
221 quad.corner_radii.bottom_right == 0.0 && quad.border_widths.top == 0.0 &&
222 quad.border_widths.left == 0.0 && quad.border_widths.right == 0.0 &&
223 quad.border_widths.bottom == 0.0) {
224 return input.background_color;
225 }
226
227 let half_size = quad.bounds.size / 2.0;
228 let center = quad.bounds.origin + half_size;
229 let center_to_point = input.position.xy - center;
230
231 let corner_radius = pick_corner_radius(center_to_point, quad.corner_radii);
232
233 let rounded_edge_to_point = abs(center_to_point) - half_size + corner_radius;
234 let distance =
235 length(max(vec2<f32>(0.0), rounded_edge_to_point)) +
236 min(0.0, max(rounded_edge_to_point.x, rounded_edge_to_point.y)) -
237 corner_radius;
238
239 let vertical_border = select(quad.border_widths.left, quad.border_widths.right, center_to_point.x > 0.0);
240 let horizontal_border = select(quad.border_widths.top, quad.border_widths.bottom, center_to_point.y > 0.0);
241 let inset_size = half_size - corner_radius - vec2<f32>(vertical_border, horizontal_border);
242 let point_to_inset_corner = abs(center_to_point) - inset_size;
243
244 var border_width = 0.0;
245 if (point_to_inset_corner.x < 0.0 && point_to_inset_corner.y < 0.0) {
246 border_width = 0.0;
247 } else if (point_to_inset_corner.y > point_to_inset_corner.x) {
248 border_width = horizontal_border;
249 } else {
250 border_width = vertical_border;
251 }
252
253 var color = input.background_color;
254 if (border_width > 0.0) {
255 let inset_distance = distance + border_width;
256 // Blend the border on top of the background and then linearly interpolate
257 // between the two as we slide inside the background.
258 let blended_border = over(input.background_color, input.border_color);
259 color = mix(blended_border, input.background_color,
260 saturate(0.5 - inset_distance));
261 }
262
263 return color * vec4<f32>(1.0, 1.0, 1.0, saturate(0.5 - distance));
264}
265
266// --- shadows --- //
267
268struct Shadow {
269 view_id: ViewId,
270 layer_id: u32,
271 order: u32,
272 bounds: Bounds,
273 corner_radii: Corners,
274 content_mask: Bounds,
275 color: Hsla,
276 blur_radius: f32,
277 pad: u32,
278}
279var<storage, read> b_shadows: array<Shadow>;
280
281struct ShadowVarying {
282 @builtin(position) position: vec4<f32>,
283 @location(0) @interpolate(flat) color: vec4<f32>,
284 @location(1) @interpolate(flat) shadow_id: u32,
285 //TODO: use `clip_distance` once Naga supports it
286 @location(3) clip_distances: vec4<f32>,
287}
288
289@vertex
290fn vs_shadow(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> ShadowVarying {
291 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
292 var shadow = b_shadows[instance_id];
293
294 let margin = 3.0 * shadow.blur_radius;
295 // Set the bounds of the shadow and adjust its size based on the shadow's
296 // spread radius to achieve the spreading effect
297 shadow.bounds.origin -= vec2<f32>(margin);
298 shadow.bounds.size += 2.0 * vec2<f32>(margin);
299
300 var out = ShadowVarying();
301 out.position = to_device_position(unit_vertex, shadow.bounds);
302 out.color = hsla_to_rgba(shadow.color);
303 out.shadow_id = instance_id;
304 out.clip_distances = distance_from_clip_rect(unit_vertex, shadow.bounds, shadow.content_mask);
305 return out;
306}
307
308@fragment
309fn fs_shadow(input: ShadowVarying) -> @location(0) vec4<f32> {
310 // Alpha clip first, since we don't have `clip_distance`.
311 if (any(input.clip_distances < vec4<f32>(0.0))) {
312 return vec4<f32>(0.0);
313 }
314
315 let shadow = b_shadows[input.shadow_id];
316 let half_size = shadow.bounds.size / 2.0;
317 let center = shadow.bounds.origin + half_size;
318 let center_to_point = input.position.xy - center;
319
320 let corner_radius = pick_corner_radius(center_to_point, shadow.corner_radii);
321
322 // The signal is only non-zero in a limited range, so don't waste samples
323 let low = center_to_point.y - half_size.y;
324 let high = center_to_point.y + half_size.y;
325 let start = clamp(-3.0 * shadow.blur_radius, low, high);
326 let end = clamp(3.0 * shadow.blur_radius, low, high);
327
328 // Accumulate samples (we can get away with surprisingly few samples)
329 let step = (end - start) / 4.0;
330 var y = start + step * 0.5;
331 var alpha = 0.0;
332 for (var i = 0; i < 4; i += 1) {
333 let blur = blur_along_x(center_to_point.x, center_to_point.y - y,
334 shadow.blur_radius, corner_radius, half_size);
335 alpha += blur * gaussian(y, shadow.blur_radius) * step;
336 y += step;
337 }
338
339 return input.color * vec4<f32>(1.0, 1.0, 1.0, alpha);
340}
341
342// --- path rasterization --- //
343
344struct PathVertex {
345 xy_position: vec2<f32>,
346 st_position: vec2<f32>,
347 content_mask: Bounds,
348}
349var<storage, read> b_path_vertices: array<PathVertex>;
350
351struct PathRasterizationVarying {
352 @builtin(position) position: vec4<f32>,
353 @location(0) st_position: vec2<f32>,
354 //TODO: use `clip_distance` once Naga supports it
355 @location(3) clip_distances: vec4<f32>,
356}
357
358@vertex
359fn vs_path_rasterization(@builtin(vertex_index) vertex_id: u32) -> PathRasterizationVarying {
360 let v = b_path_vertices[vertex_id];
361
362 var out = PathRasterizationVarying();
363 out.position = to_device_position_impl(v.xy_position);
364 out.st_position = v.st_position;
365 out.clip_distances = distance_from_clip_rect_impl(v.xy_position, v.content_mask);
366 return out;
367}
368
369@fragment
370fn fs_path_rasterization(input: PathRasterizationVarying) -> @location(0) f32 {
371 let dx = dpdx(input.st_position);
372 let dy = dpdy(input.st_position);
373 if (any(input.clip_distances < vec4<f32>(0.0))) {
374 return 0.0;
375 }
376
377 let gradient = 2.0 * input.st_position.xx * vec2<f32>(dx.x, dy.x) - vec2<f32>(dx.y, dy.y);
378 let f = input.st_position.x * input.st_position.x - input.st_position.y;
379 let distance = f / length(gradient);
380 return saturate(0.5 - distance);
381}
382
383// --- paths --- //
384
385struct PathSprite {
386 bounds: Bounds,
387 color: Hsla,
388 tile: AtlasTile,
389}
390var<storage, read> b_path_sprites: array<PathSprite>;
391
392struct PathVarying {
393 @builtin(position) position: vec4<f32>,
394 @location(0) tile_position: vec2<f32>,
395 @location(1) color: vec4<f32>,
396}
397
398@vertex
399fn vs_path(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> PathVarying {
400 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
401 let sprite = b_path_sprites[instance_id];
402 // Don't apply content mask because it was already accounted for when rasterizing the path.
403
404 var out = PathVarying();
405 out.position = to_device_position(unit_vertex, sprite.bounds);
406 out.tile_position = to_tile_position(unit_vertex, sprite.tile);
407 out.color = hsla_to_rgba(sprite.color);
408 return out;
409}
410
411@fragment
412fn fs_path(input: PathVarying) -> @location(0) vec4<f32> {
413 let sample = textureSample(t_sprite, s_sprite, input.tile_position).r;
414 let mask = 1.0 - abs(1.0 - sample % 2.0);
415 return input.color * mask;
416}
417
418// --- underlines --- //
419
420struct Underline {
421 view_id: ViewId,
422 layer_id: u32,
423 order: u32,
424 bounds: Bounds,
425 content_mask: Bounds,
426 color: Hsla,
427 thickness: f32,
428 wavy: u32,
429}
430var<storage, read> b_underlines: array<Underline>;
431
432struct UnderlineVarying {
433 @builtin(position) position: vec4<f32>,
434 @location(0) @interpolate(flat) color: vec4<f32>,
435 @location(1) @interpolate(flat) underline_id: u32,
436 //TODO: use `clip_distance` once Naga supports it
437 @location(3) clip_distances: vec4<f32>,
438}
439
440@vertex
441fn vs_underline(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> UnderlineVarying {
442 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
443 let underline = b_underlines[instance_id];
444
445 var out = UnderlineVarying();
446 out.position = to_device_position(unit_vertex, underline.bounds);
447 out.color = hsla_to_rgba(underline.color);
448 out.underline_id = instance_id;
449 out.clip_distances = distance_from_clip_rect(unit_vertex, underline.bounds, underline.content_mask);
450 return out;
451}
452
453@fragment
454fn fs_underline(input: UnderlineVarying) -> @location(0) vec4<f32> {
455 // Alpha clip first, since we don't have `clip_distance`.
456 if (any(input.clip_distances < vec4<f32>(0.0))) {
457 return vec4<f32>(0.0);
458 }
459
460 let underline = b_underlines[input.underline_id];
461 if ((underline.wavy & 0xFFu) == 0u)
462 {
463 return vec4<f32>(0.0);
464 }
465
466 let half_thickness = underline.thickness * 0.5;
467 let st = (input.position.xy - underline.bounds.origin) / underline.bounds.size.y - vec2<f32>(0.0, 0.5);
468 let frequency = M_PI_F * 3.0 * underline.thickness / 8.0;
469 let amplitude = 1.0 / (2.0 * underline.thickness);
470 let sine = sin(st.x * frequency) * amplitude;
471 let dSine = cos(st.x * frequency) * amplitude * frequency;
472 let distance = (st.y - sine) / sqrt(1.0 + dSine * dSine);
473 let distance_in_pixels = distance * underline.bounds.size.y;
474 let distance_from_top_border = distance_in_pixels - half_thickness;
475 let distance_from_bottom_border = distance_in_pixels + half_thickness;
476 let alpha = saturate(0.5 - max(-distance_from_bottom_border, distance_from_top_border));
477 return input.color * vec4<f32>(1.0, 1.0, 1.0, alpha);
478}
479
480// --- monochrome sprites --- //
481
482struct MonochromeSprite {
483 view_id: ViewId,
484 layer_id: u32,
485 order: u32,
486 bounds: Bounds,
487 content_mask: Bounds,
488 color: Hsla,
489 tile: AtlasTile,
490}
491var<storage, read> b_mono_sprites: array<MonochromeSprite>;
492
493struct MonoSpriteVarying {
494 @builtin(position) position: vec4<f32>,
495 @location(0) tile_position: vec2<f32>,
496 @location(1) @interpolate(flat) color: vec4<f32>,
497 @location(3) clip_distances: vec4<f32>,
498}
499
500@vertex
501fn vs_mono_sprite(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> MonoSpriteVarying {
502 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
503 let sprite = b_mono_sprites[instance_id];
504
505 var out = MonoSpriteVarying();
506 out.position = to_device_position(unit_vertex, sprite.bounds);
507 out.tile_position = to_tile_position(unit_vertex, sprite.tile);
508 out.color = hsla_to_rgba(sprite.color);
509 out.clip_distances = distance_from_clip_rect(unit_vertex, sprite.bounds, sprite.content_mask);
510 return out;
511}
512
513@fragment
514fn fs_mono_sprite(input: MonoSpriteVarying) -> @location(0) vec4<f32> {
515 let sample = textureSample(t_sprite, s_sprite, input.tile_position).r;
516 // Alpha clip after using the derivatives.
517 if (any(input.clip_distances < vec4<f32>(0.0))) {
518 return vec4<f32>(0.0);
519 }
520 return input.color * vec4<f32>(1.0, 1.0, 1.0, sample);
521}
522
523// --- polychrome sprites --- //
524
525struct PolychromeSprite {
526 view_id: ViewId,
527 layer_id: u32,
528 order: u32,
529 bounds: Bounds,
530 content_mask: Bounds,
531 corner_radii: Corners,
532 tile: AtlasTile,
533 grayscale: u32,
534 pad: u32,
535}
536var<storage, read> b_poly_sprites: array<PolychromeSprite>;
537
538struct PolySpriteVarying {
539 @builtin(position) position: vec4<f32>,
540 @location(0) tile_position: vec2<f32>,
541 @location(1) @interpolate(flat) sprite_id: u32,
542 @location(3) clip_distances: vec4<f32>,
543}
544
545@vertex
546fn vs_poly_sprite(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> PolySpriteVarying {
547 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
548 let sprite = b_poly_sprites[instance_id];
549
550 var out = PolySpriteVarying();
551 out.position = to_device_position(unit_vertex, sprite.bounds);
552 out.tile_position = to_tile_position(unit_vertex, sprite.tile);
553 out.sprite_id = instance_id;
554 out.clip_distances = distance_from_clip_rect(unit_vertex, sprite.bounds, sprite.content_mask);
555 return out;
556}
557
558@fragment
559fn fs_poly_sprite(input: PolySpriteVarying) -> @location(0) vec4<f32> {
560 let sample = textureSample(t_sprite, s_sprite, input.tile_position);
561 // Alpha clip after using the derivatives.
562 if (any(input.clip_distances < vec4<f32>(0.0))) {
563 return vec4<f32>(0.0);
564 }
565
566 let sprite = b_poly_sprites[input.sprite_id];
567 let distance = quad_sdf(input.position.xy, sprite.bounds, sprite.corner_radii);
568
569 var color = sample;
570 if ((sprite.grayscale & 0xFFu) != 0u) {
571 let grayscale = dot(color.rgb, GRAYSCALE_FACTORS);
572 color = vec4<f32>(vec3<f32>(grayscale), sample.a);
573 }
574 color.a *= saturate(0.5 - distance);
575 return color;
576}
577
578// --- surfaces --- //
579
580struct SurfaceParams {
581 bounds: Bounds,
582 content_mask: Bounds,
583}
584
585var<uniform> surface_locals: SurfaceParams;
586var t_y: texture_2d<f32>;
587var t_cb_cr: texture_2d<f32>;
588var s_surface: sampler;
589
590const ycbcr_to_RGB = mat4x4<f32>(
591 vec4<f32>( 1.0000f, 1.0000f, 1.0000f, 0.0),
592 vec4<f32>( 0.0000f, -0.3441f, 1.7720f, 0.0),
593 vec4<f32>( 1.4020f, -0.7141f, 0.0000f, 0.0),
594 vec4<f32>(-0.7010f, 0.5291f, -0.8860f, 1.0),
595);
596
597struct SurfaceVarying {
598 @builtin(position) position: vec4<f32>,
599 @location(0) texture_position: vec2<f32>,
600 @location(3) clip_distances: vec4<f32>,
601}
602
603@vertex
604fn vs_surface(@builtin(vertex_index) vertex_id: u32) -> SurfaceVarying {
605 let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
606
607 var out = SurfaceVarying();
608 out.position = to_device_position(unit_vertex, surface_locals.bounds);
609 out.texture_position = unit_vertex;
610 out.clip_distances = distance_from_clip_rect(unit_vertex, surface_locals.bounds, surface_locals.content_mask);
611 return out;
612}
613
614@fragment
615fn fs_surface(input: SurfaceVarying) -> @location(0) vec4<f32> {
616 // Alpha clip after using the derivatives.
617 if (any(input.clip_distances < vec4<f32>(0.0))) {
618 return vec4<f32>(0.0);
619 }
620
621 let y_cb_cr = vec4<f32>(
622 textureSampleLevel(t_y, s_surface, input.texture_position, 0.0).r,
623 textureSampleLevel(t_cb_cr, s_surface, input.texture_position, 0.0).rg,
624 1.0);
625
626 return ycbcr_to_RGB * y_cb_cr;
627}