Procedural Planets

Integrated Sebastian Lague's Planet Generator
Created Tour function in SectorRenderer which makes the camera follow each terrestrial planet in turn
This commit is contained in:
Reinier Vens 2020-12-05 23:43:02 +00:00
commit 53a91351b7
332 changed files with 11904 additions and 78 deletions

View file

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = "Celestial Body/Shapes/Alien")]
public class AlienShape : CelestialBodyShape {
[Header ("Continent settings")]
public float oceanDepthMultiplier = 5;
public float oceanFloorDepth = 1.5f;
public float oceanFloorSmoothing = 0.5f;
public float mountainBlend = 1.2f; // Determines how smoothly the base of mountains blends into the terrain
[Header ("Noise settings")]
public SimpleNoiseSettings continentNoise;
public SimpleNoiseSettings maskNoise;
public SimpleNoiseSettings warpNoise;
public RidgeNoiseSettings ridgeNoise;
public CraterSettings craterSettings;
public Vector4 testParams;
protected override void SetShapeData () {
var prng = new PRNG (seed);
continentNoise.SetComputeValues (heightMapCompute, prng, "_continents");
ridgeNoise.SetComputeValues (heightMapCompute, prng, "_mountains");
maskNoise.SetComputeValues (heightMapCompute, prng, "_mask");
warpNoise.SetComputeValues (heightMapCompute, prng, "_warp");
craterSettings.SetComputeValues (heightMapCompute, seed);
heightMapCompute.SetFloat ("oceanDepthMultiplier", oceanDepthMultiplier);
heightMapCompute.SetFloat ("oceanFloorDepth", oceanFloorDepth);
heightMapCompute.SetFloat ("oceanFloorSmoothing", oceanFloorSmoothing);
heightMapCompute.SetFloat ("mountainBlend", mountainBlend);
heightMapCompute.SetVector ("params", testParams);
}
public override void ReleaseBuffers () {
base.ReleaseBuffers ();
craterSettings.ReleaseBuffers ();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd6237f4841244919bd904a9c5b610a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class CelestialBodyShape : ScriptableObject {
public bool randomize;
public int seed;
public ComputeShader heightMapCompute;
public bool perturbVertices;
public ComputeShader perturbCompute;
[Range (0, 1)]
public float perturbStrength = 0.7f;
public event System.Action OnSettingChanged;
ComputeBuffer heightBuffer;
public virtual float[] CalculateHeights (ComputeBuffer vertexBuffer) {
//Debug.Log (System.Environment.StackTrace);
// Set data
SetShapeData ();
heightMapCompute.SetInt ("numVertices", vertexBuffer.count);
heightMapCompute.SetBuffer (0, "vertices", vertexBuffer);
ComputeHelper.CreateAndSetBuffer<float> (ref heightBuffer, vertexBuffer.count, heightMapCompute, "heights");
// Run
ComputeHelper.Run (heightMapCompute, vertexBuffer.count);
// Get heights
var heights = new float[vertexBuffer.count];
heightBuffer.GetData (heights);
return heights;
}
public virtual void ReleaseBuffers () {
ComputeHelper.Release (heightBuffer);
}
protected virtual void SetShapeData () {
}
protected virtual void OnValidate () {
if (OnSettingChanged != null) {
OnSettingChanged ();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 641df4aa2320b4864944c337c6f88982
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = "Celestial Body/Earth-Like/Earth Shape")]
public class EarthShape : CelestialBodyShape {
[Header ("Continent settings")]
public float oceanDepthMultiplier = 5;
public float oceanFloorDepth = 1.5f;
public float oceanFloorSmoothing = 0.5f;
public float mountainBlend = 1.2f; // Determines how smoothly the base of mountains blends into the terrain
[Header ("Noise settings")]
public SimpleNoiseSettings continentNoise;
public SimpleNoiseSettings maskNoise;
public RidgeNoiseSettings ridgeNoise;
public Vector4 testParams;
protected override void SetShapeData () {
var prng = new PRNG (seed);
continentNoise.SetComputeValues (heightMapCompute, prng, "_continents");
ridgeNoise.SetComputeValues (heightMapCompute, prng, "_mountains");
maskNoise.SetComputeValues (heightMapCompute, prng, "_mask");
heightMapCompute.SetFloat ("oceanDepthMultiplier", oceanDepthMultiplier);
heightMapCompute.SetFloat ("oceanFloorDepth", oceanFloorDepth);
heightMapCompute.SetFloat ("oceanFloorSmoothing", oceanFloorSmoothing);
heightMapCompute.SetFloat ("mountainBlend", mountainBlend);
heightMapCompute.SetVector ("params", testParams);
//
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f311f2d93be44f27934ae782409335b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = "Celestial Body/Moat/Moat Shape")]
public class MoatShape : CelestialBodyShape {
[Header ("Continent settings")]
public float shoreSteepness = 4;
public float continentLevel = -0.05f;
public float continentFlatness = 0.27f;
[Header ("Mountain settings")]
public float mountainSmoothing = 1f; // Reduces excessive jaggedness of mountains in some regions
public float mountainBlend = 1; // Determines how smoothly the base of mountains blends into the terrain
public Vector2 maskMinMax = new Vector2 (0.35f, 0.5f);
[Header ("Noise settings")]
public SimpleNoiseSettings continentNoise;
public CraterSettings craterSettings;
public Vector4 testParams;
protected override void SetShapeData () {
var prng = new PRNG (seed);
continentNoise.SetComputeValues (heightMapCompute, prng, "_continents");
craterSettings.SetComputeValues (heightMapCompute, seed);
heightMapCompute.SetFloat ("shoreSteepness", shoreSteepness);
heightMapCompute.SetFloat ("continentFlatness", continentFlatness);
heightMapCompute.SetFloat ("continentLevel", continentLevel);
heightMapCompute.SetFloat ("mountainSmoothing", mountainSmoothing);
heightMapCompute.SetFloat ("mountainBlend", mountainBlend);
heightMapCompute.SetVector ("maskMinMax", maskMinMax);
heightMapCompute.SetVector ("params", testParams);
}
public override void ReleaseBuffers () {
base.ReleaseBuffers ();
craterSettings.ReleaseBuffers ();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d970fe15b3771438c8f70d6282f2925b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,99 @@
using UnityEngine;
[CreateAssetMenu (menuName = "Celestial Body/Moon/Moon Shape")]
public class MoonShape : CelestialBodyShape {
public CraterSettings craterSettings;
public SimpleNoiseSettings shapeNoise;
public RidgeNoiseSettings ridgeNoise;
public RidgeNoiseSettings ridgeNoise2;
public Vector4 testParams;
protected override void SetShapeData () {
var prng = new PRNG (seed);
SetCraterSettings (prng, seed, randomize);
SetShapeNoiseSettings (prng, randomize);
SetRidgeNoiseSettings (prng, randomize);
heightMapCompute.SetVector ("testParams", testParams);
}
void SetCraterSettings (PRNG prng, int seed, bool randomizeValues) {
if (randomizeValues) {
var chance = new Chance (prng);
if (chance.Percent (70)) { // Medium amount of mostly small to medium craters
craterSettings.SetComputeValues (heightMapCompute, seed, prng.Range (100, 700), new Vector2 (0.01f, 0.1f), 0.57f);
} else if (chance.Percent (15)) { // Many small craters
craterSettings.SetComputeValues (heightMapCompute, seed, prng.Range (800, 1800), new Vector2 (0.01f, 0.08f), 0.74f);
} else if (chance.Percent (15)) { // A few large craters
craterSettings.SetComputeValues (heightMapCompute, seed, prng.Range (50, 150), new Vector2 (0.01f, 0.2f), 0.4f);
}
} else {
craterSettings.SetComputeValues (heightMapCompute, seed);
}
}
void SetShapeNoiseSettings (PRNG prng, bool randomizeValues) {
const string suffix = "_shape";
if (randomizeValues) {
var chance = new Chance (prng);
SimpleNoiseSettings randomizedShapeNoise = new SimpleNoiseSettings () {
numLayers = 4, lacunarity = 2, persistence = 0.5f
};
if (chance.Percent (80)) { // Minor deformation
randomizedShapeNoise.elevation = Mathf.Lerp (0.2f, 3, prng.ValueBiasLower (0.3f));
randomizedShapeNoise.scale = prng.Range (1.5f, 2.5f);
} else if (chance.Percent (20)) { // Major deformation
randomizedShapeNoise.elevation = Mathf.Lerp (3, 8, prng.ValueBiasLower (0.4f));
randomizedShapeNoise.scale = prng.Range (0.3f, 1);
}
// Assign settings
randomizedShapeNoise.SetComputeValues (heightMapCompute, prng, suffix);
} else {
shapeNoise.SetComputeValues (heightMapCompute, prng, suffix);
}
}
void SetRidgeNoiseSettings (PRNG prng, bool randomizeValues) {
const string ridgeSuffix = "_ridge";
const string detailSuffix = "_ridge2";
if (randomizeValues) {
// Randomize ridge mask
var randomizedMaskNoise = new SimpleNoiseSettings () {
numLayers = 4, lacunarity = 2, persistence = 0.6f, elevation = 1
};
randomizedMaskNoise.scale = prng.Range (0.5f, 2f);
// Randomize ridge noise
var chance = new Chance (prng);
var randomizedRidgeNoise = new RidgeNoiseSettings () {
numLayers = 4, power = 3, gain = 1, peakSmoothing = 2
};
randomizedRidgeNoise.elevation = Mathf.Lerp (1, 7, prng.ValueBiasLower (0.3f));
randomizedRidgeNoise.scale = prng.Range (1f, 3f);
randomizedRidgeNoise.lacunarity = prng.Range (1f, 5f);
randomizedRidgeNoise.persistence = 0.42f;
randomizedRidgeNoise.power = prng.Range (1.5f, 3.5f);
randomizedRidgeNoise.SetComputeValues (heightMapCompute, prng, ridgeSuffix);
randomizedMaskNoise.SetComputeValues (heightMapCompute, prng, detailSuffix);
} else {
ridgeNoise.SetComputeValues (heightMapCompute, prng, ridgeSuffix);
ridgeNoise2.SetComputeValues (heightMapCompute, prng, detailSuffix);
}
}
public override void ReleaseBuffers () {
base.ReleaseBuffers ();
craterSettings.ReleaseBuffers ();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf0ef91efa296423fbbde98ce5af19ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = "Celestial Body/Shapes/Shattered")]
public class ShatteredShape : CelestialBodyShape {
[Header ("Noise settings")]
public float plateauHeight;
public float plateauSmoothing;
public SimpleNoiseSettings continentNoise;
public SimpleNoiseSettings warpNoise;
public RidgeNoiseSettings ridgeNoise;
public RidgeNoiseSettings ridgeNoise2;
public CraterSettings craterSettings;
public Vector4 testParams;
protected override void SetShapeData () {
var prng = new PRNG (seed);
continentNoise.SetComputeValues (heightMapCompute, prng, "_continents");
ridgeNoise.SetComputeValues (heightMapCompute, prng, "_mountains");
ridgeNoise2.SetComputeValues (heightMapCompute, prng, "_mountains2");
warpNoise.SetComputeValues (heightMapCompute, prng, "_warp");
craterSettings.SetComputeValues (heightMapCompute, seed);
heightMapCompute.SetFloat ("plateauHeight", plateauHeight);
heightMapCompute.SetFloat ("plateauSmoothing", plateauSmoothing);
heightMapCompute.SetVector ("params", testParams);
}
public override void ReleaseBuffers () {
base.ReleaseBuffers ();
craterSettings.ReleaseBuffers ();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3b0ccad980254b91a2375e9a49c87df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: