-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
issue with shape::plane uv or indices order #1018
Comments
Could you maybe upload the whole project? |
Hi, sorry, for some reason the modified 3d_scene was not attached. |
Yup that definitely looks flipped to me! |
I have looked into that, because I have experienced weird UV-Mapping for Boxes and Cubes. I would be willing to fix this, however I would need to know as @trashuj noted if the UVs or the indices are wrong. |
Running into this as well. I'm playing with building out quads by hand for voxel chunks and wanting to use a generated texture atlas, so having the UVs be intuitive would be very helpful. Curious if you think this will be addressed as part of the v0.6 graphics pipeline changes @cart or if the best solution here is to just invert the UVs (I believe subtracting them from 1 should do the trick but haven't tested). |
This won't be directly addressed by graphics pipeline changes. But this definitely seems like something that should be fixed. We should do a quick comparison to other applications like godot + blender just to make sure we're aligning to the ecosystem. Whoever wants to pick this up is welcome to do it! |
I'm relatively new to rendering, but I found several supporting posts with what I had assumed might be the issue. I assume that when we load the images we are loading them the standard 0,0 at the top left position. However OpenGL (and I assume SPIRV) assumes UV originates at the bottom left of the image. The options seem to be:
I wanted to toss this out here as rust's image library does have a Again, I want to caveat that this is pretty new to me, so I didn't want to go proposing changes collecting concerns first. Posts |
wgpu is "top left y down" for images afaik (same as vulkan and metal). I don't think we should try to change that (or flip things on load). Images are also generally defined this way. I think we need to account for this solely in the uvs we generate for our meshes. |
Ah, indeed that's where my limited knowledge was likely getting in the way. Understanding that UV coordinates in this renderer are top left helps immensely. I'm assuming for model loading, e.g. In either case I think this should be enough to correct my understanding. I may add a note to the bevy cheatbook regarding UVs. |
# Objective Fix bevyengine#1018 (Textures on the `Plane` shape appear flipped). This bug have been around for a very long time apparently, I tested it was still there (see test code bellow) and sure enough, this image: ![test](https://github.com/bevyengine/bevy/assets/134181069/4cda7cf8-57d9-4677-91f5-02240d1e79b1) ... is flipped vertically when used as a texture on a plane (in main, 0.10.1 and 0.9): ![image](https://github.com/bevyengine/bevy/assets/134181069/0db4f52a-51af-4041-9c45-7bfe1f08b0cc) I'm pretty confused because this bug is so easy to fix, it has been around for so long, it is easy to encounter, and PRs touching this code still didn't fix it: bevyengine#7546 To the point where I'm wondering if it's actually intended. If it is, please explain why and this PR can be changed to "mention that in the doc". ## Solution Fix the UV mapping on the Plane shape Here is how it looks after the PR ![image](https://github.com/bevyengine/bevy/assets/134181069/e07ce641-3de8-4da3-a4f3-95a6054c86d7) ## Test code ```rust use bevy::{ prelude::*, }; fn main () { App::new() .add_plugins(DefaultPlugins) .add_startup_system(setup) .run(); } fn setup( mut commands: Commands, assets: ResMut<AssetServer>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>, ) { commands.spawn(Camera3dBundle { transform: Transform::from_xyz(0., 3., 0.).looking_at(Vec3::ZERO, Vec3::NEG_Z), ..default() }); let mesh = meshes.add(Mesh::from(shape::Plane::default())); let texture_image = assets.load("test.png"); let material = materials.add(StandardMaterial { base_color_texture: Some(texture_image), ..default() }); commands.spawn(PbrBundle { mesh, material, ..default() }); } ``` ## Changelog Fix textures on `Plane` shapes being flipped vertically. ## Migration Guide Flip the textures you use on `Plane` shapes.
Bevy version
commit 1398d78 (HEAD -> master, origin/master, origin/HEAD)
Author: Corey Farwell coreyf@rwell.org
Date: Fri Dec 4 17:31:17 2020 -0500
Operating system & version
Windows 10
What you did
Display a texture on a shape::Plane.
I modified the 3d_scene.rs to create a simple example (in zip file):
shape.zip
What you expected to happen
Looking at the original png ("textures/rpg/mobs/boss_bee.png"), we can see it's mirrored, ie it looks like we would look at it from the bottom except we look at it from the top (hope that makes sense)
What actually happened
texture is flipped
Additional information
I tried playing with the uv and indices order in shape.rs / struct Plane, but i'm not sure what is the global logic (are the indices wrong or UV?).
Also note that shape::Quad version is correct.
The text was updated successfully, but these errors were encountered: