bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.15k stars 3.57k forks source link

Need to manually set thickness property when importing gltf scene #10931

Open GitGhillie opened 11 months ago

GitGhillie commented 11 months ago

Bevy version

0.12.1

What you did

  1. Create new principled BSDF material in Blender
  2. Set transmission close to 1
  3. Set IOR to something other than 1 to get some refraction going
  4. Export gltf
  5. Load the scene in Bevy using the following code:
    commands.spawn(SceneBundle {
        scene: asset_server.load("scene.glb#Scene0"),
        ..default()
    });

What went wrong

No refraction is seen when the scene is loaded in the Bevy app. Need to manually set the thickness property of the StandardMaterial to achieve a similar look to the Eevee renderer in Blender. The StandardMaterial documentation does not seem to include how to approach this exactly. But ideally it would work out of the box.

transmission

Additional information

Let me know if a reproducer would help, wanted to post first in case I just missed some export setting in Blender.

alice-i-cecile commented 10 months ago

A reproducer would be great. Once you have something small working; can you check if the property is correctly set in the gltF file? There's a chance this bug is on the Blender end, not the Bevy one.

GitGhillie commented 10 months ago

We had some discussion about the issue ⁠here. IMO we should ignore Blender for now and try to figure out the following: How does one create a solid glass material in Bevy?

For example, if you have a Suzanne made of solid glass, you'd set the IOR to 1.5, but what do you set thickness to? Shouldn't it not be necessary to set a thickness value?

Once that is clear it should be easy to create a workaround and/or figure out if it's a Blender issue.

mockersf commented 10 months ago

Thickness in gltf is defined in an extension: KHR_materials_volume https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md

This is loaded by Bevy if it's available.

So you need to setup Blender to export materials with this extension. It can do it (https://github.com/KhronosGroup/glTF-Blender-IO/pull/1646) but I don't know Blender enough to know how to set it there.

GitGhillie commented 10 months ago

Yeah just to be clear, when I ask "How does one create a solid glass material in Bevy?" I'm talking about a Bevy material, nothing gltf related

janhohenheim commented 8 months ago

Quick googling for the Blender export settings says:

Blender 3.3 allows you to add a glTF Material Output node, which includes values for occlusion, thickness, and specular – all the data needed for outputting volumes into a glTF file. When importing a glTF file, this node and associated values are automatically added and set.

If you are creating an object from scratch and wish to output to glTF, you can enable the glTF Output Node in preferences: Preferences > Add-ons > Import-Export: glTF 2.0 format > Shader Editor Add-On

Once enabled, the glTF Material Output Node will appear in the menu under Output Nodes.