Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Earth Scale with SubScenes

Discussion in 'Entity Component System' started by turick00, Sep 19, 2020.

  1. turick00

    turick00

    Joined:
    Jul 14, 2020
    Posts:
    31
    Hi all! I'm working on a visualization project to see real-time positions of satellites.



    I have an idea that I'd like to be able to "jump in" to the world and be able to look up at all the satellites moving, perhaps even make it a VR experience so you can just look around. I'm using an amazing globe asset from the asset store from kronnect that is beautiful and feature rich. Clearly this wouldn't be an exact 1:1 representation, because you'd never see the satellites.

    The issue is, the globe itself is actually very small... I think it's just a 1x1x1. I have it scaled to 10x10x10. When I move the camera close to the earth, it's clear this isn't going to work.



    So why not just scale it up to real world values? Because of this.

    My idea is, instead of just moving the camera to the surface of this globe, I could jump into a brand new scene that doesn't use this globe at all. My earliest thought was, create an earth sized sphere to stand on, but then move the point the player is standing on to 0,0,0 so that the distance to the satellite isn't big enough for the floating point problems. Maybe in this scene, 0,0,0 is always the normal of some point of the earth's surface, and as you move around, it's really just the globe spinning underneath you. I don't have a lot of polys, so who cares what the rendering looks like on some other part of this globe?

    But then it got me thinking of how to incorporate this with subscenes. Is this a good fit? Or since it's also an entirely new scene, could I do something where I dynamically create new scenes that are just like an instance of that position on the earth, with proper coordinate mapping for like a 1km x 1km square or something. I doubt curvature is in any way important for a 1km x 1km square, but i suppose if i wanted to i could just use a plane and apply an accurate curvature with shaders?

    I REALLY like the subscene idea, because this is all networked and that means you could seamlessly travel anywhere on the earth and potentially run into another player. Does this sound reasonable for my application?
     

    Attached Files:

    bb8_1 likes this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    The reason that artifacting happens is because of the dynamic precision of floating point numbers. As the scale of your numbers increase, the accuracy decreases. Using double instead of float typically solves this.

    In practice, people typically use one of two techniques:
    1) double-precision camera-relative rendering - All positions are represented in double precision and right before rendering, the objects have their position subtracted from the camera position and the result is converted to float values for the GPU.
    2) floating origin - Effectively, there are multiple origin points that you "jump" between, each having a different representation.
     
  3. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    I'm working on similar indie-project(mmo space combat with earth size planets, moons etc(using dots/netcode)) - but my planet-engine is still in early phase of development. My idea is to have virtual planet in doubles and then to scale it down say with scale factore = 1000 using second camera ofc. So i have vector from camera to double vertex(using Vector3d class from github) i scale it down, convert to float so that gpu can handle it(vecF=vecD/1000 for example). Earth is 6m units so gpu although has doubles they are criminally slow so u must convert d==>f. Trick is similar to eclipse effect : moon is 1.7k km in radius and sun 500+k km radius but during eclipse the sizes(apparent size - not sure this is the right english word) are the same looking from earth. I think proland use similar technique but writing floats directly to screen space - if i understand it correctly - my shader knowledge is not that good currently so i dont know how to do that or is it possible in unity3D. U can check on google proland project they have source code(c++ + opengl though). Important data structure are quadtrees so programmer can have more details on the planet-mesh near camera and less far from camera. Anyways what would be nice is that dots/netcode give support for big worlds making it easier for us to create games which are imo future of gaming(huge scale worlds games) ...
     
    Last edited: Sep 20, 2020
    turick00 likes this.
  4. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    Hi @turick00, I like the way you visually constructed the problem and demonstrated it. As others say, the key is to use a form of floating origin. I take a continuous moving origin approach, you can see an example here:
    . Others move it in steps.
    I give a comparison of the two approaches here. The channel for the video above and the research link cover many different aspects of this issue. I have tried to be thorough but it is a rather big subject and there is more to do :).
    I will have more to say once I release a full scale relative space framework for doing all of this.
     
    turick00 and bb8_1 like this.
  5. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    A few notes about this. It is a good idea to have your geo referenced objects in double for greater accuracy when positioning and doing conversions between coordinates in degrees and cartesian for display in unity.
    Scaling does not solve the general problem of jitter and resolution because the problem scales with it.
    Floating origin allows full scale and reduces jitter, error etc so that is what I recommend to solve the general problems.The degree of full scale accuracy and anti-jitter then depends on how far you allow the camera to move from the origin. You have control over the spatial resolution.
     
    bb8_1 likes this.
  6. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    @cosmochristo Yes - thx for comment - I will also move origin point towards camera position(and change position of all objects in scene according to the change of origin position) - something like ksp did(also in proland project devs do the same thing i think) (there is video of ksp's planet rendering on Unity channel on yt). Idea is when i get close to surface then i will have in main camera space chunk of terrain (that is the closest to the camera position) and 2nd camera will show distant objects. 2nd Camera is something like camera that draws distant objects/parts of big terrain mesh or to say a sky-box dynamic camera. This is my current understanding of the problem. In Proland they do some shader trick they - write directly to screen space without having scaled Earth size objects near camera - but to be honest my shader knowledge is rather shallow so not sure how to do that in Unity3d. There is also Galaxia project by dexyfex (he makes planets size 10 or 15 or even 20 earth size i think). Star Citizen has even planet editor. But in my opinion the best looking planets are in the game Battlescape Infinity.

    Anyways in my opinion Unity especially dots branch of Unity should have support for big worlds since imo that is future of the gaming. Their concurrent engines already have assets that are free for rendering planets etc. Also Unity should have free assets for mesh destruction since this kind of assets are free in other engines too.
     
    Last edited: Oct 4, 2020
  7. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    @cosmochristo If I may ask do you also scale down big objects(along with moving origin position) - since i think - Unity complains if objects are bigger than 1 000 000 units and earth is 6X bigger than that limit? Also there are problems with depth buffer but remedy is to log values as i saw in some script or u do this in some other way? And for example in that galaxia project by dexyfex planets can be 120 000 000 units and his opengl engine(first version and now he uses ue4) renders it with ease - i think that big objects of 120m units must be scaled down right? Say camera is in origin position and some parts of mesh are 60 000 000 units from that position - do some unwanted artifacts like jitter still happen if say 20Xearth-size object is not scaled down? Simply i dont see how Unity can digest 120m units sized object if not scaled down?
     
    Last edited: Oct 4, 2020
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    Unless something changed, when start using doubles with Dots, like burst etc, you loosong lots of its benefits. I haven't tested, but apparently you loose much, on performance gain, if that is an important aspect.

    Regarding large scale objects, just fake them. Use multiple cameras. Smoke and mirrors.
     
    bb8_1 likes this.
  9. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    @Antypodish Yes that might be a problem - mesh of the planet we must represent as a quadtree the fastest data structure i know is linear representation of quadtree so basically u have as element struct with father's id and index of first of his children and after that index 3 next places are the rest of his children and as u get closer to planet near quads are divided so structure grows in runtime and ofc some of quads need to be removed(so one should keep list of free places to populate them with newly added nodes).
    We remove quads(children) when we are farther from father node quad. Other Quad data like node-position(unfortunately must be double) should be placed in hashmap id(key)=>data(value) - there are also local space that is cube and deformed space(proland terms - deformed because we deform cube to sphere for example or we can deform plane/cube to cylinder or ring) and distances are calculated in local space. Sure there might be some faster ways to render planet, structures to use etc but this is my current understanding of the problem- as i wrote in above post - having in mind this is project in early phase. Ofc it would be nice if burst is faster when dealing with doubles - though idk details how much slower it is - i hope it is not some drastic difference.
    Again(i think i wrote this 5 times in my posts here on forums) imo Unity dots should add support for big worlds(especially planets) and also if possible for mesh destruction - all other big engines already have it for free.
    Those links and benchmarks might be interesting i found them few mins ago i need to read it later :
    1. https://github.com/nxrighthere/BurstBenchmarks/tree/9e1387d75279fa0de08a336180b6a6d66ac518ac
    2. https://forum.unity.com/threads/ben...fibonacci-mandelbrot-nbody-and-others.715133/

     
    Last edited: Oct 7, 2020
  10. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    Yeah if you are referring to the warnings in the editor, ignore that, it is misleading because it is simply wrong if you are managing space and resolution with floating origin.
    If you mean to use a log z-buffer then I don't think that is needed. I saw a post about log zbuffer so I did something similar and demoed it in the video added below: after going down to Mars, I go inside the "head" of one after another "angels", each time I increase the resolution of a subspace within the main world space by a factor of 10 (bring far clip plane of first camera closer - make is smaller, and set the second camera front clip to start at same value.
    You need to understand that at the origin the floating point resolution - gap between representable coordinate numbers - is sub millimetre or better. Gap is twice as big at 2, twice as big at 4, ... and so on. So as long as you manage the space by moving things around you while staying at the origin then these issues won't don't show in rendering. I try to explain all these things in my 2019 paper: https://www.researchgate.net/public...ng_Cracks_in_Cyberspace_towards_best_practice.
    this is the "log space" video:
    [/QUOTE]
     
    bb8_1 likes this.
  11. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    @bb8_1 and more abut your z buffer comments: I have a full scale Earth here (vid below) with some more detailed terrain intersecting at a shallow angle - like water on a beach. Z buffer stays rock solid. So with continuous floating origin the rendering issues are solved. With the threshold based floating origin approaches, you can mostly manage rendering issues by keeping the threshold small enough.
     
    bb8_1 likes this.
  12. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    @turick00, the short answer to your questions is that your ideas are good and will work pretty much as you expect. I did a similar thing once on a planet earth project where viewpoints were selected via server web page. Each viewpoint moved the camera to a place on the planet bye reverse-transforming the scene so that the view was a the origin. It is old, done in VRML, but the example can be seen at the end of this presentation video:
     
    bb8_1 likes this.
  13. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    For all ppl who work on planet engine in unity dots here is explained how to calculate normals on gpu i.e. to convert your height map to normal map : https://forum.unity.com/threads/sobel-operator-height-to-normal-map-on-gpu.33159/ also here is proland way of using guadtrees to generate planet mesh - quite a few interesting math facts about quadtrees and planet meshes : http://proland.inrialpes.fr/doc/proland-4.0/core/html/index.html
    also atmosphere rendering is covered here : https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky
     
  14. turick00

    turick00

    Joined:
    Jul 14, 2020
    Posts:
    31
    This thread is proving to be quite invaluable. Thank you all so much for all of the information. I haven't had time to circle back to this issue and try some of these solutions, but I definitely will soon.
     
    bb8_1 likes this.