Getting string from metadata into unreal material

So i wanted to process some strings from tileset metadata in a material. Say i want to hide some object by name. That’s a bit tricky, as we can’t really send strings into a shader(as far as i know).
So lets say I agree to settle for just being able to know that a certain string is present in metadata for a certain vertex. Right now any non-number strings are being interpreted as 0.0, but what if we hash them instead, and send hash through a float? User can then write cpp code to hash their own string, and compare the floats.

And here’s actually my commit that adds this functionality via fnv1-32 into the plugin: Hash metadata attribute strings via Fnv1a by installgentoo · Pull Request #902 · CesiumGS/cesium-unreal · GitHub
Could be done as a fnv1-128/vec4 instead, but 32 was sufficiently unique when i used it.

@Kevin_Ring you are helping me with the transparency commit, so could you help with this one too?

Now, i understand people will look at this and go “eww”, but this can’t really be implemented, you just don’t send strings onto a gpu in a vbo. Hash value can be extremely useful, and this functionality is tiny, doesn’t really impact anything else, and will never be invoked unless you setup your metadata to specifically take a non-numeric string.
I present my case in the spirit of ye olde hacker programming, and our business would find this very useful.

The question of documenting this remains - there are comments about metadata attribute casts, but i didn’t see any other documentation, specifically facing editor user. The fact that it’s u32 bits written into a float has to be gotten across, as well as the fact that reinterpret_cast is ub, and similar operation should be performed via char* memcpy, if you want to match those hashes in your own cpp code.

Hi @Alexander_Drozdoff,

I think the best way to hook something like this into Cesium for Unreal is to implement what’s described here:

The custom transformations could potentially be C++ instead of Blueprints.


@Kevin_Ring your enhancement proposal certainly makes sense as a system, but it’s a tremendous system to be implemented, and i don’t have time for that. And i suspect it’s not a priority for you guys, so a small commit, like hashes one, that adds some information load to strings would be useful until a proper system is implemented.

Understood, and thank you for your pull request! Your pull request is a breaking change, though: it used to use the default value for non-numbers, now it returns a hash value. I don’t think it makes sense to hard-code something like that into the official relase of Cesium for Unreal, but you’re of course welcome to continue using your custom changes in a fork.