Skip to content

Vertex Colors without a texture in 2D ColorMaterial #5679

Closed
@jwagner

Description

@jwagner

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

It seems that it is currently impossible to use vertex colors (Mesh::ATTRIBUTE_COLOR) without a texture in the 2D Color Material.

I currently have two use cases for this, one is drawing flat colored meshes, the other is in my debug renderer.

What solution would you like?

I would like vertex colors to have an effect even if no texture is applied to the ColorMaterial.

I'm new to bevy and WGSL but at least from a quick test it looks like this can be achieved by a simple change to the fragment shader:

@fragment
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
    var output_color: vec4<f32> = material.color;
#ifdef VERTEX_COLORS
    output_color = output_color * in.color;
#endif
    if ((material.flags & COLOR_MATERIAL_FLAGS_TEXTURE_BIT) != 0u) {
        output_color = output_color * textureSample(texture, texture_sampler, in.uv);
    }
    return output_color;
}

What alternative(s) have you considered?

The alternative is to use a white texture to make vertex colors work. :))

Additional context

I couldn't come up with a good reason why it shouldn't be possible to use vertex colors without a texture but I might be missing something.

Happy to create a PR if this is considered desirable behavior in bevy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions