public static float GetHeight(Vector3 p, float radius, DisplacementLayer[] displace) { if (displace != null) { float maxHeight = 0f; float addedHeight = 0f; for (var i = 0; i < displace.Length; i++) { var d = displace[i]; var strength = 1f; if (maxHeight > 0f) { strength = d.heightStrength.Evaluate(addedHeight / maxHeight); } if (d.noise == NOISE.Perlin) { addedHeight += d.height * Noise.Perlin(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength; } else if (d.noise == NOISE.Worley) { addedHeight += d.height * Noise.Worley(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength; } else if (d.noise == NOISE.FractalMapped) { addedHeight += d.height * Noise.FractalMapped(d.detail * p.x + d.seed, d.detail * p.y, d.detail * p.z) * strength; } else { var np = PTHelpers.GetHeightmapCoord(p); addedHeight += d.height * d.texture.GetPixelBilinear(np.x, np.y).grayscale; } maxHeight += d.height; } return(radius + addedHeight); } return(radius); }