Godot Version
4.5 beta3 but honestly not that important here.
Question
I’m making a 3D pixel-art game with gridmaps. I was hoping to use palette swapping on each gridmap so I don’t have to bake the same texture a dozen times. I DO have a working palette-swap shader I hacked together from a 2D canvas_item one, all I need to do is change 1 shader parameter variable, but 3D array meshes have a caveat: You can’t edit shader properties per-object without duplicating the entire mesh resource using it. (Otherwise it will affect all gridmaps using the texture instead of just the one.)
Unfortunately, the only way 3D palette swapping (or just changing textures in general) on Gridmaps/Mesh Libraries can work is by calling .duplicate(true) on the entire mesh library and editing every mesh’s texture via set_shader_parameter(). This TECHNICALLY works…
…But the problem is that we now have an entirely duplicated mesh library of 86 meshes in the background just to edit one texture. For every gridmap. I fear that it will affect performance later on.
Possible Fixes
I know that the texture created from this will at least be shared by every mesh in the duplicated meshlib, but the meshes themselves are still a problem. We shouldn’t be duplicating 86 meshes just to edit a single MaterialShader variable…
I think individual meshes DO have a seperate override material setting that would work here, but mesh libraries (and by extension Gridmaps) do not have this option? Is it possible to do some dark magic by turning the gridmap into another kind of combined mesh at run-time that supports material overriding, maybe? (Even applying the entire thing with 1 texture will work for me as I’m using an atlas texture.)
I could also just bite the bullet and add each new textured mesh as part of the mesh library but that’s basically the same problem with extra steps?
tl;dr I need to edit a Shadermaterial parameter on a GridMap without affecting other GridMaps. Duplicating the entire meshlibrary works but is very wasteful. Alternative?