bevy_hanabi icon indicating copy to clipboard operation
bevy_hanabi copied to clipboard

`ColorOverLifetimeModifier` doesn't correctly support masks other than RGBA

Open eswartz opened this issue 10 months ago • 0 comments

Crate versions

bevy version: 0.16.1 bevy_hanabi version: 0.16.0

Describe the bug Using anything but ColorBlendMask::RGBA in ColorOverLifetimeModifier leads to wgsl build errors.

Expected behavior No errors and pretty colors :)

To Reproduce

let mut gradient = Gradient::new();
    gradient.add_key(0.0, Vec4::ONE);
    gradient.add_key(0.3333, Vec4::splat(0.5));
    gradient.add_key(1.0, Vec4::ZERO);

....
EffectAsset::new(memory as _, spawner, module) 
   ...
.render(ColorOverLifetimeModifier {
                gradient,
                blend: ColorBlendMode::Add,  // (or any other)
                mask: ColorBlendMask::RGB,
            })

leads to:

2025-06-08T14:41:46.030049Z ERROR bevy_render::render_resource::pipeline_cache: failed to process shader:
error: expected `)`, found ";"
    ┌─ hanabi/orbit_render_655207567374119500.wgsl:232:80
    │
232 │ color.rgb += (color_gradient_94140E69E337E387(particle.age / particle.lifetime);
    │                                                                                ^ expected `)`
    │
    = expected `)`, found ";"

Similarly:

   ...
.render(ColorOverLifetimeModifier {
                gradient,
                blend: ColorBlendMode::Add,  // (or any other)
                mask: ColorBlendMask::A,
            })

leads to:

2025-06-08T14:46:05.686556Z ERROR bevy_render::render_resource::pipeline_cache: failed to process shader:
error: expected identifier, found "+="
    ┌─ hanabi/orbit_render_12363769464819147455.wgsl:232:8
    │
232 │ color. += (color_gradient_94140E69E337E387(particle.age / particle.lifetime);
    │        ^^ expected identifier
    │
    = expected identifier, found "+="

That would also have the parenthesis error if the field were filled correctly.

I wondered it might be user error from switching the mode while the wrong type of Gradient, but it must be Gradient<Vec4> per gradient's definition.

eswartz avatar Jun 08 '25 14:06 eswartz