Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex Colors without a texture in 2D ColorMaterial #5679

Closed
jwagner opened this issue Aug 13, 2022 · 2 comments
Closed

Vertex Colors without a texture in 2D ColorMaterial #5679

jwagner opened this issue Aug 13, 2022 · 2 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@jwagner
Copy link
Contributor

jwagner commented Aug 13, 2022

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.

@jwagner jwagner added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Aug 13, 2022
@rparrett rparrett added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen and removed C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Aug 13, 2022
@rparrett
Copy link
Contributor

rparrett commented Aug 13, 2022

This seems like a bug to me. Your proposed fix would seem to bring this in line with what we do in the PBR shader.

I'd say fire away on the PR.

@superdump
Copy link
Contributor

I agree. This looks like a bug. It doesn't make sense that vertex colours require a texture. Please make a PR.

@bors bors bot closed this as completed in 1108311 Aug 16, 2022
maccesch pushed a commit to Synphonyte/bevy that referenced this issue Sep 28, 2022
)

# Objective

This PR changes it possible to use vertex colors without a texture using the bevy_sprite ColorMaterial.

Fixes bevyengine#5679 

## Solution

- Made multiplication of the output color independent of the COLOR_MATERIAL_FLAGS_TEXTURE_BIT bit
- Extended mesh2d_vertex_color_texture example to show off both vertex colors and tinting

Not sure if extending the existing example was the right call but it seems to be reasonable to me.

I couldn't find any tests for the shaders and I think adding shader testing would be beyond the scope of this PR. So no tests in this PR. 😬 

Co-authored-by: Jonas Wagner <jonas@29a.ch>
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
)

# Objective

This PR changes it possible to use vertex colors without a texture using the bevy_sprite ColorMaterial.

Fixes bevyengine#5679 

## Solution

- Made multiplication of the output color independent of the COLOR_MATERIAL_FLAGS_TEXTURE_BIT bit
- Extended mesh2d_vertex_color_texture example to show off both vertex colors and tinting

Not sure if extending the existing example was the right call but it seems to be reasonable to me.

I couldn't find any tests for the shaders and I think adding shader testing would be beyond the scope of this PR. So no tests in this PR. 😬 

Co-authored-by: Jonas Wagner <jonas@29a.ch>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
)

# Objective

This PR changes it possible to use vertex colors without a texture using the bevy_sprite ColorMaterial.

Fixes bevyengine#5679 

## Solution

- Made multiplication of the output color independent of the COLOR_MATERIAL_FLAGS_TEXTURE_BIT bit
- Extended mesh2d_vertex_color_texture example to show off both vertex colors and tinting

Not sure if extending the existing example was the right call but it seems to be reasonable to me.

I couldn't find any tests for the shaders and I think adding shader testing would be beyond the scope of this PR. So no tests in this PR. 😬 

Co-authored-by: Jonas Wagner <jonas@29a.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants