Greetings,
I have been searching for this issue for quite a long time. I am looking for a way to always set my GLTF mesh on top of everything. I am familiar with quite a few tactics
- depthWrite, depthTest
- custom layers, one for model and one for scene
- using an invisible box, setting render to 999, then adding mesh and setting render to 999 (must tap into onBeforeRender hooks)
All of these solutions are not really ideal. depthWrite renders the mesh out of order. The layers and invisible box have different challenges. I couldn’t utilize layers for my mesh because I needed my mesh to use an environmentMap, which was providing some additional challenges due to the unique ways I had it set up. The final solution almost works, but it involves transparent objects always rendering on top, and any sprites I strike at an intersection also end up being on top of everything.
Is there a way I could implement a mesh always on top based through GLSL? I would love to understand how this would work if possible.
const material = new THREE.ShaderMaterial({
uniforms: {},
vertexShader: `
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
void main() {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
`,
});
I understand this would not work but I believe gl_Position could be changed ever so slightly to make this work correctly. However, I’m also thinking it might be outside of the scope of what is provided by three to us in GLSL (local space, world space, etc). I am also open to any other possibilities of always rendering a mesh on top.
Feel free to let me know your thoughts.