raea-page's premultiply pass (Premul, its WGSL and straight_target) moved to raea-sys-filters with the page's other fullscreen passes, raea-sys-page back under its 2000 lines

This commit is contained in:
shinyobjectz committed 2026-11-07 15:08:26 -08:00
1 parent d03eb9d7c9
commit 318b1939ab
7 files changed
+109 -103

No files matched your search

+4 -4
View File
@@ -109,8 +109,6 @@ doesn't pay.
| ui/text/strikethrough_and_underline | 5 | 0.990823 | 15 | 0 / 0 | 454 / 492 | 5 / 7 | 1 / 1 | 57.274 / 1.935 = 1.768 + 0.167 | yes | |
| ui/scroll_and_overflow/overflow | 10 | 0.998763 | 4 | 0 / 0 | 461 / 492 | 5 / 7 | 1 / 1 | 1.907 / 1.143 = 0.952 + 0.191 | yes | |
| ui/scroll_and_overflow/overflow | 5 | 0.998763 | 4 | 0 / 0 | 461 / 492 | 5 / 7 | 1 / 1 | 55.299 / 2.367 = 2.067 + 0.300 | yes | |
| ui/images/ui_texture_atlas | 10 | 0.999776 | 6 | 0 / 0 | 445 / 492 | 5 / 7 | 1 / 1 | 1.608 / 1.173 = 0.973 + 0.200 | yes | |
| ui/images/ui_texture_atlas | 5 | 0.999776 | 6 | 0 / 0 | 445 / 492 | 5 / 7 | 1 / 1 | 55.372 / 2.004 = 1.821 + 0.183 | yes | |
| 2d/mesh2d_vertex_color_texture | 10 | 0.998651 | 6 | 0 / 0 | 442 / 495 | 6 / 9 | 1 / 1 | 31.381 / 1.123 = 0.978 + 0.145 | yes | |
| 2d/mesh2d_repeated_texture | 10 | 0.991205 | 17 | 0 / 0 | 437 / 496 | 8 / 10 | 1 / 1 | 22.753 / 1.237 = 1.01 + 0.227 | yes | |
| ui/layout/flex_layout | 10 | 0.992327 | 8 | 0 / 0 | 602 / 492 | 5 / 7 | 1 / 1 | 30.162 / 1.132 = 1.05 + 0.082 | yes | |
@@ -122,9 +120,11 @@ doesn't pay.
| ui/text/letter_spacing | 10 | 0.996458 | 13 | 0 / 0 | 455 / 492 | 5 / 7 | 1 / 1 | 30.146 / 1.22 = 1.084 + 0.136 | yes | |
| ui/styling/borders | 10 | 0.992828 | 9 | 0 / 0 | 591 / 492 | 5 / 7 | 1 / 1 | 28.137 / 1.093 = 1.02 + 0.073 | yes | |
| ui/window_fallthrough | 10 | 0.992068 | 16 | 0 / 0 | 441 / 492 | 5 / 7 | 1 / 1 | 30.023 / 1.097 = 0.942 + 0.155 | yes | |
| ui/text/inline_image | 10 | 0.998473 | 8 | 0 / 0 | 446 / 492 | 5 / 7 | 1 / 1 | 31.458 / 1.309 = 1.109 + 0.200 | yes | |
| ui/layout/z_index | 10 | 1.000000 | 0 | 0 / 0 | 447 / 492 | 5 / 7 | 1 / 1 | 30.365 / 1.202 = 1.047 + 0.155 | yes | |
| ui/styling/stacked_gradients | 10 | 0.994550 | 1 | 0 / 0 | 442 / 492 | 5 / 7 | 1 / 1 | 32.23 / 1.124 = 0.988 + 0.136 | yes | |
| ui/images/ui_texture_atlas | 10 | 0.999776 | 6 | 0 / 0 | 445 / 492 | 5 / 7 | 1 / 1 | 2.103 / 1.706 = 1.515 + 0.191 | yes | |
| ui/images/ui_texture_atlas | 5 | 0.999776 | 6 | 0 / 0 | 445 / 492 | 5 / 7 | 1 / 1 | 55.621 / 2.426 = 2.226 + 0.200 | yes | |
| ui/text/inline_image | 10 | 0.998473 | 8 | 0 / 0 | 446 / 492 | 5 / 7 | 1 / 1 | 30.442 / 1.739 = 1.421 + 0.318 | yes | |
| ui/styling/stacked_gradients | 10 | 0.994550 | 1 | 0 / 0 | 442 / 492 | 5 / 7 | 1 / 1 | 31.919 / 1.669 = 1.514 + 0.155 | yes | |
## Excluded
+4 -4
View File
@@ -96,8 +96,6 @@
{"example":"ui/text/strikethrough_and_underline","frame":5,"ssim":0.990823,"tile":15,"bevy":{"batch_keys":0,"entities":454,"extents":[],"frame":5,"frame_ms":57.274,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":12,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.768,"step_ms":0.167,"cost_ms":1.935},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/scroll_and_overflow/overflow","frame":10,"ssim":0.998763,"tile":4,"bevy":{"batch_keys":0,"entities":461,"extents":[],"frame":10,"frame_ms":1.907,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.952,"step_ms":0.191,"cost_ms":1.143},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/scroll_and_overflow/overflow","frame":5,"ssim":0.998763,"tile":4,"bevy":{"batch_keys":0,"entities":461,"extents":[],"frame":5,"frame_ms":55.299,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":12,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.067,"step_ms":0.300,"cost_ms":2.367},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/images/ui_texture_atlas","frame":10,"ssim":0.999776,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":10,"frame_ms":1.608,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.973,"step_ms":0.200,"cost_ms":1.173},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/images/ui_texture_atlas","frame":5,"ssim":0.999776,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":5,"frame_ms":55.372,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":12,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.821,"step_ms":0.183,"cost_ms":2.004},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"2d/mesh2d_vertex_color_texture","frame":10,"ssim":0.998651,"tile":6,"bevy":{"batch_keys":0,"entities":442,"extents":[],"frame":10,"frame_ms":31.381,"materials":1,"mesh_entities":0,"meshes":6,"other_material":0,"visible":0},"raea":{"frame":17,"entities":495,"mesh_entities":0,"visible":0,"meshes":9,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.978,"step_ms":0.145,"cost_ms":1.123},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"2d/mesh2d_repeated_texture","frame":10,"ssim":0.991205,"tile":17,"bevy":{"batch_keys":0,"entities":437,"extents":[],"frame":10,"frame_ms":22.753,"materials":1,"mesh_entities":0,"meshes":8,"other_material":0,"visible":0},"raea":{"frame":17,"entities":496,"mesh_entities":0,"visible":0,"meshes":10,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.01,"step_ms":0.227,"cost_ms":1.237},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/layout/flex_layout","frame":10,"ssim":0.992327,"tile":8,"bevy":{"batch_keys":0,"entities":602,"extents":[],"frame":10,"frame_ms":30.162,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.05,"step_ms":0.082,"cost_ms":1.132},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
@@ -109,6 +107,8 @@
{"example":"ui/text/letter_spacing","frame":10,"ssim":0.996458,"tile":13,"bevy":{"batch_keys":0,"entities":455,"extents":[],"frame":10,"frame_ms":30.146,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.084,"step_ms":0.136,"cost_ms":1.22},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/styling/borders","frame":10,"ssim":0.992828,"tile":9,"bevy":{"batch_keys":0,"entities":591,"extents":[],"frame":10,"frame_ms":28.137,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.02,"step_ms":0.073,"cost_ms":1.093},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/window_fallthrough","frame":10,"ssim":0.992068,"tile":16,"bevy":{"batch_keys":0,"entities":441,"extents":[],"frame":10,"frame_ms":30.023,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.942,"step_ms":0.155,"cost_ms":1.097},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/text/inline_image","frame":10,"ssim":0.998473,"tile":8,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":31.458,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.109,"step_ms":0.200,"cost_ms":1.309},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/layout/z_index","frame":10,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":[],"frame":10,"frame_ms":30.365,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.047,"step_ms":0.155,"cost_ms":1.202},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/styling/stacked_gradients","frame":10,"ssim":0.994550,"tile":1,"bevy":{"batch_keys":0,"entities":442,"extents":[],"frame":10,"frame_ms":32.23,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.988,"step_ms":0.136,"cost_ms":1.124},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/images/ui_texture_atlas","frame":10,"ssim":0.999776,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":10,"frame_ms":2.103,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.515,"step_ms":0.191,"cost_ms":1.706},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/images/ui_texture_atlas","frame":5,"ssim":0.999776,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":5,"frame_ms":55.621,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":12,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.226,"step_ms":0.200,"cost_ms":2.426},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/text/inline_image","frame":10,"ssim":0.998473,"tile":8,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":30.442,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.421,"step_ms":0.318,"cost_ms":1.739},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/styling/stacked_gradients","frame":10,"ssim":0.994550,"tile":1,"bevy":{"batch_keys":0,"entities":442,"extents":[],"frame":10,"frame_ms":31.919,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.514,"step_ms":0.155,"cost_ms":1.669},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
+1 -1
View File
@@ -99,7 +99,7 @@ with a capital, hooks with `use`. A component's props are in its file.
## `raea/ui` (sdk/raea/src/ui.ts)
`AbsoluteFill`, `BorderRadius`, `CornerRadius`, `FontVariationTag`, `ImageNode`, `ImagePlugin`, `InlineImage`, `Node`, `Overflow`, `OverflowClipMargin`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiRect`, `UiScale`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontVariationTag`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
## `raea/video` (sdk/raea/src/video.ts)
+2
View File
@@ -9,10 +9,12 @@
mod painter;
mod passes;
mod premul;
mod primitives;
pub use painter::Painter;
pub use passes::Passes;
pub use premul::{PREMUL_WGSL, Premul, straight_target};
use std::sync::Arc;
+65
View File
@@ -0,0 +1,65 @@
//! raea-page's last pass, with the other fullscreen passes a page runs: Vello's straight, sRGB-encoded storage
//! texture made into a page's premultiplied image, and a premultiplied picture (a camera's) made straight for Vello's atlas.
use wgpu::{TextureDimension, TextureFormat, TextureUsages};
/// Vello stores straight alpha in an `Rgba8Unorm` storage texture (sRGB-encoded values); a page's image is
/// `Rgba8UnormSrgb` and premultiplied. One fullscreen triangle reads the one and writes the other.
pub struct Premul {
pub pipeline: wgpu::RenderPipeline,
/// the same pass for a StraightAlpha page: the colour decoded, its alpha kept apart
pub straight: wgpu::RenderPipeline,
/// a premultiplied picture (a camera's) made straight for Vello, which takes an element's picture so
pub unpremul: wgpu::RenderPipeline,
pub layout: wgpu::BindGroupLayout,
}
pub const PREMUL_WGSL: &str = include_str!("premul.wgsl");
impl Premul {
pub fn new(device: &wgpu::Device) -> Premul {
let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("raea-page premul"), source: wgpu::ShaderSource::Wgsl(PREMUL_WGSL.into()) });
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("raea-page premul"),
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { filterable: false }, view_dimension: wgpu::TextureViewDimension::D2, multisampled: false },
count: None,
}],
});
let pl = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("raea-page premul"), bind_group_layouts: &[Some(&layout)], immediate_size: 0 });
let make = |entry: &str| device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("raea-page premul"),
layout: Some(&pl),
vertex: wgpu::VertexState { module: &module, entry_point: Some("vs"), compilation_options: Default::default(), buffers: &[] },
fragment: Some(wgpu::FragmentState {
module: &module,
entry_point: Some(entry),
compilation_options: Default::default(),
targets: &[Some(wgpu::ColorTargetState { format: TextureFormat::Rgba8UnormSrgb, blend: None, write_mask: wgpu::ColorWrites::ALL })],
}),
primitive: Default::default(),
depth_stencil: None,
multisample: Default::default(),
multiview_mask: None,
cache: None,
});
let (pipeline, straight, unpremul) = (make("fs"), make("fs_straight"), make("fs_unpremul"));
Premul { pipeline, straight, unpremul, layout }
}
}
/// A straight copy's texture: sRGB-encoded, as Vello's atlas takes a picture's texels.
pub fn straight_target(device: &wgpu::Device, size: wgpu::Extent3d) -> wgpu::Texture {
device.create_texture(&wgpu::TextureDescriptor {
label: Some("raea-page view made straight"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: TextureDimension::D2,
format: TextureFormat::Rgba8UnormSrgb,
usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::COPY_SRC,
view_formats: &[],
})
}
+32
View File
@@ -0,0 +1,32 @@
@group(0) @binding(0) var src: texture_2d<f32>;
@vertex fn vs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));
return vec4f(p * 2.0 - 1.0, 0.0, 1.0);
}
fn linear(c: vec3f) -> vec3f {
return select(pow((c + 0.055) / 1.055, vec3f(2.4)), c / 12.92, c <= vec3f(0.04045));
}
// premultiplied in the encoded values (as bevy_ui's page holds them); the target's sRGB view encodes what's written
@fragment fn fs(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
return vec4f(linear(c.rgb * c.a), c.a);
}
@fragment fn fs_straight(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
return vec4f(linear(c.rgb), c.a);
}
fn encoded(c: vec3f) -> vec3f {
return select(1.055 * pow(c, vec3f(1.0 / 2.4)) - 0.055, c * 12.92, c <= vec3f(0.0031308));
}
// a camera's picture (premultiplied in its stored, sRGB-encoded values) made straight as raea's render makes its
// layered 3D (sdk/react motion.rs scene_straight): its alpha the largest of its four values, so light left in the
// clear (a sky, a glow) keeps; read decoded through an sRGB view, written through one
@fragment fn fs_unpremul(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
let e = round(encoded(c.rgb) * 255.0);
let a = max(max(e.r, e.g), max(e.b, round(c.a * 255.0)));
if c.a >= 1.0 || a == 0.0 {
return c;
}
return vec4f(linear(min(floor((e * 255.0 + floor(a / 2.0)) / a), vec3f(255.0)) / 255.0), a / 255.0);
}
+1 -94
View File
@@ -5,6 +5,7 @@
use std::collections::HashMap;
use super::*;
use raea_sys_filters::{Premul, straight_target};
/// The render world's copy of this frame's scenes.
#[derive(Resource, Default)]
@@ -56,86 +57,6 @@ pub fn view_at(app: &mut App, image: vello::peniko::ImageData, placed: Option<Pl
}
}
/// Vello stores straight alpha in an `Rgba8Unorm` storage texture (sRGB-encoded values); a page's image is
/// `Rgba8UnormSrgb` and premultiplied. One fullscreen triangle reads the one and writes the other.
pub struct Premul {
pub pipeline: wgpu::RenderPipeline,
/// the same pass for a StraightAlpha page: the colour decoded, its alpha kept apart
pub straight: wgpu::RenderPipeline,
/// a premultiplied picture (a camera's) made straight for Vello, which takes an element's picture so
pub unpremul: wgpu::RenderPipeline,
pub layout: wgpu::BindGroupLayout,
}
pub const PREMUL_WGSL: &str = r"
@group(0) @binding(0) var src: texture_2d<f32>;
@vertex fn vs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));
return vec4f(p * 2.0 - 1.0, 0.0, 1.0);
}
fn linear(c: vec3f) -> vec3f {
return select(pow((c + 0.055) / 1.055, vec3f(2.4)), c / 12.92, c <= vec3f(0.04045));
}
// premultiplied in the encoded values (as bevy_ui's page holds them); the target's sRGB view encodes what's written
@fragment fn fs(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
return vec4f(linear(c.rgb * c.a), c.a);
}
@fragment fn fs_straight(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
return vec4f(linear(c.rgb), c.a);
}
fn encoded(c: vec3f) -> vec3f {
return select(1.055 * pow(c, vec3f(1.0 / 2.4)) - 0.055, c * 12.92, c <= vec3f(0.0031308));
}
// a camera's picture (premultiplied in its stored, sRGB-encoded values) made straight as raea's render makes its
// layered 3D (sdk/react motion.rs scene_straight): its alpha the largest of its four values, so light left in the
// clear (a sky, a glow) keeps; read decoded through an sRGB view, written through one
@fragment fn fs_unpremul(@builtin(position) p: vec4f) -> @location(0) vec4f {
let c = textureLoad(src, vec2i(p.xy), 0);
let e = round(encoded(c.rgb) * 255.0);
let a = max(max(e.r, e.g), max(e.b, round(c.a * 255.0)));
if c.a >= 1.0 || a == 0.0 {
return c;
}
return vec4f(linear(min(floor((e * 255.0 + floor(a / 2.0)) / a), vec3f(255.0)) / 255.0), a / 255.0);
}
";
impl Premul {
pub fn new(device: &wgpu::Device) -> Premul {
let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("raea-page premul"), source: wgpu::ShaderSource::Wgsl(PREMUL_WGSL.into()) });
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("raea-page premul"),
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { filterable: false }, view_dimension: wgpu::TextureViewDimension::D2, multisampled: false },
count: None,
}],
});
let pl = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("raea-page premul"), bind_group_layouts: &[Some(&layout)], immediate_size: 0 });
let make = |entry: &str| device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("raea-page premul"),
layout: Some(&pl),
vertex: wgpu::VertexState { module: &module, entry_point: Some("vs"), compilation_options: default(), buffers: &[] },
fragment: Some(wgpu::FragmentState {
module: &module,
entry_point: Some(entry),
compilation_options: default(),
targets: &[Some(wgpu::ColorTargetState { format: TextureFormat::Rgba8UnormSrgb, blend: None, write_mask: wgpu::ColorWrites::ALL })],
}),
primitive: default(),
depth_stencil: None,
multisample: default(),
multiview_mask: None,
cache: None,
});
let (pipeline, straight, unpremul) = (make("fs"), make("fs_straight"), make("fs_unpremul"));
Premul { pipeline, straight, unpremul, layout }
}
}
pub fn extract(painted: Extract<Option<Res<Painted>>>, image_views: Extract<Option<Res<view3d::ImageViews>>>, mut scenes: ResMut<Scenes>, mut vello: NonSendMut<Vello>) {
if let Some(p) = painted.as_ref() {
scenes.todo = std::mem::take(&mut *p.0.lock().unwrap());
@@ -143,20 +64,6 @@ pub fn extract(painted: Extract<Option<Res<Painted>>>, image_views: Extract<Opti
vello.image_views = image_views.as_ref().map(|v| v.0.clone()).unwrap_or_default();
}
/// A straight copy's texture: sRGB-encoded, as Vello's atlas takes a picture's texels.
pub fn straight_target(device: &wgpu::Device, size: wgpu::Extent3d) -> wgpu::Texture {
device.create_texture(&wgpu::TextureDescriptor {
label: Some("raea-page view made straight"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: TextureDimension::D2,
format: TextureFormat::Rgba8UnormSrgb,
usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::COPY_SRC,
view_formats: &[],
})
}
/// Each scene drawn by Vello into its page's storage texture on Bevy's device, then premultiplied into the page's
/// image, before the frame's passes sample it. No readback: Vello's non-robust path (B1f).
pub fn draw(mut scenes: ResMut<Scenes>, mut vello: NonSendMut<Vello>, device: Res<RenderDevice>, queue: Res<RenderQueue>, images: Res<RenderAssets<GpuImage>>) {