- Home /
How to Render a Mesh Always, Ignoring Z-Distance
I'm trying to figure out how to always render a mesh's triangles fully, even if it's partially or completely behind another mesh. Thus, even as it moves further away behind other objects you'd only see it get smaller but still be drawn "in front of" them, with no occlusion culling or Z distance taken into consideration.
Applications might be, for example, to elminate z-fighting of meshes that line the contours of the terrain, or for a line renderer that's right on the surface of a mesh which becomes half-buried depending on the camera angle. You just want things like this to be drawn fully and not chopped off by any meshes they happen to intersect with.
Is this something that can only be done with a shader? I tried setting "ZWrite off
" and "ZTest Always
", but triangles still get chopped off by intersecting meshes regardless, thus I'm not sure what those commands actually accomplish. Tried also setting "Queue" to "Overlay" to no avail.
Try taking a look at the source code for the default 3DText shader. You can download a zip with source for all the built in shaders here:
http://forum.unity3d.com/threads/2085-Builtin-Unity-shaders-source
That shader was made to ignore depths so the 3DText always renders on top of things. $$anonymous$$aybe you can copy whatever it's doing do make a custom shader do the same for your mesh.
Good call, Christian. For future reference, the Text Shader just draws in the regular "transparent" queue and sets:
Lighting Off Cull Off ZTest Always ZWrite Off Fog { $$anonymous$$ode Off }
These are all things I had already tried, and I'm not sure why they didn't work then, but for some reason after I copied them over to my shader the "ZTest Always" setting now does the trick.
I got $$anonymous$$e working by copying UI-Default.shader from the built-in shaders. Setting ZTest Off
and _$$anonymous$$ainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
Answer by Kiwasi · Sep 28, 2015 at 03:57 AM
I would tackle this with two cameras. Put your unhiddable object on a layer only rendered by the second camera. Then set the second camera up to render everything on top of the first camera.
This is the general technique used for things like guns and UI that must always be on top.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024243im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you add something to your pass? 1 Answer
Questions about render distance in an open world game 0 Answers
Hardware skinning support in unity? 1 Answer
Prevent inner edges from being at front 0 Answers
Combining Objects for Performance 0 Answers