Add multiple materials to a single geometry via code?

#1

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!

0 Likes

#2

You something like Quake III’s multi-textures? I think you’d have to write a custom shader for that.

…or use multiple geometries (or models) on the same location.

0 Likes

#3

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?)

0 Likes

#4

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.

0 Likes

#5

That’s what I’m trying :slight_smile: Specifically -0.000025. I’ll try to play with values a bit more to make it work.
Thanks!

0 Likes

#6

The cursor’s material in Edddy uses <depthbias constant="-0.0000023"/>.

1 Like

#7

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.

2 Likes

#8

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.

1 Like

#9

Hi sorry for not replying I just saw your reply.
Unfortunately I do need different UVs so I can’t use your suggestion. Thanks though! :slight_smile:

I ended up using layers and getting depth bias to work.

0 Likes