- Home /
Render Extremely Far off Objects
I'm trying to render objects that are very very very very (1.5x10^15) far away. I can adjust clipping planes on the camera to render this far away but the objects are so far away that they don't even render on the screen regardless. Is there any way to render objects this far away as a minimum of 1 pixel or even 5?
Answer by jpthek9 · Mar 01, 2015 at 12:04 AM
You could hard code this feature in with something like...
public float FarRender = 10000; //Minimum distance to far render
void OnGUI()
{
if (Vector3.sqrMagnitude(transform.position, Camera.main.transform.position) < 10000 * 10000)
{
Vector2 ScreenPos = Camera.main.WorldToScreenPoint(transform.position);
if (new Rect (1,1, Screen.Width - 2, Screen.Height - 2).Contains(ScreenPos))
{
GUI.DrawTexture(new Rect(ScreenPos.x, ScreenPos.y, 5,5), *Your 'far texture' for the object*);
}
}
}
This is actually a pretty fantastic solution, but the textures start looping across the screen and even display when the object isn't being looked at, and when rotating the camera the texture doesn't follow the object. I am not an experienced GUI programmer, so is there any way to fix this?
Oh, sorry about that. You have to check if the object is within the camera's view. You can check by doing:
if (new Rect (1,1, Screen.Width - 2, Screen.Height - 2).contains(ScreenPos)) { Gui.DrawTexture(...) }
I added it in to the answer's code. By the way, this is all theorycrafting so no guarantees but I do hope it works for you. I'm not very experienced with GUI either :D
Would there be any other way to do this same strategy but not in OnGUI()? This works great for up to 3 objects but when 100 pop up it becomes more than unplayable...
OnGUI would probably be your best bet though I haven't tested it with that many objects. Definitely don't let the possibility of high performance demand stop you from trying it out. I can't think of any other methods except for maybe rendering to a texture then manually drawing the objects on the texture each frame. If OnGUI turns out to be a bust performance-wise, you could try that out and it might also give you a bit more control over the drawings but editing textures with code can get pretty messy.
Your answer
Follow this Question
Related Questions
How can I make a GameObject move from one side to the other 0 Answers
GameObject Scale as World Coordinates (Units)? 1 Answer
Procedural Skyboxes Based on Scene Data 1 Answer
Extremely Fast Travel 1 Answer
Normal Texture to Skybox 0 Answers