- Home /
Increase render distance for one object only
I would like to increase the render distance of one specific object. I need to be able to see the object from very far away, but I cant have other objects render from that far. I need a script to put on the object, not the camera. I have no clue how to script (Im trying to learn) Thanks for the help. If I need to be more specific then just tell me. (this is my first question) Thanks again!
Answer by Owen-Reynolds · Oct 17, 2013 at 03:45 AM
Seems like there must be a "correct" way to do this. But this would probably work:
Make a 2nd camera with a crazy big view distance, which only shows that object.
Specifically (and this is elsewhere under 2nd cam tricks): make a new layer, maybe FAR_SHOW. Set the object to that layer. Set the main cam's mask to skip that layer, and the 2nd cam to only show that layer. Child cam2 to the main cam (so always exact spot.) Cam#2 depth to 1 (so it draws after cam2) and clearflags to none (unless you want far-thing to show through, then use depth.)
Not as wasteful as you think. But camera's only key off of layers, so won't work if you need far-thing on a layer for physics or whatnot.
I think using two (or more) cameras is the only solution.
You can also just set the second camera's clip plane to start where your first camera's clip plane ends so you don't have to mess with layers (I think).
This is what they do in $$anonymous$$erbal Space Program to render far-away planets. They discuss this in their Unite talk here: http://www.youtube.com/watch?v=mXTxQko-JH0
I've not tested this, but suppose that layers cull out objects much faster than the near/far planes: a well written game engine like Unity probably only applies frustum culling to objects that are in enabled layers.
This is good, however, I cant touch the main camera at all. I can add cameras, but cannot edit the main camera. And, you almost guessed it, I am trying to make a mod for $$anonymous$$erbal Space Program. So is there a way to use other cameras to render it and the main camera (that cant be edited) able to see the rendering of the other cameras? Or am I just reading your answer wrong and thinking of something else. Thanks for your time!
Use both tricks? 2nd cam draws only "far" layer and has near plane increased (to hopefully prevent double-drawing.) Would want to test this right at the "far" boundary for double-draws/no-draws (can push in cam#2 near plane to prevent no-draws) and how bad double-draws look if they happen.
I don't think having the main cam ignore a layer that didn't previously exist counts as changing it. Or you mean mechanically you can't touch it?
I mechanically cannot touch it, cannot select it or anything
Answer by Recluse · Dec 04, 2019 at 12:29 PM
The simplest way would be to add a script to your camera to use layer distance culling.
Set the camera far clip plane to the maximum needed distance.
Then use layer distance culling to set individual distances for layers, with a 'far' layer for your distant object using the camera's maximum clip distance and reducing distance for all the other layers. For example, you could have a 'detail' layer for small objects that only renders up to 50 meters away.
This approach is more flexible than using multiple cameras, and probably more economical.
public class LayerDistanceCulling : MonoBehaviour {
private Camera cam;
public float[] distances;
void Start()
{
cam = GetComponent<Camera>();
cam.layerCullDistances = distances;
}
}
In general this seems better than an extra camera, but not an answer to this Q, since they can't modify the original camera in any way. A script setting cullDistances wouldn't need to be on the camera -- any script could reach out and change them. And multiple cameras is clearly more flexible (each can have slightly different settings). Just not needed if the only thing you want to do is set distance cut-offs.