Initial commit

This commit is contained in:
msk
2022-01-22 20:13:49 -08:00
parent f9d23e5bcf
commit 687473573d
878 changed files with 70957 additions and 0 deletions
@@ -0,0 +1,178 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
// We don't need this for MeatKit because it gets imported with the game assembly.
/*
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using UnityEngine;
using UnityEngine.Serialization;
[ExecuteInEditMode]
[RequireComponent(typeof(Light))]
[AddComponentMenu(AlloyUtils.ComponentMenu + "Area Light")]
public class AlloyAreaLight : MonoBehaviour {
// Minimum non-zero value for light size, so we can use sign for specular toggle.
const float c_minimumLightSize = 0.00001f;
// Minimum light intensity to prevent divide by zero (because Epsilon causes infinity).
const float c_minimumLightIntensity = 0.01f;
[HideInInspector]
public Texture2D DefaultSpotLightCookie;
[FormerlySerializedAs("m_size")]
[SerializeField]
float m_radius;
[SerializeField]
float m_length;
[SerializeField]
bool m_hasSpecularHightlight = true;
Light m_light;
Color m_lastColor;
float m_lastIntensity;
float m_lastRange;
Light Light {
get {
// Ensures that we have the light component, even if light is disabled.
if (m_light == null)
m_light = GetComponent<Light>();
return m_light;
}
}
public float Radius {
get { return m_radius; }
set {
if (m_radius != value) {
m_radius = value;
UpdateBinding();
}
}
}
public float Length {
get { return m_length; }
set {
if (m_length != value) {
m_length = value;
UpdateBinding();
}
}
}
public bool HasSpecularHighlight {
get { return m_hasSpecularHightlight; }
set {
if (m_hasSpecularHightlight != value) {
m_hasSpecularHightlight = value;
UpdateBinding();
}
}
}
void Reset() {
m_hasSpecularHightlight = true;
m_radius = 0.0f;
m_length = 0.0f;
m_lastColor = Color.black;
m_lastIntensity = 0.0f;
m_lastRange = 0.0f;
UpdateBinding();
}
// Must run after all other light scripts and animation clips.
void LateUpdate() {
var l = Light;
// Poll the Light component, since we can't extend it.
if (l.color != m_lastColor
|| l.intensity != m_lastIntensity
|| l.range != m_lastRange) {
UpdateBinding();
}
}
public void UpdateBinding() {
var l = Light;
var color = l.color;
var intensity = l.intensity;
var range = l.range;
#if UNITY_EDITOR
EnsureCookie();
#endif
if (l.type == LightType.Directional) {
m_radius = Mathf.Clamp01(m_radius);
color.a = 10.0f * m_radius; // Cancel 0.1 * n in the shader.
}
else {
// Radius packed into fractional component of number.
var maxRadius = range;
m_radius = Mathf.Clamp(m_radius, 0.0f, maxRadius);
color.a = Mathf.Min(0.999f, m_radius / maxRadius);
if (l.type == LightType.Point) {
// Length packed into integer component of number.
var maxLength = 2.0f * range;
m_length = Mathf.Clamp(m_length, 0.0f, maxLength);
color.a += Mathf.Ceil(1000.0f * Mathf.Min(1.0f, m_length / maxLength));
}
}
// Specular highlight toggle in sign component of number.
color.a = Mathf.Max(c_minimumLightSize, color.a); // Must be non-zero!
color.a *= (m_hasSpecularHightlight ? 1.0f : -1.0f);
// Cancel Unity's implicit intensity multiply.
color.a /= Mathf.Max(intensity, c_minimumLightIntensity);
l.color = color;
m_lastColor = color;
m_lastIntensity = intensity;
m_lastRange = range;
}
#if UNITY_EDITOR
public void EnsureCookie() {
var l = Light;
if (l.type == LightType.Spot && l.cookie == null) {
l.cookie = DefaultSpotLightCookie;
EditorUtility.SetDirty(this);
} else if (l.type == LightType.Point && l.cookie == DefaultSpotLightCookie) {
l.cookie = null;
EditorUtility.SetDirty(this);
}
}
#endif
// DEPRECATED BEGIN
[Obsolete("Please use Unity Light component's \"color\" field.")]
public Color Color {
get { return Light.color; }
set { Light.color = value; }
}
[Obsolete("Please use Unity Light component's \"intensity\" field.")]
public float Intensity {
get { return Light.intensity; }
set { Light.intensity = value; }
}
[Obsolete("No longer used. Please remove all references to it.")]
public bool IsAnimated { get; set; }
// DEPRECATED END
}
*/
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e13ed666bcef6874386610d2ef878488
timeCreated: 1468958632
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences:
- DefaultSpotLightCookie: {fileID: 2800000, guid: d21bb2c11f0e5a2498a9ecc9cccfab62,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bc738ca46cba47944874e267a234d9a9
folderAsset: yes
timeCreated: 1468957796
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,79 @@
fileFormatVersion: 2
guid: d21bb2c11f0e5a2498a9ecc9cccfab62
timeCreated: 1442345799
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 1
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: 1
aniso: 0
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 5
buildTargetSettings:
- buildTarget: iPhone
maxTextureSize: 128
textureFormat: 33
compressionQuality: 50
allowsAlphaSplitting: 0
- buildTarget: Android
maxTextureSize: 128
textureFormat: 13
compressionQuality: 50
allowsAlphaSplitting: 0
- buildTarget: BlackBerry
maxTextureSize: 128
textureFormat: 13
compressionQuality: 50
allowsAlphaSplitting: 0
- buildTarget: WP8
maxTextureSize: 128
textureFormat: 12
compressionQuality: 50
allowsAlphaSplitting: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 0e3681edec2f2044bbbc59c604b43ec3
folderAsset: yes
DefaultImporter:
userData:
assetBundleName:
@@ -0,0 +1,190 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using UnityEngine;
using UnityEditor;
#if H3VR_IMPORTED
[CustomEditor(typeof(AlloyAreaLight))]
[CanEditMultipleObjects]
public class AlloyAreaLightEditor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();
var hasSpecularHightlight = serializedObject.FindProperty("m_hasSpecularHightlight");
var maxRange = float.MaxValue;
var isSpecularAreaLight = false;
var isPointLight = false;
// Light Type.
foreach (AlloyAreaLight area in targets) {
var light = area.GetComponent<Light>();
if (light.type == LightType.Directional) {
maxRange = 1.0f;
}
else {
maxRange = Mathf.Min(light.range, maxRange);
}
isPointLight = light.type == LightType.Point;
if (isPointLight
|| light.type == LightType.Spot
|| light.type == LightType.Directional) {
isSpecularAreaLight = true;
}
}
// Specular Highlight.
if (isSpecularAreaLight) {
hasSpecularHightlight.boolValue = EditorGUILayout.Toggle("Specular Highlight", hasSpecularHightlight.boolValue);
isSpecularAreaLight = isSpecularAreaLight && hasSpecularHightlight.boolValue;
}
// Radius.
if (isSpecularAreaLight) {
EditorGUILayout.Slider(serializedObject.FindProperty("m_radius"), 0.0f, maxRange);
} else {
var radius = serializedObject.FindProperty("m_radius");
if (radius.floatValue != 0.0f) {
GUI.changed = true;
radius.floatValue = 0.0f;
}
}
// Length.
if (isSpecularAreaLight && isPointLight) {
EditorGUILayout.Slider(serializedObject.FindProperty("m_length"), 0.0f, maxRange * 2.0f);
} else {
var length = serializedObject.FindProperty("m_length");
if (length.floatValue != 0.0f) {
GUI.changed = true;
length.floatValue = 0.0f;
}
}
serializedObject.ApplyModifiedProperties();
if (GUI.changed) {
foreach (AlloyAreaLight area in targets) {
area.UpdateBinding();
}
}
}
internal static void DrawTwoShadedWireDisc(Vector3 position, Vector3 axis, float radius) {
Color color1 = Handles.color;
Color color2 = color1;
color1.a *= 0.2f;
Handles.color = color1;
Handles.DrawWireDisc(position, axis, radius);
Handles.color = color2;
}
internal static void DrawTwoShadedWireDisc(Vector3 position, Vector3 axis, Vector3 from, float degrees, float radius) {
Handles.DrawWireArc(position, axis, from, degrees, radius);
Color cur = Handles.color;
Color set = cur;
set.a *= 0.2f;
Handles.color = set;
Handles.DrawWireArc(position, axis, from, degrees - 360f, radius);
Handles.color = cur;
}
static Vector3[] s_directionArray = {
Vector3.right,
Vector3.up,
Vector3.forward,
-Vector3.right,
-Vector3.up,
-Vector3.forward
};
static void DoRadiusHandle(Vector3 position, float radius, float length) {
Vector3 dif = position - Camera.current.transform.position;
float sqrMagnitude = dif.sqrMagnitude;
float radiusSqr = radius * radius;
float radiusDiv = radiusSqr * radiusSqr / sqrMagnitude;
//float ratio = radiusDiv / radiusSqr;
float total = Mathf.Sqrt(radiusSqr - radiusDiv);
Handles.DrawWireDisc(position - radiusSqr * dif / sqrMagnitude, dif, total);
for (int j = 0; j < 3; j++) {
float angle = Vector3.Angle(dif, s_directionArray[j]);
angle = 90f - Mathf.Min(angle, 180f - angle);
float tanAngle = Mathf.Tan(angle * Mathf.Deg2Rad);
float viewSize = Mathf.Sqrt(radiusDiv + tanAngle * tanAngle * radiusDiv) / radius;
if (viewSize < 1f) {
float finalArcAngle = Mathf.Asin(viewSize) * Mathf.Rad2Deg;
Vector3 vector2 = Vector3.Cross(s_directionArray[j], dif).normalized;
vector2 = Quaternion.AngleAxis(finalArcAngle, s_directionArray[j]) * vector2;
DrawTwoShadedWireDisc(position, s_directionArray[j], vector2, (90f - finalArcAngle) * 2f, radius);
}
else {
DrawTwoShadedWireDisc(position, s_directionArray[j], radius);
}
}
}
float DrawCapsuleGizmo(Transform transform, float radius, float length) {
var fwd = Vector3.forward * radius;
var side = Vector3.up * radius;
var halfLength = 0.5f * length;
// Exclude light transform scale, and pre-rotate capsule to follow the Y-axis.
Handles.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, 90.0f), Vector3.one);
Handles.DrawWireArc(-halfLength * Vector3.right, Vector3.forward, Vector3.up, 180.0f, radius);
Handles.DrawWireArc(-halfLength * Vector3.right, Vector3.up, -Vector3.forward, 180.0f, radius);
Handles.DrawWireArc(halfLength * Vector3.right, Vector3.forward, -Vector3.up, 180.0f, radius);
Handles.DrawWireArc(halfLength * Vector3.right, Vector3.up, Vector3.forward, 180.0f, radius);
Handles.DrawWireDisc(-halfLength * Vector3.right, Vector3.right, radius);
Handles.DrawWireDisc(halfLength * Vector3.right, Vector3.right, radius);
Handles.DrawLine(-halfLength * Vector3.right + fwd, halfLength * Vector3.right + fwd);
Handles.DrawLine(-halfLength * Vector3.right - fwd, halfLength * Vector3.right - fwd);
Handles.DrawLine(-halfLength * Vector3.right + side, halfLength * Vector3.right + side);
Handles.DrawLine(-halfLength * Vector3.right - side, halfLength * Vector3.right - side);
if (!Event.current.alt && !Event.current.shift) {
radius = Handles.RadiusHandle(Quaternion.identity, -halfLength * Vector3.right, radius, true);
radius = Handles.RadiusHandle(Quaternion.identity, halfLength * Vector3.right, radius, true);
}
Handles.matrix = Matrix4x4.identity;
return radius;
}
void OnSceneGUI() {
var area = target as AlloyAreaLight;
var light = area.GetComponent<Light>();
if (light.type == LightType.Point
|| light.type == LightType.Spot) {
area.Radius = DrawCapsuleGizmo(area.transform, area.Radius, area.Length);
}
//DoRadiusHandle(area.transform.position, area.Size, 1.0f);
if (GUI.changed) {
Undo.RecordObject(area, "Adjust area light");
}
}
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 895b6d1a02c68594f89e4586bdfff530
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,51 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using UnityEditor;
using UnityEngine;
public static class AlloyLightCreator {
#if H3VR_IMPORTED
const string c_lightMenuPath = "GameObject/Light/";
const string c_undoMessage = "Created ";
const string c_directionalLight = "Alloy Directional Light";
const string c_pointLight = "Alloy Point Light";
const string c_spotLight = "Alloy Spotlight";
[MenuItem(c_lightMenuPath + c_directionalLight)]
static void CreateDirectionalLight() {
BuildLight(c_directionalLight, LightType.Directional);
}
[MenuItem(c_lightMenuPath + c_pointLight)]
static void CreateSphereAreaLight() {
BuildLight(c_pointLight, LightType.Point);
}
[MenuItem(c_lightMenuPath + c_spotLight)]
static void CreateSpotSphereAreaLight() {
BuildLight(c_spotLight, LightType.Spot);
}
static void BuildLight(string name, LightType type) {
var go = new GameObject();
var lastSceneView = SceneView.lastActiveSceneView;
Undo.RegisterCreatedObjectUndo(go, c_undoMessage + name);
go.name = name;
var light = go.AddComponent<Light>();
light.type = type;
go.AddComponent<AlloyAreaLight>();
if (lastSceneView != null)
go.transform.position = lastSceneView.pivot;
else
go.transform.position = Vector3.zero;
Selection.activeGameObject = go;
}
#endif
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f5d3ae613b034fe4599db89f5c75351a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,67 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using System;
using System.Linq;
using System.Reflection;
using MeatKit;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Light))]
[CanEditMultipleObjects]
public class AlloyLightEditor : Editor {
#if H3VR_IMPORTED
Editor m_editor;
Action m_onSceneGUIReflected;
Type GetTypeGlobal(string typeName) {
return AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypesSafe()).FirstOrDefault(t => t.Name == typeName);
}
void OnEnable() {
m_editor = CreateEditor(targets, GetTypeGlobal("LightEditor"));
Undo.undoRedoPerformed += RebindAreaLights;
RebindAreaLights();
m_onSceneGUIReflected = (Action)Delegate.CreateDelegate(typeof(Action), m_editor, "OnSceneGUI", false, true);
}
void OnSceneGUI() {
m_onSceneGUIReflected();
}
void OnDisable() {
Undo.undoRedoPerformed -= RebindAreaLights;
//Calls on destroy on light editor
DestroyImmediate(m_editor);
}
public override void OnInspectorGUI() {
m_editor.OnInspectorGUI();
bool anyMissing = targets.Any(l => ((Light)l).GetComponent<Light>().type != LightType.Area
&& ((Light)l).GetComponent<AlloyAreaLight>() == null);
if (anyMissing) {
if (GUILayout.Button("Convert to Alloy area light", EditorStyles.toolbarButton)) {
foreach (Light light in targets) {
Undo.AddComponent<AlloyAreaLight>(light.gameObject);
}
}
}
if (GUI.changed) {
RebindAreaLights();
}
}
void RebindAreaLights() {
var lights = targets.Select(l => ((Light)l).GetComponent<AlloyAreaLight>()).Where(a => a != null);
foreach (AlloyAreaLight ar in lights) {
ar.UpdateBinding();
}
}
#endif
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f83832185bd1caa4d9aab41ddfbc423d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName: