Dynamic (procedural) texture in glTF


I would like to generate a texture in JavaScript and then apply it to a glTF Model. When the texture is updated it should be reapplied to the glTF Model.

Is this possible with Cesium/glTF?


Perhaps through a uniform sampler2d exposed through the glTF material? But how?

Cesium doesn’t expose material/texture editing on a model, but there is a workaround in this thread that might be helpful: https://github.com/AnalyticalGraphicsInc/cesium/issues/5094

That should work, thanks!

Also, do you know how to make the Cesium glTF converter support Textured Models? They always seem to fail.

I tried a few simple models and it seems ok from my end. Are you making sure to drag all the files onto the window? Also feel free to post them here or email to me directly.

Thanks, we have managed to make it work by using the glTF 2.0 exporter for Blender. Exporting a .glb embedded the textures as wanted.

I have another question, is it ok to keep going in this thread? I’ll do it anyway, and will relocate if necessary.

We only managed to make the texture export work with glTF 2.0 (because that is the only format supported by the Blender plugin). glTF 2.0 uses PBR, which does not expose shaders to the end user, while 1.0 did make editing shaders possible.

I made a custom shader for the glTF 1.0 model that reacted to the sun position in Cesium and also made the model less bright when the sun was set.

Using the 2.0 workflow the model does seem to react to the sun position, but does not become dimmer when the sun goes down. Is it possible to make the model react to night scenarios?

Maybe we should persue the 1.0 pipeline a bit longer.

Were you able to get this method to work to update the texture programmatically? We were not able to make this work in the past.



Yes, I was. You have to make sure the replacement texture has the same dimensions as the original. That’s where it failed for me at first. Promise.then swallows errors so you might want to add a .catch behind it to see if you had any errors. Or check in debugger with pause on caught exceptions. Good luck.

Hey Laurens

Interesting point about the texture sizes - it might be helpful to recommend that on the github issue too.

For your question above, Cesium doesn’t have proper day-night lighting on generated shaders - but I wrote up an issue for it: https://github.com/AnalyticalGraphicsInc/cesium/issues/6437. By the way, the glTF 2.0 + GLSL extension is coming pretty soon: https://github.com/KhronosGroup/glTF/pull/1296.

Thanks for creating an issue for the lighting. I will be watching both that issue and the glTF 2.0 GLSL PR closely.

Hey would anyone be able to assist. I'm trying to dynamically change the model of an entity by a click. it works for some but sometimes the fragment shader crashes. Thanks guys!

Can you post what crash/error message you’re getting, what browser this is happening on, and a Sandcastle example (https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/) that reproduces that issue? That’ll help a lot in figuring this out!