-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
KTX2 integration -- Dropping support for KTX #9040
Conversation
…cs to handle KTX2, added relevant models/textures
Thanks for the pull request @YoussefV!
Reviewers, don't forget to make sure that:
|
PS. Need to update |
@YoussefV two high level things:
|
@YoussefV could you add a KTX2/Basis sample to |
@lilleyse So should we not include the Balloon 3DTile in this PR? |
@YoussefV yes, the balloon tileset can be removed once the other sample is generated |
Why was |
It showed up as a white thumbnail on my computer, which is exactly how old ktx pictures looked like. So I accidentally deleted it while clearing out old .ktx files. Added it back in the latest commit. My bad! |
// 1 - Download the Filament release (https://github.com/google/filament/releases). | ||
// 2 - Run `cmgen --type=ktx --deploy=/path/to/output /path/to/image.hdr`. Other formats are also supported. Run `cmgen --help` for all options. | ||
// 3 - Take the generated coefficients and the KTX file and load them in CesiumJS as shown below. | ||
// This environment map was processed using Google's Filament project. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these instructions out of date/not working?
One problem we had when initially creating this Sandcastle is it was completely opaque what all these coefficients meant, or how to get your own. The user was never supposed to do this process manually. The glTF IBL extension just wasn't ready at the time.
But now it is: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_lights_image_based#ext_lights_image_based.
This example can be greatly simplified into essentially one line if we just add support for that extension. I would suggest we do that (not necessarily in this PR, open an issue for it?), and/or just remove this example because it isn't very useful to Cesium users as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Google's Filament hasn't been updated to support KTX2. I had to rebuild this cubemap by using this website, which gave six PNG images, which I then had adjust the opacity of and then convert to KTX2 using the command line tool from this repo.
We could always open up an issue to build a tool that automates this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One limitation of using EXT_lights_image_based
is that it needs to be added to the glTF's individually whereas Cesium users might want to set an environment map for the entire scene.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's critical for users to be able to select their own HDR, IBL environments. Can't expect ordinary models to bundle them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would most users know how to/want to manually specify the 9 coefficients as shown here? That was the part I was thinking we could omit from this sandcastle, and fallback to the procedural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you fall back to procedural, the diffuse lighting on the model won't match the specular lighting environment, which is not what a user who cares about lighting environments is going to want to see. That said, I'm no fan of manually specifying spherical harmonics in code, that seems ridiculous and error-prone. But is the alternative to force all users to always accept a default procedural diffuse lighting environment?
By comparison, BabylonJS stores pre-filtered lighting environments in .env
files of their own design, which users can create in their Sandbox (instructions). The .env file contains both diffuse and specular lighting pre-filtered, making it ready to render models with. I don't know if the format is standard or open, but I suppose we could ask. For users this is very easy, just load the env and assign it to the scene, and all your models will have the correct lighting and reflections of the environment.
In ThreeJS, they can now load *.hdr
files directly. But these need some pre-filtering at load time, and they have a class called PMREMGenerator that will do exactly this. This costs some load-time performance, but offers users the convenience of directly using the most common HDR environment format found online.
I like the KTX file, but it looks like the file is only storing the pre-filtered specular lighting environment, and dumping out the diffuse as a bunch of SH coefficients for users to deal with separately. Unless maybe KTX2 has some way to include the diffuse environment as well? Ideally there should be a standard environment format that includes both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been working on the VSCode glTF preview, trying to get nice IBLs in all the preview windows, and it would be nice to include Cesium in this too.
In this commit I hacked up a little sh.txt
file reader, which is the text file that cmgen writes out when it processed an IBL into a KTX. It loads the Spherical Harmonics and builds the array of Cartesians for them. Not sure if this will actually get published, but it seems to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watching a Virtual SIGGRAPH presentation on Filament (Moving Mobile Graphics, ~2:28:00). Romain says they're not using spherical harmonics at all anymore. Instead, they stop the specular IBL mipmaps at 16x16 smallest size with roughness == 1.0 at that size, and they re-use that particular mip level as their diffuse IBL.
I think Cesium should do that too, and ditch the SH coefficients.
// 1 - Download the Filament release (https://github.com/google/filament/releases). | ||
// 2 - Run `cmgen --type=ktx --deploy=/path/to/output /path/to/image.hdr`. Other formats are also supported. Run `cmgen --help` for all options. | ||
// 3 - Take the generated coefficients and the KTX file and load them in CesiumJS as shown below. | ||
// This environment map was processed using Google's Filament project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The environment map looks different than master
. Is this because the image changed or did the IBL implementation change? The environment map should come with a prefiltered mipmap so that rougher materials produce blurrier reflections. Filament was doing this previously but I'm not sure what the new KTX2 generation process is like.
More background: https://learnopengl.com/PBR/IBL/Specular-IBL
From the Image-Based Lighting
sandcastle:
master
ktx2-integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the new image is 4.28MB compared to the previous 2MB. The smaller the better so that we don't bloat the CesiumJS zip release too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YoussefV you mentioned that a straight up KTX -> KTX2 conversion failed. How quick would it be to write our own script just for this? I guess this depends on the number of breaking changes between KTX and KTX2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would take a while because the spec has changed a decent amount. It might be worth it to open an issue in the KTX2 repo about it if we're 100% confident the original KTX file is valid.
The reason why the KTX2 file is larger is because the mip map is uncompressed, so it unpacks the RGB values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was the one who created the KTX2 image, the mip map didn't make the reflections blurrier because it autogenerated the levels without taking into account it was a specular IBL. I think the best approach here is to fix the existing converter since the problem may most likely be that the converter has a bug.
I'll open up an issue there.
@@ -113,7 +113,7 @@ describe( | |||
sampleOctahedralMap(octahedralMap, directionFlipY, lod, function ( | |||
octahedralMapColor | |||
) { | |||
return expect(cubeMapColor).toEqualEpsilon(octahedralMapColor, 5); | |||
return expect(cubeMapColor).toEqualEpsilon(octahedralMapColor, 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember talking about this offline. Once #9040 (comment) is addressed it should be fine to use 5
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That probably explains that. Ok will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to this: the bug currently seems to be with Filament generating an invalid KTX file. More Here
Few miscellaneous things:
Youssef's Comment: All of the above comments have been addressed in latest commit. |
@YoussefV do you by chance have a code example for testing KTX2 as a |
Ok that should be it for my first round of reviews. I haven't actually looked at Aside from mostly minor comments, so far so good. |
Technically, this isn't released yet, so I have no "official" link for this as in here, would I just include the link to the relevant PR? |
Linking to the PR is fine. If this PR gets merged before |
@lilleyse made an incremental push with most of your comments addressed, there still remains a few which are not struck out above. I removed the commented code in This test: |
Talked about this offline, it works with the |
Thanks again for your contribution @YoussefV! No one has commented on this pull request in 30 days. Maintainers, can you review, merge or close to keep things tidy? I'm going to re-bump this in 30 days. If you'd like me to stop, just comment with |
@cesium-concierge stop |
@@ -173,6 +172,8 @@ var uriToGuid = {}; | |||
* {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_techniques_webgl/README.md|KHR_techniques_webgl} | |||
* </li><li> | |||
* {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md|KHR_texture_transform} | |||
* </li><li> | |||
* {@link https://github.com/KhronosGroup/glTF/pull/1751|KHR_texture_basisu} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of this writing the PR has been accepted: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I closed #9054, we can get the fix into this PR now.
the tale of
|
58ad10f
to
6358371
Compare
continued in #9513... |
LoadKTX2.js
that do not pass due to a race condition when calling.simulateError()