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

Panic when normalMatrix uniform is sent to the shader but not used #404

Closed
briteroses opened this issue Oct 9, 2023 · 5 comments
Closed

Comments

@briteroses
Copy link

briteroses commented Oct 9, 2023

Hi, I want to load an object with the three_d_asset load utility and display it in my 3d environment. I'm loading the object as a mesh so I can translate and rotate it before adding it to a Gm, and all of this works, but when I call frame_input().screen().render() on it, I get the error

thread 'main' panicked at 'the uniform normalMatrix is sent to the shader but not defined or never used'

I haven't found a way around this order yet, and an not sure what it means. For reference, the version of three_d and three_d_asset I am using is

three-d = "0.15.0"
three-d-asset = {version="0.5.0", features=["obj"]}

Would greatly appreciate any pointers here!

@asny
Copy link
Owner

asny commented Oct 13, 2023

Thanks for reporting 🙏 can you try to update to version 0.16 and see if it's still a problem? I guess the mesh you are loading doesn't contain normals?

@briteroses
Copy link
Author

briteroses commented Oct 16, 2023

Thanks for the tip! My project currently uses 0.15.0, and it looks like I can't update three-d to 0.16.1 for my project, as that breaks too many things in my project. For the mesh, I'm loading from a .obj and .mtl that I export out of Blender. This is the code I'm using to load an obj mesh:

let mut bot_model_mesh: CpuMesh = raw_assets.deserialize("smallbot.obj").unwrap();
let mat4_from_pose: Matrix4<f32> = isometry_to_matrix(pose);
bot_model_mesh.transform(&mat4_from_pose).unwrap();
Rc::new(Gm::new(
    Mesh::new(context, &bot_model_mesh),
    PhysicalMaterial::default(),
))

and the error occurs on the frame_input render call,

frame_input.screen().render(camera, vec![bot_model], &[]);

@asny
Copy link
Owner

asny commented Oct 21, 2023

It's not a great error message, but the problem is probably that your mesh doesn't contain any normals, at least please check that! The PhysicalMaterial requires normals, so you need to have them on the mesh. You can compute them by bot_model_mesh.compute_normals().

@rcywongaa
Copy link

rcywongaa commented Jan 25, 2024

three-d = "0.16.3"
Btw, this problem is reproducible with the shapes example by removing the lights on
https://github.com/asny/three-d/blob/master/examples/shapes/src/main.rs#L115 (playground)
Or by changing one light to AmbientLight and removing the other light (playground)

Having both lights as AmbientLight triggers a different error

@asny asny changed the title can't render .obj mesh Panic when normalMatrix uniform is sent to the shader but not used Feb 26, 2024
@asny asny closed this as completed in 17b1f13 Feb 26, 2024
@asny
Copy link
Owner

asny commented Feb 26, 2024

@rcywongaa I don't get that error when removing the lights on the shapes example, my guess is that you are on Linux or Chrome OS? The shader compilers are different depending on the OS.

I've tried fixing this particular error in 17b1f13 but since I can't reproduce, it's difficult to know if I solved both of your problems (they might be different problems). At least it should work on Linux/Chrome OS now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants