bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Lighting of GLTF models with negative scale is inverted

Open adamwych opened this issue 1 year ago • 4 comments

Update https://github.com/bevyengine/bevy/issues/7901#issuecomment-1454984501

Bevy version

0.9.1 / main branch at f87de368436a1a65aecb8e0088d93244dd5a467c

Relevant system information

AdapterInfo { name: "NVIDIA GeForce GTX 1080 Ti", vendor: 4318, device: 6918, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "528.49", backend: Vulkan }

What you did

I made a model in Blender, exported it to GLTF and imported it inside my Bevy application using SceneBundle:

let box_dude = assets.load("box_dude.glb#Scene0");

commands.spawn(SceneBundle {
    scene: box_dude,
    ..default()
});

commands.spawn(Camera3dBundle {
    transform: Transform::from_xyz(12.0, 36.0, 12.0).looking_at(Vec3::ZERO, Vec3::Y),
    ..default()
});

commands.spawn(PointLightBundle {
    transform: Transform::from_xyz(4.0, 2.0, 4.0),
    point_light: PointLight {
        color: Color::WHITE,
        shadows_enabled: true,
        ..Default::default()
    },
    ..Default::default()
});

What went wrong

Outside faces of box_dude are not lit up: image

If you zoom in, you can see that the edge of the face is kinda lit up, but I guess this is just some bleeding due to the camera being far away and it's actually the inside that's lit up.

If I move the box_dude to be inside the point light, you can see that his head's outside faces are lit up, which is incorrect. image

I tried flipping the normals and re-exporting, but it does not change anything.

The same file looks correct in online GLTF viewers: image

Additional information

Here's the .glb file I used: https://www80.zippyshare.com/v/4UrsUvvL/file.html

adamwych avatar Mar 05 '23 00:03 adamwych

Just to be sure, can you reproduce this on main? 0.10 is just about to release.

james7132 avatar Mar 05 '23 00:03 james7132

Update (another update below!): I fixed it using https://www.gltfeditor.com/ to flip the normals instead of Blender: image

I guess Blender is not flipping the normals correctly for some reason, but the issue still stands, since now the normals are actually inverted (going towards inside), while they were correct in the original file and now it looks wrong in other viewers.

@james7132 I used 0.9.1, I'll have to build 0.10 first. I'll try that in a moment.

adamwych avatar Mar 05 '23 00:03 adamwych

@james7132 Also happens on main at f87de368436a1a65aecb8e0088d93244dd5a467c: image

adamwych avatar Mar 05 '23 03:03 adamwych

Update 2: Using "Apply Transform" on the entire object in Blender fixes the issue.

I did some experiments and figured out that while modeling, I must have mirrored everything at some point. Blender implements mirroring by simply setting the scale to the negative of whatever it currently is and that's where the issue was - the scale of my model was negative so my lighting was "negative" too.

image

I understand the issue now, but maybe there should be some mechanism in place in Bevy to fix those kinds of models during import? Other apps didn't have such problem with this file and it might be very confusing to someone in the future.

adamwych avatar Mar 05 '23 04:03 adamwych

I can confirm that this still happens on 0.10, since I just spent a while debugging it :/

janhohenheim avatar Apr 10 '23 05:04 janhohenheim

Perhaps setting double_sided to true on the material would fix it. Not really sure why we don't enable it by default.

tim-blackbird avatar Apr 10 '23 11:04 tim-blackbird