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

"gltfviewer -s" results in no lighting #3366

Closed
JackKaiXing opened this issue Dec 15, 2020 · 34 comments
Closed

"gltfviewer -s" results in no lighting #3366

JackKaiXing opened this issue Dec 15, 2020 · 34 comments
Assignees

Comments

@JackKaiXing
Copy link

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?

@JackKaiXing
Copy link
Author

thanks in advance

@romainguy
Copy link
Collaborator

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.

@JackKaiXing
Copy link
Author

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"
]
}

@JackKaiXing
Copy link
Author

JackKaiXing commented Dec 15, 2020

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

@romainguy
Copy link
Collaborator

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.

@romainguy
Copy link
Collaborator

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.

@bejado
Copy link
Member

bejado commented Dec 16, 2020

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.

@JackKaiXing
Copy link
Author

The entire glTF file.

https://github.com/JackKaiXing/glTF/tree/master/glTF

@romainguy
Copy link
Collaborator

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

@JackKaiXing
Copy link
Author

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

@romainguy
Copy link
Collaborator

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.

@JackKaiXing
Copy link
Author

@romainguy
Copy link
Collaborator

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?

@JackKaiXing
Copy link
Author

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

@cx20
Copy link

cx20 commented Dec 17, 2020

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

@JackKaiXing
Copy link
Author

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

@cx20
Copy link

cx20 commented Dec 17, 2020

@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

@romainguy
Copy link
Collaborator

Filament supports KHR_lights_punctual.

@cx20
Copy link

cx20 commented Dec 17, 2020

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

@romainguy
Copy link
Collaborator

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

@JackKaiXing
Copy link
Author

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

@romainguy

@romainguy
Copy link
Collaborator

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

@cx20
Copy link

cx20 commented Dec 17, 2020

@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?

@romainguy
Copy link
Collaborator

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

@prideout
Copy link
Contributor

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.

@prideout
Copy link
Contributor

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

iso50

iso100

@cx20
Copy link

cx20 commented Dec 17, 2020

@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.

@romainguy
Copy link
Collaborator

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.

@cx20
Copy link

cx20 commented Dec 17, 2020

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

@romainguy
Copy link
Collaborator

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.

@cx20
Copy link

cx20 commented Dec 17, 2020

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

@cx20
Copy link

cx20 commented Dec 18, 2020

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

@cx20
Copy link

cx20 commented Dec 18, 2020

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

@prideout
Copy link
Contributor

prideout commented Apr 7, 2021

I think this bug is resolved, if not feel free to add a comment.

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

5 participants