Skip to content

Commit

Permalink
E21
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Lague authored and Sebastian Lague committed Jun 8, 2017
1 parent d492979 commit e350384
Show file tree
Hide file tree
Showing 1,513 changed files with 4,130 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Proc Gen E21/Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Proc Gen E21/Assets/Editor/MapPreviewEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor (typeof (MapPreview))]
public class MapPreviewEditor : Editor {

public override void OnInspectorGUI() {
MapPreview mapPreview = (MapPreview)target;

if (DrawDefaultInspector ()) {
if (mapPreview.autoUpdate) {
mapPreview.DrawMapInEditor ();
}
}

if (GUILayout.Button ("Generate")) {
mapPreview.DrawMapInEditor ();
}
}
}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Editor/MapPreviewEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Proc Gen E21/Assets/Editor/UpdatableDataEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor (typeof(UpdatableData), true)]
public class UpdatableDataEditor : Editor {

public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();

UpdatableData data = (UpdatableData)target;

if (GUILayout.Button ("Update")) {
data.NotifyOfUpdatedValues ();
EditorUtility.SetDirty (target);
}
}

}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Editor/UpdatableDataEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Proc Gen E21/Assets/Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Proc Gen E21/Assets/Materials/Map Mat.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions Proc Gen E21/Assets/Materials/Map Mat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Proc Gen E21/Assets/Materials/Mesh Mat.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions Proc Gen E21/Assets/Materials/Mesh Mat.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Proc Gen E21/Assets/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Proc Gen E21/Assets/Scenes/Scene.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Proc Gen E21/Assets/Scenes/Scene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Proc Gen E21/Assets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;

[CreateAssetMenu()]
public class HeightMapSettings : UpdatableData {

public NoiseSettings noiseSettings;

public bool useFalloff;

public float heightMultiplier;
public AnimationCurve heightCurve;

public float minHeight {
get {
return heightMultiplier * heightCurve.Evaluate (0);
}
}

public float maxHeight {
get {
return heightMultiplier * heightCurve.Evaluate (1);
}
}

#if UNITY_EDITOR

protected override void OnValidate() {
noiseSettings.ValidateValues ();
base.OnValidate ();
}
#endif

}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/HeightMapSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEngine;
using System.Collections;

[CreateAssetMenu()]
public class MeshSettings : UpdatableData {

public const int numSupportedLODs = 5;
public const int numSupportedChunkSizes = 9;
public const int numSupportedFlatshadedChunkSizes = 3;
public static readonly int[] supportedChunkSizes = {48,72,96,120,144,168,192,216,240};

public float meshScale = 2.5f;
public bool useFlatShading;

[Range(0,numSupportedChunkSizes-1)]
public int chunkSizeIndex;
[Range(0,numSupportedFlatshadedChunkSizes-1)]
public int flatshadedChunkSizeIndex;


// num verts per line of mesh rendered at LOD = 0. Includes the 2 extra verts that are excluded from final mesh, but used for calculating normals
public int numVertsPerLine {
get {
return supportedChunkSizes [(useFlatShading) ? flatshadedChunkSizeIndex : chunkSizeIndex] + 5;
}
}

public float meshWorldSize {
get {
return (numVertsPerLine - 3) * meshScale;
}
}


}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/MeshSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/TextureData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using UnityEngine;
using System.Collections;
using System.Linq;

[CreateAssetMenu()]
public class TextureData : UpdatableData {

const int textureSize = 512;
const TextureFormat textureFormat = TextureFormat.RGB565;

public Layer[] layers;

float savedMinHeight;
float savedMaxHeight;

public void ApplyToMaterial(Material material) {

material.SetInt ("layerCount", layers.Length);
material.SetColorArray ("baseColours", layers.Select(x => x.tint).ToArray());
material.SetFloatArray ("baseStartHeights", layers.Select(x => x.startHeight).ToArray());
material.SetFloatArray ("baseBlends", layers.Select(x => x.blendStrength).ToArray());
material.SetFloatArray ("baseColourStrength", layers.Select(x => x.tintStrength).ToArray());
material.SetFloatArray ("baseTextureScales", layers.Select(x => x.textureScale).ToArray());
Texture2DArray texturesArray = GenerateTextureArray (layers.Select (x => x.texture).ToArray ());
material.SetTexture ("baseTextures", texturesArray);

UpdateMeshHeights (material, savedMinHeight, savedMaxHeight);
}

public void UpdateMeshHeights(Material material, float minHeight, float maxHeight) {
savedMinHeight = minHeight;
savedMaxHeight = maxHeight;

material.SetFloat ("minHeight", minHeight);
material.SetFloat ("maxHeight", maxHeight);
}

Texture2DArray GenerateTextureArray(Texture2D[] textures) {
Texture2DArray textureArray = new Texture2DArray (textureSize, textureSize, textures.Length, textureFormat, true);
for (int i = 0; i < textures.Length; i++) {
textureArray.SetPixels (textures [i].GetPixels (), i);
}
textureArray.Apply ();
return textureArray;
}

[System.Serializable]
public class Layer {
public Texture2D texture;
public Color tint;
[Range(0,1)]
public float tintStrength;
[Range(0,1)]
public float startHeight;
[Range(0,1)]
public float blendStrength;
public float textureScale;
}


}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/TextureData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;

public class UpdatableData : ScriptableObject {

public event System.Action OnValuesUpdated;
public bool autoUpdate;

#if UNITY_EDITOR

protected virtual void OnValidate() {
if (autoUpdate) {
UnityEditor.EditorApplication.update += NotifyOfUpdatedValues;
}
}

public void NotifyOfUpdatedValues() {
UnityEditor.EditorApplication.update -= NotifyOfUpdatedValues;
if (OnValuesUpdated != null) {
OnValuesUpdated ();
}
}

#endif

}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Scripts/Data/UpdatableData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Proc Gen E21/Assets/Scripts/FalloffGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections;

public static class FalloffGenerator {

public static float[,] GenerateFalloffMap(int size) {
float[,] map = new float[size,size];

for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
float x = i / (float)size * 2 - 1;
float y = j / (float)size * 2 - 1;

float value = Mathf.Max (Mathf.Abs (x), Mathf.Abs (y));
map [i, j] = Evaluate(value);
}
}

return map;
}

static float Evaluate(float value) {
float a = 3;
float b = 2.2f;

return Mathf.Pow (value, a) / (Mathf.Pow (value, a) + Mathf.Pow (b - b * value, a));
}
}
12 changes: 12 additions & 0 deletions Proc Gen E21/Assets/Scripts/FalloffGenerator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e350384

Please sign in to comment.