InstancedMesh with instances having different polygonOffsetFactors?

I’m wondering if it’s possible to create a material for an InstancedMesh that has an additional buffer attribute to allow different polygonOffsetFactors and polygonOffsetUnits? I’m not at all familiar with how materials for instanced mesh’s support setting different colors, but figure if that’s possible I might just be able to pull off supporting this other material attribute. If it’s not possible I’m hoping someone wiser than me can help me prevent spending too much time diving into it to figure out that answer on my own

It is not, unless you implement this yourself in the shader somehow.

2 Likes

Thanks! Yea I figured it would likely involve making my own shader. Hopefully this doesn’t turn out to be too time consuming to figure out

Are you sure you need that?
notice the polygonOffsetUnits and polygonOffsetFactor…

I think the ratios of those values control how the offset is distributed over distance.

I use them to layer 2D UI within the same plane for digitalbacon-ui

I’m open to suggestions that avoid the polygonOffset attributes if it still lets me do things like the below example

What about rendering one thing first, then another thing on top of it?

Do you mean using renderOrder? I think there’s still be z-fighting happening for that?

Well, you can turn off ordering altogether and order them any way you want. You can also turn off depth testing.

You can try renderer.logarithmicDepthBuffer

@dubois I’ll play around with that and see if I can apply that to the shader for instanced meshes. I do want depth testing for the rest of the scene, but there might be a way to get that all sorted out
@manthrax Will see if that helps thanks for the rec

You can render the background of the plate and write to stencil and depth, then you can render the contents and clip them inside the stencil without depth testing, then render the rest of the scene.

1 Like