Accessing mesh surface material data in spatial shader

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DDoop

How would I access the albedo color of a given MeshInstance’s mesh’s surfaces inside a spatial shader?
As you can see I have 18 unique surfaces on this mesh, each with its own material (I generated this mesh procedurally and saved it, if I can host it somewhere and share the link here please suggest where I should host it).
enter image description here
I would like to apply a shader to the mesh, eventually taking the albedo of each surface and mapping the color value to one out of a collection of textures, and blending the differences between each tile (digression: this lets me use square tiling textures for irregularly/non-square shaped tiles, which is my purpose for writing this shader). I’m just not sure how to first get the surface’s original albedo to the shader.
EDIT: also I’ve been using the material_override to apply the shader, how much does that override? The MeshInstance itself also has 18 empty material slots – the current albedos are strictly from the mesh resource’s surfaces.
EDIT2: The material engine actually has a built-in ability to add shaders on top of each other in succession called “Next Pass;” I didn’t realize this. That answers the organizational aspect of the shaders, but I’m still confused about how to get the previous color into the new shader (without using discard, of course, since that just makes the shader transparent).
EDIT3: Doing some debugging on the mesh revealed I’m setting the UV coordinates incorrectly, it seems that the same UV value is being applied to the entire mesh. I’ve tried fiddling with the generator (which I discussed in my previous question) and I cannot figure out the proper use of the Mesh.ARRAY_TEX_UV array. I wouldn’t expect that to cause problems just passing a color to the next pass of the shader, though.

Is this… Zelda related?

Friends-Games | 2020-07-10 19:43

No, strategy/history sim. I want higher terrain diversity and more control over where political boundaries are placed, so I chopped up the hex tiles of the gameboard into 18 congruent pieces.

DDoop | 2020-07-10 19:45

Hi DDoop, I’m running into a similar problem on 4.0.beta8 and I was wondering if you ever figured this out. If so, how were you able to access the surface materials? Or did you take a different approach? I have more details in this question as well if you’re curious and have the time. Thanks!

bananasam | 2022-12-17 18:41