Hi all,
Is it possible to set multiple materials on the same geometry (of a static model) during runtime from code?
Or maybe there’s a better way to do what I want - multiple textures on the same plane with different UV, color, depth bias and other material-related properties. Any ideas?
Must happen from code, as materials are generated at runtime…
Thanks! Since its a simple geometry it wouldn’t be that bad, but how do I avoid the z-fighting? For some reason even with depth bias I’m seeing flickering (or maybe I just didn’t use depth bias properly?)
Depth bias is exactly what should prevent that. What values are you using? Negative values bring a surface towards the camera - as it were - and should be pretty small: Generally below 10-5.
Are you certain you require separate UVs per material? This requires that the vertex geometry supply multiple UV sets.
If you can use a fixed set of textures that share a common uv per vertex, then you can use an existing multi-texture blending shader, such as the terrain shader, and apply it to any geometry that provides for at least one uv.
Blending shaders avoid all z-fighting, by choosing a texel from one of N input textures, and blending the inputs in some additive way to the output pixel. There is no z-fighting in that use-case. And, there is no overdraw. Multiple objects at the same position and rotation is likely to cause z-fighting, when a slightly more sophisticated shader can do it.