Skip to content

thirtwo/Perlin-Noise-C-in-Unity

Repository files navigation

Perlin Noise C in Unity

Procedural terrain generation using native C code + Unity


🚀 What’s this

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.


📂 Structure

/Native_Code/            ← C source + build project for the native DLL  
/Perlin-Noise-Terrain-Generator/ ← Unity project / C# scripts  
.vscode/                 ← Editor configuration  
.gitignore  
LICENSE  

🎥 Demo

Here’s a GIF showing the terrain generation:

Unity vs Native Comparison


⚡ Performance (Editor, 64‑bit PC)

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  

⚠️ Limitations

  • 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.

🎯 Why do this?

  • 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

📋 License

This project is under the MIT License. See the LICENSE file for details.


🤝 Contributing

Feel free to open issues or pull requests. If you add platform support or improve performance or style, that’d be awesome.


💬 Contact

If you want to discuss internal design or have questions, feel free to create an issue.

About

Perlin Noise with C dll

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors