Procedural terrain generation using native C code + Unity
This repository is an example showing how to use native C code (DLL) from Unity to generate Perlin‐noise based terrain.
It includes two implementations:
- Native C implementation (compiled into a DLL and called from Unity)
- Pure C# implementation inside Unity
It is not production‑ready; the code is somewhat hacky, especially the Unity side. It’s mainly for learning how to interoperate Unity with native C code.
/Native_Code/ ← C source + build project for the native DLL
/Perlin-Noise-Terrain-Generator/ ← Unity project / C# scripts
.vscode/ ← Editor configuration
.gitignore
LICENSE
Here’s a GIF showing the terrain generation:
Some sample log timings:
[22:06:29] Terrain generated in NativePerlinTerrainGenerator class, 0.03817844 ms
[22:06:31] Terrain generated in UnitysPerlinTerrainGenerator class, 0.113718 ms
[22:06:34] Terrain generated in NativePerlinTerrainGenerator class, 0.03506756 ms
[22:06:37] Terrain generated in UnitysPerlinTerrainGenerator class, 0.1167059 ms
- Only tested in the Unity Editor on Windows/ 64‑bit .
- Unity integration of Perlin Noise 3D is a bit hacky. So, don't count on the results.
- DLL build / native code may require specific platform settings; may need adaptation if you move to other platforms.
- To understand interop between managed (.NET / C#) and unmanaged/native (C) code
- To see the performance trade‑offs: speed vs ease of development, memory copying, data marshaling
- As a learning tool or proof‑of‑concept
This project is under the MIT License. See the LICENSE file for details.
Feel free to open issues or pull requests. If you add platform support or improve performance or style, that’d be awesome.
If you want to discuss internal design or have questions, feel free to create an issue.
