Author Topic: Storing a string value in a custom shader  (Read 531 times)

Hi, I'm trying to store a "layer_name" variable for a custom layered shader.  I tried using a sampler2d parameter to store the name in since that is the only GLSL data type that can contain string data.  That works, but the shader seems to be trying to load the non-existant texture and it is causing huge performance issues.  It goes from 60fps to 20fps when I store the data this way.  I also tried to just store the name as an extra parameter on the Materials array objects, and I can read it fine, but I can't find any way to set that extra parameter from within Painter.  The only parameter that it seems you can set from Javascript on the shader is the "value" parameter.  Is there another way I can store string values in the shader file and have them be editable by the user?
Lead Technical Artist
Cloud Chamber
2K Games

Hacking our shader system to load custom metadata seems like the wrong way to go to me (unless I misunderstood your use-case). I would suggest managing your data on the side and feeding it to the shader manually instead. You can store custom metadata in projects via the API (both Javascript and Python).
Don't forget your log file. It can be exported from the Help menu of the software.
-----------
Fabrice Piquet aka Froyok. Product Manager, Technical Artist and Documentation at Adobe.

Yeah I ended up trying to store the data in project settings.  However it's definitely not straightforward, as a alg.project.setttings call from my shaders custom_ui.qml file sets data that is not available when alg.project.settings is called independently from my custom exporter.  I ended up having to also store all my data in an external JSON file so that two different Javascript contexts could both access it.  Additionally it's quite fragile as the data is tied to either shaderID or shader name, both of which can change and leave messy data behind.  Being able to attach it to the actual shader object would be much cleaner, but doesn't appear possible currently. 
Lead Technical Artist
Cloud Chamber
2K Games

Right each plugins has only access to its own settings only. We know it's not ideal and have plan to improve that in the future with the Python API. Meanwhile the best I can suggest would be to make two plugin communicate via a socket/server to exchange information. This way you have a plugin that store the data independently from the shader settings view (and bypass the file on disk).
Don't forget your log file. It can be exported from the Help menu of the software.
-----------
Fabrice Piquet aka Froyok. Product Manager, Technical Artist and Documentation at Adobe.