пятница, 22 июня 2012 г.

Procedural terrain. Part 1. Basic terrain render.

Decided to play with procedural terrain a bit. Terrain's square shouldn't be extremely high, so i decided to set 1 chunk = 1 level.

At first, i'm generating a terrain with Perlin Noise (as a highmap, highlighting it with particles). Then, i convert data to per-layer(matrix) form: now i can access to every layer and get known, where is air and where is ground.
Next step is mesh-creation:

Upper side

+ Left side
 + Front side
All sides except bottom one. Now its time to continue correction terrain data

Added vertices number to debug info, now there are 1320. And limit is 65.000. Not sure, if i should worry about it for now. Anyway, size was taken as random, i can change it at anytime.

Finished with terrain chunk data. 8.700 vertices for the largest (lowest) chunk - i'm considering to make chunks smaller.
Dont render top side, if have a block above... Oh, something goes wrong.
Only 19 drawcalls for whole terrain - sounds good. No need in particles anymore.
Developer's view. Players should never see it.
Chunk generation take at most 0.03 seconds. 20 chunks = 0.6 seconds. Not bad + i have some ideas on further optimizations.


I'm satisfied at this point. Next step (Part 2) would be to adopt TerrainController to slicing camera. It was planned from the very begining, so it shouldn't be hard.
Final part is realtime terrain editing (Part 3). 



Info grabbed here:
http://www.blockstory.net/ru/node/58
http://unitycoder.com/blog/2012/02/15/dummy-craft-chunk-renderer-js/
http://forum.unity3d.com/threads/63149-After-playing-minecraft...

2 комментария: