Search Unity

Planetary Terrain: Quadtree Planets for Unity

Discussion in 'Assets and Asset Store' started by simitro, Nov 10, 2017.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    I had a bit more time to experiment, and it's absolutely related to the detail levels, and not the size of the planet.

    The planet I want to make (and shown above) is 475,000 units in radius. My detail distances array is size 8-9, I didn't experiment with much variations there yet. Detail distances calculator starts at 2,500,000.

    For a test, I just tried a 100,000 radius planet, with the detail levels set to size 6, same heightmap, detail distances calculator starts at 500000, and it looks ok.
    I expand the size of the details array to 7, and the artifacts appear again, just not as clearly. Settting the detail levels to 8 and the artifacts become very clear again.

    I then made a planet 5000 unit radius, distance calculator 25,000, with 8 detail levels, same heightmap, and I can see the artifacts.

    It seems that the size of the planet doesnt matter, but for detail levels 7 and higher the artifacts appear, the higher the detail level, the clearer the patterns become.

    I am just experimenting with with various parameters so far to get a nice result. I can't really say what I need yet, but I notice that my planet looks all smoothed and blurred out if I have lower detail levels. I want crisp , sharp geometry as much as possible. I've been adding in extremely high frequency noise along with the hieightmap in Hybrid mode (this extras noise is not included in the screenshot above) but I find that I need these high detail levels, maybe even higher, otherwise everything looks like soft, gently rolling hills when flying near the surface. If there's a better way to get rougher, more detailed terrain I'd be grateful to hear about it.
     
  2. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    The terrain is generated while the planet is still at a radius of one, so the problem being unrelated to the planet just points to floating point accuracy again. I only ever had these problems with way higher subdivisions though, I'd be grateful if you could send me your project so I can have a detailed look at it.

    The smooth terrain is the product of interpolation. Without it you'd just see pixel-like blocky chunks of terrain, with it those chunks are smoothed, especially with bicubic interpolation. At some point, if you add more subdivision levels it will just make the terrain smoother.

    You can get around that by using higher-res heightmaps (take a look at streaming heightmaps), or by incorporating noise into the terrain generation, either with hybrid mode or using pure noise.
     
  3. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    I created a discord server for support, suggestions and such. Feel free to join!
     
  4. danielsenna

    danielsenna

    Joined:
    Oct 24, 2018
    Posts:
    2
    Can this be used with voxeland or uterrain? Also, can I use my own heightmap instead of generating one? I want to build a voxel model of Mars and wanted to use my own heightmaps to represent the main geographical landmarks of Mars such as Olympus Mons or Valles Marineris. In other words, would I be able to patch together a bunch of my own heightmaps to make a planet and use that planet with voxeland or uterrain to get the voxel aspect that I'm looking for? Thanks in advance!
     
  5. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    1) Unfortunately there's no support for any other terrain assets.
    2) Sure, it just needs to be an equirectangular heightmap.
    3) PT isn't using voxels in any way, that's just unrealistic for terrains as large as planets. The required memory would be huge, even when using very large voxels.
    4) Combining heightmaps of different qualities is still easy though. You'd have to write some custom code for the streaming heightmap, contact me if you need help.
     
  6. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Edit: Fix is out

    Deserialization fails in 2019.1, this is because the noise modules are saved with the wrong extension.


    To use noise modules, change their extension from .txt to .bytes to signalize that the TextAssets contain binary data. The three included noise modules can be found in Planetary Terrain/Noise Modules/: noiseEarthLike, noiseFPSControllerPlanet and noiseSmallEarthLike.

    You can also edit the line that gives new noise modules their extension, SavingNode.cs
    GetInputValue<ModuleWrapper>("input", null).m.Serialize(new FileStream(Application.dataPath + "/" + filename + ".txt", FileMode.Create));

    Just replace ".txt" with ".bytes". Fix will be out soon.

    I'll also transition PT to use Unity.Mathematics and Burst now that they are out. Stay tuned!
     
    Last edited: Apr 25, 2019
  7. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    I'm reading Planetary terrain uses multiple cameras.
    As in my game project I use one camera for on land action and another for flying-in-a-ship action (the game swichts between cameras runtime) I'm afraid it is going to be tricky to configure that.

    Any clarification?

    BTW please, could I see the asset documentation (PDF)?
     
    Last edited: Apr 25, 2019
  8. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Yeah, PT uses multiple cameras. One near camera, one far camera (which is just a child of the near camera), and a scaled space camera. Switching is really not an issue though:

    You'll just need a near and far camera for each single camera you have right now. Then you can enabled/disable the near and far camera just like you would with your single camera.

    Every time you switch you also need to set the following variables to the active near camera: ScaledSpace.mainCamera (Transform), Planet.mainCamera (Camera, make public), Planet.mainCameraTr (Transform, make public).

    Alternatively, you could just teleport cameras instead of switching between them.

    Documentation is attached.
     

    Attached Files:

  9. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    This is a little confusing but I will read the docs. Thanks.
     
  10. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    Hi simitro.
    I purchased the asset and test the FPS Controller. When the planet doesn't moving, is correct but when the planet is rotate, the FPS on the surface doesn't have force rotation.
    Is planned to fix it and/or how I can solve it ?

    Also for Atmosphere, is possible to have more documentation ?
     
  11. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Is your issue that the FPS Controller is not moved along with the surface? That can be resolved like so:
    Just attach the Rotate Around Planet script to your FPS Controller, assign your planet as Parent Planet and set Rotation Speed to the same value as you did on the Rotate script.

    Which atmosphere model are you using (Atmosphere (old) or Atmosphere Mesh), and what are you having difficulties with? I am happy to clarify anything or add a section to the docs!
     
  12. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    I use Atmosphere (old) (isn't Atmosphere Mesh).
    Thanks also for a solve with the problem above, I will test.
     
  13. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Any specific things you want me to explain more thoroughly, or just a bigger general overview? The shader is based on this one which is a port of the GPU Gems Atmospheric Scattering.
     
  14. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    When I use it and add this, I have a black atmosphere with any change (here I want blue for example). Here screenshots (I put a sphere to the Directional Light for show where is the "Sun") :
    upload_2019-5-1_18-45-44.png
    upload_2019-5-1_18-47-2.png
     
  15. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    I see. The atmosphere shader is designed for larger planets, therefore some tweaking is necessary to get good results with a smaller one. I attached an edited version of the script which allows you to move the atmosphere higher (Atmosphere Height slider, default is 0.5). Couple that with an increased Hdr Exposure and you should get better results.
     

    Attached Files:

  16. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    Thanks but I have the same problem so I change to a another script for Atmosphere.
    Some questions
    For "SphericalGravity", is update automatically if the Planet set on "FPSController" change or we need to change also ? I see a your example on the scene System so I try to retry (for test, I reduce distance and size) with the FPSController. I think is can be a new section for your guide/scene example.
    Quads can support shadow like eclipse. I have a another pack for make eclipse and put this on the Planet object but the shadow doesn't show on the Quad. I don't know for this if I contact you or the author of the other pack.
    Thanks in advance.
     
  17. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Atmosphere works for me if you set Atmosphere height to 0.5 and HDR Exposure to something like 5 or higher.
    Capture.PNG

    I'm sorry, I don't understand your other question. There's really nothing you need to do at runtime when using Spherical Gravity, just make sure all GameObjects that should be attracted are in the Objects array. You don't need to do anything in Update.

    I doubt that your eclipse pack is compatible, sorry. Maybe try attaching it to the Quad GameObjects directly (you can enable those by disabling "Hide Quads in Hierarchy")?
     
  18. SinDeSiecle

    SinDeSiecle

    Joined:
    Sep 30, 2017
    Posts:
    18
    Hi Simitro,

    I am tying to use Brunetons Improved Atmosphere on planet with radius 10000. I am gettin this error:

    RenderTexture.Create failed: format unsupported for random writes - RGBA32 SFloat (52).
    UnityEngine.RenderTexture:Create()
    PlanetaryTerrain.Atmosphere.TextureBuffer:NewRenderTexture2D(Int32, Int32, Boolean) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/TextureBuffer.cs:203)
    PlanetaryTerrain.Atmosphere.TextureBuffer:NewTexture2DArray(Int32, Int32, Boolean) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/TextureBuffer.cs:137)
    PlanetaryTerrain.Atmosphere.TextureBuffer:.ctor(Boolean) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/TextureBuffer.cs:35)
    PlanetaryTerrain.Atmosphere.Model:Init(ComputeShader, Int32) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/Model.cs:317)
    PlanetaryTerrain.Atmosphere.AtmosphereMesh:Start() (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/AtmosphereMesh.cs:163)

    This is just one error which comes repeatedly. Others are:

    Kernel 'ClearTex2D' not found
    UnityEngine.ComputeShader:FindKernel(String)
    PlanetaryTerrain.Atmosphere.TextureBuffer:ClearTexture(ComputeShader, RenderTexture) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/TextureBuffer.cs:184)
    PlanetaryTerrain.Atmosphere.TextureBuffer:Clear(ComputeShader) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/TextureBuffer.cs:105)
    PlanetaryTerrain.Atmosphere.Model:Init(ComputeShader, Int32) (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/Model.cs:318)
    PlanetaryTerrain.Atmosphere.AtmosphereMesh:Start() (at Assets/Planetary Terrain/Scripts/BrunetonsImprovedAtmosphere/AtmosphereMesh.cs:163)

    and an argument exception related to this kernel. I am not sure what is going on. What do you think I can do?

    I am on Unity 2019.1.1

    EDIT: This seems to be a version control issue. I tried on the master project on the master computer and none of those errors appeared.
     
    Last edited: May 7, 2019
  19. SinDeSiecle

    SinDeSiecle

    Joined:
    Sep 30, 2017
    Posts:
    18
    However, this time I have another issue: terrain textures are sometimes rendered as black. There are large black areas on the textures on surface.
     
  20. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    The intensity of each of the six textures is stored in the four vertex colors plus the two uv4 channels. If the intensity of every texture is zero, the shader will simply render black. Take another look at Textures in the Visual tab, specifically the Texture Selection Type. With Gradient you shouldn't get any black spots, please send me a screenshot if you do. With Range you get black spots if there are black areas visible in the preview. With Splatmap you get black spots if every channel is zero at a given point. If None is selected, the whole planet will be black when using PT's built-in materials.
     
  21. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116

    The docs says nothing about all the camera setup required. Also Scaled Space camera concept is not well explained. I expected this asset to be better prepared for multicamera situations,(flying in space and landing-walking on planet).In these cases two cameras system is the easiest solution.
     
    Last edited: May 9, 2019
  22. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    You're right, will add a section. As I said, multi-camera is no problem at all, you just need to get used to the complexity of three cameras. I can send you an example scene with a multi-camera setup if that would help.
    What would you want me to add to the scaled space explanation?
     
  23. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    I think the explanation makes it seem too complex.
    Wouldn't it be easier to change the planet object by a simple sphere mesh with a colormap texture applied? (deactivating the planet object and activating the sphere impostor, and viceversa, depending on distance)
    About far and near cameras I don't see why they are necessary.
     
  24. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    The enabling/disabling a sphere object is basically what already happens, it's just integrated into the planet script. I will make a separate script if that simplifies things and also simplify the explanation.

    You're right, for smaller scenes near and far cameras are not necessary. But as planets get bigger and we need a larger render distance, you start to get z-buffer issues as the clipping planes are very far apart. Splitting the depth into two cameras helps avoid this. This is also why near and far cameras are only used in scenes with large planets.
     
  25. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    You also get issues with shadows... if the camera far distance is very big, the resolution of the shadows near the camera get very low. For this reason I recommend experimenting with a cockpit camera, which has a very short far distance, like some 10's of unity units, and another camera for the external stuff. You will get very nice crisp shadows in your cockpit. Note that Unity has a very annoying feature that shadows fade away as they approach the camera far distance, creating ugly bands of no shadow where the two cameras overlap, but there's not much you can do about it. See: https://forum.unity.com/threads/shadow-fadeoff-approaching-far-clip-plane.356893/
     
  26. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    In my project I use other assets as GPUInstancer and this one depends on the active camera in the scene to work.
    I'm afraid the far- near camera setup is going to interfere with that asset and others related to the scene camera.
     
    Last edited: May 10, 2019
  27. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    I'm fairly sure these assets would work just fine if you declare the near or far camera as your scene camera.
    If not, you are unfortunately bound to small planets, as this is a technical limitation of Unity's 32-bit depth I can't do anything about.
     
  28. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    You could also perhaps change the other assets to not rely on camera.main but be provided with a reference to a specific camera?

    I was vaguely thinking of trying GPUinstancer to scatter tons of rocks around on my planet. If you have any success (or negative experiences) in this area please let us know, as I guess many of us are wrestling with similar problems when working with large scale planets.
     
  29. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    If finally I decide to buy PT I will report my experience of integration with GPUInstancer and another assets I use concerning cameras on scene.;)
     
  30. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Can you provide some info on the streaming heightmap?
    The documentation just says I need a .bytes file. What format should this have? What mapping should it use, how are the coordinates for the detailed areas specified...
     
  31. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    It's just a normal PT .bytes file, a normal heightmap file like you would use anywhere else in PT, just way larger usually.
    You don't need to specify any coordinates, the relevant area around the player is always kept in memory. You just need to set the size of that area, and the movement threshold after which said area is reloaded.
     
  32. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Sorry, but this isnt anywhere near enough information to implement. I dont know what the format of a PT file is either, there's utilities for generating them from textures.
     
  33. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    The PT file format is very simple. As described in the docs, it has a 9-byte header encoding width, height (both little endian 4-byte signed int) and is16bit (1-byte, true if nonzero). The raw bytes/ushorts follow, in little endian order, indexed with [y * width + x], (0,0) is lower left. You can import heightmaps from Unity textures with Planetary Terrain -> Utils ->Texture Heightmap to RAW, or from .raw files and uncompressed tiffs with Planetary Terrain -> Utils -> Heightmap Importer.

    To use streaming heightmaps, do the following:
    1) Set Generation Mode to streaming heightmap.
    2) Set the Base Heightmap, a low resolution copy of the actual heightmap you want to use. It is used in places where the high-res copy isn't loaded.
    3) Set the path to your high-res heightmap file. This is a standard PT heightmap file, same format you'd use as a Base Heightmap, or in normal Heightmap Generation Mode. Internally, the path is appended to Application.dataPath, after building you might want to change that (l.52 in StreamingHeightmap.cs). E.g. path to the included desertHeightmap would be "Planetary Terrain/Heightmaps/desertHeightmap.bytes".
    4) Set Loaded Area Size, this is the size of the high-res section of the heightmap that will be kept in memory, where
    (1, 1) would be the complete high res heightmap. A decent value would be (0.1, 0.1), depending on the size of your planet.
    5) Set Reload Threshold to the threshold after which you want, where 1 is the planet's radius. A decent value would be 0.01.

    For visualization purposes you can set Base Heightmap as an empty heightmap with zero elevation everywhere. This makes the loaded area visible.

    Sorry for the inconvenience, will expand the sections in the docs!
     
    Last edited: May 15, 2019
  34. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Ahh, perfect, thanks :)
     
  35. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    How is the height map scaling calculated? The default value is 0.02, what is that, a percentage of the radius? It also looks (from experiment) that the heightmap is only added to the radius, where I would expect the mid-level of the heightmap to correspond with the radius.
     
  36. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Yeah, height scale is max elevation as a percentage of radius. For simplicity it is always added, though you could easily change that.
     
  37. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    I wish to position stuff like houses on the surface of my planet. I wrote a script where I provide the latitude and longitude, and this works nicely, however, I want to snap to the surface of the planet, by casting a ray from high altitude towards the center and detecting the collision, but this only works where the collider has been generated.
    Can I..
    a) enable colliders for all levels without much of a performance hit (maybe have them on a layer only used for this task)
    b) detect when the collider under an object gets re-generated so I can do the raycast as the detail level changes for a position?
    c) generate all colliders at maximum detail during loading, do the raycasting, save the results, and then discard the unneeded colliders?

    There are probably a few other ways to go about this, so any suggestions would be really welcome. Right now I manually fly to the location, and adjust the height up and down until it looks right, but this is time consuming and breaks if I alter the heightmap.

    One other thing that's kind of related, which I haven't looked at yet, is that I want to perform a raycast to a distant object, and detect when it goes behind the horizon and loses line-of-sight. This probably requires detailed colliders located on the horizon. I don't know what accuracy I need yet, but pretty accurate. Any ideas how to approach this?
     
    angel_m likes this.
  38. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    As can you, since I think it is more natural to have highs and lows in the heightmap, deviating from the average planet radius :p
     
  39. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Regarding texturing, I am just looking for ideas for a rocky moon, which looks good both on the surface, and all the way up into space. I can sort of see how I would go about providing texture based purely on distance to the camera. Has anyone tried this and does it help? I'm also not entirely sure how to go about generating textures at different distances that would work well together.
     
  40. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    a) I'm not sure about the performance hit when using colliders everywhere, just try the profiler and see for yourself if it is manageable.
    b) Adding colliders is handled by QuadGameObjectPool.GetGameObject(), which is called in Quad.UpdateDistances(). You can also check if the quad you placed objects on is splitting (Quad.isSplitting), or add something to the end of the Quad.Split() coroutine.
    c) Sure. Would not have optimal performance, but as long as you don't have to something every frame, you should be fine.

    I generally try to stay out of the scene space for such calculations, as Raycast is slow. Have you tried using heightProvider.HeightAtXYZ to get the elevation, like in Planet.InstantiateOnPlanet()? Of course, it will not take the detail level into account, but might be worth a shot.

    Your other problem is way harder to solve without using scene-space raycasting, in this case it's probably the best way. If your planets are fairly small and flat you could perhaps raycast against the scaled space copy?
     
    Last edited: May 17, 2019
  41. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Will add a define :)
     
  42. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    There are the Fade Materials that fade between two textures based on distance, with the right textures and tuning it looks pretty good. I'm also thinking about adding some noise to a TextureProvider so that flat areas don't just have one uniform color anymore.
     
  43. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Is it possible there's a bug in the Fade shader? It looks to me like only the Tiling value from the near texture 0 is used for all other tiling values...
     
  44. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Works fine for me, just make sure to use Texture Scale instead of the usual Tiling and Offset fields.
     
  45. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    Good new, the shader I have on the pack is fixed so I can put this on Quad but I don't know where on the Quad.cs to add the composent in question to allow shadow on this.
    upload_2019-5-21_18-0-24.png
    Thanks in advance for help.
     
  46. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    Do you want to add a specific component to each quad that is being generated? You can attach the component to all quad GameObjects in Pools.cs, after line 117, e.g:

    Code (CSharp):
    1. if(rquad.GetComponent<SgtShadowLayer>() == null)
    2.     rquad.AddComponent<SgtShadowLayer>();
    3.  
     
    Quarior likes this.
  47. Quarior

    Quarior

    Joined:
    Aug 28, 2017
    Posts:
    23
    Thank, is work (with and without "Hide Quads in Hierarchy").
     
    simitro likes this.
  48. Hellgeist

    Hellgeist

    Joined:
    Feb 13, 2017
    Posts:
    5
    I can confirm that everything works fine with one camera at a time (even assuming you switch cams for various reasons such as pilot vs panoramic, etc). For GPU instancing thousands of objects, that gets into an issue that isn't really exclusive to Planetary Terrain, its a floating origin issue.

    This particular floating origin script is pretty flexible. If the impostor asteroids are parented to something, then just add that to object list. If they are always individual objects, then you could set an event at the max threshold where you swap to a single impostor such as a textured disk. Worse case, change the object array to a List, and just dynamically add all the objects to it.

    I dunno how if the latter option would tax resources or not, I haven't added any asteroid fields so far. But I doubt there would be any show stoppers.
     
    Last edited: Jun 19, 2019 at 10:07 AM
  49. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,116
    "..one camera at a time..."

    But Planetary Terrain is not using at least two cameras (far - near) at a time?
     
  50. simitro

    simitro

    Joined:
    Feb 13, 2015
    Posts:
    106
    I think that's what meant, as near and far are in the same place. PT also works fine with just one camera (just near), but then the viewing distance is limited by the zbuffer.