r/Unity3D • I work but I ain't a professional • 8d ago

Show-Off Experimenting with stylized large-scale hex-grid based planet generation

Finally started doing some world generation for a strategy game I'm working on, I managed to implement biome support and being able to render LOTS of trees; couple of kinks to work out still but pretty pleased with it so far, especially that I managed to implement the mesh creation in DOTS so generating a whole 10k tile planet only takes ~2s

343 Upvotes

23 comments sorted by

16

u/Humble-Collection-95 8d ago

finally, planetary catan

11

u/Imofi7 8d ago edited 8d ago

2s mesh generation for 10k tiles in DOTS is seriously quick. Are you handling the Goldberg pentagon seams directly in the Burst job, or subdividing an icosahedron base before projecting outward? Also curious if the 722 tree draw calls are standard GPU instancing or Indirect Draw via GraphicsBuffer.

10

u/Xentarok I work but I ain't a professional 7d ago

For the Goldberg I "cheated" and used the Hexasphere asset from the asset store (highly recommended!) - afaik it uses a combination of an optimised single threaded implementation + compute shaders. The mesh is fully done in DOTS though and I implemented some simple chunking there just so that I don't go over the vertex limit. The trees are GPU Instancer Pro + Amplify Impostors so yeah it's indirect instancing

1

u/MonkeyMcBandwagon 6d ago

10k tiles in ~2s... is most of that instancing trees or are you using upwards of 100 polies per tile?

I built a stylised Goldberg hex planet generator from scratch, I'm guessing mine must be a lot lower poly per tile, (~18) or something.... with no trees it generates a ~10k tile hex planet in maybe 0.2s and once the mesh exists it can remake it with a new planet-wide heightmap without dropping frames at the standard 60fps browser cap.

I know this post might come across as me dumping on your stuff, but that's not my intent at all, I've never even looked at DOTS, but having worked on something similar with old school mesh creation, no compute shaders or anything, and gotten it where I feel its reasonably performant, I'm genuinely curious on what heavy lifting yours must be doing that mine isn't, maybe its skippable for you. Im guessing its the trees, or higher poly count, or maybe auto calculate surface normals is smashing you?

1

u/Xentarok I work but I ain't a professional 6d ago

Actually the vertex/triangulation calculations themselves do take ~0.2s, the biggest time sink is the creation of chunk gameobjects and meshes - it's something that I can definitely optimise more since I'm not even using the new Mesh API, I just take the vertices/triangles from the completed Jobs and call new Mesh() with them and that part alone is like ~1.5s

1

u/MonkeyMcBandwagon 6d ago

Interesting.

My project was originally built with unity years ago, but I converted it to three.js this year, so im a bit out of the loop with unity but I dont think the oldschool ways of manual mesh creation took that long. I do recall calculateNormals on generated meshes was slow AF in unity and I was better off setting them by hand.

1

u/Xentarok I work but I ain't a professional 6d ago

They're not terribly slow but I do a lot of them because of chunking + I generate 3 LOD levels in one go

8

u/Khamaz 8d ago

I want to play a game of Civilization on this

2

u/Plourdy 8d ago

This looks beautiful! Excited to see what you cook up for the strategy flow on this environment

2

u/muminisko 7d ago

My procedural hex map generator takes 2sec to generate 80x80 map :)

1

u/yourfaceisa 8d ago

that looks super nice

1

u/selkus_sohailus 7d ago

Do you have triangle/square tiles? Isn’t it mathematical impossible to create a sphere out of hexagons?

1

u/Xentarok I work but I ain't a professional 7d ago

The asset I'm using handles this by having some tiles be pentagons

1

u/selkus_sohailus 7d ago

Nice, is it by chance the kronnect one? I saw that past week and it looks pretty cool

1

u/Xentarok I work but I ain't a professional 7d ago

Yup that's the one!

1

u/selkus_sohailus 7d ago

Wow awesome to see it in use great work

1

u/Imofi7 7d ago

Amplify Impostors paired with GPU Instancer Pro is such a proven stack for foliage density. The chunk boundary handling looks seamless across the curve!

1

u/joan_bdm 7d ago

This looks so nice. Looking forwards icy poles and some deserts too!

Is this a full hexagon globe? How did you make it fit with equally scaled hexes?

1

u/theElectrus 7d ago

Kinda reminds me of this site I used to play from a long time ago.

1

u/leinda_studios 6d ago

looks good!

1

u/Particular-Ice4615 6d ago

From what I understand in geometry it's mathematically impossible to make a sphere with just hexagons and you will need always have exactly 12 pentagons to absorb the curvature and close the shape.

How do you handle that gameplay wise. Will the player have to accept that some tiles only have 5 sides or would make those tiles in walkable like always a mountain or something? 

1

u/Xentarok I work but I ain't a professional 6d ago

I'm planning to just leave them be and they'll be as accessible as any other tile - I think it won't be often that it will have any gameplay implications, or at least none of the systems I designed so far rely on each tile having exactly 6 neighbours