CesiumGS / CesiumGS/cesium

Make it easier to load textures and cubemaps

Open
#9,741 2 comments 0 reactions 0 assignees View on GitHub
type - enhancement
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

while working on Custom shaders (https://github.com/CesiumGS/cesium/pull/9725) I noticed that the process of building a `Texture` can be a bit cumbersome. Images have to be fetched, you need an `update()` function (since it requires a Context) to actually build the `Texture` object. And these objects must be `destroy()`-ed properly like any GPU resource.

Throughout the code I see a couple places that load an image from a URI or other source:

* `Material.js` -- for image uniforms you can load them from a URI/Resource, but also an HTMLImageElement or HTMLVideoElement. KTX2 and cubemaps are also supported.
* `GltfImageLoader.js` -- glTF images are loaded from a URI/Resource or a typed array. KTX2 is also handled.
* `CustomShader.js` -- slimmed down version of Mateiral.js until we find a better solution
* I'd need to look around to see how imagery, the skybox, and other things load textures.

Some thoughts:

* Using the `ResourceLoader` interface, one could make a more general image loader. Then GltfImageLoader could be a thin wrapper around it.
* Or it could be several simpler image loaders (one for images, one for videos, one for cubemaps)
* This could be used with `ResourceCache` (though depending on the use case this may/may not be desirable depending on the scenario)
* for custom shaders it's necessary to change the value of the texture at runtime
* It would be nice if the interface was even simpler than `ResourceLoader`, e.g. `Texture.fromUri(uri).then((texture) => {...})`, though I'd imagine this would be tricky given the need to load GPU resources in the render loop.

@lilleyse and I plan to talk about this soon.

Contributor guide

Open the contributing guide

Research direction

Read Material.js, GltfImageLoader.js, and CustomShader.js first, then trace the imagery and skybox loading paths mentioned in the issue. Compare their ResourceLoader and ResourceCache usage and clarify the desired loader interface, runtime texture updates, and GPU-resource lifetime; the issue does not yet define a completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.