Shader - Don't render parts at certain distance

Hey all! I’ve written a shader, which uses quite a few passes to achieve the right effect. Obviously, this is very expensive, and the issue is that some of these passes are only really necessary close up. So I’m wondering whether it’s possible to skip the rendering of certain pixels if they are too far away from the camera, or to skip out entire passes depending on the distance from the camera. I could even make do with a custom fallback, meaning it uses a different shader at a certain distance. Is there any way I can achieve this? I won’t say I’m an expert at CG or ShaderLab, but I do understand the basic concept of how shaders work, and it seems like one or all of the above should be possible…

That’s a really good question. I think the only way to do that is to render the mesh 2 times. Condition in shader should be avoided. But I’m not 100% sure it’s the best way, maybe benchmark multiple solution will be a good idea.

I would make a low quality shader to render only after a certain distance from the camera with a fade value. So pixel too near the camera will be ignore with an alpha of 0. After I render the same mesh with the high quality shader only before the start fading distance of the low quality shader. It would create a nice blend with the low quality/high quality transition.