#Can't tint sprite white

10 messages · Page 1 of 1 (latest)

bitter rampart
#

I have a sprite using SpriteSheetBundle with a TextureAtlas.

This works correctly:
sprite.color = Color::rgba_u8(0, 0, 0, 255);

This does nothing:
sprite.color = Color::rgba_u8(255, 255, 255, 255);

Is it possible white is just not supported and I have to make a shader?
Attaching screenshots, with black and white tint.

#

blue with max opacity does this o.O that makes no sense to me whatsoever (at max opacity it should basically do a tint fill of exactly that color)

#

ah its probably because of blend mode it works with (multiply?), I dont see anything about a blend mode for 2d textures though 😅 this is confusing

hollow wyvern
#

I haven’t looked at what the shader or algorithm does under the hood, but it certainly looks like a multiply blending. You can check the sprite shader at the bevy_sprite crate

However, this “tint” behaviour works like that, I guess it feels natural for me because it works in the same way in other engines like Unity or Godot

What you are looking for is probably an overlay color, or something like that, that isn’t supported out of the box because the sprite renderer is very simple, afaik it doesn’t even use materials

So, your only options here is to write your own shader, based on Bevy’s, but replacing or adding the color instead of multiplying it.

To override Bevy’s sprite shader, I think you can do the same that Bevy does internally: call load_internal_assset! macro passing the SPRITE_SHADER_HANDLE but pointing to your own shader instead

#

Alternatively you can have a white version of the sprite on top of yours and modify it’s opacity 🤣

bitter rampart
#

@hollow wyvern thanks for advice! yeah multiply is not what I expected ;p I will try to just write a shader and apply it to 2d material somewhat like here https://bevyengine.org/examples/Shaders/shader-material-2d/, if that wont do I will fallback to your option 😄 although I would rather not interfere with bevy internals like the default sprite shader, code like that tends to break with updates later on :/

#

I will mark it as resolved, because as you say there is probably no other way around this for now other than just writing a shader and using it any way that will display what you need Pepe_shrug

hollow wyvern
#

Oh, good point, using a mesh 2D and a material 2D instead of the basic sprite will give you more flexibility 👌

mossy root
#

Setting the sprite.color is indeed using a multiply blending. The default color is white, that means every pixel is multiplied with 1.0 and thus shows the pixels of the sprite unaltered.
However, there is a slight trick you can do. Instead of setting the sprite.color to Color::WHITE you can set it to something like Color::WHITE * 10.0. Rgba values are not clamped between 0.0 and 1.0, so using a color like this will effectively render a complete white version of the sprite