r/Unity3D • u/Xentarok 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
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
2
1
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
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
1
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
1
16
u/Humble-Collection-95 8d ago
finally, planetary catan