public float CalculateBiomeOnPlanet(Vector3 pos) { if (mColorSetting == null) { return(0f); } if (mColorSetting.Biomes == null) { return(0f); } int numBiomes = mColorSetting.Biomes.Length; if (numBiomes == 0) { return(0f); } float heightPercent = (pos.y + 1f) * 0.5f; heightPercent += (mNoise.Evaluate(pos) - mColorSetting.NoiseOffset) * mColorSetting.NoiseStrength; float blendRange = mColorSetting.BlendAmount * 0.5f + 0.001f; float biome = 0f; for (int i = 0; i < numBiomes; ++i) { float weight = Mathf.InverseLerp(-blendRange, blendRange, heightPercent - mColorSetting.Biomes[i].startHeight); biome *= (1 - weight); biome += weight * i; } return((float)biome / Mathf.Max(1, numBiomes - 1)); }
public float CalculateUnscaledElevation(Vector3 pos) { if (mSetting == null) { return(0f); } float firstLayerValue = 0f; float elevation = 0f; if (mSetting.PlanetNoises != null) { mNoise.Initialize(mSetting.PlanetNoises[0].Noise); firstLayerValue = mNoise.Evaluate(pos); if (mSetting.PlanetNoises[0].Enabled) { elevation = firstLayerValue; } for (int i = 1; i < mSetting.PlanetNoises.Length; ++i) { if (mSetting.PlanetNoises[i] == null) { continue; } if (mSetting.PlanetNoises[i].Enabled == false) { continue; } mNoise.Initialize(mSetting.PlanetNoises[i].Noise); float mask = mSetting.PlanetNoises[i].UseFirstLayerAsMask ? firstLayerValue : 1f; elevation += mNoise.Evaluate(pos) * mask; } } mValueMinMax.AddValue(elevation); return(elevation); }