Providing additional shader parameter to the material instance


I need to provide additional parameters to the material instance used by CesiumGltfComponent, but I’m not sure of how I could do that.

For what I see in the plugin code, the best place to register shader parameters is inside “UCesiumGltfComponent::CreateOnGameThread” (“loadModelGameThreadPart”) function… This function is called inside “UnrealResourcePreparer::prepareInMainThread”, and this class is instanced inside “ACesium3DTileset::LoadTileset”. The cleaner would be to allow user dev to override the default “UnrealResourcePreparer” with a custom one.

Another method would be to create a custom tileset actor (inheriting from “ACesiumTileset”) and check new “UCesiumGltfComponent” on each tick, to setup our additional shader params, but I think it’s a more “hackish” way of doing.

What do you think of those 2 approach, and what would you recommend to provide programmatically additional parameters to the shader (any other idea?)

Hello @Nodrev ,

I think your first approach is a pretty good idea! We’ve had some internal discussion about the current rigidity of the material parameterization code.

Based on your idea, I hardcoded the below code modification in UnrealResourcePreparer::prepareInMainThread (within Cesium3DTileset.cpp). It could just as easily be put in a custom IPrepareRenderResources implementation that is somehow passed in to the tileset as you suggested. For your reference, any custom IPrepareRenderResources should be passed into the TilesetExternals in Cesium3DTileset::LoadTileset where the UnrealResourcePreparer is currently being used.

A small tweak to the GltfMaterialWithRasterOverlay material to test it.

The result

However, such a solution will still only be run on the initial creation of the gltf mesh. To continually update parameters over time, you will still need to hold references or find the wanted CesiumGltfComponent, find the dynamic materials from it as done here, and then update the wanted parameters. Maybe a better way would be to add some virtual functions in CesiumGltfComponent for initializing custom parameters and for updating custom parameters on Tick. Then CesiumGltfComponent can be inherited with implementations for the custom shader parameter handling.

I will open an issue for this and link it here for any plugin changes required to enable custom shader parameters! Please let me know any follow up thoughts or questions you have.


Started an issue for this here: Custom shader parameters · Issue #429 · CesiumGS/cesium-unreal · GitHub