Can't take transparent screenshots
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.15.0
## What you did
I have this system:
```rust
fn add_icon_camera(
mut commands: Commands,
mut images: ResMut>,
) {
let size = Extent3d {
width: 512,
height: 512,
..default()
};
// This is the texture that will be rendered to.
let mut image = Image::new_fill(
size,
TextureDimension::D2,
&[0, 0, 0, 0],
TextureFormat::Bgra8UnormSrgb,
//TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::default(),
);
// You need to set these texture usage flags in order to use the image as a render target
image.texture_descriptor.usage =
TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST | TextureUsages::RENDER_ATTACHMENT;
let image_handle = images.add(image);
let first_pass_layer = RenderLayers::layer(2);
commands.spawn((
Camera2d,
Camera {
hdr: false,
target: image_handle.clone().into(),
clear_color: bevy::render::camera::ClearColorConfig::None,
viewport: None,
..Default::default()
},
OrthographicProjection {
far: 1.,
near: -10000000.,
..OrthographicProjection::default_2d()
},
//first_pass_layer.clone(),
Msaa::Sample4,
IconCamera,
));
commands.insert_resource(IconCameraImage(image_handle));
}
```
Then I try screenshot with the image as the target
## What went wrong
In the screenshot it always has a black background. I tried `ClearColorConfig::Custom(Color::NONE)` too, but that just had pitch black screen (wouldn't even show foreground anymore)
I would've expected it to be transparent because there's an alpha channel to the format and because of the clear color
Contributor guide
Research direction
Start with the add_icon_camera system shown in the issue and reproduce the Bevy 0.15.0 screenshot using the image render target. Inspect the target image's texture format and usage flags alongside the camera clear-color configuration. Done means the captured image preserves transparency while the foreground remains visible rather than showing a black background.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100