title: how to programmatically allow Unity Shader to control which object renders in front?
body: <p>I've only just started learning Unity, but because I come from a background of coding in C#, I've found the standard scripting to be very quick to learn. Unfortunately, I've now come across a problem for which I believe a custom shader is required and I'm completely lost when it comes to shaders. </p>
  
  <p><strong>Scenario:</strong>
  I'm using a custom distance scaling process so that really big, far away objects are moved within a reasonable floating point precision range from the player. This works great and handles scaling of the objects based on their adjusted distance so they appear to actually be really far away. The problem occurs though when two of these objects pass close to eachother in game space (this would still be millions of units apart in real scale) because they visibly collide. 
  Ex: <a href="https://www.youtube.com/watch?v=KFnuQg4R8NQ" rel="nofollow noreferrer">https://www.youtube.com/watch?v=KFnuQg4R8NQ</a></p>
  
  <p><strong>Attempted Solution 1:</strong>
  I've looked into flattening the objects along the player's view axis and this fixes the collision, but this affects shading and particle effects so wasn't a good option</p>
  
  <p><strong>Attempted Solution 2:</strong>
  I've tried changing the RenderOrder, but because sometimes one object is inside the mesh of another (though the centre of this object is still closer to the camera) it doesn't fix the issue and particle effects are problematic again.</p>
  
  <p><strong>Attempted Solution 3:</strong>
  I've tried moving the colliding objects to their own layer, spawning a new camera with a higher depth at the same position as my main camera and forcing the cameras to only see the items on their respective layers, but this caused lighting issues as some objects are lighting others and I had only a limited number of layers so this solution was quite limiting as it forced me to only have a low number of objects that could be overlapping at a time. NOTE: this solution is probably the closest I was able to come to what I need though.
  Ex: <a href="https://www.youtube.com/watch?v=CyFDgimJ2-8" rel="nofollow noreferrer">https://www.youtube.com/watch?v=CyFDgimJ2-8</a></p>
  
  <p><strong>Attempted Solution 4:</strong>
  I've tried updating the Standard shader code by downloading it from Unity's downloads page and creating my own, custom shader that allows me to modify the ZWrite and ZTest properties, but because I've no real understanding of how these work, I'm not getting anywhere.</p>
  
  <p><strong>Request:</strong>
  I would greatly appreciate a Shader script code example of how I can programmatically force one object who's mesh is either colliding with or completely inside another mesh to render in front of said mesh. I'm hoping I can then take that example and apply it to all the shaders that I'm currently using (Standard, Particle Additive) to achieve the effect I'm looking for. Thanks in advance for your help.</p>