Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Procedural asteroid generation?

Discussion in 'Scripting' started by JoeStrout, Sep 9, 2016.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    I'm gearing up to generate procedural asteroids for High Frontier. I've got a quad sphere with an appropriate resolution...


    And now I just need to pull this out of round and add various lumps and craters, so it looks more like this.


    But before I reinvent the wheel, I'd like to know if that wheel is already lying around somewhere (free or for purchase).

    I found several old threads on this topic, but none of them produced very convincing results, as far as I can tell.

    I also found a lot of gorgeous asteroid models on the Asset Store, but none that can generate them procedurally (though I might have missed something).

    Anybody know of some off-the-shelf solution that would apply here?

    Thanks,
    - Joe
     
  2. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    I haven't tinkered around with anything like this, but a POST a while back made an earth like procedural planet.
     
  3. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,309
    Not my area of expertise, but I found this post which shows some similar results, and some code samples above the linked post:
    http://forum.unity3d.com/threads/procedural-terrain-on-a-planet.127292/#post-930018

    Hopefully this is useful to you. It's not so much deformation of a sphere but the creation of a sphere from segments. I think if you used the right noise function you could get some nice lumps. I feel the craters are best applied in a normal map perhaps, or some predefined geometry additions.
     
  4. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    265
    I've used Dynagon in the past for something similar. It might be a little lower poly than what you're looking for, but it's well written and fast. If it doesn't work as a drop in, the source will get you in the direction you need to go.

    https://github.com/lanius/dynagon
     
    FreeFly90 likes this.
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    Thanks, guys. But making a planet is much easier than making an asteroid. :) Lumpy spheres are easy enough, but randomly generating something like a cratered potato, that's decidedly non-spherical... well, I guess I'd better just roll up my sleeves and get to work. :)

    Yes, that's a very good idea.
     
    jeffreyschoch likes this.
  6. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    3,690
    Why exactly do you need them to be procedurally generated? Wouldn't 10 or so assets give enough variation? Imho it would likely be faster to even make 2 dozen different ones than to properly implement runtime procedural generation of them.

    Either way, here is a blender tutorial, maybe that sparks an idea if you want to go procedural:


    Also tagging @Billy4184 because I think he recently worked on asteroid assets iirc.
     
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    Because the player will be able to visit hundreds, maybe thousands of asteroids, and they're not mere scene dressing; each one will be central to a player's game for a while. If the same two-dozen asteroids keep popping up, I think they'll begin to notice, and it will break the illusion of there being an essentially limitless endless variety (as is the case in real life). This would be especially true if the game becomes popular and people start posting screen shots or videos.

    But I may be worrying about it too much... if the procedural route doesn't pan out, I'll reconsider.

    Here's what I have so far:



    Needs more work, obviously, but it's a decent start.
     
  8. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    411
    Similar to the above, I also recommend starting with some asteroid assets and manipulating them to generate variation. While generating an asteroid from scratch can be a fun learning experiment, it may not be the most (time) efficient way to produce pleasing results.

    A long, long time ago, back when I was much less experienced, I wanted to do something similar. I started with a sphere and applied various combinations of noise and vertex displacements and polycounts to it to get the asteroid look. I spent a lot of time tweaking various settings and wasn't satisfied with any of the results. What I ended up settling with was actually creating several variations of asteroid models in a modeling program, then deforming them via displacement maps (which could have been generated at runtime from noise). This technique provided a great amount of variety with pleasant results.
     
    Kurt-Dekker and Martin_H like this.
  9. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    411
    One of the great benefits of starting with created assets and manipulating them procedurally is that I was able to create asteroids that were concave and very interesting. It was much easier to model some holes and complex geo, then move the vertices around, than to try and build the same type of complex shapes purely procedurally.
     
    Dave-Carlile, JoeStrout and Martin_H like this.
  10. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    3,690
    I see, nice start so far. You could try to use a procedural Substance material (there is native support for those in Unity) and use a triplanar shader to avoid visible seams.
    https://share.allegorithmic.com/libraries?by_category_id=27&page=2
    The good thing about Substances is that they should have a randomize button that calculates the textures with a different seed to give you even more variation.
     
    JoeStrout likes this.
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    @kru: Well, you may be right. I don't suppose you have any pictures handy?
     
  12. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    3,927
    I probably wouldn't bother to make it procedural, it's going to be too much work compared to the gain. In my space game kit there is exactly one asteroid in the whole scene and it's not really noticeable imo, you just rotate and scale randomly, and lighting makes it look different. If you had randomly generated full environments with vastly different characteristics, it might be called for but I don't think it's going to have as much impact as you imagine.

    If you wanted to, I'd probably do what @kru suggested. Get a bunch of different displacement maps and via script, push and pull the vertices according to the displacement value on at the UV position. Then you can blend and offset the maps and so forth to get as much variation as you like

    For small normal detail, all you really need is one or two maps with fine bumps and tiny craters.

    The large craters will be the biggest issue. The problem is that you can't really blend between them the same way that you can with more uniform detail, or you get 'ghost' craters here and there. Incidentally in substance designer you'll have the same problem with the triplanar projection, it's a nuisance both for projecting craters and for planetary landmasses. Probably the best thing would be to have a couple of crater maps that you've inspected manually (making sure that none of the craters drift off the UVs) and just choose one of them to use as is without any blending.

    Anyway, if you don't have substance designer I definitely recommend it, here's what you can cook up with a few nodes, no manual textures whatsoever:

    OldLava.png

    You can see 'ghost' craters on the top from the triplanar but it looks good enough in my opinion.
     
    Martin_H likes this.
  13. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    3,690
    Another thought: if you use a triplanar shader that blends textures you could blend each texture direction twice at different scales (similar to Distingo) and by tweaking the texture tiling offset and texture scale, you would get easy variations on the final look. That might already be enough, combined with what you have already to deform the mesh.

    P.S.: I think you could just use the Distingo mesh-shader as it is for that, using a solid-color splatmap and 1 of the 4 slots for terrain textures.
     
    JoeStrout likes this.
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    I hadn't heard of Distingo before. I'll certainly give it a look!
     
  15. FreeFly90

    FreeFly90

    Joined:
    May 28, 2016
    Posts:
    177
    Stupid idea of the day: how about using heightmaps to modify the sphere geometry? (Though, capsules might be better for that)
     
  16. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    288
    How about using 1-5 spheres, merging them, and wrapping them in a deformable mesh. I think that's called something, but I can't remember what.

    EDIT: You could also subtract spheres from this, giving you more weird shapes.
     
  17. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    7,444
    Well, as some advised, I decided to start with a model from the Asset Store (I'm using this pack) and then deform it for more variation. I think the result looks pretty good!



    This is the same model, but every three seconds I'm applying a new random deformation. Eventually I suppose you could learn to recognize the same crater patterns on different asteroids, but you'd have to play the game a long time before I think that would click. And I still have five other models (textures) to mix in!

    Thanks, everyone!
     
  18. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,309
    That is looking great! Nice work.
     
  19. ob103ninja

    ob103ninja

    Joined:
    Nov 19, 2014
    Posts:
    45
    Neat! Now all you need to do is figure out how to procedurally generate the texture and use your own model (so that more of the work is your own).
     
  20. tkrumple

    tkrumple

    Joined:
    Nov 18, 2017
    Posts:
    1
    I'm arriving late to this. The method I went with is to take a UV sphere with always the same number of slices. So I know the number of vertex it has. Then I simply run a random distance change for each vertex from it's center. But I also use a bell curve on the randomness. Because without the bell curve you can have drastic changes in the radius for each vertex. So I number each vertex and run through each vertex either by increasing it's distance from the center of the "UVsphere" or by bringing the vertex closer to it's center. The adjacent vertex have a threshold of randomness to prevent sharp differences. This gives them a more "rounded" look. Once they have their shape, I complete the process by using a random choice of textures with their corresponding bump maps and changing their tiling rate randomly. So some textures will have a few large craters and others will have some small and some large and others only small craters.

    Once I did it like this. I could spawn in each UV sphere and run the script to "distort" their shape. No two asteroids look a like. Especially when you randomly adjust scale prior to running the "disfiguring" script.
     
  21. Steve_O

    Steve_O

    Joined:
    Dec 10, 2012
    Posts:
    20
    tkrumple

    Would you be able to post your code, very interested in how you did it.
     
  22. Soulice

    Soulice

    Joined:
    Aug 18, 2014
    Posts:
    38
    Did you create this procedurally? If so, you mind sharing the code?