I’m sorry if this question sounds stupid, but does the world size of an object have any potential impact on performance ?
For example,let’s take a 20 sides textured sphere, is there a performance difference if it’s 20 meters wide versus 2000 kilometers wide ?
I thought about rendering test rays having to travel a lot of units before landing on the 2000 kmeters sphere, considering both are in a world based on centimeters units.
The main thing you would have to worry about is floating point inaccuracies. The further away from the origin you are, the less accurate your calculations will be.
That and any application of physics. Most physics modules, in 3d packages like things to be real world size. But if you’re in space, you should be fine.
No, I didn’t mention bad lighting, I said floating point inaccuracies. This applies to anything that uses floating point numbers, including but not limited to lighting, physics, Vector math, etc.
So for example lets say its accurate to 6 significant numbers. Within 1 unit from the origin, you can be accurate up to 0.000001. Then if you’re between 1 and 10 Units you can be accurate to 1.00001. Move to 10 Units away, 10.0001. 100 Units away it becomes 100.001. At 1000 Units from the origin it’s at 1000.01, which means if you are treating 1 Unit as 1 meter, you can only get accurate to 1cm. Move to 10000 Units away and you can only become accurate to 10cm!
Now this isn’t exactly how it works in Unity, but it should give you an idea of how it can affect calculations on many different areas. If you can only measure a players position to the nearest 10cm, well I think you’re going to have some very jittery movement.
It is a background planet, so it should not create any problem
I wonder how other devs would handle the problem if they use such huge units in some effective geometry for other kinds of games, like a big map in a platformer …
Unfortunately, it will. With a planet that large and (presumably) far away, you would need to set your far plane to an astronomically large range to prevent the planet from being culled. This will probably mean you will loose depth buffer precision in your playing area. Also, you will lose performance from not being able to cull distant objects.
Ok, I’ll see this week-end if I have to reduce that planet size onto another separate cam. This would lead to an additional draw call, though … Too bad.
But I want to put a realtime sunset growing from behind this planet, so I’m stuck with 3D :roll:
On another hand, what was interesting with using huge distances is that even if I moved the main camera from 4000 units left to right, the foreground objects would move, but not the planet.
That gave a great sense of hugeness
I think I will reduce its size to meters and put it on a second camera.
this is an old thread, but I thought I’d mention my approach to a similar problem.
I have a special layer called “celestialBodies”, where I put planets, the sun, basically huge objects I want to be seen from huge distances.
The player has two cameras attached. They are set up like this:
planetsCamera
Clear Flags: Skybox
Far clip plane: 100000
Depth: 0
Culling Mask: celestialBodies
-----------------------------
Camera
Clear Flags: Depth only
Far clip plane: 3000
Depth: 1
Culling Mask: Everything except "celestialBodies"
Like that, my planets are drawn at pretty much any distance, but everything else isn’t. In the attached screenshot, the planet is 4000 units large and about 25000 units away; the sun is just a big light with a flare, about 40000 units away, and the other stuff is in the near plane, max. 3000 units away. If you look closely, you can see the planet is illuminated by the sun.
Now, this might not be the best way to implement this; especially the huge light source is probably quite a hit on performance. For planets I guess a custom shader with an illuminated an a dark side, properly rotated, would be better. To be honest, I hacked this together in maybe half an hour, but it works for now
Hello everyone, just thought I’d post a fix I found for the far clip issue. This may not be eitirely economical but it worked for me. Attach two cameras to your player, title one Main Camera and the other Distance Camera. Use normal clipping on main Camera, and set Distance camera to have an astronomical far clip plane, but force it to render only objects tagged “Distant Object” or something like that. I used this approach to create a Distant View effect, much like Bethesda Softwork’s Oblivion game. It gave the desired effect without having a significant impact on preformance, as distant cam is only rendering a few objects.
This is a common problem for most game engines. Typically you don’t really want to go beyond 10,000 units from the world origin in most games or you start getting strange rendering artifacts.
Perhaps you can use a seperate camera and small scene setup which just renders the planet. Render to a texture , you can display that on a billboard in the distance. Can still have your fancy lighting then.