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:
parent
f8165878e0
commit
53a91351b7
332 changed files with 11904 additions and 78 deletions
|
|
@ -0,0 +1,79 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (menuName = "Celestial Body/Alein/Alien Shading")]
|
||||
public class AlienShading : CelestialBodyShading {
|
||||
|
||||
public AlienColours customizedCols;
|
||||
public AlienColours randomizedCols;
|
||||
|
||||
[Header ("Shading Data")]
|
||||
public SimpleNoiseSettings detailWarpNoise;
|
||||
public SimpleNoiseSettings detailNoise;
|
||||
public SimpleNoiseSettings largeNoise;
|
||||
public SimpleNoiseSettings smallNoise;
|
||||
|
||||
public SimpleNoiseSettings noise2;
|
||||
public SimpleNoiseSettings warp2;
|
||||
|
||||
public override void SetTerrainProperties (Material material, Vector2 heightMinMax, float bodyScale) {
|
||||
|
||||
material.SetVector ("heightMinMax", heightMinMax);
|
||||
material.SetFloat ("oceanLevel", oceanLevel);
|
||||
material.SetFloat("bodyScale", bodyScale);
|
||||
|
||||
if (randomize) {
|
||||
SetRandomColours (material);
|
||||
ApplyColours (material, randomizedCols);
|
||||
} else {
|
||||
ApplyColours (material, customizedCols);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ApplyColours (Material material, AlienColours colours) {
|
||||
material.SetColor ("_ShoreCol", colours.shoreCol);
|
||||
material.SetColor ("_FlatColA", colours.flatColA1);
|
||||
material.SetColor ("_FlatColA2", colours.flatColA2);
|
||||
material.SetColor ("_FlatColB", colours.flatColB1);
|
||||
material.SetColor ("_FlatColB2", colours.flatColB2);
|
||||
material.SetColor ("_SteepColA", colours.steepColA);
|
||||
material.SetColor ("_SteepColB", colours.steepColB);
|
||||
}
|
||||
|
||||
void SetRandomColours (Material material) {
|
||||
PRNG random = new PRNG (seed);
|
||||
randomizedCols.shoreCol = ColourHelper.Random (random, 0.3f, 0.7f, 0.4f, 0.8f);
|
||||
randomizedCols.flatColA1 = ColourHelper.RandomSimilar (random, randomizedCols.shoreCol);
|
||||
randomizedCols.flatColB1 = ColourHelper.RandomSimilar (random, randomizedCols.flatColA1);
|
||||
|
||||
randomizedCols.flatColA2 = ColourHelper.RandomSimilar (random, randomizedCols.flatColA1);
|
||||
randomizedCols.flatColB2 = ColourHelper.RandomSimilar (random, randomizedCols.flatColA2);
|
||||
|
||||
randomizedCols.steepColA = ColourHelper.Random (random, 0.3f, 0.7f, 0.2f, 0.85f);
|
||||
randomizedCols.steepColB = ColourHelper.RandomSimilar (random, randomizedCols.steepColA);
|
||||
}
|
||||
|
||||
protected override void SetShadingDataComputeProperties () {
|
||||
PRNG random = new PRNG (seed);
|
||||
detailNoise.SetComputeValues (shadingDataCompute, random, "_detail");
|
||||
detailWarpNoise.SetComputeValues (shadingDataCompute, random, "_detailWarp");
|
||||
largeNoise.SetComputeValues (shadingDataCompute, random, "_large");
|
||||
smallNoise.SetComputeValues (shadingDataCompute, random, "_small");
|
||||
|
||||
noise2.SetComputeValues (shadingDataCompute, random, "_noise2");
|
||||
warp2.SetComputeValues (shadingDataCompute, random, "_warp2");
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct AlienColours {
|
||||
public Color shoreCol;
|
||||
public Color flatColA1;
|
||||
public Color flatColA2;
|
||||
public Color flatColB1;
|
||||
public Color flatColB2;
|
||||
public Color steepColA;
|
||||
public Color steepColB;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 83a436a8ab50b445abf81aaf5383b802
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
Responsible for the shading of a celestial body.
|
||||
This is paired with a specific CelestialBodyShape.
|
||||
*/
|
||||
|
||||
public abstract class CelestialBodyShading : ScriptableObject {
|
||||
|
||||
public event System.Action OnSettingChanged;
|
||||
|
||||
public bool randomize;
|
||||
public int seed;
|
||||
|
||||
public Material terrainMaterial = null;
|
||||
// public bool hasAtmosphere;
|
||||
// public AtmosphereSettings atmosphereSettings;
|
||||
// public bool hasOcean;
|
||||
[Range (0, 1)]
|
||||
public float oceanLevel;
|
||||
// public OceanSettings oceanSettings;
|
||||
|
||||
public ComputeShader shadingDataCompute;
|
||||
|
||||
protected Vector4[] cachedShadingData;
|
||||
ComputeBuffer shadingBuffer;
|
||||
|
||||
//
|
||||
public virtual void Initialize (CelestialBodyShape shape) { }
|
||||
|
||||
// Generate Vector4[] of shading data. This is stored in mesh uvs and used to help shade the body
|
||||
public Vector4[] GenerateShadingData (ComputeBuffer vertexBuffer) {
|
||||
int numVertices = vertexBuffer.count;
|
||||
Vector4[] shadingData = new Vector4[numVertices];
|
||||
|
||||
if (shadingDataCompute) {
|
||||
// Set data
|
||||
SetShadingDataComputeProperties ();
|
||||
|
||||
shadingDataCompute.SetInt ("numVertices", numVertices);
|
||||
shadingDataCompute.SetBuffer (0, "vertices", vertexBuffer);
|
||||
ComputeHelper.CreateAndSetBuffer<Vector4> (ref shadingBuffer, numVertices, shadingDataCompute, "shadingData");
|
||||
|
||||
// Run
|
||||
ComputeHelper.Run (shadingDataCompute, numVertices);
|
||||
|
||||
// Get data
|
||||
shadingBuffer.GetData (shadingData);
|
||||
}
|
||||
|
||||
cachedShadingData = shadingData;
|
||||
return shadingData;
|
||||
}
|
||||
|
||||
// Set shading properties on terrain
|
||||
public virtual void SetTerrainProperties (Material material, Vector2 heightMinMax, float bodyScale) {
|
||||
|
||||
}
|
||||
|
||||
// public virtual void SetOceanProperties (Material oceanMaterial) {
|
||||
// if (oceanSettings) {
|
||||
// oceanSettings.SetProperties (oceanMaterial, seed, randomize);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Override this to set properties on the shadingDataCompute before it is run
|
||||
protected virtual void SetShadingDataComputeProperties () {
|
||||
|
||||
}
|
||||
|
||||
public virtual void ReleaseBuffers () {
|
||||
ComputeHelper.Release (shadingBuffer);
|
||||
}
|
||||
|
||||
public static void TextureFromGradient (ref Texture2D texture, int width, Gradient gradient, FilterMode filterMode = FilterMode.Bilinear) {
|
||||
if (texture == null) {
|
||||
texture = new Texture2D (width, 1);
|
||||
} else if (texture.width != width) {
|
||||
texture.Resize (width, 1);
|
||||
}
|
||||
if (gradient == null) {
|
||||
gradient = new Gradient ();
|
||||
gradient.SetKeys (
|
||||
new GradientColorKey[] { new GradientColorKey (Color.black, 0), new GradientColorKey (Color.black, 1) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey (1, 0), new GradientAlphaKey (1, 1) }
|
||||
);
|
||||
}
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
texture.filterMode = filterMode;
|
||||
|
||||
Color[] cols = new Color[width];
|
||||
for (int i = 0; i < cols.Length; i++) {
|
||||
float t = i / (cols.Length - 1f);
|
||||
cols[i] = gradient.Evaluate (t);
|
||||
}
|
||||
texture.SetPixels (cols);
|
||||
texture.Apply ();
|
||||
}
|
||||
|
||||
protected virtual void OnValidate () {
|
||||
/*
|
||||
Shader activeShader = (shader) ? shader : Shader.Find ("Unlit/Color");
|
||||
if (material == null || material.shader != activeShader) {
|
||||
if (material == null) {
|
||||
material = new Material (activeShader);
|
||||
} else {
|
||||
material.shader = activeShader;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (OnSettingChanged != null) {
|
||||
OnSettingChanged ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 37ebad5240372447ca7de34d94e1abd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ColourHelper {
|
||||
|
||||
// Create random colour within a given range of saturation and value
|
||||
public static Color Random (PRNG random, float satMin, float satMax, float valMin, float valMax) {
|
||||
return Color.HSVToRGB (random.Value (), random.Range (satMin, satMax), random.Range (valMin, valMax));
|
||||
}
|
||||
|
||||
public static Color TweakHSV (Color colRGB, float deltaH, float deltaS, float deltaV) {
|
||||
float hue, sat, val;
|
||||
Color.RGBToHSV (colRGB, out hue, out sat, out val);
|
||||
return Color.HSVToRGB ((hue + deltaH) % 1, sat + deltaS, val + deltaV);
|
||||
}
|
||||
|
||||
public static Color RandomSimilar (PRNG random, Color original, float maxHueDelta, float maxSatDelta, float maxValDelta) {
|
||||
float hue, sat, val;
|
||||
Color.RGBToHSV (original, out hue, out sat, out val);
|
||||
hue = (hue + random.SignedValue () * maxHueDelta) % 1;
|
||||
sat += random.SignedValue () * maxSatDelta;
|
||||
val += random.SignedValue () * maxValDelta;
|
||||
return Color.HSVToRGB (hue, sat, val);
|
||||
}
|
||||
|
||||
public static Color RandomSimilar (PRNG random, Color original) {
|
||||
float hue, sat, val;
|
||||
Color.RGBToHSV (original, out hue, out sat, out val);
|
||||
hue = (hue + random.SignedValue () * 0.25f) % 1;
|
||||
sat += random.Sign () * random.Range (0.2f, 0.4f);
|
||||
sat = Mathf.Clamp (sat, 0.2f, 0.8f);
|
||||
val += random.Sign () * random.Range (0.2f, 0.4f);
|
||||
val = Mathf.Clamp (val, 0.2f, 0.8f);
|
||||
return Color.HSVToRGB (hue, sat, val);
|
||||
}
|
||||
|
||||
public static Color RandomContrasting (PRNG random, Color original) {
|
||||
float hue, sat, val;
|
||||
Color.RGBToHSV (original, out hue, out sat, out val);
|
||||
hue = (hue + 0.5f + random.SignedValue () * 0.1f) % 1;
|
||||
sat += random.SignedValue () * 0.2f;
|
||||
val = (val < 0.5f) ? random.Range (val + 0.2f, 0.9f) : random.Range (0.1f, val - 0.2f);
|
||||
return Color.HSVToRGB (hue, sat, val);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fdcc106ed0a4f4ec88ef7257347b32ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
101
Assets/Plugins/Celestial Body/Scripts/Shading/EarthShading.cs
Normal file
101
Assets/Plugins/Celestial Body/Scripts/Shading/EarthShading.cs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (menuName = "Celestial Body/Earth-Like/Earth Shading")]
|
||||
public class EarthShading : CelestialBodyShading {
|
||||
|
||||
public EarthColours customizedCols;
|
||||
public EarthColours randomizedCols;
|
||||
|
||||
[Header ("Shading Data")]
|
||||
public SimpleNoiseSettings detailWarpNoise;
|
||||
public SimpleNoiseSettings detailNoise;
|
||||
public SimpleNoiseSettings largeNoise;
|
||||
public SimpleNoiseSettings smallNoise;
|
||||
|
||||
public override void SetTerrainProperties (Material material, Vector2 heightMinMax, float bodyScale) {
|
||||
|
||||
material.SetVector ("heightMinMax", heightMinMax);
|
||||
material.SetFloat ("oceanLevel", oceanLevel);
|
||||
material.SetFloat ("bodyScale", bodyScale);
|
||||
|
||||
if (randomize) {
|
||||
SetRandomColours (material);
|
||||
ApplyColours (material, randomizedCols);
|
||||
} else {
|
||||
ApplyColours (material, customizedCols);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyColours (Material material, EarthColours colours) {
|
||||
material.SetColor ("_ShoreLow", colours.shoreColLow);
|
||||
material.SetColor ("_ShoreHigh", colours.shoreColHigh);
|
||||
|
||||
material.SetColor ("_FlatLowA", colours.flatColLowA);
|
||||
material.SetColor ("_FlatHighA", colours.flatColHighA);
|
||||
|
||||
material.SetColor ("_FlatLowB", colours.flatColLowB);
|
||||
material.SetColor ("_FlatHighB", colours.flatColHighB);
|
||||
|
||||
material.SetColor ("_SteepLow", colours.steepLow);
|
||||
material.SetColor ("_SteepHigh", colours.steepHigh);
|
||||
}
|
||||
|
||||
void SetRandomColours (Material material) {
|
||||
PRNG random = new PRNG (seed);
|
||||
//randomizedCols.shoreCol = ColourHelper.Random (random, 0.3f, 0.7f, 0.4f, 0.8f);
|
||||
randomizedCols.flatColLowA = ColourHelper.Random (random, 0.45f, 0.6f, 0.7f, 0.8f);
|
||||
randomizedCols.flatColHighA = ColourHelper.TweakHSV (
|
||||
randomizedCols.flatColLowA,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.SignedValue () * 0.15f,
|
||||
random.Range (-0.25f, -0.2f)
|
||||
);
|
||||
|
||||
randomizedCols.flatColLowB = ColourHelper.Random (random, 0.45f, 0.6f, 0.7f, 0.8f);
|
||||
randomizedCols.flatColHighB = ColourHelper.TweakHSV (
|
||||
randomizedCols.flatColLowB,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.SignedValue () * 0.15f,
|
||||
random.Range (-0.25f, -0.2f)
|
||||
);
|
||||
|
||||
randomizedCols.shoreColLow = ColourHelper.Random (random, 0.2f, 0.3f, 0.9f, 1);
|
||||
randomizedCols.shoreColHigh = ColourHelper.TweakHSV (
|
||||
randomizedCols.shoreColLow,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.Range (-0.3f, -0.2f)
|
||||
);
|
||||
|
||||
randomizedCols.steepLow = ColourHelper.Random (random, 0.3f, 0.7f, 0.4f, 0.6f);
|
||||
randomizedCols.steepHigh = ColourHelper.TweakHSV (
|
||||
randomizedCols.steepLow,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.SignedValue () * 0.2f,
|
||||
random.Range (-0.35f, -0.2f)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void SetShadingDataComputeProperties () {
|
||||
PRNG random = new PRNG (seed);
|
||||
detailNoise.SetComputeValues (shadingDataCompute, random, "_detail");
|
||||
detailWarpNoise.SetComputeValues (shadingDataCompute, random, "_detailWarp");
|
||||
largeNoise.SetComputeValues (shadingDataCompute, random, "_large");
|
||||
smallNoise.SetComputeValues (shadingDataCompute, random, "_small");
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct EarthColours {
|
||||
public Color shoreColLow;
|
||||
public Color shoreColHigh;
|
||||
public Color flatColLowA;
|
||||
public Color flatColHighA;
|
||||
public Color flatColLowB;
|
||||
public Color flatColHighB;
|
||||
|
||||
public Color steepLow;
|
||||
public Color steepHigh;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: db6f66ab3e2604c0d9bcf6649e6d7915
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
277
Assets/Plugins/Celestial Body/Scripts/Shading/MoonShading.cs
Normal file
277
Assets/Plugins/Celestial Body/Scripts/Shading/MoonShading.cs
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (menuName = "Celestial Body/Moon/Moon Shading")]
|
||||
public class MoonShading : CelestialBodyShading {
|
||||
|
||||
public Color primaryColA = Color.white;
|
||||
public Color secondaryColA = Color.black;
|
||||
public Color primaryColB = Color.white;
|
||||
public Color secondaryColB = Color.black;
|
||||
public Color steepCol = Color.black;
|
||||
|
||||
[Header ("Shading Data")]
|
||||
public int numBiomePoints = 20;
|
||||
public Vector2 radiusMinMax = new Vector2 (0.02f, 0.1f);
|
||||
|
||||
public SimpleNoiseSettings biomeWarpNoise;
|
||||
public SimpleNoiseSettings detailNoise;
|
||||
public SimpleNoiseSettings detailWarpNoise;
|
||||
|
||||
[Header ("Rays")]
|
||||
[Range (0, 1)]
|
||||
public float candidatePoolSize = 0.2f;
|
||||
public int desiredNumCraterRays = 2;
|
||||
public int ejectaRaySeed;
|
||||
public float ejectaRaysScale = 10;
|
||||
|
||||
[Header ("Normal maps")]
|
||||
public Texture2D[] normalMapsFlat;
|
||||
public Texture2D[] normalMapsSteep;
|
||||
|
||||
ComputeBuffer craterBuffer;
|
||||
ComputeBuffer pointBuffer;
|
||||
MoonShape moonShape;
|
||||
|
||||
public override void Initialize (CelestialBodyShape shape) {
|
||||
base.Initialize (shape);
|
||||
moonShape = shape as MoonShape;
|
||||
}
|
||||
|
||||
public override void SetTerrainProperties (Material material, Vector2 heightMinMax, float bodyScale) {
|
||||
material.SetVector ("heightMinMax", heightMinMax);
|
||||
material.SetFloat ("bodyScale", bodyScale);
|
||||
|
||||
var prng = new PRNG (seed);
|
||||
|
||||
if (randomize) {
|
||||
|
||||
SetColours (prng, material);
|
||||
|
||||
material.SetFloat ("_SmoothnessA", Mathf.Lerp (0f, 0.6f, prng.SmallestRandom01 (4)));
|
||||
material.SetFloat ("_SmoothnessB", Mathf.Lerp (0f, 0.6f, prng.SmallestRandom01 (4)));
|
||||
material.SetFloat ("_Metallic", Mathf.Lerp (0f, 0.5f, prng.SmallestRandom01 (3)));
|
||||
|
||||
var randomNormalMapFlat = prng.RandomElement (normalMapsFlat);
|
||||
var randomNormalMapSteep = randomNormalMapFlat;
|
||||
int loopSafety = 0;
|
||||
while (randomNormalMapSteep == randomNormalMapFlat && loopSafety < 20) {
|
||||
randomNormalMapSteep = prng.RandomElement (normalMapsSteep);
|
||||
loopSafety++;
|
||||
}
|
||||
material.SetTexture ("_NormalMapFlat", randomNormalMapFlat);
|
||||
material.SetTexture ("_NormalMapSteep", randomNormalMapSteep);
|
||||
|
||||
SetBiomeSettings (prng, material);
|
||||
|
||||
} else {
|
||||
material.SetColor ("_PrimaryColA", primaryColA);
|
||||
material.SetColor ("_SecondaryColA", secondaryColA);
|
||||
material.SetColor ("_PrimaryColB", primaryColB);
|
||||
material.SetColor ("_SecondaryColB", secondaryColB);
|
||||
material.SetColor ("_SteepCol", steepCol);
|
||||
}
|
||||
|
||||
//
|
||||
if (cachedShadingData != null) {
|
||||
float biomeNoiseSum = 0;
|
||||
for (int i = 0; i < cachedShadingData.Length; i++) {
|
||||
biomeNoiseSum += cachedShadingData[i].w;
|
||||
}
|
||||
material.SetFloat ("_AvgBiomeNoiseDst", biomeNoiseSum / cachedShadingData.Length);
|
||||
} else {
|
||||
Debug.LogError ("Cached shading noise null");
|
||||
material.SetFloat ("_AvgBiomeNoiseDst", 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetBiomeSettings (PRNG prng, Material material) {
|
||||
var biomeValues = new Vector4 (
|
||||
prng.SignedValueBiasExtremes (0.3f),
|
||||
prng.SignedValueBiasExtremes (0.3f) * 0.4f,
|
||||
prng.SignedValueBiasExtremes (0.3f) * 0.3f,
|
||||
prng.SignedValueBiasCentre (0.3f) * .7f
|
||||
);
|
||||
material.SetVector ("_RandomBiomeValues", biomeValues);
|
||||
float warpStrength = prng.SignedValueBiasCentre (.65f) * 30;
|
||||
material.SetFloat ("_BiomeBlendStrength", prng.Range (2f, 12) + Mathf.Abs (warpStrength) / 2);
|
||||
material.SetFloat ("_BiomeWarpStrength", warpStrength);
|
||||
}
|
||||
|
||||
void SetColours (PRNG rand, Material material) {
|
||||
|
||||
var colChance = new Chance (rand);
|
||||
var primaryA_HSV = Vector3.zero;
|
||||
var secondaryA_HSV = Vector3.zero;
|
||||
var primaryB_HSV = Vector3.zero;
|
||||
var secondaryB_HSV = Vector3.zero;
|
||||
|
||||
// One light grey, one dark grey
|
||||
if (colChance.Percent (25)) {
|
||||
primaryA_HSV = new Vector3 (0, 0, Mathf.Lerp (0.55f, 1, rand.ValueBiasUpper (.4f)));
|
||||
secondaryA_HSV = primaryA_HSV + new Vector3 (0, 0, rand.SignedValueBiasCentre (0.4f));
|
||||
primaryB_HSV = new Vector3 (0, 0, Mathf.Lerp (0f, 0.45f, rand.ValueBiasLower (.4f)));
|
||||
secondaryB_HSV = primaryB_HSV + new Vector3 (0, 0, rand.SignedValueBiasCentre (0.4f));
|
||||
}
|
||||
// One colour, one grey
|
||||
else if (colChance.Percent (25)) {
|
||||
// Pick grey, tending towards either very dark or very light
|
||||
float greyValue = rand.ValueBiasExtremes (0.8f);
|
||||
primaryA_HSV = new Vector3 (0, 0, greyValue);
|
||||
secondaryA_HSV = new Vector3 (0, 0, greyValue + rand.SignedValueBiasCentre (0.5f) * .3f);
|
||||
// If grey is dark, use bright colour, otherwise dark colour
|
||||
float colourValue = (greyValue < 0.5f) ? rand.ValueBiasUpper (0.7f) : rand.ValueBiasLower (0.7f);
|
||||
primaryB_HSV = new Vector3 (rand.Value (), rand.Range (0.2f, 0.9f), Mathf.Lerp (0.1f, 0.9f, colourValue));
|
||||
secondaryB_HSV = primaryB_HSV + rand.JiggleVector3 (0.1f, 0.2f, 0.4f);
|
||||
}
|
||||
|
||||
// Two similar colours
|
||||
else if (colChance.Percent (25)) {
|
||||
primaryA_HSV = new Vector3 (rand.Range (0, 1), rand.Range (0.1f, 0.8f), rand.Range (0.2f, 0.8f));
|
||||
secondaryA_HSV = primaryA_HSV + rand.JiggleVector3 (0.1f, 0.2f, 0.3f);
|
||||
primaryB_HSV = new Vector3 (primaryA_HSV.x + rand.Range (0.05f, 0.1f), rand.Range (0.1f, 0.8f), rand.Range (0.2f, 0.8f));
|
||||
secondaryB_HSV = primaryB_HSV + rand.JiggleVector3 (0.1f, 0.2f, 0.3f);
|
||||
}
|
||||
|
||||
// Two distinct colours
|
||||
else if (colChance.Percent (25)) {
|
||||
primaryA_HSV = new Vector3 (rand.Value (), rand.Range (0.2f, 0.9f), rand.Range (0.1f, 0.9f));
|
||||
secondaryA_HSV = primaryA_HSV + rand.JiggleVector3 (0.1f, 0.2f, 0.3f);
|
||||
primaryB_HSV = new Vector3 ((primaryA_HSV.x + rand.Range (0.2f, 0.8f)) % 1, rand.Range (0.2f, 0.9f), rand.Range (0.1f, 0.9f));
|
||||
secondaryB_HSV = primaryB_HSV + rand.JiggleVector3 (0.1f, 0.2f, 0.3f);
|
||||
|
||||
}
|
||||
|
||||
material.SetColor ("_PrimaryColA", HSVToRGB (primaryA_HSV));
|
||||
material.SetColor ("_SecondaryColA", HSVToRGB (secondaryA_HSV));
|
||||
material.SetColor ("_PrimaryColB", HSVToRGB (primaryB_HSV));
|
||||
material.SetColor ("_SecondaryColB", HSVToRGB (secondaryB_HSV));
|
||||
}
|
||||
|
||||
Color GreyscaleColor (float value) {
|
||||
return new Color (value, value, value, 1);
|
||||
}
|
||||
|
||||
Color HSVToRGB (Vector3 col) {
|
||||
return Color.HSVToRGB (Mathf.Clamp01 (col.x), Mathf.Clamp01 (col.y), Mathf.Clamp01 (col.z));
|
||||
}
|
||||
|
||||
protected override void SetShadingDataComputeProperties () {
|
||||
SetCraters (moonShape);
|
||||
SetRandomPoints ();
|
||||
SetShadingNoise ();
|
||||
}
|
||||
|
||||
void SetShadingNoise () {
|
||||
const string biomeWarpNoiseSuffix = "_biomeWarp";
|
||||
const string detailWarpNoiseSuffix = "_detailWarp";
|
||||
const string detailNoiseSuffix = "_detail";
|
||||
|
||||
PRNG prng = new PRNG (seed);
|
||||
PRNG prng2 = new PRNG (seed);
|
||||
if (randomize) {
|
||||
// warp 1
|
||||
var randomizedBiomeWarpNoise = new SimpleNoiseSettings ();
|
||||
randomizedBiomeWarpNoise.elevation = prng.Range (0.8f, 3f);
|
||||
randomizedBiomeWarpNoise.scale = prng.Range (1f, 3f);
|
||||
randomizedBiomeWarpNoise.SetComputeValues (shadingDataCompute, prng2, biomeWarpNoiseSuffix);
|
||||
|
||||
// warp 2
|
||||
var randomizedDetailWarpNoise = new SimpleNoiseSettings ();
|
||||
randomizedDetailWarpNoise.scale = prng.Range (1f, 3f);
|
||||
randomizedDetailWarpNoise.elevation = prng.Range (1f, 5f);
|
||||
randomizedDetailWarpNoise.SetComputeValues (shadingDataCompute, prng2, detailWarpNoiseSuffix);
|
||||
|
||||
detailNoise.SetComputeValues (shadingDataCompute, prng2, detailNoiseSuffix);
|
||||
|
||||
} else {
|
||||
biomeWarpNoise.SetComputeValues (shadingDataCompute, prng2, biomeWarpNoiseSuffix);
|
||||
detailWarpNoise.SetComputeValues (shadingDataCompute, prng2, detailWarpNoiseSuffix);
|
||||
detailNoise.SetComputeValues (shadingDataCompute, prng2, detailNoiseSuffix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetRandomPoints () {
|
||||
Random.InitState (seed);
|
||||
|
||||
int randomizedNumPoints = numBiomePoints;
|
||||
if (randomize) {
|
||||
randomizedNumPoints = Random.Range (15, 50);
|
||||
}
|
||||
Random.InitState (seed);
|
||||
var randomPoints = new Vector4[randomizedNumPoints];
|
||||
for (int i = 0; i < randomPoints.Length; i++) {
|
||||
var point = Random.onUnitSphere;
|
||||
var radius = Mathf.Lerp (radiusMinMax.x, radiusMinMax.y, Random.value);
|
||||
randomPoints[i] = new Vector4 (point.x, point.y, point.z, radius);
|
||||
}
|
||||
|
||||
ComputeHelper.CreateAndSetBuffer<Vector4> (ref pointBuffer, randomPoints, shadingDataCompute, "points");
|
||||
shadingDataCompute.SetInt ("numRandomPoints", randomPoints.Length);
|
||||
}
|
||||
|
||||
// Pick craters to be shaded with radial streaks emanating from them
|
||||
void SetCraters (MoonShape moonShape) {
|
||||
PRNG random = new PRNG (ejectaRaySeed);
|
||||
//int desiredNumCraterRays = random.Range (5, 15);
|
||||
//desiredNumCraterRays = 2;
|
||||
|
||||
// Sort craters from largest to smallest
|
||||
var sortedCraters = new List<CraterSettings.Crater> (moonShape.craterSettings.cachedCraters);
|
||||
sortedCraters.Sort ((a, b) => b.size.CompareTo (a.size));
|
||||
int poolSize = Mathf.Clamp ((int) ((sortedCraters.Count - 1) * candidatePoolSize), 1, sortedCraters.Count);
|
||||
sortedCraters = sortedCraters.GetRange (0, poolSize);
|
||||
random.Shuffle (sortedCraters);
|
||||
|
||||
// Choose craters
|
||||
var chosenCraters = new List<CraterSettings.Crater> ();
|
||||
|
||||
for (int i = 0; i < sortedCraters.Count; i++) {
|
||||
var currentCrater = sortedCraters[i];
|
||||
|
||||
// Reject those which are too close to already chosen craters as the textures may not overlap
|
||||
bool overlapsOtherEjecta = false;
|
||||
for (int j = 0; j < chosenCraters.Count; j++) {
|
||||
float dst = (currentCrater.centre - chosenCraters[j].centre).magnitude;
|
||||
float ejectaRadiusSum = (currentCrater.size + chosenCraters[j].size) * ejectaRaysScale / 2;
|
||||
|
||||
if (dst < ejectaRadiusSum) {
|
||||
overlapsOtherEjecta = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.DrawRay (currentCrater.centre, currentCrater.centre * 0.2f, (overlapsOtherEjecta) ? Color.red : Color.green);
|
||||
if (!overlapsOtherEjecta) {
|
||||
chosenCraters.Add (currentCrater);
|
||||
|
||||
}
|
||||
if (chosenCraters.Count >= desiredNumCraterRays) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set
|
||||
var ejectaCraters = new Vector4[chosenCraters.Count];
|
||||
for (int i = 0; i < chosenCraters.Count; i++) {
|
||||
var crater = chosenCraters[i];
|
||||
ejectaCraters[i] = new Vector4 (crater.centre.x, crater.centre.y, crater.centre.z, crater.size * ejectaRaysScale);
|
||||
//CustomDebug.DrawSphere (crater.centre, crater.size * ejectaRaysScale / 2, Color.yellow);
|
||||
}
|
||||
|
||||
ComputeHelper.CreateAndSetBuffer<Vector4> (ref craterBuffer, ejectaCraters, shadingDataCompute, "ejectaCraters");
|
||||
shadingDataCompute.SetInt ("numEjectaCraters", chosenCraters.Count);
|
||||
}
|
||||
|
||||
public override void ReleaseBuffers () {
|
||||
base.ReleaseBuffers ();
|
||||
ComputeHelper.Release (craterBuffer, pointBuffer);
|
||||
}
|
||||
|
||||
protected override void OnValidate () {
|
||||
base.OnValidate ();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6dc781a665a4a49f09ef89610d5413ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Plugins/Celestial Body/Scripts/Shading/TestShading.cs
Normal file
18
Assets/Plugins/Celestial Body/Scripts/Shading/TestShading.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (menuName = "Celestial Body/Shading/Test")]
|
||||
public class TestShading : CelestialBodyShading {
|
||||
|
||||
public Color colorA = Color.black;
|
||||
public Color colorB = Color.white;
|
||||
public Vector2 remapMinMax = new Vector2 (0, 1);
|
||||
|
||||
public override void SetTerrainProperties (Material material, Vector2 heightMinMax, float bodyScale) {
|
||||
material.SetColor ("_ColorA", colorA);
|
||||
material.SetColor ("_ColorB", colorB);
|
||||
material.SetVector ("heightMinMax", heightMinMax);
|
||||
material.SetVector ("remapMinMax", remapMinMax);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1abc4f20cbf864ddd9bf012426173ef9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue