-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
bevy_pbr2: added vertex color support #3187
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use bevy::{ | ||
math::Vec3, | ||
pbr2::{PbrBundle, PointLightBundle, StandardMaterial}, | ||
prelude::{App, Assets, Commands, ResMut, Transform}, | ||
render2::{ | ||
camera::PerspectiveCameraBundle, | ||
mesh::{shape, Mesh, VertexAttributeValues}, | ||
}, | ||
PipelinedDefaultPlugins, | ||
}; | ||
|
||
/// This example illustrates how to use the vertex colors attribute. | ||
fn main() { | ||
App::new() | ||
.add_plugins(PipelinedDefaultPlugins) | ||
.add_startup_system(setup) | ||
.run(); | ||
} | ||
|
||
fn setup( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<StandardMaterial>>, | ||
) { | ||
// create a generic cube | ||
let mut cube_with_colors = Mesh::from(shape::Cube { size: 2.0 }); | ||
|
||
// set some nice nice colors! | ||
cube_with_colors.set_attribute( | ||
Mesh::ATTRIBUTE_COLOR, | ||
// NOTE: the attribute count has to be consistent across all attributes, otherwise bevy | ||
// will panic. | ||
VertexAttributeValues::from(vec![ | ||
// top | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
// bottom | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
// right | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
// left | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
// front | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
// back | ||
[0.79, 0.73, 0.07, 1.], | ||
[0.74, 0.14, 0.29, 1.], | ||
[0.08, 0.55, 0.74, 1.], | ||
[0.20, 0.27, 0.29, 1.], | ||
]), | ||
); | ||
// cube | ||
commands.spawn_bundle(PbrBundle { | ||
mesh: meshes.add(cube_with_colors), // use our cube with vertex colors | ||
material: materials.add(Default::default()), | ||
transform: Transform::from_xyz(0.0, 0.0, 0.0), | ||
..Default::default() | ||
}); | ||
// light | ||
commands.spawn_bundle(PointLightBundle { | ||
transform: Transform::from_xyz(4.0, 8.0, 4.0), | ||
..Default::default() | ||
}); | ||
// camera | ||
commands.spawn_bundle(PerspectiveCameraBundle { | ||
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y), | ||
..Default::default() | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it make more sense for the vertex color to be multiplied with the base color from the material, rather than overriding it?
It seems a lot more useful to me (though I admit I don't know what's the typical/standard behavior for this case / what other game engines do).
That way, the shader combines the color from the texture (if any), the color from the material (if any), and the color from the vertex (if any). This gives the most flexibility, as the user could use all of these variables to create cool graphics effects. It seems strictly more useful than what you are doing right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep totally makes sense. I've actually moved on to another method and personally no longer use the color vertices. I set the material base color to white and then create a custom texture with the colors I need. Instead of using vertex colors I then simply use correct uv coords for the texture. Once that other pr is merged, I'll update this PR and change it to multiply instead. Great suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which other PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he’s referring to #3120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so but didn't see any direct reference. :) I agree it makes sense to get the flexible vertex attributes merged first and then this. I have added both of these to the rendering project board so they get prioritised as these are common problems that people hit.