bevyengine / bevyengine/bevy

Support a map for alpha masking

Open
#8,148 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

The current `AlphaMode`s available on `StandardMaterial` are restricted to inspecting the `base_color_texture`'s alpha channel which can be restrictive when content is authored with one texture representing the albedo, and another representing the alpha. This would also map to Blender's Principled BSDF shader directly, so materials in scenes constructed this way would match accordingly (provided that glTF supports this, which I have not verified).

My use case involves rendering trading cards, which has a good library of imagery that does not contain an alpha channel. It can be combined with an alpha mask to construct a clean looking final image.

## What solution would you like?

Add options to `AlphaMode` that can be constructed with an image, e.g. something that looks like `Blend(Handle)`. Alternatively add a `alpha_texture: Option>` similar to `base_color_texture` that is implicitly used by the existing `AlphaMode`s. The shader would have to consider using a texture with a sampler for the alpha tap instead of relying on the existing texture format including alpha.

## What alternative(s) have you considered?

The most obvious alternative is to (either offline, or at runtime) (pre)process textures to tack on their alpha channel. This may be unavoidable at runtime though, and the cost of doing this is unnecessary.

Another alternative is to write a custom shader to do this, but I believe that makes it difficult to use the existing PBR setup in `StandardMaterial` without a bunch of duplicate effort. I'd be very happy to know I'm incorrect in this assessment, and if extending the existing shader is "easy".

One other alternative for my particular case is to not use alpha to achieve "transparency" here but to modify the geometry to leave holes where appropriate. This would work for me because my alpha channel could be considered binary (and so alpha-clip would work) without much quality loss.

## Additional context

Here's a screenshot of a simple Blender material that uses an alpha mask.
![image](https://user-images.githubusercontent.com/607460/226551714-70ae6f70-34f4-44be-a3c4-134efdb41dea.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.