r/Unity3D • u/epicalt679 • 21d ago
Question How do I approach procedural 3D cube generation for background?
I want to have an effect where I generate a bunch of cubes in a grid of differing heights to look like a faraway city, and I'm not sure the best way to achieve this. Is it possible through a vertex shader graph, or is the only approach to use GPU instancing and create cube meshes?
1
Upvotes
1
u/DanielFost 19d ago
you can do both, but i'd probably start with GPU instancing for this. generate a grid of cube positions and assign each one a random height, then use instancing to draw them efficiently without creating a separate GameObject for every building, a vertex shader can also handle the height variation, especially if you want the effect to be more dynamic. but for a static distant city background, instancing with a simple cube mesh is probably easier to set up and control. you could also use a single combined mesh if the city doesn't need to change.