Search Unity

Planetary Terrain

Discussion in 'Assets and Asset Store' started by HenryV, Dec 4, 2013.

Thread Status:
Not open for further replies.
  1. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, sorry to say DX11 support has not yet been added but it will be soon.

    Better water and atmospheric scattering are on my list but I cannot guarantee they will be added very soon. I am focusing on the terrain part at the moment so texture and normal map generation, additional noise algorithms, heightmap import and improving the terrain painting are the highest priorities.

    There wont be any additional charges for updates and fixes.
     
  2. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    I can live without the atmosphere shader for now, however if you have the other 2 working would you be willing to send them to me if I buy now? I have other assets that use dx11 in my project..
     
  3. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Sure thing, I uploaded the newer versions of the shaders that run under DX11. The atmosphere shader and final versions of these will follow soon and I will update the package then.

    http://planetaryterrain.com/files/TerrainAndWaterDX11.zip
     
  4. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    excellent, purchase inbound ;)

    sweet! got it ;)
     
    Last edited: Dec 14, 2013
  5. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Thanks for the DX11 Shaders.
    Deal!!!. New customer here. :D

    Edit :

    First contact is pretty good. Stunning frame rate. :cool:
     
    Last edited: Dec 15, 2013
  6. HeadClot88

    HeadClot88

    Joined:
    Jul 3, 2012
    Posts:
    736
    @HenryV - I am really loving the look of this asset so far. I have only glanced over the tutorial video and this thread. However I love how it looks so far. :)

    Just curious about a thing or two -
    - Does this work on Linux? This is one of my targeted platforms so if this could be answered it would be very much appreciated. :)
    - Would it be possible to have planetary terrain orbit a star or another celestial body?


    Also a possible list of improvements for this plugin -

    - A Biome Editor - An tool for Planetary Terrain that accepts textures and 3D models from Unity3D. Which then we can "Paint" the biomes over our planets or generate the pre-made biomes at run time for pre-defined planets. This is just to make our planets allot more vibrant and alive looking than a giant tessellated sphere. I am not trying to insult or anything this is just how the player will see it...

    Thank you for your time,

    Ben
     
    Last edited: Dec 15, 2013
  7. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    ok, first impressions:

    overall, not bad, but there are a few issues that I spent time fixing and some thoughts:

    • there was a useTextures bool that was getting set however nothing was using it. I added an additional if statement above the useBumps statement
    • seaming... a lot of it. even with textures turned off.. as with other ROAM/CLOD implementations, there is a lot of popping.. to be honest, for those of us that are using the dx11 shaders, why not use tessellation and displacement? I think it'd look better and the overall framerate would increase dramatically..
    • i'm getting weird artifacts and vertex shuddering when I change the near clipping plane to less than 0.5..
    • initially, I was getting the message "Shader wants tangents, but the mesh doesn't have them".. so I added a function to generate the tangents..
    • the noise functions can be generated on the GPU.. check out the turbulence library.. it's good stuff.. I think he's even updated it with 4d implementations as well..
    • the rendering feels a bit clunky, with all of the homegrown patch visibility stuff going on.
    • if threading is available for the editor, then it should take advantage of it imo.
    • this is going to need a *really* good texture blending/splatting/detail shader that will blend from the center -> out.. 7 or more blend textures at least.
    • atmospheric scattering. fortunately, I have sources available to me to address this, however absolutely needs to be added to the asset
    • water. water. water. this is going to be one of the most difficult things to accomplish however could be one of it's most major selling points. needs a 4d ocean/FFT shader solution ala outerra/proland with shoreline/depth detection etc..
    • the cool thing about having a texture splatting shader is that you already have the basis for slopes/terrain types for biomes built in..

    ultimately I think it was a good purchase, price point is about right, and as long as the author supports and maintains this I think it can be a huge seller and benefit to the community at large.

    it has *huge* potential, please don't let this go by the wayside henry, I don't have time to finish my proland port lol
     
    Last edited: Dec 15, 2013
  8. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Very nice, I am clad the first contact was good. :) Hopefully the experience will continue the same way!
     
  9. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    This was a bug, good catch, thanks!

    I have and will further investigate using DirectX11 vertex displacement shaders in the future, definitely should increase performance and hopefully help with other issues.

    Do you mean the z-fighting between the water and terrain? That is the reason I use dual camera setup in the demo scenes.

    This is caused by the DirectX11 shaders I sent you earlier, the current regular shaders suppress that message by setting the tangent to zero.

    I am aware of this and will investigate implementation feasibility of the whole node system in the shader.

    Lots of good improvement ideas here! I will consider all of them in future updates. Setting the bar at Outerra / Proland level seems bit high at the moment though. :) But maybe something could be achieved if there was enough community support...

    I am clad you are overall satisfied with the package. I plan to improve the product if there continues to be enough interested users!
     
  10. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Thanks for the input!

    I am not sure about the Linux support since I haven't been able to test it. I don't know about any issues there could be with it but I really don't know how well Unity applications translate to that platform.

    Setting a planet to orbit another celestial body is definitely possible!

    The biome editor is a very interesting idea and actually something I have been considering! I see how this would help with designing more interesting planets overall.
     
  11. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    no worries ;)
    i'll post the tangent generation code if you like as well.. I think I actually got it from the community here anyway ;)

    i'm investigating as we speak as well ;)

    .. so far, i'm seeing not only an increased framerate, but load as well. one thing I've noticed is the draw calls.. we need to get that *waaaay* down.. 250+ when on the planet is a killer considering that's without water and atmosphere/scattering, stars, nebulae, other planets, biomes etc.. just terrain.. at least while running it in the editor, I haven't tested it with a build yet.. the additional threading will help, but throwing more threads at it is definitely more of a brute force approach ;(

    yes. it's more apparent the smaller the radius of the planet. no worries though, there are things that can be done relatively easily to address that

    thanks ;)
    and yeah, outerra/proland is indeed a high bar, but if it was easy, everyone would be doing it! <grin>.. seriously though, this asset has been needed for a while imo, and a serious thank you to you for doing it. I know there is also etherea1, however I just couldn't get myself to pull the trigger on buying it, I feel this has more potential. again, just my opinion ;)

    as far as community support? count me in! hehe i'm already tearing through your asset for things I can do that might be of benefit to you or other licensees, like some sort of terrain mapper for biomes, texture splatting etc.. i'd *love* to throw some FFT at your water to see what can be done.. if I do and you like it, add it to the asset, but that's in the future ;)

    so yeah, overall i'm excited with it ;)
     
  12. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Can you post the fix please?

    Edit :

    Thanks. :D


    +1, i'm also an Etherea customer. ;)
     
    Last edited: Dec 15, 2013
  13. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    oh, btw.. while experimenting I came across your mesh generation stuff.. if I just render the mesh.. there are gaps between the shells, and correct me if i'm wrong, but it looks like you spend a bit of time sorting that out.. is that true? if so, I have relatively the same alg for creating the 6 shells that don't have that issue.. I can post that as well if you like?
     
  14. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    (henry, please check your pm's)

    sure ;)

    add the following to the Surface.cs. I added mine above the GenerateMesh func, but it really doesn't matter ;)

    to be honest, it was a quick hack.. this could (and probably should) be done in the GenerateMesh func instead of going thru the entire vertex array, but.. shrug..

    Code (csharp):
    1. private Vector4[] calculateMeshTangents(Mesh mesh)
    2.     {
    3.         //speed up math by copying the mesh arrays
    4.         int[] triangles = mesh.triangles;
    5.         Vector3[] vertices = mesh.vertices;
    6.         Vector2[] uv = mesh.uv;
    7.         Vector3[] normals = mesh.normals;
    8.  
    9.         //variable definitions
    10.         int triangleCount = triangles.Length;
    11.         int vertexCount = vertices.Length;
    12.  
    13.         Vector3[] tan1 = new Vector3[vertexCount];
    14.         Vector3[] tan2 = new Vector3[vertexCount];
    15.  
    16.         Vector4[] tangents = new Vector4[vertexCount];
    17.  
    18.         for (long a = 0; a < triangleCount; a += 3)
    19.         {
    20.             long i1 = triangles[a + 0];
    21.             long i2 = triangles[a + 1];
    22.             long i3 = triangles[a + 2];
    23.  
    24.             Vector3 v1 = vertices[i1];
    25.             Vector3 v2 = vertices[i2];
    26.             Vector3 v3 = vertices[i3];
    27.  
    28.             Vector2 w1 = uv[i1];
    29.             Vector2 w2 = uv[i2];
    30.             Vector2 w3 = uv[i3];
    31.  
    32.             float x1 = v2.x - v1.x;
    33.             float x2 = v3.x - v1.x;
    34.             float y1 = v2.y - v1.y;
    35.             float y2 = v3.y - v1.y;
    36.             float z1 = v2.z - v1.z;
    37.             float z2 = v3.z - v1.z;
    38.  
    39.             float s1 = w2.x - w1.x;
    40.             float s2 = w3.x - w1.x;
    41.             float t1 = w2.y - w1.y;
    42.             float t2 = w3.y - w1.y;
    43.  
    44.             float r = 1.0f / (s1 * t2 - s2 * t1);
    45.  
    46.             Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
    47.             Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
    48.  
    49.             tan1[i1] += sdir;
    50.             tan1[i2] += sdir;
    51.             tan1[i3] += sdir;
    52.  
    53.             tan2[i1] += tdir;
    54.             tan2[i2] += tdir;
    55.             tan2[i3] += tdir;
    56.         }
    57.  
    58.         for (long a = 0; a < vertexCount; ++a)
    59.         {
    60.             Vector3 n = normals[a];
    61.             Vector3 t = tan1[a];
    62.  
    63.             Vector3.OrthoNormalize(ref n, ref t);
    64.             tangents[a].x = t.x;
    65.             tangents[a].y = t.y;
    66.             tangents[a].z = t.z;
    67.  
    68.             tangents[a].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
    69.         }
    70.  
    71.         return tangents;
    72.     }

    then in the GenerateMesh func I added: mesh.tangents = calculateMeshTangents(mesh); right after the normals are assigned in the action delegate..

    like so:

    Code (csharp):
    1. Action ApplyMesh = () =>
    2.         {
    3.             if (mesh != null)
    4.             {
    5.                 // create mesh
    6.                 mesh.vertices = vertices;
    7.                 mesh.colors = vertexColors;
    8.                 mesh.triangles = indexbuffer;
    9.                 mesh.uv = uvs;
    10.                 mesh.normals = normals;
    11.                 mesh.tangents = calculateMeshTangents(mesh);
    12.                 //mesh.RecalculateNormals();
    13.                 mesh.RecalculateBounds();
    14.  
    15.                
    16.             }
    17.  
    18.             if (this != null)
    19.             {
    20.                 transform.localPosition = Vector3.zero;
    21.                 transform.localRotation = Quaternion.identity;
    22.                 transform.position = transform.parent.position;
    23.                 transform.rotation = transform.parent.rotation;
    24.             }
    25.  
    26.             // set mesh to collider
    27.             if (planet.generateColliders[lodLevel])
    28.             {
    29.                 MeshCollider collider = (MeshCollider)gameObject.GetComponent(typeof(MeshCollider));
    30.                 if (collider == null)
    31.                     collider = (MeshCollider)gameObject.AddComponent(typeof(MeshCollider));
    32.  
    33.                 collider.sharedMesh = mesh;
    34.             }
    35.  
    36.             // report to planet
    37.             planet.ReportGeneration(this);
    38.  
    39.             // event to parent surface
    40.             if (GenerationComplete != null)
    41.                 GenerationComplete(this);
    42.         };
    the textures code:
    Code (csharp):
    1. public void ApplyToSurface(Surface surface)
    2.     {
    3.         if (surface == null)
    4.             return;
    5.  
    6.         if (material == null)
    7.             material = new Material(shader);
    8.  
    9.         surface.renderer.sharedMaterial = material;
    10.  
    11.         surface.renderer.sharedMaterial.SetFloat("_Value1", value1);
    12.         surface.renderer.sharedMaterial.SetFloat("_Value2", value2);
    13.         surface.renderer.sharedMaterial.SetFloat("_Value3", value3);
    14.  
    15.         surface.renderer.sharedMaterial.SetFloat("_Brightness", brightness);
    16.  
    17.         surface.renderer.sharedMaterial.SetColor("_Color1", color1);
    18.         surface.renderer.sharedMaterial.SetColor("_Color2", color2);
    19.         surface.renderer.sharedMaterial.SetColor("_Color3", color3);
    20.         surface.renderer.sharedMaterial.SetColor("_Color4", color4);
    21.  
    22.         if (useTextures)
    23.         {
    24.             surface.renderer.sharedMaterial.SetTexture("_Texture1", texture1);
    25.             surface.renderer.sharedMaterial.SetTexture("_Texture2", texture2);
    26.             surface.renderer.sharedMaterial.SetTexture("_Texture3", texture3);
    27.             surface.renderer.sharedMaterial.SetTexture("_Texture4", texture4);
    28.         }
    29.  
    30.         surface.renderer.sharedMaterial.SetVector("_UvScale", textureScales);
    31.  
    32.         if (useBumpMaps)
    33.         {
    34.             surface.renderer.sharedMaterial.SetTexture("_Normal1", normal1);
    35.             surface.renderer.sharedMaterial.SetTexture("_Normal2", normal2);
    36.             surface.renderer.sharedMaterial.SetTexture("_Normal3", normal3);
    37.             surface.renderer.sharedMaterial.SetTexture("_Normal4", normal4);
    38.  
    39.             surface.renderer.sharedMaterial.SetVector("_NormalUvScale", normalScales);
    40.         }
    41.  
    42.         // poles
    43.         surface.renderer.sharedMaterial.SetColor("_PolarColor", polarColor);
    44.         surface.renderer.sharedMaterial.SetFloat("_Polarity", polarity);
    45.         surface.renderer.sharedMaterial.SetFloat("_PolarStrenght", polarStrenght);
    46.  
    47.         // equator
    48.         surface.renderer.sharedMaterial.SetColor("_EquatorColor", equatorColor);
    49.         surface.renderer.sharedMaterial.SetVector("_Equator", new Vector4(equatorWidth, equatorStrenght, equatorHeight));
    50.     }
     
    Last edited: Dec 15, 2013
  15. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Thanks for the support! I see you are already knee-deep in it. :)

    I agree there are lots of things to be done to make this asset the best it can be. I definitely will welcome contributions, especially in the water/atmosphere -shader side, since the focus of this asset is foremost in the terrain part, ie. Planetary TERRAIN. :)

    Could you please elaborate on this? I am not sure what gaps you mean.
     
  16. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    What about the collisions with the terrain ?
     
  17. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, there is an option to generate colliders for selected LOD levels.
     
  18. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    @Marionette
    Thank for the scripts. :cool:

    @HenryV
    I just found out that the player takes the same time to start (or end) no matter if the planet is generated in run-time or is pre-generated. Is this normal?
    I thought that a prebuilt planet improves the startup process ?!
     
  19. softrare

    softrare

    Joined:
    Jun 12, 2011
    Posts:
    444
    Hi Henry,

    Congratulations, looks like an awesome asset! I am very interested!

    However it says Unity 4.3 is needed. In the the current state of version 4.3, I won't do the upgrade, I discovered a lot of things/bugs which don't suite me and my current project. Is Unity 4.3 really needed because of graphical features/API details or is this just the version you happened to upload the asset with? Anyway, I would like to purchase, I guess I can give you my invoice number and you could export the package for me and send it to me via mail? I use Unity 4.2.2. Thanks in advance for your answer!
     
  20. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    @Henry.
    My bad about the starting time : i've forgot to use the prefab previously generated. Works well now.

    @softrare.
    No pb with Unity 4.2.2f the version i use. But (indeed), you need a 4.3.x for downloading the tool from the Asset Store.
     
    Last edited: Dec 15, 2013
  21. softrare

    softrare

    Joined:
    Jun 12, 2011
    Posts:
    444
    Hi ZJP, thanks a lot for clearifying! ;) Will do the purchase these next days.
     
    Last edited: Dec 15, 2013
  22. softrare

    softrare

    Joined:
    Jun 12, 2011
    Posts:
    444
    One other thing: How is the perfomance with multiple mid- to highpoly planets in the same scene?
     
  23. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Currently I am working on a planet with a diameter of 40000 units. I get a range of 700-1000 fps with my config : Windows 7 32b/Radeon HD7850/ Intel C2Q 8300 (old CPU). Stunning!! ;)
     
  24. softrare

    softrare

    Joined:
    Jun 12, 2011
    Posts:
    444
    This is indeed stunning, by any measure. Very exicted ;)
     
  25. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Seem a good product and the developer is very reactive. So, ;)

    @Henry V
    Can you post the template you have used here please?
     
    Last edited: Dec 16, 2013
  26. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Please can we access to the PDF docs?
     
  27. cfusion

    cfusion

    Joined:
    Jul 18, 2011
    Posts:
    12
    Would it be possible to add static or dynamic prefabs on a planets surface? For instance, adding a bunch of 'resource nodes' that a player can mine on a planet's surface? And taking that one step further, could the player instantiate prefabs like buildings and save it on the planet's surface?
     
  28. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, nice to hear that you are interested! I dont think 4.3 is really needed, I just happened to have that version at my development machine. I have another machine that is at 4.2.2f and it works normally. I can make you the package and send it if you like, just send me an email! It might be possible also to download it from the asset store using a browser and import it in to your project. But throw me an email if you are having any trouble!
     
  29. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    There you go: http://planetaryterrain.com/files/MountainCurveFlat.txt

    It is just the standard MountainCurve with additional Curve modifier at the end. You might want to play around with Height Variation and Frequency Scale in planet inspector to get the results exactly the way you want.

    There you go: http://planetaryterrain.com/files/PlanetaryTerrain.pdf

    The manual is also available at http://planetaryterrain.com, but I haven't completely finished the site yet.

    Yeah this is very much possible. There is a script called PlacementHelper that can place objects on the planet during generation (you can select at which LOD level). You can set the object to instantiate, chance %, height range and polarity range (distance from poles) and the script will instantiate the objects per vertex with the given chance.

    Unfortunately there is no premade solution for saving player instantiated objects though, you will have to come up with your own at this point. It should be very possible to do, depending on your projects requirements.
     
  30. DSebJ

    DSebJ

    Joined:
    Mar 30, 2013
    Posts:
    101
    The webplayer makes the planets feel a bit small - what scale are you using in the demos? Is 1 unit = 1 meter?
     
  31. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, yeah they are quite small scenes. The smaller one is 10 units in radius and the larger one is 100. The user can determine the radius freely when generating the planet. I have planned to make a larger demo scene in the future and post it here, possibly one with a first person controller.
     
  32. blackanub1s

    blackanub1s

    Joined:
    Dec 12, 2013
    Posts:
    21
    If you make a demo with a controller in the first person that works correctly, I buy directly. :D
     
  33. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Good to know, I'll have to work on it! :)
     
  34. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    @HenryV
    The standard FPS controller doesn't work around a planet. Have a look here for the solution.
     
  35. blackanub1s

    blackanub1s

    Joined:
    Dec 12, 2013
    Posts:
    21
    Faux Gravity is good, but it lacks a lot.

    If it can help you, I found a much more comprehensive project (sorry for the source I do not remember)

    This project aims to replace the "characterMotor", with some modifications.

    To test : https://dl.dropboxusercontent.com/u/45391150/world-gravity.zip

    PS : think there was some problems with Unity 4 at the camera (you will quickly find the problem)
     
  36. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Thanks for the link. I'll give it a try.
     
  37. DSebJ

    DSebJ

    Joined:
    Mar 30, 2013
    Posts:
    101
    OK, when you have a planet with a radius of 20,000 let us know - that's when it will suit our game :)
     
  38. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    +1
     
  39. Havoc Unit

    Havoc Unit

    Joined:
    Dec 18, 2013
    Posts:
    3
    Hello. Works on mobile?
     
  40. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    hey HenryV,
    i have played around a bit with your package and managed to get a rectangular heightmap of a planet (i need this for a minimap). if you don't mind i share the code here. it only acesses terrain.module.GetValue and thus should not leak any important information / code. i also have implemented it as an extension method to be safe when the package gets updated (and thus your files overwritten).
    as the coloring + blending is done in a shader i now try to make a colored rectmap. when dealing with this i also want to include a normal map, a day/night scheme and maybe a cloud layer.

    some remarks:
    the code and the shaders could use some comments on what is going on.
    there is a shader called BumpedPlanet. are there differences to the TexturedPlanet beside bumpmapping?
    how can the tiling of the detail textures be influenced?
    could'nt the bumpmap be calculated from the detail textures automatically? or is my understanding wrong?


    any details / eta about that? if you are already working on something i could spend my time on other aspects. what i'm especially interested in is a cloud layer which throws shadows on the surface. the clouds must not look "awesome" for me. any ideas how this could be achieved? i consider using 4d noise for the clouds (animation) and render them in a texture which is invisibly mapped over the planet. then some particles are spawned at clouds position to allow fly through. but when solar lighting comes into effect my understanding of the shader mechanics is not enough to pull everything together. i guess putting it this will be a horrible complex shader anyway. so i am interested to hear on what you work and what you think about shadowing clouds.
     
  41. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    what you want are volumetric clouds, same here ;)
     
  42. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    I sent henry a message and waiting for his confirmation.
    I prepared a triplanar bumpmapped terrain shader with 4 textures, a nice atmosphere shader and an even nicer water shader.
    These are mostly configured for my personal needs but my needs are very generic anyways.
    Clouds are just 2d textures on my atmosphere shader, they can cast shadows with some slight adjustments but not implemented currently.

    EDIT: Anyways, dont wait up for me in any case.
     
  43. Casto

    Casto

    Joined:
    Aug 14, 2013
    Posts:
    44
    Hi HenryV, I must say I'm quite impressed by your product.

    I'm working myself on a procedurally generated terrain (not a planet but anyway) and I was wondering how you succeed in getting such performance with multithreading? I would be extremely thankful if you could get a look to my question here: http://forum.unity3d.com/threads/218545-Multithreading-and-frame-rate-drops
    I'm sure you could help me.

    Thanks in advance!
     
  44. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, that totally can be done with the asset already. :)

    You may freely determine the radius of the planet when generating, anything up to 100,000 and even beyond, but after that you might start experiencing floating point precision problems.

    Hey, this is not tested yet but I have planned to do a test soon. I will post the results here then!
     
  45. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey. Very interesting, please share your results. I don't mind, quite the opposite and I think it is nice that you are doing this!

    The shaders have been made using Strumpy Shader Editor and the SSE shader graphs are included in the package in PlanetaryTerrain/Resources/Shaders/Strumpy -folder. I agree they could use some comments though.

    There should be no difference other than the bump mapping, but I have to say I am not sure those shaders are doing the bump mapping correctly in all aspects, I have to do little research on this.

    The tiling of the detail textures can be influenced in the shader side by setting the "_UvScale" (and "_NormalUvScale") parameters in the shaders. These are vector4 fields and the x,y,z,w each are tiling of one texture. The SurfaceColor-script has a field for setting these. In the mesh generation side there is no other way than to adjust the code direcly in Surface script, lines 71-83 and 260.

    I am not sure I understand what you mean by calculating the bump maps from the details though?
     
  46. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    This sounds very nice, can't wait to test them out!
     
  47. HenryV

    HenryV

    Joined:
    Apr 25, 2012
    Posts:
    100
    Hey, nice to hear that!

    I took a look at your question but I am afraid I cannot tell what is the problem without looking at the code. I have total of 8 threads running in the default setting and in the examples I am generating 32x32 or 64x64 patches. I also have a queue system in place that prevents too many surfaces trying to generate simultaneously. Maybe your problem could be related to the unloading of the meshes? Are you destroying the unused meshes correctly?
     
  48. DSebJ

    DSebJ

    Joined:
    Mar 30, 2013
    Posts:
    101
    Awesome, can you post up a web player demo of that resolution?

    Also, can we mix in pre-build structures to parts of the planet? Like a base?
     
  49. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    This is EXACTLY the sort of planet i'm looking for :D

     
  50. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    Here you go.
    Code (csharp):
    1.  
    2. public static class PlanetExtensionMethods
    3. {
    4.     public static Texture2D RectangularPlanetMap(this Planet planet, int texwidth)
    5.     {// creates a rectangular heightmap with "distorted" poles from the planet, texture height is calculated from width
    6.         int texheight = texwidth/2,ty, tx;
    7.         Texture2D tex = new Texture2D(texwidth,texheight,TextureFormat.ARGB32, false);
    8.         float x, y, z, polar, azimut, onebyty, onebytx, halfx, halfy, sinpolar, cospolar, height = 0.0f;
    9.         onebytx = 1.0f / (float)texwidth;   // onebytx/y is an optimization to prevent recurring divisions
    10.         onebyty = 1.0f / (float)texheight;
    11.         halfx = onebytx * 0.5f;             // halfx/y is the width/height of a half pixel to calculate the midpoint of a pixel
    12.         halfy = onebyty * 0.5f;
    13.         for (ty = 0; ty < texheight; ++ty)
    14.         {// calculate the 3d position of each pixel on the surface of a normalized sphere (radius 1)
    15.             // description of spherical coordinate system (polar + azimut) can be found here: http://upload.wikimedia.org/wikipedia/commons/8/82/Sphericalcoordinates.svg and here http://en.wikipedia.org/wiki/Spherical_coordinate_system
    16.             polar = ( (float)ty * onebyty + halfy ) * Mathf.PI;     // calculate the polar angle (between positive y in unity (northpole) and the line to the point in space), required in radians 0 to pi
    17.             sinpolar = Mathf.Sin ( polar ); // cache these values as they are the same for each column in the next line
    18.             cospolar = Mathf.Cos ( polar );
    19.             for (tx = 0; tx < texwidth; ++tx)
    20.             {
    21.                 azimut = ( ( ( (float)tx * onebytx + halfx ) * 2.0f ) - 1.0f ) * Mathf.PI;      // calculate the azimut angle (between positive x axis and the line to the point in space), required in radians -pi to +pi,
    22.                 x = sinpolar * Mathf.Cos ( azimut );
    23.                 z = sinpolar * Mathf.Sin ( azimut );// this is y in the wikipedia formula but because unitys axis are differerent (y and z swapped) its changed here
    24.                 y = cospolar;// this is z in the wikipedia formula but because unitys axis are differerent (y and z swapped) its changed here
    25.                 height = planet.Terrain.module.GetValue(new Vector3(x, y, z));  // retrieve the height on the actual planet surface by passing the normalized position to the terrain module
    26.                 tex.SetPixel(tx,texheight - ty - 1,new Color(height,height,height));    // the y direction needs to be reversed to match unity up (+y) equals texture up, otherwise the texture is y-reversed compared with the planet (maybe due to v-definition)
    27.             }
    28.         }
    29.         tex.Apply();    // apply the texture to make the changes persistent
    30.         return tex;
    31.     }
    32. }
    33.  
    as i said currently it only generates a heightmap (0-1) of the planet. note that the y direction of the texture is reversed to match the planet. you are free to do with this code what you want. you can even include it in your package if you see fit. as i said its mainly usefull for minimap like features.
    feature on the planet:
    $planet_feature.png
    feature image link
    the corresponding heightmap (try to find the feature).
    $heights.png
    heightmap image link

    i will later share some functions to calculate a uv in 3d position and vice versa so when you click on the texture you know where on the planet is clicked and when you have some object on the surface where it must be placed on the texture. but i'm busy these days and away over christmas holidays so it may take a while.

    again some questions and thanks for your patience:
    the threshold for the texture blending goes from 0 - 2. normal noise range is -1 to 1. so is the output of the terrain module expected beween 0-2? i have testlogged some heightvalues retrieved by Terrain.module.GetValue and had none >=1 but a few slightly below 0.
    the nodes in the module editor display the value range. are these values estimated or "theoretical" values?

    Edit:
    Forum seems to have screwed up the images. have added some links.

    edit2:
    how is the seeding of the planet working? what is the seed used for?
     
    Last edited: Dec 20, 2013
Thread Status:
Not open for further replies.