I have been working on a personal project on-off for a few months now. It is a dedicated server for Valheim called Valhalla, written in c++ (GitHub - ricosolana/Valhalla: Valheim server written in C++). One of the primary mechanics requires the included Unity Random class and PerlinNoise function for consistency between the server and the client when provided a world generation seed (terrain generation, height map, etc…).
I have scoured the internet high and low within the limits of my abilities, and have found frighteningly few sources on the exact algorithm implementation that the Random class and PerlinNoise functions use. Here are my findings: UnityCsReference, a forum post, and the C# documentation for Random and Perlin Noise. The Mathf.PerlinNoise function likely uses a variation of the algorithm by Ken Perlin. Unity Random uses the Xorshift 128 algorithm to generate random numbers, but again, the implementation varies. I thought I could just create a texture to hold precomputed Unity PerlinNoise generated values, but I was wrong because I assumed the input values had to be within 0 to 1 (they are not).
I have no financial motive for requesting this information. This project is a totally personal hobby of mine, formed out of self-interest. I could always try spending countless hours reverse engineering the exact algorithm implementation with AI and pattern recognition— something that I have sparse knowledge of. Doing this on my own would be like trying to find a needle in a haystack. By native code, I am referring to the under-the-hood calls made by C# scripts to the internal UnityEngine. These functions are native :
Let me be clear in saying that I am not looking for the proprietary native code for these implementations (although that would be nice). I am simply looking for an algorithm that produces identical results to the Unity implementation; an algorithm consistent with that of the Random/Mathf.PerlinNoise algorithms. Native code or accurate pseudocode, I have no preference. If someone can point me toward a meaningful direction to how exactly Unity implements these, that would be grand.
TLDR; I am looking for an algorithm for Random and PerlinNoise that spits out values equal to the Unity counterparts.
Thank you, and I really appreciate your time in reading this.