-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add gram-schmidt fast approximation tangent generation algorithm #17989
base: main
Are you sure you want to change the base?
Conversation
c41e77e
to
e409343
Compare
crates/bevy_gltf/src/lib.rs
Outdated
@@ -124,6 +124,8 @@ pub mod prelude { | |||
#[derive(Default)] | |||
pub struct GltfPlugin { | |||
custom_vertex_attributes: HashMap<Box<str>, MeshVertexAttribute>, | |||
/// The strategy to use when computing mesh tangents. | |||
pub computed_tangent_strategy: TangentStrategy, |
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.
pub computed_tangent_strategy: TangentStrategy, | |
pub tangent_calculation_strategy: TangentCalculationStrategy, |
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.
renamed
b4ef353
to
ec40cb6
Compare
ec40cb6
to
3495615
Compare
the |
i was making tangent generation for the primitives, but with a very naive algorithm #17691, if your method works without causing seams then my PR becames redundant |
The sphere looks much better with the gram-schmidt tangents. I actually left mikktspacesphere_mikktspace.mp4gram-schmidtsphere_gramschmidt.mp4 |
Provide a fast alternative algorithm for tangent generation
Fixes: #17834
Related (maybe): #17877
Solution
Add a new enum
TangentStrategy
that gives the user the option to select how tangents are generated.The GLTF loader now has a property to set which algorithm is used for models that are missing tangents.
The
FastApproximation
strategy is implemented with the Gram-Schmidt fast approximation technique. TheHighQuality
variant uses MikkTSpace.Testing
Unit tests have been added to assert that both tangent computation strategies produce similar tangents for simple shapes. I also tried to check several examples to verify that the visual results are acceptable with both algorithms. I wasn't able to tell any visible difference.
I checked the
deferred_rendering
,parallax_mapping
, andanisotropy
examples. Suspiciously, when I produced intentionally invalid tangents, the deferred_rendering and parallax_mapping examples seemed to render fine. I didn't try the anisotropy example with intentionally invalid values. I'm curious if there is an unrelated bug in the shader where tangents are ignored (or the examples I tested somehow didn't leverage tangents).Migration Guide
GenerateTangentsError::MikktspaceError
has been renamedGenerateTangentsError::AlgorithmError
Mesh::generate_tangents
andMesh::with_generated_tangents
methods are now deprecated. They are replaced bycompute_tangents
andwith_computed_tangents
, both of which accept aTangentStrategy
parameter. The naming conventino of these methods now matchescompute_normals
.