bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Emissive materials not displayed properly when imported from gltf files

Open Overblob opened this issue 1 year ago • 4 comments

Bevy version

0.13

Relevant system information

`AdapterInfo { name: "NVIDIA GeForce GTX 970", vendor: 4318, device: 5058, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "550.67", backend: Vulkan }`

What you did

Load a gltf (glb) scene using materials for bloom effect, and using KHR_materials_emissive_strength extension (supported since 0.12: #9553 ) Specifically the glb file used for this test: https://github.com/KhronosGroup/glTF-Sample-Models/tree/main/2.0/EmissiveStrengthTest

What went wrong

  • what were you expecting? Bloom shall be displayed properly, as showed in the previous link

  • what actually happened? No bloom at all

Additional information

Seems to be a regression since 0.12 as it worked properly initially:

From v0.12.0 image

From v0.13.0 image

Edit : if the background seems brighter for v0.13 it's because the code uses the default exposure, which changed for this version, but as far as I can tell, this as no direct relation with the bloom issue (I tested the different const exposure values from the API)

Edit 2: minimal code to reproduce the issue:

use bevy::{core_pipeline::bloom::BloomSettings, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn((
        Camera3dBundle {
            camera: Camera {
                hdr: true,
                ..default()
            },
            transform: Transform::from_xyz(0.0, 6., 12.0)
                .looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
            ..default()
        },
        BloomSettings::default(),
    ));

    commands.spawn((SceneBundle {
        scene: asset_server.load("EmissiveStrengthTest.glb#Scene0"),
        ..default()
    },));
}

Overblob avatar Apr 29 '24 10:04 Overblob

I encountered this issue too while exporting a GLTF from Blender. What might be happening is that during the conversion process the value is somehow super scaled down.

  • Blender: 5.0 Emission strength - Should be quite emissive, it shines brightly in Blender and other GLTF viewers, in Bevy you cannot see any glow.

  • Blender: 200_000.0 Emission strength - The emission radius is several times the size of the object in Blender and other GLTF viewers are broken, in Bevy you can finally see a bit of glow.

IDEDARY avatar Apr 29 '24 13:04 IDEDARY

No exact causes, but here's some info: Gltf emission map is in candela per square meter. Emission strength is a unit-less quantity which scales the emission map (so that the final output also has units of candela per square meter). This issue means we probably are messing up the units somewhere.

NthTensor avatar Apr 29 '24 14:04 NthTensor

I just bisected between v0.12 and v0.13 to find the responsible commit: fcd7c0fc3d10591ba586880bd2cd24d366bd8d21 and associated PR: #11347

(Despite what I said, it finally may be related to exposure...)

Overblob avatar Apr 29 '24 15:04 Overblob

https://github.com/bevyengine/bevy/blob/dae9e5407edb1dbb222e282b5eb88e0f3519d0ac/crates/bevy_pbr/src/render/pbr_functions.wgsl#L453-L457

Here we can see that the emissive_light gets multiplied by the exposure.

I tested after having moved out this variable from the parenthesis and boom, bloom worked again!

Still I'm not sure about this solution, as I don't master the exposure semantics.

As a side note, I 'd like to mention that as of #11347 examples for 2d and 3d bloom are not homogeneous when defining color values: not the same function, nor the same value ranges at all:

https://github.com/bevyengine/bevy/blob/dae9e5407edb1dbb222e282b5eb88e0f3519d0ac/examples/2d/bloom_2d.rs#L38-L47

https://github.com/bevyengine/bevy/blob/dae9e5407edb1dbb222e282b5eb88e0f3519d0ac/examples/3d/bloom_3d.rs#L43-L46

Overblob avatar Apr 29 '24 16:04 Overblob

No exact causes, but here's some info: Gltf emission map is in candela per square meter. Emission strength is a unit-less quantity which scales the emission map (so that the final output also has units of candela per square meter). This issue means we probably are messing up the units somewhere.

Does that mean the tested value corresponds to 5 cd/m^2? Since that's is pretty low considering an LCD computer monitor is 200-300 cd/m^2 and Bevy's default exposure corresponds to a very bright indoor space / a heavily overcast outdoor scene. In those conditions, there's no way something 40x dimmer is going look like it is glowing...

fintelia avatar May 03 '24 05:05 fintelia

The issue is that, as I understand it, the default exposure is tuned to match blender. So one would expect a gltf exported from blender to have visually similar emission. That's not the case.

NthTensor avatar May 03 '24 07:05 NthTensor

The default exposure is tuned so that point lights and directional lights match Blender. Everyone assumes that Blender got the math right, but I'm personally not very convinced.

One possible explanation is that blender is multiplying the values of lights by 683 before exporting, but is leaving the emissive materials with their original scale. Thus when imported into Bevy emissives are 683x dimmer than they appear in Blender.

fintelia avatar May 03 '24 17:05 fintelia

The default exposure is tuned so that point lights and directional lights match Blender. Everyone assumes that Blender got the math right, but I'm personally not very convinced.

One possible explanation is that blender is multiplying the values of lights by 683 before exporting, but is leaving the emissive materials with their original scale. Thus when imported into Bevy emissives are 683x dimmer than they appear in Blender.

This simple multiplication doesn't really match my observed values, either the problem is more complex, or a different number is used :P

Blender: 5.0 Emission strength - Should be quite emissive, it shines brightly in Blender and other GLTF viewers, in Bevy you cannot see any glow. Blender: 200_000.0 Emission strength - The emission radius is several times the size of the object in Blender and other GLTF viewers are broken, in Bevy you can finally see a bit of glow.

IDEDARY avatar May 03 '24 19:05 IDEDARY