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,58 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class TextureViewer : MonoBehaviour {
|
||||
|
||||
public TextureGenerator generator;
|
||||
|
||||
[Header ("Preview Settings")]
|
||||
[Range (1, 10)]
|
||||
public int tiling = 1;
|
||||
public Material previewMaterial;
|
||||
public MeshRenderer[] previewObjects;
|
||||
|
||||
void Update () {
|
||||
UpdateTexture ();
|
||||
}
|
||||
|
||||
public void UpdateTexture () {
|
||||
if (generator) {
|
||||
var renderTexture = generator.GenerateTexture ();
|
||||
DisplayPreview (renderTexture);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayPreview (RenderTexture renderTexture) {
|
||||
if (previewMaterial == null) {
|
||||
previewMaterial = new Material (Shader.Find ("Unlit/Texture"));
|
||||
}
|
||||
|
||||
previewMaterial.SetTexture ("_MainTex", renderTexture);
|
||||
previewMaterial.mainTextureScale = new Vector2 (tiling, tiling);
|
||||
if (previewObjects != null) {
|
||||
foreach (var previewObject in previewObjects) {
|
||||
if (previewObject) {
|
||||
previewObject.sharedMaterial = previewMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveTexture (string path) {
|
||||
if (generator) {
|
||||
var renderTexture = generator.GenerateTexture ();
|
||||
var oldRT = RenderTexture.active;
|
||||
|
||||
var tex2D = new Texture2D (renderTexture.width, renderTexture.height);
|
||||
RenderTexture.active = renderTexture;
|
||||
tex2D.ReadPixels (new Rect (0, 0, renderTexture.width, renderTexture.height), 0, 0);
|
||||
tex2D.Apply ();
|
||||
|
||||
System.IO.File.WriteAllBytes (System.IO.Path.Combine (path, renderTexture.name + ".png"), tex2D.EncodeToPNG ());
|
||||
RenderTexture.active = oldRT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue