Filament: "gltfviewer -s" results in no lighting

Created on 15 Dec 2020  Â·  33Comments  Â·  Source: google/filament

Describe the bug
in windows, command "gltf_viewer my.gltf", that point lighting effect is visible; however, command "gltf_viewer -s my.gltf",that point lighting effect is gone. However, we do not want to scale the scene.

Expected behavior
how could be modify the code to control this?

Most helpful comment

Filament supports KHR_lights_punctual.

All 33 comments

thanks in advance

There’s a directional light by default, no point lights. Could you provide screenshots please? Directional lighting works with or without -s in all my tests.

without -s
无标题
with -s
无标题1
and here is my gltf string, as listed below:
{
"asset": {
"version": "2.0",
},
"extensionsUsed": [
"KHR_lights_punctual",
"KHR_draco_mesh_compression"
],
"scene": 0,
"scenes": [
{
"nodes": [
0,
1,
2
]
}
],
"nodes": [
{
"mesh": 0,
"translation": [
-0.5439453,
0,
8.354431
],
"name": "Box001",
"rotation": [
0,
0,
0,
1
],
"scale": [
1,
1,
1
]
},
{
"translation": [
8.409393,
24.04018,
11.8579865
],
"rotation": [
-0.707106769,
0,
0,
0.707106769
],
"name": "PhotometricLight001",
"extensions": {
"KHR_lights_punctual": {
"light": 0
}
},
"scale": [
1,
1,
1
]
},
{
"translation": [
4.13425446,
-16.18853,
12.9804688
],
"rotation": [
-0.707106769,
0,
0,
0.707106769
],
"name": "PhotometricLight002",
"extensions": {
"KHR_lights_punctual": {
"light": 1
}
},
"scale": [
1,
1,
1
]
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 1,
"TANGENT": 2,
"NORMAL": 3,
"TEXCOORD_0": 4
},
"indices": 0,
"material": 0,
"mode": 4,
"extensions": {
"KHR_draco_mesh_compression": {
"bufferView": 0,
"attributes": {
"POSITION": 0,
"TANGENT": 1,
"NORMAL": 2,
"TEXCOORD_0": 3
}
}
}
}
],
"name": "Box001"
}
],
"accessors": [
{
"componentType": 5123,
"count": 36,
"type": "SCALAR",
"name": "accessorIndices"
},
{
"componentType": 5126,
"count": 24,
"max": [
58.259484098680986,
11.356984611626771,
62.89313910600879
],
"min": [
-58.2570391060088,
-0.061389106008793354,
-62.893139106008796
],
"type": "VEC3",
"name": "accessorPositions"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC4",
"name": "accessorTangents"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC3",
"name": "accessorNormals"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC2",
"name": "accessorUVs"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 573
}
],
"buffers": [
{
"name": "test",
"byteLength": 576,
"uri": "test.bin"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
0.1764706,
0.388235331,
0.24313727,
1
],
"metallicFactor": 0,
"roughnessFactor": 1
},
"name": "01 - Default",
"emissiveFactor": [
0,
0,
0
],
"alphaMode": "OPAQUE",
"doubleSided": false
}
],
"extensions": {
"KHR_lights_punctual": {
"lights": [
{
"color": [
2.78720665,
0.5679655,
0.000001
],
"intensity": 10000,
"type": "point"
},
{
"color": [
0.904883146,
1.0083766,
1.19620013
],
"intensity": 10000,
"type": "point"
}
]
}
},
"extensionsRequired": [
"KHR_draco_mesh_compression"
]
}

In my gltf, there are two point light. we checked the code, without -s, gltf_viewer would execute function "fitIntoUnitCube", why is that?

It does this so the loaded glTF can be visible from the default camera position and entirely visible on screen. This is a pretty common thing to do in 3D viewers.

Can you please share the entire glTF file with us?

@prideout @bejado Any idea why scale would impact lights? I imagine we don't rescale their falloff which would explain why it's more visible without -s.

If the glTF file doesn't have a range set for punctual lights, we give it an arbitrary one (10.0 units I believe). When using -s, the light and geometry probably fall outside this arbitrary range. Perhaps we should be scaling this falloff, or at least using the surrounding AABB to dictate the falloff value.

@bejado That must be it then, I don't see a range in the glTF file.

Based on the above discussion, we added "range":4000 for light property. with -s, lighting is still invisible.

I can't open the glTF file in Blender because of the Draco mesh compression extension.

@JackKaiXing Sorry to bother you, do you have a version of the asset that doesn't use Draco? I'd like to check where the lights are.

@romainguy .

gltf with no draco compression: https://github.com/JackKaiXing/glTF/tree/master/glTF/gltf_WithoutDraco

The positions are correct, so either there's a bug on our side or it's simply that the intensity of the lights isn't enough for the distances because of the falloff.

@JackKaiXing Could you try with brighter lights?

we tried brighter lights by changing its intensity and still no lighting .

It seems that this glTF model includes the KHR_lights_punctual extension, but I don't think Filament supports this extension yet.

For reference, here are the results displayed by other libraries.
|Library|Result|
|:-----:|:-----:|
|Three.js|image|
|Babylon.js|image|

Also, I think the lights on this model are too bright.
image
The specification of this extension says that the unit of intensity is candela (lm/sr).
https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual

sorry for the intensity of 50000 value, it is for our test. However, if we change the intensity to 3000, without -s there is lighting and with -s there is no lighting.

About KHR_lights_punctual, without -s, lighting effects is visible. so I do think it is related.

@cx20

@JackKaiXing I'm sorry. Your point seems to be correct, PhotometricLight001 seems to be a light included in glTF.

|Sun light|Photometric Light 001|Image|
|:----:|:----:|:----:|
|off|on|image|
|off|off|image|

Filament supports KHR_lights_punctual.

Hmm, I tried to display the following model with gltf_viewer, but it doesn't seem to reflect the lights.

https://github.com/Reon90/glTF-Sample-Models/tree/master/2.0/Lights

|No|object name|type |color |intensity|
|-:|:-----------|:----------|:-----:|--------:|
| 1|Light |point |[1,0,0]| 5|
| 2|Spot |spot |[0.1,0]| 10|
| 3|Spot.001 |spot |[0,0,1]| 10|
| 4|Sun |directional|[0,1,1]| 1|

|Sun|Spot.001|Spot|Light|Image|
|:---:|:---:|:---:|:---:|:---:|
|on|on|on|on|image|

Those intensities are too low for the default camera exposure. glTF uses photometric units, so those lights use 5 lumens, 1 lux, etc. Here is the scene with a different exposure:

Screen Shot 2020-12-17 at 8 04 21 AM

Does exposure also works for my case? I really hope to find out as we do not scale the scene.

@romainguy

Yes the exposure works since the light is visible without -s.

@romainguy Does exposure also work for the JavaScript API? I tried setExposure() in JavaScript API, but the box stayed black.

let aperture = 1;
let shutterSpeed = 1;
let ISO = 350;
this.camera.setExposure(aperture, shutterSpeed, ISO);

Perhaps I need to retrieve the glTF light extension information and set it individually like the embedded camera?

Exposure should work in JavaScript yes. @prideout might help here

We do have a JavaScript binding for the 3-argument setExposure, but I have not tested it explicitly. I can give it a try. Let us know if you see any errors in your Developer Tools.

setExposure seems to work for me fine in JavaScript. Below are screenshots with ISO levels 50 and 200.

iso50
iso100

@prideout Hmm, I tried setting setExposure() in the gltf-test Filament sample, but it didn't work as expected.

https://cx20.github.io/gltf-test/examples/filament/index.html?category=tutorialModels&model=FlightHelmet&scale=3&type=glTF

|setExposure()|Skybox|Lights|IBL|Image|
|:----:|:----:|:----:|:----:|:----:|
|N/A|On|Off|On|image|
|(1,1,100)|On|Off|On|image|
|(1,1,100)|On|On|Off|image|

It would be helpful if you could give me some advice.

Those results look correct to me. 1/1/100 is extremely bright, it's a 1 second exposure at Æ’/1, it's the kind of exposure you'd use for night time shots.

@romainguy I'm sorry, I don't know much about cameras, so please tell me what parameters I should set.

For what? The exposure you want to set depends on the intensity of your lights and the visuals you want to achieve. Note that we have a tone mapper that helps with this called "display range". It shows the exposure in EVs using color codes.

@romainguy Thank you for the information. I have to go out now and will try it when I get back.

I completely misunderstood the use of shutter speed in setExposure(). As you pointed out, I used the reciprocal of the shutter speed, and that solved the problem of the blank white.

I improved the Filament sample in gltf-test so that you can adjust the Exposure settings like in gltf_viewer.
https://cx20.github.io/gltf-test/examples/filament/index.html?category=tutorialModels&model=FlightHelmet&scale=3&type=glTF
|setExposure()|Image|
|:-----:|:-----:|
|(16,1/125,50)|image|
|(16,1/125,200)|image|

I understand how to change the Exposure, but I couldn't figure out how to display the KHR_lights_punctual model in the JavaScript API. Can you give me some advice?

https://cx20.github.io/gltf-test/examples/filament/index.html?category=tutorialModels&model=Lights&scale=1&type=glTF
|setExposure()|Image|
|:-----:|:-----:|
|(16,1/125,100)|image|
|(1,1,300)|image|

I have confirmed that the JavaScript API can also display the lights of the KHR_lights_punctual extension by adding the following code.

const lights = asset.getLightEntities();
for (let i = 0; i < lights.length; i++) {
    this.scene.addEntity(lights[i]);
}

https://cx20.github.io/gltf-test/examples/filament/index.html?category=tutorialModels&model=Lights&scale=1&type=glTF
|setExposure()|Image|
|:-----:|:-----:|
|(1,1,300)|image|

https://cx20.github.io/gltf-test/examples/filament/index.html?url=https://rawcdn.githack.com/JackKaiXing/glTF/f593cb10952c373cc11074b50142ff3a299a89ea/glTF/gltf_WithoutDraco/test.gltf&scale=0.02
|setExposure()|Image|
|:-----:|:-----:|
|(16,1/125,100)|image|

Was this page helpful?
0 / 5 - 0 ratings