portals and dash. Also a bit of terrain building and level design

This commit is contained in:
2022-03-13 00:26:35 +02:00
parent 813cd0c451
commit e82799c36a
6242 changed files with 2160679 additions and 188245 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 803df85fca46f2042afbffbbfcb2fef3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,485 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Rendering;
using DateTime = System.DateTime;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Pinwheel.Jupiter
{
public static class JCommon
{
public static string SUPPORT_EMAIL = "support@pinwheel.studio";
public static string BUSINESS_EMAIL = "hello@pinwheel.studio";
public static string YOUTUBE_CHANNEL = "https://www.youtube.com/channel/UCebwuk5CfIe5kolBI9nuBTg";
public static string ONLINE_MANUAL = "https://docs.google.com/document/d/1Wf4CDlD96c6tna1ee0fpquWkdSrGDIO-eKuQDxjJedY/edit?usp=sharing";
public static string FORUM = "https://forum.unity.com/threads/pre-released-jupiter-procedural-sky-builtin-lwrp-urp.799635/";
public static string DISCORD = "https://discord.gg/HXNnFpS";
public const int PREVIEW_TEXTURE_SIZE = 512;
public const int TEXTURE_SIZE_MIN = 1;
public const int TEXTURE_SIZE_MAX = 8192;
public static JRenderPipelineType CurrentRenderPipeline
{
get
{
string pipelineName = Shader.globalRenderPipeline;
if (pipelineName.Equals("UniversalPipeline,LightweightPipeline"))
{
return JRenderPipelineType.Universal;
}
else if (pipelineName.Equals("LightweightPipeline"))
{
return JRenderPipelineType.Lightweight;
}
else
{
return JRenderPipelineType.Builtin;
}
}
}
private static Vector2[] fullRectUvPoints;
public static Vector2[] FullRectUvPoints
{
get
{
if (fullRectUvPoints == null)
{
fullRectUvPoints = new Vector2[]
{
Vector2.zero,
Vector2.up,
Vector2.one,
Vector2.right
};
}
return fullRectUvPoints;
}
}
private static Mesh emptyMesh;
public static Mesh EmptyMesh
{
get
{
if (emptyMesh == null)
{
emptyMesh = new Mesh();
}
return emptyMesh;
}
}
private static Material[] emptyMaterials;
public static Material[] EmptyMaterials
{
get
{
if (emptyMaterials==null)
{
emptyMaterials = new Material[0];
}
return emptyMaterials;
}
}
public static Rect UnitRect
{
get
{
return new Rect(0, 0, 1, 1);
}
}
public static string GetUniqueID()
{
string s = GetTimeTick().ToString();
return Reverse(s);
}
public static long GetTimeTick()
{
DateTime time = DateTime.Now;
return time.Ticks;
}
public static string Reverse(string s)
{
char[] chars = s.ToCharArray();
System.Array.Reverse(chars);
return new string(chars);
}
public static void SetDirty(Object o)
{
#if UNITY_EDITOR
EditorUtility.SetDirty(o);
#endif
}
public static void AddObjectToAsset(Object objectToAdd, Object asset)
{
#if UNITY_EDITOR
AssetDatabase.AddObjectToAsset(objectToAdd, asset);
#endif
}
public static Texture2D CreateTexture(int resolution, Color fill, TextureFormat format = TextureFormat.ARGB32)
{
Texture2D t = new Texture2D(resolution, resolution, format, false);
Color[] colors = new Color[resolution * resolution];
JUtilities.Fill(colors, fill);
t.SetPixels(colors);
t.Apply();
return t;
}
public static void CopyToRT(Texture t, RenderTexture rt)
{
RenderTexture.active = rt;
Graphics.Blit(t, rt);
RenderTexture.active = null;
}
public static void CopyFromRT(Texture2D t, RenderTexture rt)
{
RenderTexture.active = rt;
t.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
t.Apply();
RenderTexture.active = null;
}
public static void CopyTexture(Texture2D src, Texture2D des)
{
RenderTexture rt = new RenderTexture(des.width, des.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default);
CopyToRT(src, rt);
CopyFromRT(des, rt);
rt.Release();
JUtilities.DestroyObject(rt);
}
public static Texture2D CloneTexture(Texture2D t)
{
RenderTexture rt = new RenderTexture(t.width, t.height, 0, RenderTextureFormat.ARGB32);
CopyToRT(t, rt);
Texture2D result = new Texture2D(t.width, t.height, TextureFormat.ARGB32, false);
result.filterMode = t.filterMode;
result.wrapMode = t.wrapMode;
CopyFromRT(result, rt);
rt.Release();
Object.DestroyImmediate(rt);
return result;
}
public static void FillTexture(Texture2D t, Color c)
{
Color[] colors = new Color[t.width * t.height];
JUtilities.Fill(colors, c);
t.SetPixels(colors);
t.Apply();
}
public static void FillTexture(RenderTexture rt, Color c)
{
Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
tex.SetPixel(0, 0, c);
tex.Apply();
CopyToRT(tex, rt);
JUtilities.DestroyObject(tex);
}
public static Texture2D CloneAndResizeTexture(Texture2D t, int width, int height)
{
RenderTexture rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32);
CopyToRT(t, rt);
Texture2D result = new Texture2D(width, height, TextureFormat.ARGB32, false);
result.filterMode = t.filterMode;
result.wrapMode = t.wrapMode;
CopyFromRT(result, rt);
rt.Release();
Object.DestroyImmediate(rt);
return result;
}
public static RenderTexture CopyToRT(Texture src, int startX, int startY, int width, int height, Color defaultColor)
{
int endX = startX + width - 1;
int endY = startY + height - 1;
Vector2 startUV = new Vector2(
JUtilities.InverseLerpUnclamped(0, src.width - 1, startX),
JUtilities.InverseLerpUnclamped(0, src.height - 1, startY));
Vector2 endUV = new Vector2(
JUtilities.InverseLerpUnclamped(0, src.width - 1, endX),
JUtilities.InverseLerpUnclamped(0, src.height - 1, endY));
Material mat = JInternalMaterials.CopyTextureMaterial;
mat.SetTexture("_MainTex", src);
mat.SetVector("_StartUV", startUV);
mat.SetVector("_EndUV", endUV);
mat.SetColor("_DefaultColor", defaultColor);
mat.SetPass(0);
RenderTexture rt = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
RenderTexture.active = rt;
Graphics.Blit(src, mat);
RenderTexture.active = null;
return rt;
}
public static void DrawTexture(RenderTexture rt, Texture texture, Rect uvRect, Material mat, int pass = 0)
{
if (mat == null)
mat = JInternalMaterials.UnlitTextureMaterial;
RenderTexture.active = rt;
GL.PushMatrix();
mat.SetTexture("_MainTex", texture);
mat.SetPass(pass);
GL.LoadOrtho();
GL.Begin(GL.QUADS);
GL.TexCoord(new Vector3(0, 0, 0));
GL.Vertex3(uvRect.min.x, uvRect.min.y, 0);
GL.TexCoord(new Vector3(0, 1, 0));
GL.Vertex3(uvRect.min.x, uvRect.max.y, 0);
GL.TexCoord(new Vector3(1, 1, 0));
GL.Vertex3(uvRect.max.x, uvRect.max.y, 0);
GL.TexCoord(new Vector3(1, 0, 0));
GL.Vertex3(uvRect.max.x, uvRect.min.y, 0);
GL.End();
GL.PopMatrix();
RenderTexture.active = null;
}
public static void DrawTriangle(RenderTexture rt, Vector2 v0, Vector2 v1, Vector2 v2, Color c)
{
Material mat = JInternalMaterials.SolidColorMaterial;
mat.SetColor("_Color", c);
RenderTexture.active = rt;
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.TRIANGLES);
GL.Vertex3(v0.x, v0.y, 0);
GL.Vertex3(v1.x, v1.y, 0);
GL.Vertex3(v2.x, v2.y, 0);
GL.End();
GL.PopMatrix();
RenderTexture.active = null;
}
public static void DrawQuad(RenderTexture rt, Vector2[] quadCorners, Material mat, int pass)
{
RenderTexture.active = rt;
GL.PushMatrix();
mat.SetPass(pass);
GL.LoadOrtho();
GL.Begin(GL.QUADS);
GL.TexCoord(new Vector3(0, 0, 0));
GL.Vertex3(quadCorners[0].x, quadCorners[0].y, 0);
GL.TexCoord(new Vector3(0, 1, 0));
GL.Vertex3(quadCorners[1].x, quadCorners[1].y, 0);
GL.TexCoord(new Vector3(1, 1, 0));
GL.Vertex3(quadCorners[2].x, quadCorners[2].y, 0);
GL.TexCoord(new Vector3(1, 0, 0));
GL.Vertex3(quadCorners[3].x, quadCorners[3].y, 0);
GL.End();
GL.PopMatrix();
RenderTexture.active = null;
}
public static List<System.Type> GetAllLoadedTypes()
{
List<System.Type> loadedTypes = new List<System.Type>();
List<string> typeName = new List<string>();
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var t in assembly.GetTypes())
{
if (t.IsVisible && !t.IsGenericType)
{
typeName.Add(t.Name);
loadedTypes.Add(t);
}
}
}
return loadedTypes;
}
public static IEnumerable<Rect> CompareHeightMap(int gridSize, Color[] oldValues, Color[] newValues)
{
if (oldValues.LongLength != newValues.LongLength)
{
return new Rect[1] { new Rect(0, 0, 1, 1) };
}
Rect[] rects = new Rect[gridSize * gridSize];
for (int x = 0; x < gridSize; ++x)
{
for (int z = 0; z < gridSize; ++z)
{
rects[JUtilities.To1DIndex(x, z, gridSize)] = GetUvRange(gridSize, x, z);
}
}
HashSet<Rect> dirtyRects = new HashSet<Rect>();
int index = 0;
int resolution = Mathf.RoundToInt(Mathf.Sqrt(newValues.LongLength));
for (int rectIndex = 0; rectIndex < rects.Length; ++rectIndex)
{
Rect r = rects[rectIndex];
int startX = (int)Mathf.Lerp(0, resolution - 1, r.min.x);
int startY = (int)Mathf.Lerp(0, resolution - 1, r.min.y);
int endX = (int)Mathf.Lerp(0, resolution - 1, r.max.x);
int endY = (int)Mathf.Lerp(0, resolution - 1, r.max.y);
for (int x = startX; x <= endX; ++x)
{
for (int y = startY; y <= endY; ++y)
{
index = JUtilities.To1DIndex(x, y, resolution);
if (oldValues[index].r == newValues[index].r &&
oldValues[index].g == newValues[index].g &&
oldValues[index].b == newValues[index].b &&
oldValues[index].a == newValues[index].a)
continue;
dirtyRects.Add(r);
Rect hRect = new Rect();
hRect.size = new Vector2(r.width * 1.2f, r.height);
hRect.center = r.center;
dirtyRects.Add(hRect);
Rect vRect = new Rect();
vRect.size = new Vector2(r.width, r.height * 1.2f);
vRect.center = r.center;
dirtyRects.Add(vRect);
break;
}
if (dirtyRects.Contains(r))
break;
}
}
return dirtyRects;
}
public static Rect GetUvRange(int gridSize, int x, int z)
{
Vector2 position = new Vector2(x * 1.0f / gridSize, z * 1.0f / gridSize);
Vector2 size = Vector2.one / gridSize;
return new Rect(position, size);
}
public static Texture2D CreateTextureFromCurve(AnimationCurve curve, int width, int height)
{
Texture2D t = new Texture2D(width, height, TextureFormat.ARGB32, false);
t.wrapMode = TextureWrapMode.Clamp;
Color[] colors = new Color[width * height];
for (int x = 0; x < width; ++x)
{
float f = Mathf.InverseLerp(0, width - 1, x);
float value = curve.Evaluate(f);
Color c = new Color(value, value, value, value);
for (int y = 0; y < height; ++y)
{
colors[JUtilities.To1DIndex(x, y, width)] = c;
}
}
t.filterMode = FilterMode.Bilinear;
t.SetPixels(colors);
t.Apply();
return t;
}
public static Vector3[] GetBrushQuadCorners(Vector3 center, float radius, float rotation)
{
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, rotation, 0));
Vector3[] corners = new Vector3[]
{
center + matrix.MultiplyPoint(new Vector3(-1,0,-1)*radius),
center + matrix.MultiplyPoint(new Vector3(-1,0,1)*radius),
center + matrix.MultiplyPoint(new Vector3(1,0,1)*radius),
center + matrix.MultiplyPoint(new Vector3(1,0,-1)*radius)
};
return corners;
}
//public static void RegisterBeginRender(Camera.CameraCallback callback)
//{
// Camera.onPreCull += callback;
//}
//public static void RegisterBeginRenderSRP(System.Action<Camera> callback)
//{
// RenderPipelineManager.beginCameraRendering += callback;
//}
//public static void UnregisterBeginRender(Camera.CameraCallback callback)
//{
// Camera.onPreCull -= callback;
//}
//public static void UnregisterBeginRenderSRP(System.Action<Camera> callback)
//{
// RenderPipeline.beginCameraRendering -= callback;
//}
//public static void RegisterEndRender(Camera.CameraCallback callback)
//{
// Camera.onPostRender += callback;
//}
public static void ClearRT(RenderTexture rt)
{
RenderTexture.active = rt;
GL.Clear(true, true, Color.clear);
RenderTexture.active = null;
}
public static void SetMaterialKeywordActive(Material mat, string keyword, bool active)
{
if (active)
{
mat.EnableKeyword(keyword);
}
else
{
mat.DisableKeyword(keyword);
}
}
public static void Editor_ProgressBar(string title, string detail, float percent)
{
#if UNITY_EDITOR
EditorUtility.DisplayProgressBar(title, detail, percent);
#endif
}
public static void Editor_CancelableProgressBar(string title, string detail, float percent)
{
#if UNITY_EDITOR
if (EditorUtility.DisplayCancelableProgressBar(title, detail, percent))
{
throw new JProgressCancelledException();
}
#endif
}
public static void Editor_ClearProgressBar()
{
#if UNITY_EDITOR
EditorUtility.ClearProgressBar();
#endif
}
public static Camera CreateCamera()
{
GameObject g = new GameObject();
Camera cam = g.AddComponent<Camera>();
return cam;
}
}
}

View File

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

View File

@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public enum JDetailOverlayLayer
{
AfterSky,
AfterStars,
AfterSun,
AfterMoon,
AfterHorizonCloud,
AfterOverheadCloud
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public enum JFogSyncOption
{
DontSync,
SkyColor,
HorizonColor,
GroundColor,
CustomColor
}
}

View File

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

View File

@@ -0,0 +1,125 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
//[CreateAssetMenu(menuName = "Jupiter/Settings")]
public class JJupiterSettings : ScriptableObject
{
private static JJupiterSettings instance;
public static JJupiterSettings Instance
{
get
{
if (instance == null)
{
instance = Resources.Load<JJupiterSettings>("JupiterSettings");
if (instance == null)
{
instance = ScriptableObject.CreateInstance<JJupiterSettings>() as JJupiterSettings;
}
}
return instance;
}
}
[SerializeField]
private Material defaultSkybox;
public Material DefaultSkybox
{
get
{
return defaultSkybox;
}
set
{
defaultSkybox = value;
}
}
[SerializeField]
private Texture2D noiseTexture;
public Texture2D NoiseTexture
{
get
{
return noiseTexture;
}
set
{
noiseTexture = value;
}
}
[SerializeField]
private Texture2D cloudTexture;
public Texture2D CloudTexture
{
get
{
return cloudTexture;
}
set
{
cloudTexture = value;
}
}
[SerializeField]
private JSkyProfile defaultProfileSunnyDay;
public JSkyProfile DefaultProfileSunnyDay
{
get
{
return defaultProfileSunnyDay;
}
set
{
defaultProfileSunnyDay = value;
}
}
[SerializeField]
private JSkyProfile defaultProfileStarryNight;
public JSkyProfile DefaultProfileStarryNight
{
get
{
return defaultProfileStarryNight;
}
set
{
defaultProfileStarryNight = value;
}
}
[SerializeField]
private JDayNightCycleProfile defaultDayNightCycleProfile;
public JDayNightCycleProfile DefaultDayNightCycleProfile
{
get
{
return defaultDayNightCycleProfile;
}
set
{
defaultDayNightCycleProfile = value;
}
}
[SerializeField]
private JInternalShaderSettings internalShaders;
public JInternalShaderSettings InternalShaders
{
get
{
return internalShaders;
}
set
{
internalShaders = value;
}
}
}
}

View File

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

View File

@@ -0,0 +1,334 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine.Rendering;
namespace Pinwheel.Jupiter
{
public static class JMat
{
public static readonly int NOISE_TEX = Shader.PropertyToID("_NoiseTex");
public static readonly int CLOUD_TEX = Shader.PropertyToID("_CloudTex");
public static readonly int SKY_COLOR = Shader.PropertyToID("_SkyColor");
public static readonly int HORIZON_COLOR = Shader.PropertyToID("_HorizonColor");
public static readonly int GROUND_COLOR = Shader.PropertyToID("_GroundColor");
public static readonly int HORIZON_THICKNESS = Shader.PropertyToID("_HorizonThickness");
public static readonly int HORIZON_EXPONENT = Shader.PropertyToID("_HorizonExponent");
public static readonly int HORIZON_STEP = Shader.PropertyToID("_HorizonStep");
public static readonly int FOG_COLOR = Shader.PropertyToID("_FogColor");
public static readonly string KW_STARS = "STARS";
public static readonly string KW_STARS_LAYER_0 = "STARS_LAYER_0";
public static readonly string KW_STARS_LAYER_1 = "STARS_LAYER_1";
public static readonly string KW_STARS_LAYER_2 = "STARS_LAYER_2";
public static readonly int STARS_START = Shader.PropertyToID("_StarsStartPosition");
public static readonly int STARS_END = Shader.PropertyToID("_StarsEndPosition");
public static readonly int STARS_OPACITY = Shader.PropertyToID("_StarsOpacity");
public static readonly int STARS_COLOR_0 = Shader.PropertyToID("_StarsColor0");
public static readonly int STARS_COLOR_1 = Shader.PropertyToID("_StarsColor1");
public static readonly int STARS_COLOR_2 = Shader.PropertyToID("_StarsColor2");
public static readonly int STARS_DENSITY_0 = Shader.PropertyToID("_StarsDensity0");
public static readonly int STARS_DENSITY_1 = Shader.PropertyToID("_StarsDensity1");
public static readonly int STARS_DENSITY_2 = Shader.PropertyToID("_StarsDensity2");
public static readonly int STARS_SIZE_0 = Shader.PropertyToID("_StarsSize0");
public static readonly int STARS_SIZE_1 = Shader.PropertyToID("_StarsSize1");
public static readonly int STARS_SIZE_2 = Shader.PropertyToID("_StarsSize2");
public static readonly int STARS_GLOW_0 = Shader.PropertyToID("_StarsGlow0");
public static readonly int STARS_GLOW_1 = Shader.PropertyToID("_StarsGlow1");
public static readonly int STARS_GLOW_2 = Shader.PropertyToID("_StarsGlow2");
public static readonly int STARS_TWINKLE_0 = Shader.PropertyToID("_StarsTwinkle0");
public static readonly int STARS_TWINKLE_1 = Shader.PropertyToID("_StarsTwinkle1");
public static readonly int STARS_TWINKLE_2 = Shader.PropertyToID("_StarsTwinkle2");
public static readonly string KW_STARS_BAKED = "STARS_BAKED";
public static readonly int STARS_CUBEMAP = Shader.PropertyToID("_StarsCubemap");
public static readonly int STARS_TWINKLE_MAP = Shader.PropertyToID("_StarsTwinkleMap");
public static readonly string KW_SUN = "SUN";
public static readonly string KW_SUN_USE_TEXTURE = "SUN_USE_TEXTURE";
public static readonly int SUN_TEX = Shader.PropertyToID("_SunTex");
public static readonly int SUN_COLOR = Shader.PropertyToID("_SunColor");
public static readonly int SUN_SIZE = Shader.PropertyToID("_SunSize");
public static readonly int SUN_SOFT_EDGE = Shader.PropertyToID("_SunSoftEdge");
public static readonly int SUN_GLOW = Shader.PropertyToID("_SunGlow");
public static readonly int SUN_DIRECTION = Shader.PropertyToID("_SunDirection");
public static readonly int SUN_TRANSFORM_MATRIX = Shader.PropertyToID("_PositionToSunUV");
public static readonly int SUN_LIGHT_COLOR = Shader.PropertyToID("_SunLightColor");
public static readonly int SUN_LIGHT_INTENSITY = Shader.PropertyToID("_SunLightIntensity");
public static readonly string KW_SUN_BAKED = "SUN_BAKED";
public static readonly int SUN_CUBEMAP = Shader.PropertyToID("_SunCubemap");
public static readonly int SUN_ROTATION_MATRIX = Shader.PropertyToID("_SunRotationMatrix");
public static readonly string KW_MOON = "MOON";
public static readonly string KW_MOON_USE_TEXTURE = "MOON_USE_TEXTURE";
public static readonly int MOON_TEX = Shader.PropertyToID("_MoonTex");
public static readonly int MOON_COLOR = Shader.PropertyToID("_MoonColor");
public static readonly int MOON_SIZE = Shader.PropertyToID("_MoonSize");
public static readonly int MOON_SOFT_EDGE = Shader.PropertyToID("_MoonSoftEdge");
public static readonly int MOON_GLOW = Shader.PropertyToID("_MoonGlow");
public static readonly int MOON_DIRECTION = Shader.PropertyToID("_MoonDirection");
public static readonly int MOON_TRANSFORM_MATRIX = Shader.PropertyToID("_PositionToMoonUV");
public static readonly int MOON_LIGHT_COLOR = Shader.PropertyToID("_MoonLightColor");
public static readonly int MOON_LIGHT_INTENSITY = Shader.PropertyToID("_MoonLightIntensity");
public static readonly string KW_MOON_BAKED = "MOON_BAKED";
public static readonly int MOON_CUBEMAP = Shader.PropertyToID("_MoonCubemap");
public static readonly int MOON_ROTATION_MATRIX = Shader.PropertyToID("_MoonRotationMatrix");
public static readonly string KW_HORIZON_CLOUD = "HORIZON_CLOUD";
public static readonly int HORIZON_CLOUD_COLOR = Shader.PropertyToID("_HorizonCloudColor");
public static readonly int HORIZON_CLOUD_START = Shader.PropertyToID("_HorizonCloudStartPosition");
public static readonly int HORIZON_CLOUD_END = Shader.PropertyToID("_HorizonCloudEndPosition");
public static readonly int HORIZON_CLOUD_SIZE = Shader.PropertyToID("_HorizonCloudSize");
public static readonly int HORIZON_CLOUD_STEP = Shader.PropertyToID("_HorizonCloudStep");
public static readonly int HORIZON_CLOUD_ANIMATION_SPEED = Shader.PropertyToID("_HorizonCloudAnimationSpeed");
public static readonly string KW_OVERHEAD_CLOUD = "OVERHEAD_CLOUD";
public static readonly int OVERHEAD_CLOUD_COLOR = Shader.PropertyToID("_OverheadCloudColor");
public static readonly int OVERHEAD_CLOUD_ALTITUDE = Shader.PropertyToID("_OverheadCloudAltitude");
public static readonly int OVERHEAD_CLOUD_SIZE = Shader.PropertyToID("_OverheadCloudSize");
public static readonly int OVERHEAD_CLOUD_STEP = Shader.PropertyToID("_OverheadCloudStep");
public static readonly int OVERHEAD_CLOUD_ANIMATION_SPEED = Shader.PropertyToID("_OverheadCloudAnimationSpeed");
public static readonly int OVERHEAD_CLOUD_FLOW_X = Shader.PropertyToID("_OverheadCloudFlowDirectionX");
public static readonly int OVERHEAD_CLOUD_FLOW_Z = Shader.PropertyToID("_OverheadCloudFlowDirectionZ");
public static readonly int OVERHEAD_CLOUD_REMAP_MIN = Shader.PropertyToID("_OverheadCloudRemapMin");
public static readonly int OVERHEAD_CLOUD_REMAP_MAX = Shader.PropertyToID("_OverheadCloudRemapMax");
public static readonly int OVERHEAD_CLOUD_SHADOW_CLIP_MASK = Shader.PropertyToID("_OverheadCloudShadowClipMask");
public static readonly string KW_DETAIL_OVERLAY = "DETAIL_OVERLAY";
public static readonly string KW_DETAIL_OVERLAY_ROTATION = "DETAIL_OVERLAY_ROTATION";
public static readonly int DETAIL_OVERLAY_COLOR = Shader.PropertyToID("_DetailOverlayTintColor");
public static readonly int DETAIL_OVERLAY_CUBEMAP = Shader.PropertyToID("_DetailOverlayCubemap");
public static readonly int DETAIL_OVERLAY_LAYER = Shader.PropertyToID("_DetailOverlayLayer");
public static readonly int DETAIL_OVERLAY_ROTATION_SPEED = Shader.PropertyToID("_DetailOverlayRotationSpeed");
public static readonly string KW_ALLOW_STEP_EFFECT = "ALLOW_STEP_EFFECT";
private static Material activeMaterial;
public static void SetActiveMaterial(Material mat)
{
activeMaterial = mat;
}
public static void GetColor(int prop, ref Color value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
value = activeMaterial.GetColor(prop);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void GetFloat(int prop, ref float value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
value = activeMaterial.GetFloat(prop);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void GetVector(int prop, ref Vector4 value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
value = activeMaterial.GetVector(prop);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void GetTexture(int prop, ref Texture value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
value = activeMaterial.GetTexture(prop);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void GetKeywordEnabled(string kw, ref bool value)
{
try
{
value = activeMaterial.IsKeywordEnabled(kw);
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetColor(int prop, Color value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
activeMaterial.SetColor(prop, value);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetFloat(int prop, float value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
activeMaterial.SetFloat(prop, value);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetVector(int prop, Vector4 value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
activeMaterial.SetVector(prop, value);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetTexture(int prop, Texture value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
activeMaterial.SetTexture(prop, value);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetMatrix(int prop, Matrix4x4 value)
{
try
{
if (activeMaterial.HasProperty(prop))
{
activeMaterial.SetMatrix(prop, value);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetKeywordEnable(string kw, bool enable)
{
try
{
if (enable)
{
activeMaterial.EnableKeyword(kw);
}
else
{
activeMaterial.DisableKeyword(kw);
}
}
catch (NullReferenceException nullEx)
{
Debug.LogError(nullEx.ToString());
}
catch { }
}
public static void SetOverrideTag(string tag, string value)
{
activeMaterial.SetOverrideTag(tag, value);
}
public static void SetRenderQueue(int queue)
{
activeMaterial.renderQueue = queue;
}
public static void SetRenderQueue(RenderQueue queue)
{
activeMaterial.renderQueue = (int)queue;
}
public static void SetSourceBlend(BlendMode mode)
{
activeMaterial.SetInt("_SrcBlend", (int)mode);
}
public static void SetDestBlend(BlendMode mode)
{
activeMaterial.SetInt("_DstBlend", (int)mode);
}
public static void SetZWrite(bool value)
{
activeMaterial.SetInt("_ZWrite", value ? 1 : 0);
}
public static void SetBlend(bool value)
{
activeMaterial.SetInt("_Blend", value ? 1 : 0);
}
public static void SetShader(Shader shader)
{
activeMaterial.shader = shader;
}
}
}

View File

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

View File

@@ -0,0 +1,261 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace Pinwheel.Jupiter
{
[ExecuteInEditMode]
public class JSky : MonoBehaviour
{
public static readonly Vector3 DefaultSunDirection = Vector3.forward;
public static readonly Vector3 DefaultMoonDirection = Vector3.forward;
[SerializeField]
private JSkyProfile profile;
public JSkyProfile Profile
{
get
{
return profile;
}
set
{
profile = value;
}
}
[SerializeField]
private Light sunLightSource;
public Light SunLightSource
{
get
{
return sunLightSource;
}
set
{
Light src = value;
if (src != null && src.type == LightType.Directional)
{
sunLightSource = src;
}
else
{
sunLightSource = null;
}
}
}
[SerializeField]
private Light moonLightSource;
public Light MoonLightSource
{
get
{
return moonLightSource;
}
set
{
Light src = value;
if (src != null && src.type == LightType.Directional)
{
moonLightSource = src;
}
else
{
moonLightSource = null;
}
}
}
public JDayNightCycle DNC { get; set; }
private static Mesh sphereMesh;
private static Mesh SphereMesh
{
get
{
if (sphereMesh == null)
{
sphereMesh = Resources.GetBuiltinResource<Mesh>("Sphere.fbx");
}
return sphereMesh;
}
}
private void OnEnable()
{
Camera.onPreCull += OnCameraPreCull;
RenderPipelineManager.beginCameraRendering += OnBeginCameraRenderingSRP;
}
private void OnDisable()
{
Camera.onPreCull -= OnCameraPreCull;
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRenderingSRP;
RenderSettings.skybox = JJupiterSettings.Instance.DefaultSkybox;
}
private void OnDestroy()
{
RenderSettings.skybox = JJupiterSettings.Instance.DefaultSkybox;
}
private void Reset()
{
Light[] lights = FindObjectsOfType<Light>();
for (int i = 0; i < lights.Length; ++i)
{
if (lights[i].type == LightType.Directional)
{
SunLightSource = lights[i];
break;
}
}
}
private void OnCameraPreCull(Camera cam)
{
SetupSkyMaterial();
SyncFog();
RenderShadow(cam);
}
private void OnBeginCameraRenderingSRP(ScriptableRenderContext context, Camera cam)
{
OnCameraPreCull(cam);
}
private void SetupSkyMaterial()
{
if (Profile == null)
{
RenderSettings.skybox = JJupiterSettings.Instance.DefaultSkybox;
return;
}
RenderSettings.skybox = Profile.Material;
Profile.Material.SetTexture(JMat.NOISE_TEX, JJupiterSettings.Instance.NoiseTexture);
Profile.Material.SetTexture(JMat.CLOUD_TEX, Profile.CustomCloudTexture ? Profile.CustomCloudTexture : JJupiterSettings.Instance.CloudTexture);
if (Profile.EnableSun)
{
if (SunLightSource != null)
{
JDayNightCycleProfile dncProfile = DNC ? DNC.Profile : null;
bool isSunLightColorOverridden = dncProfile != null && dncProfile.ContainProperty(nameof(Profile.SunLightColor));
if (!isSunLightColorOverridden)
{
SunLightSource.color = Profile.SunLightColor;
}
bool isSunLightIntensityOverridden = dncProfile != null && dncProfile.ContainProperty(nameof(Profile.SunLightIntensity));
if (!isSunLightIntensityOverridden)
{
SunLightSource.intensity = Profile.SunLightIntensity;
}
}
Vector3 sunDirection = SunLightSource ? SunLightSource.transform.forward : DefaultSunDirection;
if (Profile.UseBakedSun)
{
Matrix4x4 sunRotationMatrix = Matrix4x4.Rotate(
Quaternion.FromToRotation(sunDirection, DefaultSunDirection));
Profile.Material.SetMatrix(JMat.SUN_ROTATION_MATRIX, sunRotationMatrix);
}
else
{
Matrix4x4 positionToSunUV = Matrix4x4.TRS(
-sunDirection,
Quaternion.LookRotation(sunDirection),
Profile.SunSize * Vector3.one).inverse;
Profile.Material.SetVector(JMat.SUN_DIRECTION, sunDirection);
Profile.Material.SetMatrix(JMat.SUN_TRANSFORM_MATRIX, positionToSunUV);
}
}
if (Profile.EnableMoon)
{
if (MoonLightSource != null)
{
JDayNightCycleProfile dncProfile = DNC ? DNC.Profile : null;
bool isMoonLightColorOverridden = dncProfile != null && dncProfile.ContainProperty(nameof(Profile.MoonLightColor));
if (!isMoonLightColorOverridden)
{
MoonLightSource.color = Profile.MoonLightColor;
}
bool isMoonLightIntensityOverridden = dncProfile != null && dncProfile.ContainProperty(nameof(Profile.MoonLightIntensity));
if (!isMoonLightIntensityOverridden)
{
MoonLightSource.intensity = Profile.MoonLightIntensity;
}
}
Vector3 moonDirection = MoonLightSource ? MoonLightSource.transform.forward : DefaultMoonDirection;
if (Profile.UseBakedMoon)
{
Matrix4x4 moonRotationMatrix = Matrix4x4.Rotate(
Quaternion.FromToRotation(moonDirection, DefaultMoonDirection));
Profile.Material.SetMatrix(JMat.MOON_ROTATION_MATRIX, moonRotationMatrix);
}
else
{
Matrix4x4 positionToMoonUV = Matrix4x4.TRS(
-moonDirection,
Quaternion.LookRotation(moonDirection),
Profile.MoonSize * Vector3.one).inverse;
Profile.Material.SetVector(JMat.MOON_DIRECTION, moonDirection);
Profile.Material.SetMatrix(JMat.MOON_TRANSFORM_MATRIX, positionToMoonUV);
}
}
}
private void SyncFog()
{
if (Profile == null)
return;
if (Profile.FogSyncOption == JFogSyncOption.DontSync)
return;
if (Profile.FogSyncOption == JFogSyncOption.SkyColor)
{
RenderSettings.fogColor = Profile.Material.GetColor(JMat.SKY_COLOR);
}
else if (Profile.FogSyncOption == JFogSyncOption.HorizonColor)
{
RenderSettings.fogColor = Profile.Material.GetColor(JMat.HORIZON_COLOR);
}
else if (Profile.FogSyncOption == JFogSyncOption.GroundColor)
{
RenderSettings.fogColor = Profile.Material.GetColor(JMat.GROUND_COLOR);
}
else if (Profile.FogSyncOption == JFogSyncOption.CustomColor)
{
RenderSettings.fogColor = Profile.Material.GetColor(JMat.FOG_COLOR);
}
}
private void RenderShadow(Camera cam)
{
if (Profile == null)
return;
if (Profile.EnableOverheadCloud && Profile.OverheadCloudCastShadow)
{
Profile.ShadowMaterial.SetTexture(JMat.NOISE_TEX, JJupiterSettings.Instance.NoiseTexture);
Profile.ShadowMaterial.SetTexture(JMat.CLOUD_TEX, Profile.CustomCloudTexture ? Profile.CustomCloudTexture : JJupiterSettings.Instance.CloudTexture);
Graphics.DrawMesh(
SphereMesh,
Matrix4x4.TRS(Vector3.zero, Quaternion.identity, 2 * Vector3.one * Profile.OverheadCloudAltitude),
Profile.ShadowMaterial,
0,
cam,
0,
null,
ShadowCastingMode.ShadowsOnly,
false,
null,
LightProbeUsage.Off,
null);
}
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0a8cc88d832af6b428395b71519ae802
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
namespace Pinwheel.Jupiter
{
[AttributeUsage(AttributeTargets.Property)]
public class JAnimatableAttribute : Attribute
{
public string DisplayName { get; set; }
public JCurveOrGradient CurveOrGradient { get; set; }
public JAnimatableAttribute(string displayName, JCurveOrGradient curveOrGradient)
{
DisplayName = displayName;
CurveOrGradient = curveOrGradient;
}
}
}

View File

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

View File

@@ -0,0 +1,115 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
[System.Serializable]
public class JAnimatedProperty
{
[SerializeField]
private string name;
public string Name
{
get
{
if (name == null)
{
name = string.Empty;
}
return name;
}
set
{
name = value;
}
}
[SerializeField]
private string displayName;
public string DisplayName
{
get
{
if (displayName == null)
{
displayName = string.Empty;
}
return displayName;
}
set
{
displayName = value;
}
}
[SerializeField]
private JCurveOrGradient curveOrGradient;
public JCurveOrGradient CurveOrGradient
{
get
{
return curveOrGradient;
}
set
{
curveOrGradient = value;
}
}
[SerializeField]
private AnimationCurve curve;
public AnimationCurve Curve
{
get
{
if (curve == null)
{
curve = AnimationCurve.EaseInOut(0, 0, 1, 0);
}
return curve;
}
set
{
curve = value;
}
}
[SerializeField]
private Gradient gradient;
public Gradient Gradient
{
get
{
if (gradient == null)
{
gradient = JUtilities.CreateFullWhiteGradient();
}
return gradient;
}
set
{
gradient = value;
}
}
public float EvaluateFloat(float t)
{
return Curve.Evaluate(t);
}
public Color EvaluateColor(float t)
{
return Gradient.Evaluate(t);
}
public static JAnimatedProperty Create(string name, string displayName, JCurveOrGradient curveOrGradient)
{
JAnimatedProperty props = new JAnimatedProperty();
props.name = name;
props.displayName = displayName;
props.curveOrGradient = curveOrGradient;
return props;
}
}
}

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public enum JCurveOrGradient
{
Curve, Gradient
}
}

View File

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

View File

@@ -0,0 +1,386 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace Pinwheel.Jupiter
{
[ExecuteInEditMode]
public class JDayNightCycle : MonoBehaviour
{
[SerializeField]
private JDayNightCycleProfile profile;
public JDayNightCycleProfile Profile
{
get
{
return profile;
}
set
{
profile = value;
}
}
[SerializeField]
private JSky sky;
public JSky Sky
{
get
{
return sky;
}
set
{
sky = value;
}
}
[SerializeField]
private bool useSunPivot;
public bool UseSunPivot
{
get
{
return useSunPivot;
}
set
{
useSunPivot = value;
}
}
[SerializeField]
private Transform sunOrbitPivot;
public Transform SunOrbitPivot
{
get
{
return sunOrbitPivot;
}
set
{
sunOrbitPivot = value;
}
}
[SerializeField]
private bool useMoonPivot;
public bool UseMoonPivot
{
get
{
return useMoonPivot;
}
set
{
useMoonPivot = value;
}
}
[SerializeField]
private Transform moonOrbitPivot;
public Transform MoonOrbitPivot
{
get
{
return moonOrbitPivot;
}
set
{
moonOrbitPivot = value;
}
}
[SerializeField]
private float startTime;
public float StartTime
{
get
{
return startTime;
}
set
{
startTime = Mathf.Clamp(value, 0f, 24f);
}
}
[SerializeField]
private float timeIncrement;
public float TimeIncrement
{
get
{
return timeIncrement;
}
set
{
timeIncrement = Mathf.Max(0, value);
}
}
[SerializeField]
private bool autoTimeIncrement;
public bool AutoTimeIncrement
{
get
{
return autoTimeIncrement;
}
set
{
autoTimeIncrement = value;
}
}
private float time;
public float Time
{
get
{
return time % 24f;
}
set
{
time = value % 24f;
}
}
[SerializeField]
private bool shouldUpdateEnvironmentReflection;
public bool ShouldUpdateEnvironmentReflection
{
get
{
return shouldUpdateEnvironmentReflection;
}
set
{
shouldUpdateEnvironmentReflection = value;
}
}
[SerializeField]
private int environmentReflectionResolution;
public int EnvironmentReflectionResolution
{
get
{
return environmentReflectionResolution;
}
set
{
int oldValue = environmentReflectionResolution;
int newValue = Mathf.Clamp(value, 16, 2048);
environmentReflectionResolution = newValue;
if (oldValue != newValue)
{
if (environmentReflection != null)
{
JUtilities.DestroyObject(environmentReflection);
}
if (environmentProbe != null)
{
JUtilities.DestroyGameobject(environmentProbe.gameObject);
}
}
}
}
[SerializeField]
private ReflectionProbeTimeSlicingMode environmentReflectionTimeSlicingMode;
public ReflectionProbeTimeSlicingMode EnvironmentReflectionTimeSlicingMode
{
get
{
return environmentReflectionTimeSlicingMode;
}
set
{
environmentReflectionTimeSlicingMode = value;
}
}
[SerializeField]
private ReflectionProbe environmentProbe;
private ReflectionProbe EnvironmentProbe
{
get
{
if (environmentProbe == null)
{
GameObject probeGO = new GameObject("~EnvironmentReflectionRenderer");
probeGO.transform.parent = transform;
probeGO.transform.position = new Vector3(0, -1000, 0);
probeGO.transform.rotation = Quaternion.identity;
probeGO.transform.localScale = Vector3.one;
environmentProbe = probeGO.AddComponent<ReflectionProbe>();
environmentProbe.resolution = EnvironmentReflectionResolution;
environmentProbe.size = new Vector3(1, 1, 1);
environmentProbe.cullingMask = 0;
}
environmentProbe.clearFlags = ReflectionProbeClearFlags.Skybox;
environmentProbe.mode = ReflectionProbeMode.Realtime;
environmentProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
environmentProbe.timeSlicingMode = EnvironmentReflectionTimeSlicingMode;
environmentProbe.hdr = false;
return environmentProbe;
}
}
private Cubemap environmentReflection;
private Cubemap EnvironmentReflection
{
get
{
if (environmentReflection == null)
{
environmentReflection = new Cubemap(EnvironmentProbe.resolution, TextureFormat.RGBA32, true);
}
return environmentReflection;
}
}
private int probeRenderId = -1;
private float DeltaTime
{
get
{
if (Application.isPlaying)
return UnityEngine.Time.deltaTime;
else
return 1.0f / 60f;
}
}
private void Reset()
{
Sky = GetComponent<JSky>();
StartTime = 0;
TimeIncrement = 1;
AutoTimeIncrement = true;
Time = 0;
}
private void OnEnable()
{
time = StartTime;
Camera.onPreCull += OnCameraPreCull;
RenderPipelineManager.beginFrameRendering += OnBeginFrameRenderingSRP;
}
private void OnDisable()
{
Camera.onPreCull -= OnCameraPreCull;
RenderPipelineManager.beginFrameRendering -= OnBeginFrameRenderingSRP;
CleanUp();
}
private void OnCameraPreCull(Camera cam)
{
if (!Application.isPlaying)
Update();
}
private void OnBeginFrameRenderingSRP(ScriptableRenderContext context, Camera[] cameras)
{
if (!Application.isPlaying)
Update();
}
private void CleanUp()
{
if (environmentProbe != null)
{
JUtilities.DestroyGameobject(environmentProbe.gameObject);
}
if (environmentReflection != null)
{
JUtilities.DestroyObject(environmentReflection);
}
if (Sky != null)
{
Sky.DNC = null;
}
}
private void Update()
{
AnimateSky();
if (ShouldUpdateEnvironmentReflection)
{
UpdateEnvironmentReflection();
}
else
{
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Skybox;
}
}
private void AnimateSky()
{
if (Profile == null)
return;
if (Sky == null)
return;
if (Sky.Profile == null)
return;
Sky.DNC = this;
if (AutoTimeIncrement)
{
Time += TimeIncrement * DeltaTime;
}
float evalTime = Mathf.InverseLerp(0f, 24f, Time);
Profile.Animate(Sky, evalTime);
if (Sky.Profile.EnableSun && Sky.SunLightSource != null)
{
float angle = evalTime * 360f;
Matrix4x4 localRotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0));
Vector3 localDirection = localRotationMatrix.MultiplyVector(Vector3.up);
Transform pivot = (UseSunPivot && SunOrbitPivot != null) ? SunOrbitPivot : transform;
Matrix4x4 localToWorld = pivot.localToWorldMatrix;
Vector3 worldDirection = localToWorld.MultiplyVector(localDirection);
Sky.SunLightSource.transform.forward = worldDirection;
Sky.SunLightSource.color = Sky.Profile.Material.GetColor(JMat.SUN_LIGHT_COLOR);
Sky.SunLightSource.intensity = Sky.Profile.Material.GetFloat(JMat.SUN_LIGHT_INTENSITY);
}
if (Sky.Profile.EnableMoon && Sky.MoonLightSource != null)
{
float angle = evalTime * 360f;
Matrix4x4 localRotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0));
Vector3 localDirection = localRotationMatrix.MultiplyVector(Vector3.down);
Transform pivot = (UseMoonPivot && MoonOrbitPivot != null) ? MoonOrbitPivot : transform;
Matrix4x4 localToWorld = pivot.localToWorldMatrix;
Vector3 worldDirection = localToWorld.MultiplyVector(localDirection);
Sky.MoonLightSource.transform.forward = worldDirection;
Sky.MoonLightSource.color = Sky.Profile.Material.GetColor(JMat.MOON_LIGHT_COLOR);
Sky.MoonLightSource.intensity = Sky.Profile.Material.GetFloat(JMat.MOON_LIGHT_INTENSITY);
}
}
private void UpdateEnvironmentReflection()
{
if ((SystemInfo.copyTextureSupport & CopyTextureSupport.RTToTexture) != 0)
{
if (EnvironmentProbe.texture == null)
{
probeRenderId = EnvironmentProbe.RenderProbe();
}
else if (EnvironmentProbe.texture != null || EnvironmentProbe.IsFinishedRendering(probeRenderId))
{
Graphics.CopyTexture(EnvironmentProbe.texture, EnvironmentReflection as Texture);
RenderSettings.customReflection = EnvironmentReflection;
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
probeRenderId = EnvironmentProbe.RenderProbe();
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,130 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System;
namespace Pinwheel.Jupiter
{
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
[CreateAssetMenu(menuName = "Jupiter/Day Night Cycle Profile")]
public class JDayNightCycleProfile : ScriptableObject
{
private static Dictionary<string, int> propertyRemap;
private static Dictionary<string, int> PropertyRemap
{
get
{
if (propertyRemap == null)
{
propertyRemap = new Dictionary<string, int>();
}
return propertyRemap;
}
set
{
propertyRemap = value;
}
}
static JDayNightCycleProfile()
{
InitPropertyRemap();
}
private static void InitPropertyRemap()
{
PropertyRemap.Clear();
Type type = typeof(JSkyProfile);
PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo p in props)
{
JAnimatableAttribute animatable = p.GetCustomAttribute(typeof(JAnimatableAttribute), false) as JAnimatableAttribute;
if (animatable == null)
continue;
string name = p.Name;
int id = Shader.PropertyToID("_" + name);
PropertyRemap.Add(name, id);
}
}
[SerializeField]
private List<JAnimatedProperty> animatedProperties;
public List<JAnimatedProperty> AnimatedProperties
{
get
{
if (animatedProperties == null)
{
animatedProperties = new List<JAnimatedProperty>();
}
return animatedProperties;
}
set
{
animatedProperties = value;
}
}
public void AddProperty(JAnimatedProperty p, bool setDefaultValue = true)
{
if (setDefaultValue)
{
JDayNightCycleProfile defaultProfile = JJupiterSettings.Instance.DefaultDayNightCycleProfile;
if (defaultProfile != null)
{
JAnimatedProperty defaultProp = defaultProfile.AnimatedProperties.Find(p0 => p0.Name != null && p0.Name.Equals(p.Name));
if (defaultProp != null)
{
p.Curve = defaultProp.Curve;
p.Gradient = defaultProp.Gradient;
}
}
}
AnimatedProperties.Add(p);
}
public void Animate(JSky sky, float t)
{
CheckDefaultProfileAndThrow(sky.Profile);
for (int i = 0; i < AnimatedProperties.Count; ++i)
{
JAnimatedProperty aProp = AnimatedProperties[i];
int id = 0;
if (!PropertyRemap.TryGetValue(aProp.Name, out id))
{
continue;
}
if (aProp.CurveOrGradient == JCurveOrGradient.Curve)
{
sky.Profile.Material.SetFloat(id, aProp.EvaluateFloat(t));
}
else
{
sky.Profile.Material.SetColor(id, aProp.EvaluateColor(t));
}
}
}
private void CheckDefaultProfileAndThrow(JSkyProfile p)
{
if (p == null)
return;
if (p == JJupiterSettings.Instance.DefaultProfileSunnyDay ||
p == JJupiterSettings.Instance.DefaultProfileStarryNight)
{
throw new ArgumentException("Animating default sky profile is prohibited. You must create a new profile for your sky to animate it.");
}
}
public bool ContainProperty(string propertyName)
{
return AnimatedProperties.Exists((p) => p.Name.Equals(propertyName));
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 401fa1ab5d5cfd347912eece9fa7aee9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public static class JCubemapRenderer
{
public static bool Render(JCubemapRendererArgs args)
{
GameObject go = new GameObject("~CubemapRendererCamera");
go.transform.position = args.CameraPosition;
Camera cam = go.AddComponent<Camera>();
cam.clearFlags = args.CameraClearFlag;
cam.nearClipPlane = args.CameraNearPlane;
cam.farClipPlane = args.CameraFarPlane;
cam.backgroundColor = args.CameraBackgroundColor;
bool result = cam.RenderToCubemap(args.Cubemap, (int)args.Face);
JUtilities.DestroyGameobject(go);
return result;
}
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public struct JCubemapRendererArgs
{
public Cubemap Cubemap { get; set; }
public Vector3 CameraPosition { get; set; }
public float CameraNearPlane { get; set; }
public float CameraFarPlane { get; set; }
public CameraClearFlags CameraClearFlag { get; set; }
public Color CameraBackgroundColor { get; set; }
public int Resolution { get; set; }
public CubemapFace Face { get; set; }
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
namespace Pinwheel.Jupiter
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
public class JDisplayName : Attribute
{
public string DisplayName { get; set; }
public JDisplayName(string name)
{
DisplayName = name;
}
}
}

View File

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

View File

@@ -0,0 +1,48 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public static class JInternalMaterials
{
private static Material copyTextureMaterial;
public static Material CopyTextureMaterial
{
get
{
if (copyTextureMaterial == null)
{
copyTextureMaterial = new Material(JJupiterSettings.Instance.InternalShaders.CopyTextureShader);
}
return copyTextureMaterial;
}
}
private static Material solidColorMaterial;
public static Material SolidColorMaterial
{
get
{
if (solidColorMaterial == null)
{
solidColorMaterial = new Material(JJupiterSettings.Instance.InternalShaders.SolidColorShader);
}
return solidColorMaterial;
}
}
private static Material unlitTextureMaterial;
public static Material UnlitTextureMaterial
{
get
{
if (unlitTextureMaterial == null)
{
unlitTextureMaterial = new Material(Shader.Find("Unlit/Texture"));
}
return unlitTextureMaterial;
}
}
}
}

View File

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

View File

@@ -0,0 +1,66 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
[System.Serializable]
public struct JInternalShaderSettings
{
[SerializeField]
private Shader skyShader;
public Shader SkyShader
{
get
{
return skyShader;
}
set
{
skyShader = value;
}
}
[SerializeField]
private Shader skyShadowShader;
public Shader SkyShadowShader
{
get
{
return skyShadowShader;
}
set
{
skyShadowShader = value;
}
}
[SerializeField]
private Shader copyTextureShader;
public Shader CopyTextureShader
{
get
{
return copyTextureShader;
}
set
{
copyTextureShader = value;
}
}
[SerializeField]
private Shader solidColorShader;
public Shader SolidColorShader
{
get
{
return solidColorShader;
}
set
{
solidColorShader = value;
}
}
}
}

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
namespace Pinwheel.Jupiter
{
public class JProgressCancelledException : Exception
{
}
}

View File

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

View File

@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
public enum JRenderPipelineType
{
Builtin, Lightweight, Universal
}
}

View File

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

View File

@@ -0,0 +1,757 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Pinwheel.Jupiter
{
/// <summary>
/// Utility class for helper function
/// </summary>
public static class JUtilities
{
public static float DELTA_TIME = 0.0167f;
private static Mesh quadMesh;
public static Mesh QuadMesh
{
get
{
if (quadMesh == null)
{
quadMesh = JUtilities.GetPrimitiveMesh(PrimitiveType.Quad);
}
return quadMesh;
}
}
public static string ListElementsToString<T>(this IEnumerable<T> list, string separator)
{
IEnumerator<T> i = list.GetEnumerator();
System.Text.StringBuilder s = new System.Text.StringBuilder();
if (i.MoveNext())
s.Append(i.Current.ToString());
while (i.MoveNext())
s.Append(separator).Append(i.Current.ToString());
return s.ToString();
}
public static T[][] CreateJaggedArray<T>(int dimension1, int dimension2)
{
T[][] jaggedArray = new T[dimension1][];
for (int i = 0; i < dimension1; ++i)
{
jaggedArray[i] = new T[dimension2];
}
return jaggedArray;
}
public static T[] To1dArray<T>(T[][] jaggedArray)
{
List<T> result = new List<T>();
for (int z = 0; z < jaggedArray.Length; ++z)
{
for (int x = 0; x < jaggedArray[z].Length; ++x)
{
result.Add(jaggedArray[z][x]);
}
}
return result.ToArray();
}
public static T[] To1dArray<T>(T[,] grid)
{
int height = grid.GetLength(0);
int width = grid.GetLength(1);
T[] result = new T[height * width];
for (int z = 0; z < height; ++z)
{
for (int x = 0; x < width; ++x)
{
result[To1DIndex(x, z, width)] = grid[z, x];
}
}
return result;
}
public static void Fill<T>(T[] array, T value)
{
for (int i = 0; i < array.Length; ++i)
{
array[i] = value;
}
}
public static void CopyTo<T>(T[] src, T[] des)
{
int limit = Mathf.Min(src.Length, des.Length);
for (int i = 0; i < limit; ++i)
{
des[i] = src[i];
}
}
public static int Sum(int[,] array)
{
int sum = 0;
int length = array.GetLength(0);
int width = array.GetLength(1);
for (int z = 0; z < length; ++z)
{
for (int x = 0; x < width; ++x)
{
sum += array[z, x];
}
}
return sum;
}
public static int To1DIndex(int x, int z, int width)
{
return z * width + x;
}
public static bool IsInRange(float number, float minValue, float maxValue)
{
return number >= minValue && number <= maxValue;
}
public static bool IsInRangeExclusive(float number, float minValue, float maxValue)
{
return number > minValue && number < maxValue;
}
public static float GetFraction(float value, float floor, float ceil)
{
return (value - floor) / (ceil - floor);
}
public static void ClearChildren(Transform t)
{
int childCount = t.childCount;
for (int i = childCount - 1; i >= 0; --i)
{
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
{
GameObject.DestroyImmediate(t.GetChild(i).gameObject);
}
else
{
GameObject.Destroy(t.GetChild(i).gameObject);
}
#else
GameObject.Destroy(t.GetChild(i).gameObject);
#endif
}
}
public static Gradient CreateFullWhiteGradient()
{
Gradient g = new Gradient();
GradientColorKey color = new GradientColorKey(Color.white, 1);
GradientAlphaKey alpha = new GradientAlphaKey(1, 1);
g.SetKeys(new GradientColorKey[] { color }, new GradientAlphaKey[] { alpha });
return g;
}
public static Gradient CreateFullTransparentGradient()
{
Gradient g = new Gradient();
GradientColorKey color = new GradientColorKey(Color.white, 1);
GradientAlphaKey alpha = new GradientAlphaKey(0, 1);
g.SetKeys(new GradientColorKey[] { color }, new GradientAlphaKey[] { alpha });
return g;
}
public static void CalculateBarycentricCoord(Vector2 p, Vector2 p1, Vector2 p2, Vector2 p3, ref Vector3 bary)
{
Vector2 v0 = p2 - p1;
Vector2 v1 = p3 - p1;
Vector2 v2 = p - p1;
float d00 = Vector2.Dot(v0, v0);
float d01 = Vector2.Dot(v0, v1);
float d11 = Vector2.Dot(v1, v1);
float d20 = Vector2.Dot(v2, v0);
float d21 = Vector2.Dot(v2, v1);
float inverseDenom = 1 / (d00 * d11 - d01 * d01);
bary.y = (d11 * d20 - d01 * d21) * inverseDenom;
bary.z = (d00 * d21 - d01 * d20) * inverseDenom;
bary.x = 1.0f - bary.y - bary.z;
}
public static void ExpandTrisUvCoord(Texture2D tex, Vector2[] trisUv)
{
Vector2 texelSize = tex.texelSize;
Vector2 center = (trisUv[0] + trisUv[1] + trisUv[2]) / 3;
trisUv[0] += (trisUv[0] - center).normalized * texelSize.magnitude;
trisUv[0].x = Mathf.Clamp01(trisUv[0].x);
trisUv[0].y = Mathf.Clamp01(trisUv[0].y);
trisUv[1] += (trisUv[1] - center).normalized * texelSize.magnitude;
trisUv[1].x = Mathf.Clamp01(trisUv[1].x);
trisUv[1].y = Mathf.Clamp01(trisUv[1].y);
trisUv[2] += (trisUv[2] - center).normalized * texelSize.magnitude;
trisUv[2].x = Mathf.Clamp01(trisUv[2].x);
trisUv[2].y = Mathf.Clamp01(trisUv[2].y);
}
public static bool ContainIdenticalElements<T>(T[] arr1, T[] arr2)
{
if (arr1 == null && arr2 == null)
return true;
if (arr1 == null && arr2 != null)
return false;
if (arr1 != null && arr2 == null)
return false;
if (arr1.Length != arr2.Length)
return false;
for (int i = 0; i < arr1.Length; ++i)
{
if (!arr1[i].Equals(arr2[i]))
return false;
}
return true;
}
public static float GetNearestMultiple(float number, float multipleOf)
{
int multiplier = 0;
while (multipleOf * multiplier < number)
{
multiplier += 1;
}
float floor = multipleOf * (multiplier - 1);
float ceil = multipleOf * multiplier;
float f0 = number - floor;
float f1 = ceil - number;
if (f0 < f1)
return floor;
else
return ceil;
}
public static Transform GetChildrenWithName(Transform parent, string name)
{
Transform t = parent.Find(name);
if (t == null)
{
GameObject g = new GameObject(name);
g.transform.parent = parent;
ResetTransform(g.transform, parent);
t = g.transform;
}
return t;
}
public static void ResetTransform(Transform t, Transform parent)
{
t.parent = parent;
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
}
public static void DestroyGameobject(GameObject g)
{
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying)
GameObject.Destroy(g);
else
GameObject.DestroyImmediate(g);
#else
GameObject.Destroy(g);
#endif
}
public static void DestroyGameObjectWithUndo(GameObject g)
{
#if UNITY_EDITOR
Undo.DestroyObjectImmediate(g);
#else
DestroyGameobject(g);
#endif
}
public static void DestroyObject(Object o)
{
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying)
Object.Destroy(o);
else
Object.DestroyImmediate(o, true);
#else
GameObject.Destroy(o);
#endif
}
public static string Repeat(char src, int count)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(src, count);
return sb.ToString();
}
public static void MarkCurrentSceneDirty()
{
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
#endif
}
public static GameObject[] GetChildrenGameObjects(Transform parent)
{
GameObject[] children = new GameObject[parent.childCount];
for (int i = 0; i < parent.childCount; ++i)
{
children[i] = parent.GetChild(i).gameObject;
}
return children;
}
public static Transform[] GetChildrenTransforms(Transform parent)
{
Transform[] children = new Transform[parent.childCount];
for (int i = 0; i < parent.childCount; ++i)
{
children[i] = parent.GetChild(i);
}
return children;
}
/// <summary>
/// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
/// </summary>
/// <param name="vector"></param>
/// <param name="normal"></param>
/// <param name="angleDegree"></param>
/// <returns></returns>
public static Vector3 RotateVectorAroundNormal(Vector3 vector, Vector3 normal, float angleDegree)
{
float sin = Mathf.Sin(angleDegree * Mathf.Deg2Rad);
float cos = Mathf.Cos(angleDegree * Mathf.Deg2Rad);
Vector3 rotatedVector =
vector * cos +
Vector3.Cross(normal, vector) * sin +
normal * Vector3.Dot(normal, vector) * (1 - cos);
return rotatedVector;
}
public static Mesh GetPrimitiveMesh(PrimitiveType type)
{
GameObject g = GameObject.CreatePrimitive(type);
Mesh m = g.GetComponent<MeshFilter>().sharedMesh;
DestroyGameobject(g);
return m;
}
public static void ShuffleList<T>(List<T> list)
{
int length = list.Count;
for (int i = 0; i < length - 1; ++i)
{
int j = UnityEngine.Random.Range(0, length);
T tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
public static int[] GetShuffleIndicesArray(int length)
{
int[] indices = GetIndicesArray(length);
for (int i = 0; i < length - 1; ++i)
{
int j = UnityEngine.Random.Range(0, length);
int tmp = indices[i];
indices[i] = indices[j];
indices[j] = tmp;
}
return indices;
}
public static int[] GetIndicesArray(int length)
{
int[] indices = new int[length];
for (int i = 0; i < length; ++i)
{
indices[i] = i;
}
return indices;
}
public static void ResetArray<T>(ref T[] array, int count, T defaultValue)
{
if (array != null && array.Length == count)
{
JUtilities.Fill(array, defaultValue);
}
else
{
array = new T[count];
}
}
public static bool EnsureArrayLength<T>(ref T[] array, int count)
{
if (array == null || array.Length != count)
{
array = new T[count];
return false;
}
return true;
}
public static float GetValueBilinear(float[] data, int width, int height, Vector2 uv)
{
float value = 0;
Vector2 pixelCoord = new Vector2(
Mathf.Lerp(0, width - 1, uv.x),
Mathf.Lerp(0, height - 1, uv.y));
//apply a bilinear filter
int xFloor = Mathf.FloorToInt(pixelCoord.x);
int xCeil = Mathf.CeilToInt(pixelCoord.x);
int yFloor = Mathf.FloorToInt(pixelCoord.y);
int yCeil = Mathf.CeilToInt(pixelCoord.y);
float f00 = data[JUtilities.To1DIndex(xFloor, yFloor, width)];
float f01 = data[JUtilities.To1DIndex(xFloor, yCeil, width)];
float f10 = data[JUtilities.To1DIndex(xCeil, yFloor, width)];
float f11 = data[JUtilities.To1DIndex(xCeil, yCeil, width)];
Vector2 unitCoord = new Vector2(
pixelCoord.x - xFloor,
pixelCoord.y - yFloor);
value =
f00 * (1 - unitCoord.x) * (1 - unitCoord.y) +
f01 * (1 - unitCoord.x) * unitCoord.y +
f10 * unitCoord.x * (1 - unitCoord.y) +
f11 * unitCoord.x * unitCoord.y;
return value;
}
public static Color GetColorBilinear(Color[] textureData, int width, int height, Vector2 uv)
{
Color color = Color.clear;
Vector2 pixelCoord = new Vector2(
Mathf.Lerp(0, width - 1, uv.x),
Mathf.Lerp(0, height - 1, uv.y));
//apply a bilinear filter
int xFloor = Mathf.FloorToInt(pixelCoord.x);
int xCeil = Mathf.CeilToInt(pixelCoord.x);
int yFloor = Mathf.FloorToInt(pixelCoord.y);
int yCeil = Mathf.CeilToInt(pixelCoord.y);
Color f00 = textureData[JUtilities.To1DIndex(xFloor, yFloor, width)];
Color f01 = textureData[JUtilities.To1DIndex(xFloor, yCeil, width)];
Color f10 = textureData[JUtilities.To1DIndex(xCeil, yFloor, width)];
Color f11 = textureData[JUtilities.To1DIndex(xCeil, yCeil, width)];
Vector2 unitCoord = new Vector2(
pixelCoord.x - xFloor,
pixelCoord.y - yFloor);
color =
f00 * (1 - unitCoord.x) * (1 - unitCoord.y) +
f01 * (1 - unitCoord.x) * unitCoord.y +
f10 * unitCoord.x * (1 - unitCoord.y) +
f11 * unitCoord.x * unitCoord.y;
return color;
}
public static GameObject CreatePreviewGameObject(Mesh m, Material mat, Vector3 position)
{
GameObject g = new GameObject("GO");
g.transform.position = position;
g.transform.rotation = Quaternion.identity;
g.transform.localScale = Vector3.one;
MeshFilter mf = g.AddComponent<MeshFilter>();
mf.sharedMesh = m;
MeshRenderer mr = g.AddComponent<MeshRenderer>();
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
mr.receiveShadows = false;
mr.sharedMaterial = mat;
return g;
}
public static Camera CreatePreviewCamera(GameObject target, float distance, float padding)
{
GameObject g = new GameObject("CAM");
g.transform.rotation = Quaternion.identity;
g.transform.localScale = Vector3.one;
Camera cam = g.AddComponent<Camera>();
cam.orthographic = true;
cam.clearFlags = CameraClearFlags.Nothing;
cam.aspect = 1;
MeshRenderer mr = target.GetComponent<MeshRenderer>();
Bounds bounds = mr.bounds;
cam.transform.position = bounds.center + new Vector3(-1, 0.5f, -1) * distance;
cam.transform.LookAt(bounds.center);
cam.orthographicSize = Mathf.Max(bounds.size.x, bounds.size.y, bounds.size.z) / 2 + padding;
return cam;
}
public static void EnsureDirectoryExists(string dir)
{
if (!System.IO.Directory.Exists(dir))
{
System.IO.Directory.CreateDirectory(dir);
}
}
public static void SetStaticRecursively(GameObject g, bool isStatic)
{
#if UNITY_EDITOR
g.isStatic = isStatic;
GameObject[] children = GetChildrenGameObjects(g.transform);
for (int i = 0; i < children.Length; ++i)
{
SetStaticRecursively(children[i], isStatic);
}
#endif
}
public static void EnsureLengthSufficient<T>(List<T> list, int preferredLength) where T : Object
{
if (list == null)
list = new List<T>();
while (list.Count < preferredLength)
{
list.Add(null);
}
}
public static void EnsureLengthSufficient(List<string> list, int preferredLength)
{
if (list == null)
list = new List<string>();
while (list.Count < preferredLength)
{
list.Add(string.Empty);
}
}
public static void EnsureLengthSufficient(List<bool> list, int preferredLength)
{
if (list == null)
list = new List<bool>();
while (list.Count < preferredLength)
{
list.Add(false);
}
}
public static string Ellipsis(string s, int length)
{
if (s.Length < length)
return s;
string s0 = s.Substring(0, length);
return s0 + "...";
}
public static bool IsRectContainPointExclusive(Rect r, Vector2 p)
{
return
p.x > r.min.x &&
p.x < r.max.x &&
p.y > r.min.y &&
p.y < r.max.y;
}
public static Color GetColor(Color baseColor, float alpha)
{
return new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
}
public static Rect GetRectContainsPoints(params Vector2[] points)
{
float xMin = float.MaxValue;
float xMax = float.MinValue;
float yMin = float.MaxValue;
float yMax = float.MinValue;
for (int i = 0; i < points.Length; ++i)
{
xMin = points[i].x < xMin ? points[i].x : xMin;
xMax = points[i].x > xMax ? points[i].x : xMax;
yMin = points[i].y < yMin ? points[i].y : yMin;
yMax = points[i].y > yMax ? points[i].y : yMax;
}
return Rect.MinMaxRect(xMin, yMin, xMax, yMax);
}
public static float InverseLerpUnclamped(float a, float b, float value)
{
if (a != b)
{
return (value - a) / (b - a);
}
return 0f;
}
public static Vector2 PointToNormalizedUnclampled(Rect r, Vector2 point)
{
return new Vector2(InverseLerpUnclamped(r.x, r.xMax, point.x), InverseLerpUnclamped(r.y, r.yMax, point.y));
}
public static Rect GetUvRect(Vector2 v0, Vector2 v1, Vector2 v2)
{
return Rect.MinMaxRect(
Mathf.Min(v0.x, v1.x, v2.x),
Mathf.Min(v0.y, v1.y, v2.y),
Mathf.Max(v0.x, v1.x, v2.x),
Mathf.Max(v0.y, v1.y, v2.y));
}
public static Gradient Clone(Gradient src)
{
if (src == null)
return null;
Gradient des = new Gradient();
des.SetKeys(src.colorKeys, src.alphaKeys);
return des;
}
public static AnimationCurve Clone(AnimationCurve src)
{
if (src == null)
return null;
AnimationCurve des = new AnimationCurve();
Keyframe[] keys = src.keys;
for (int i = 0; i < keys.Length; ++i)
{
des.AddKey(keys[i]);
}
des.preWrapMode = src.preWrapMode;
des.postWrapMode = src.postWrapMode;
return des;
}
public static bool IsPointInsideQuadXZ(Vector3 point, Vector3[] quad)
{
Vector3 bary = Vector3.zero;
CalculateBarycentricCoord(
new Vector2(point.x, point.z),
new Vector2(quad[0].x, quad[0].z),
new Vector2(quad[1].x, quad[1].z),
new Vector2(quad[2].x, quad[2].z),
ref bary);
if (bary.x >= 0 && bary.y >= 0 && bary.z >= 0)
return true;
CalculateBarycentricCoord(
new Vector2(point.x, point.z),
new Vector2(quad[0].x, quad[0].z),
new Vector2(quad[2].x, quad[2].z),
new Vector2(quad[3].x, quad[3].z),
ref bary);
if (bary.x >= 0 && bary.y >= 0 && bary.z >= 0)
return true;
return false;
}
public static void DestroyMeshArray(Mesh[] meshes)
{
for (int i = 0; i < meshes.Length; ++i)
{
if (meshes[i] != null)
{
Object.DestroyImmediate(meshes[i], true);
}
}
}
public static Vector2 FlipY(Vector2 v)
{
return new Vector2(v.x, 1 - v.y);
}
/// <summary>
/// https://en.wikipedia.org/wiki/Delaunay_triangulation#Algorithms
/// </summary>
/// <param name="v0"></param>
/// <param name="v1"></param>
/// <param name="v2"></param>
/// <param name="p"></param>
/// <returns></returns>
public static bool IsPointInCircumcircle(Vector2 v0, Vector2 v1, Vector2 v2, Vector2 p)
{
Matrix4x4 mat = new Matrix4x4();
mat.SetRow(0, new Vector4(v0.x, v0.y, v0.x * v0.x + v0.y * v0.y, 1));
mat.SetRow(1, new Vector4(v2.x, v2.y, v2.x * v2.x + v2.y * v2.y, 1)); //a,b,c counterclockwise
mat.SetRow(2, new Vector4(v1.x, v1.y, v1.x * v1.x + v1.y * v1.y, 1));
mat.SetRow(3, new Vector4(p.x, p.y, p.x * p.x + p.y * p.y, 1));
return mat.determinant > 0;
}
public static bool IsPointInCircumcircleXZ(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 p)
{
Matrix4x4 mat = new Matrix4x4();
mat.SetRow(0, new Vector4(v0.x, v0.z, v0.x * v0.x + v0.z * v0.z, 1));
mat.SetRow(1, new Vector4(v2.x, v2.z, v2.x * v2.x + v2.z * v2.z, 1)); //a,b,c counterclockwise
mat.SetRow(2, new Vector4(v1.x, v1.z, v1.x * v1.x + v1.z * v1.z, 1));
mat.SetRow(3, new Vector4(p.x, p.z, p.x * p.x + p.z * p.z, 1));
return mat.determinant > 0;
}
public static bool AreSetEqual(ushort[] setA, ushort[] setB)
{
HashSet<ushort> a = new HashSet<ushort>(setA);
HashSet<ushort> b = new HashSet<ushort>(setB);
return a.SetEquals(b);
}
public static void Distinct<T>(this List<T> list)
{
list.Distinct();
}
public static void AddIfNotContains<T>(this IList<T> list, IEnumerable<T> items)
{
IEnumerator<T> iter = items.GetEnumerator();
while (iter.MoveNext())
{
T current = iter.Current;
if (!list.Contains(current))
{
list.Add(current);
}
}
}
public static void AddIfNotContains<T>(this IList<T> list, T item)
{
if (!list.Contains(item))
{
list.Add(item);
}
}
public static Vector3 ToX0Y(this Vector2 v)
{
return new Vector3(v.x, 0, v.y);
}
}
}

View File

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

View File

@@ -0,0 +1,52 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Jupiter
{
/// <summary>
/// Utility class contains product info
/// </summary>
public static class JVersionInfo
{
public static string Code
{
get
{
return "1.2.10";
}
}
public static string ProductName
{
get
{
return "Jupiter - Procedural Sky";
}
}
public static string ProductNameAndVersion
{
get
{
return string.Format("{0} v{1}", ProductName, Code);
}
}
public static string ProductNameShort
{
get
{
return "Jupiter";
}
}
public static string ProductNameAndVersionShort
{
get
{
return string.Format("{0} v{1}", ProductNameShort, Code);
}
}
}
}

View File

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