-
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
Qualified names for metadata access in custom shaders #10085
Comments
Had a (very rough) idea overnight after seeing some of the details in #10520 and #10569. Styling makes use of a I wonder if it's possible for custom shaders to just use a flat list of properties in the That said, such a scheme would be harder to debug, since the GLSL variable names would not have meaning depending on how vari I also am wondering how easy it would be to make the variable substitution map, given that properties can come from various places (property tables, property textures, property attributes, tileset/tile/group/content metadata). Furthermore, it would also be good to think about how this relates to the CPU picking/styling equivalent through In other words, some sort of To sketch out some rough pseudocode: const accessor = model.metadataAccessor;
// For picking/CPU styling (possibly public API?)
accessor.getValue('propertyId') // tries to find the property value but throws(?) if there's a conflict
accessor.getValue('className.propertyId') // a little more specific
accessor.getValue('schemaId.className.propertyId') // very specific
// for custom shaders (this would be private API only)
accessor.getGlslName('propertyId') // returns some auto-generated name, e.g. property_17 or maybe property_propertyId_17 for readability?
// then loop over the custom shader code and regex-replace `metadata.className.propertyId` and so on with `metadata.property_17` Still a bit cumbersome to use, but it might dodge the nested struct generation at least. Regardless, this would require more discussion to see what makes sense |
Right now, metadata is passed to the custom shaders via an
fsInput.metadata
structure that contains the properties. The shader code may access this data, with something likewhere
exampleVector
is the name of a property in "the" metadata class.When there are multiple classes, and two of them have a property with the same name, then this cannot be represented with this structure. (Right now, it will causes the shader compilation to bail out with some ~"duplicate field in struct" error message).
It will be necessary to disambiguate these names. And this disambiguation also has to take into account the schema (because there might be two schemas with the same class name, where the classes use the same property name).
A straightforward solution could be to refer to the variables with fully qualified names, as
(where
exampleSchemaId
is theschema.id
). This is complicated on the implementation side, because it requires the creation of some deeply nestedstruct
s. Alternatively, the qualification could happen with_
underscore characters, as inIn both cases, accessing these properties becomes a bit clumsy. But they both could be reasonable ways of having the data in the shader, consistently and unambiguously.
<brainstorming>
A shader that uses data similar to the example from the specification README currently looks as follows:
Adding the full qualification would yield
Not being deeply involved in the details of the custom shader mechanisms, I wondered whether it could make sense to offer some configurability on this on the API level. Roughly like
so that the respective properties can then be accessed with
fsInput.outsideTemperature
. Possible (idealistic) advantages of something like this could be that</brainstorming>
The text was updated successfully, but these errors were encountered: