summaryrefslogtreecommitdiffstats
path: root/Third_Party/at.pimaker.ltcgi/Editor
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-05-13 10:54:57 -0700
committeryum <yum.food.vr@gmail.com>2024-05-13 10:54:57 -0700
commit69a2a65710a11cbd7bfa88e35fba89c5eb412b11 (patch)
tree6d2fa8e5069783936759d85b3a58bf45ca104af2 /Third_Party/at.pimaker.ltcgi/Editor
parent1a4298d33de4420b22c723144a1afbe9a3c61b59 (diff)
Remove everything except headers, LICENSE and README from LTCGIv0.0.0
Diffstat (limited to 'Third_Party/at.pimaker.ltcgi/Editor')
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Assembly_Editor.asmdef26
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_BakeReset.cs60
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Controller.cs763
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerAutoSetup.cs161
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerBake.cs484
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerExternal.cs512
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerHelpers.cs146
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerLOD.cs148
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Emitter.cs98
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Include.cs42
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Screen.cs452
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-Logo.pngbin31831 -> 0 bytes
-rw-r--r--Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-LogoController.pngbin43404 -> 0 bytes
13 files changed, 0 insertions, 2892 deletions
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Assembly_Editor.asmdef b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Assembly_Editor.asmdef
deleted file mode 100644
index 41a61d7..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Assembly_Editor.asmdef
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "name": "at.pimaker.ltcgi.Editor",
- "references": [
- "VRC.SDK3",
- "VRC.SDK3.Editor",
- "VRC.SDKBase",
- "VRC.SDKBase.Editor",
- "VRC.Udon",
- "VRC.Udon.Editor",
- "LTCGI_Assembly",
- "UdonSharp.Lib",
- "UdonSharp.Editor",
- "UdonSharp.Runtime",
- "BakeryEditorAssembly",
- "BakeryRuntimeAssembly"
- ],
- "includePlatforms": [],
- "excludePlatforms": [],
- "allowUnsafeCode": false,
- "overrideReferences": false,
- "precompiledReferences": [],
- "autoReferenced": true,
- "defineConstraints": [],
- "versionDefines": [],
- "noEngineReferences": false
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_BakeReset.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_BakeReset.cs
deleted file mode 100644
index ad96f32..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_BakeReset.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-#if UNITY_EDITOR
-using UnityEditor;
-using UnityEngine;
-using UnityEngine.Rendering;
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- // Serialization helper for lightmap baking primitives.
- [ExecuteInEditMode]
- public class LTCGI_BakeReset : MonoBehaviour
- {
- public bool Reenable;
- public Renderer[] DisableRendererComponents;
-
- public bool ResetData;
- public Material[] Materials;
- public StaticEditorFlags Flags;
- public ShadowCastingMode ShadowCastingMode;
-
- public bool ResetLightMesh;
- public Color lightMeshColor;
- public float lightMeshIntensity;
-
- internal void ApplyReset()
- {
- if (Reenable)
- {
- this.gameObject.SetActive(true);
- }
- if (ResetData)
- {
- var rend = this.GetComponent<Renderer>();
- rend.sharedMaterials = Materials;
- rend.shadowCastingMode = ShadowCastingMode;
- GameObjectUtility.SetStaticEditorFlags(this.gameObject, Flags);
- }
-
- #if BAKERY_INCLUDED
- if (ResetLightMesh)
- {
- var lm = this.GetComponent<BakeryLightMesh>();
- if (lm != null)
- {
- lm.color = lightMeshColor;
- lm.intensity = lightMeshIntensity;
- }
- }
- #endif
-
- if (DisableRendererComponents != null)
- {
- foreach (var r in DisableRendererComponents)
- if (r) r.enabled = false;
- }
- }
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Controller.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Controller.cs
deleted file mode 100644
index 7d10357..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Controller.cs
+++ /dev/null
@@ -1,763 +0,0 @@
-// Uncomment for debug messages
-//#define DEBUG_LOG
-
-#if UNITY_EDITOR
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.IO;
-using UnityEditor;
-using UnityEngine;
-using UnityEditor.SceneManagement;
-
-#if UDONSHARP
-using UdonSharp;
-using UdonSharpEditor;
-#endif
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- [ExecuteInEditMode]
- [System.Serializable]
- public partial class LTCGI_Controller : MonoBehaviour
- {
- internal const int MAX_SOURCES = 16;
-
- [Tooltip("Intensity is set for each screen. Can be a RenderTexture for realtime updates (video players).")]
- public Texture VideoTexture;
- [Tooltip("Static textures are precomputed and *must* all be the same size. Make sure to click 'Precompute Static Textures' after any changes.")]
- public Texture2D[] StaticTextures;
- [Tooltip("Renderers that may change material during runtime. Otherwise only 'sharedMaterial's are updated for performance reasons.")]
- public Renderer[] DynamicRenderers;
-
- [Header("Expert Settings")]
- [Tooltip("Do not automatically set up the blur chain. Use this if you use AVPro to set _MainTex on the LOD1 material for example.")]
- public bool CustomBlurChain = false;
-
- [Tooltip("Apply an intensity multiplier *before* baking the lightmap. Offset with Lightmap Multiplier below.")]
- public float LightmapIntensity = 4.0f;
-
- [Tooltip("Multiply lightmap with this before applying to diffuse. Useful if you have multiple lights next to each other sharing a channel.")]
- public Vector3 LightmapMultiplier = new Vector4(0.25f, 0.25f, 0.25f, 0.25f);
-
- [Header("Internal Settings")]
- public Texture2D DefaultLightmap;
- public CustomRenderTexture LOD1s, LOD1, LOD2s, LOD2, LOD3s, LOD3;
- public Texture2D LUT1, LUT2;
-
- public static LTCGI_Controller Singleton;
-
- [NonSerialized] internal Renderer[] cachedMeshRenderers;
- [NonSerialized] private Vector4[] _LTCGI_Vertices_0, _LTCGI_Vertices_1, _LTCGI_Vertices_2, _LTCGI_Vertices_3;
- [NonSerialized] private Vector4[] _LTCGI_Vertices_0t, _LTCGI_Vertices_1t, _LTCGI_Vertices_2t, _LTCGI_Vertices_3t;
- [NonSerialized] internal Transform[] _LTCGI_ScreenTransforms;
- [NonSerialized] private Vector4[] _LTCGI_ExtraData;
- [NonSerialized] private Vector4 _LTCGI_LightmapMult;
- [NonSerialized] private Vector2[][] _LTCGI_UVs;
-
- private Texture2DArray[] _LTCGI_LOD_arrays;
-
- public bool HasDynamicScreens = false;
- public bool HasCylinders = false;
-
- public void OnEnable()
- {
- if (PrefabUtility.IsPartOfPrefabAsset(this.gameObject)) return;
- if (Singleton == null || Singleton != this)
- {
- if (PrefabUtility.IsPartOfPrefabInstance(this.gameObject))
- PrefabUtility.UnpackPrefabInstance(this.gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
- Singleton = this;
- Undo.undoRedoPerformed += this.UpdateMaterials;
- EditorApplication.playModeStateChanged += (change) => {
- if (change == PlayModeStateChange.ExitingEditMode)
- {
- UpdateMaterials();
- }
- };
- Debug.Log($"LTCGI Controller Singleton initialized (Mode: {RuntimeMode})");
-
- var ctrls = GameObject.FindObjectsOfType<LTCGI_Controller>().Length;
- if (ctrls > 1)
- {
- Debug.LogError("There must only be one LTCGI Controller per scene!");
- }
- }
-
- MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless();
- }
-
- public static void MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless()
- {
- var hasChanges = false;
- if (!AssetDatabase.IsValidFolder("Assets\\_pi_"))
- {
- AssetDatabase.CreateFolder("Assets", "_pi_");
- hasChanges = true;
- }
- if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI"))
- {
- AssetDatabase.CreateFolder("Assets\\_pi_", "_LTCGI");
- hasChanges = true;
- }
- if (!AssetDatabase.IsValidFolder("Assets\\_pi_\\_LTCGI\\Shaders"))
- {
- AssetDatabase.CreateFolder("Assets\\_pi_\\_LTCGI", "Shaders");
- hasChanges = true;
- }
- if (!File.Exists("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc"))
- {
- File.WriteAllText("Assets\\_pi_\\_LTCGI\\Shaders\\LTCGI.cginc", "#include \"Packages\\at.pimaker.ltcgi\\Shaders\\LTCGI.cginc\"");
- hasChanges = true;
- }
-
- // god I hate this part, Unity dumb dumb
- if (!AssetDatabase.IsValidFolder("Assets\\Gizmos"))
- {
- AssetDatabase.CreateFolder("Assets", "Gizmos");
- hasChanges = true;
- }
- if (!File.Exists("Assets\\Gizmos\\LTCGI_Screen_Gizmo.png"))
- {
- File.Copy("Packages\\at.pimaker.ltcgi\\LTCGI_Screen_Gizmo.png", "Assets\\Gizmos\\LTCGI_Screen_Gizmo.png", true);
- hasChanges = true;
- }
-
- if (hasChanges)
- {
- Debug.Log("LTCGI Migration took place, refreshing asset database");
- AssetDatabase.Refresh();
- }
- }
-
- public static bool MatLTCGIenabled(Material mat)
- {
- if (mat == null) return false;
- var tag = mat.GetTag("LTCGI", true);
- if (tag == null || string.IsNullOrEmpty(tag)) return false;
- if (tag == "ALWAYS") return true;
- return mat.GetFloat(tag) != 0;
- }
-
- [MenuItem("Tools/LTCGI/Force Material Update")]
- public static void UpdateMaterialsMenu() => Singleton?.UpdateMaterials();
- public void UpdateMaterials() => UpdateMaterials(false);
- public void UpdateMaterials(bool fast, LTCGI_Screen screen = null)
- {
- // don't mess with Udon emulation
- if (EditorApplication.isPlaying)
- return;
- if (Lightmapping.isRunning)
- return;
- if (UnityEngine.SceneManagement.SceneManager.loadedSceneCount == 0)
- return;
-
- #if DEBUG_LOG
- Debug.Log($"LTCGI: beginning update ({(fast ? "fast" : "full")})");
- #endif
-
- MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless();
-
- if (_LTCGI_ExtraData == null)
- fast = false;
- if (_LTCGI_LightmapMult == null)
- fast = false;
-
- if (!fast)
- {
- _LTCGI_Vertices_0 = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_1 = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_2 = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_3 = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_0t = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_1t = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_2t = new Vector4[MAX_SOURCES];
- _LTCGI_Vertices_3t = new Vector4[MAX_SOURCES];
- _LTCGI_ExtraData = new Vector4[MAX_SOURCES];
- _LTCGI_ScreenTransforms = new Transform[MAX_SOURCES];
- _LTCGI_UVs = new Vector2[MAX_SOURCES][];
- }
-
- var dynamics = false;
- var cylinders = false;
-
- // construct data
- var screens = GameObject
- .FindObjectsOfType<LTCGI_Screen>()
- .Where(x => x.enabled)
- .OrderByDescending(x => x.Dynamic)
- .ToArray();
-
- if (screens.Length > MAX_SOURCES)
- {
- if (fast) return;
- throw new Exception("Too many screens in the scene!");
- }
-
- for (int i = 0; i < screens.Length; i++)
- {
- var s = screens[i];
- if (fast && screen != null && s != screen) continue;
-
- _LTCGI_ScreenTransforms[i] = s.transform;
- LTCGI_Emitter emitter;
- if ((emitter = s as LTCGI_Emitter) != null)
- {
- _LTCGI_Vertices_0[i] = _LTCGI_Vertices_1[i] = _LTCGI_Vertices_2[i] = _LTCGI_Vertices_3[i] = Vector4.zero;
- _LTCGI_Vertices_0[i].w = s.SingleUV.x;
- _LTCGI_Vertices_1[i].w = s.SingleUV.y;
- }
- else if (s.Cylinder)
- {
- // Experimental!
- _LTCGI_Vertices_0[i] = new Vector4(
- s.CylinderBase.x,
- s.CylinderBase.y * 2,
- s.CylinderBase.z,
- s.CylinderHeight * 2
- );
- _LTCGI_Vertices_1[i] = new Vector4(
- s.CylinderBase.x,
- s.CylinderBase.y * 2,
- s.CylinderBase.z,
- s.CylinderRadius
- );
- _LTCGI_Vertices_2[i] = new Vector4(
- s.CylinderBase.x,
- s.CylinderBase.y * 2,
- s.CylinderBase.z,
- s.CylinderSize
- );
- _LTCGI_Vertices_3[i] = new Vector4(
- s.CylinderBase.x,
- s.CylinderBase.y * 2,
- s.CylinderBase.z,
- s.CylinderAngle
- );
-
- cylinders = true;
- }
- else
- {
- var mf = s.GetComponent<MeshFilter>();
- if (mf.sharedMesh == null) continue;
- if (!fast)
- {
- SetMeshImporterFormat(mf.sharedMesh, true);
- }
- var mesh = mf.sharedMesh;
- if (mesh.vertexCount != 4 && mesh.vertexCount != 3)
- {
- if (fast) return;
- throw new Exception($"Mesh on '{s.gameObject.name}' does not have 3 or 4 vertices ({mesh.vertexCount})");
- }
-
- if (mf.sharedMesh.vertexCount == 3)
- {
- // extend triangle to virtual quad
- mesh = Instantiate(mesh);
- mesh.vertices = new Vector3[] {
- mesh.vertices[0],
- mesh.vertices[1],
- mesh.vertices[2],
- mesh.vertices[2],
- };
- mesh.uv = new Vector2[] {
- mesh.uv[0],
- mesh.uv[1],
- mesh.uv[2],
- mesh.uv[2],
- };
- }
-
- var verts = mesh.vertices;
- _LTCGI_Vertices_0[i] = new Vector4(verts[0].x, verts[0].y, verts[0].z, mesh.uv[0].x);
- _LTCGI_Vertices_1[i] = new Vector4(verts[1].x, verts[1].y, verts[1].z, mesh.uv[0].y);
- _LTCGI_Vertices_2[i] = new Vector4(verts[2].x, verts[2].y, verts[2].z, mesh.uv[3].x);
- _LTCGI_Vertices_3[i] = new Vector4(verts[3].x, verts[3].y, verts[3].z, mesh.uv[3].y);
-
- var angle = Vector3.Dot(
- new Vector3(_LTCGI_Vertices_1[i].x, _LTCGI_Vertices_1[i].y, _LTCGI_Vertices_1[i].z) -
- new Vector3(_LTCGI_Vertices_0[i].x, _LTCGI_Vertices_0[i].y, _LTCGI_Vertices_0[i].z),
- new Vector3(_LTCGI_Vertices_1[i].x, _LTCGI_Vertices_1[i].y, _LTCGI_Vertices_1[i].z) -
- new Vector3(_LTCGI_Vertices_3[i].x, _LTCGI_Vertices_3[i].y, _LTCGI_Vertices_3[i].z)
- );
- // workaround for blender imports
- if (!Mathf.Approximately(angle, 0.0f))
- {
- var flip = s.FlipUV ? 1 : -1;
- var v0 = _LTCGI_Vertices_0[i];
- var v1 = _LTCGI_Vertices_1[i];
- var v2 = _LTCGI_Vertices_2[i];
- var v3 = _LTCGI_Vertices_3[i];
- _LTCGI_Vertices_0[i] = v0;
- _LTCGI_Vertices_1[i] = v3;
- _LTCGI_Vertices_2[i] = v1;
- _LTCGI_Vertices_3[i] = v2;
- _LTCGI_Vertices_0[i].w = mesh.uv[0].x * flip;
- _LTCGI_Vertices_1[i].w = mesh.uv[0].y;
- _LTCGI_Vertices_2[i].w = mesh.uv[2].x * flip;
- _LTCGI_Vertices_3[i].w = mesh.uv[2].y;
-
- if (s.FlipUV)
- {
- _LTCGI_UVs[i] = new Vector2[]
- {
- // TODO: is this required? if so, implement it. for now, no-op.
- mesh.uv[0],
- mesh.uv[3],
- mesh.uv[1],
- mesh.uv[2],
- };
- }
- else
- {
- _LTCGI_UVs[i] = new Vector2[]
- {
- mesh.uv[0],
- mesh.uv[3],
- mesh.uv[1],
- mesh.uv[2],
- };
- }
- }
- else
- {
- _LTCGI_UVs[i] = new Vector2[]
- {
- mesh.uv[0],
- mesh.uv[1],
- mesh.uv[2],
- mesh.uv[3],
- };
- }
-
- if (s.ColorMode == ColorMode.SingleUV)
- {
- _LTCGI_Vertices_0[i].w = s.SingleUV.x;
- _LTCGI_Vertices_1[i].w = s.SingleUV.y;
- }
-
- if (mf.sharedMesh.vertexCount == 3)
- {
- DestroyImmediate(mesh);
- }
-
- if (s.Dynamic)
- {
- dynamics = true;
- }
- }
-
- _LTCGI_Vertices_0t[i] = s.transform.TransformPoint(_LTCGI_Vertices_0[i]);
- _LTCGI_Vertices_0t[i].w = _LTCGI_Vertices_0[i].w;
- _LTCGI_Vertices_1t[i] = s.transform.TransformPoint(_LTCGI_Vertices_1[i]);
- _LTCGI_Vertices_1t[i].w = _LTCGI_Vertices_1[i].w;
- _LTCGI_Vertices_2t[i] = s.transform.TransformPoint(_LTCGI_Vertices_2[i]);
- _LTCGI_Vertices_2t[i].w = _LTCGI_Vertices_2[i].w;
- _LTCGI_Vertices_3t[i] = s.transform.TransformPoint(_LTCGI_Vertices_3[i]);
- _LTCGI_Vertices_3t[i].w = _LTCGI_Vertices_3[i].w;
-
- //Debug.Log($"V0: {_LTCGI_Vertices_0[i]}");
- //Debug.Log($"V1: {_LTCGI_Vertices_1[i]}");
- //Debug.Log($"V2: {_LTCGI_Vertices_2[i]}");
- //Debug.Log($"V3: {_LTCGI_Vertices_3[i]}");
-
- uint flags = 0;
- if (s.DoubleSided) flags |= 1;
- if (s.DiffuseFromLm) flags |= 2;
- if (s.Specular) flags |= 4;
- if (s.Diffuse) flags |= 8;
- flags |= ((uint)s.TextureIndex & 0xf) << 4;
- flags |= ((uint)s.ColorMode & 0x3) << 8;
- flags |= ((uint)s.LightmapChannel & 0x3) << 10;
- if (s.Cylinder) flags |= (1<<12);
- flags |= ((uint)s.AudioLinkBand & 0x3) << 13;
- if (s is LTCGI_Emitter) flags |= (1<<15); // TODO: can this be set based on other flags?
-
- var col = s.enabled && s.gameObject.activeInHierarchy ? s.Color : Color.black;
- float fflags = BitConverter.ToSingle(BitConverter.GetBytes(flags), 0);
- _LTCGI_ExtraData[i] = new Vector4(col.linear.r, col.linear.g, col.linear.b, fflags);
- }
-
- if (!fast)
- {
- HasCylinders = cylinders;
- HasDynamicScreens = dynamics;
- }
-
- /*_LTCGI_LightmapMult = new Vector4(
- 1.0f/Mathf.Max(screens.Count(s => s.LightmapChannel == 1), 1.0f),
- 1.0f/Mathf.Max(screens.Count(s => s.LightmapChannel == 2), 1.0f),
- 1.0f/Mathf.Max(screens.Count(s => s.LightmapChannel == 3), 1.0f),
- 0.0f
- );*/
-
- _LTCGI_LightmapMult = (Vector4)LightmapMultiplier;
-
- #if DEBUG_LOG
- if (!fast)
- {
- Debug.Log($"LTCGI: updated screens ({screens.Length}, {_LTCGI_LightmapMult})");
- }
- #endif
-
- if (!fast || cachedMeshRenderers == null)
- {
- // get all affected renderers
- var allRenderers = Component.FindObjectsOfType<Renderer>();
- var renderers = new List<Renderer>();
- foreach (var r in allRenderers)
- {
- foreach (var mat in r.sharedMaterials)
- {
- if (MatLTCGIenabled(mat))
- {
- if (!renderers.Contains(r))
- renderers.Add(r);
- break;
- }
- }
- }
- cachedMeshRenderers = renderers.ToArray();
-
- #if DEBUG_LOG
- Debug.Log($"LTCGI: cached renderers ({cachedMeshRenderers.Length})");
- #endif
- }
-
- // start LOD chain
- if (VideoTexture != null && !CustomBlurChain)
- {
- LOD1s?.material?.SetTexture("_MainTex", VideoTexture);
- }
-
- // find precomputed static textures
- if (!fast)
- {
- var curscene = EditorSceneManager.GetActiveScene().name;
- _LTCGI_LOD_arrays = new Texture2DArray[4];
- for (int lod = 0; lod < 4; lod++)
- {
- try
- {
- _LTCGI_LOD_arrays[lod] = AssetDatabase.LoadAssetAtPath<Texture2DArray>("Assets/LTCGI-Generated/lod-" + curscene + "-" + lod + ".asset");
- if (_LTCGI_LOD_arrays[lod] == null) throw new Exception();
- }
- catch
- {
- _LTCGI_LOD_arrays = null;
- break;
- }
- }
- }
-
- // write out uniforms into data texture
- var staticUniformTex = WriteStaticUniform(screens, fast);
- var screenCountDynamic = screens.TakeWhile(x => x.Dynamic).Count();
-
- for (int i = 0; i < cachedMeshRenderers.Length; i++)
- {
- var r = cachedMeshRenderers[i];
- if (r == null) {
- // explicitly do full update in case the renderers have become invalid
- UpdateMaterials(false);
- return;
- }
- }
-
- Shader.SetGlobalFloat("_Udon_LTCGI_GlobalEnable", screens.Length > 0 ? 1.0f : 0.0f);
-
- if (this != null && this.gameObject != null)
- {
- #if UDONSHARP
- LTCGI_UdonAdapter adapter;
- #pragma warning disable 618
- LTCGI_UdonAdapter[] adapters = this.gameObject.GetUdonSharpComponents<LTCGI_UdonAdapter>();
- #pragma warning restore 618
- #else
- LTCGI_RuntimeAdapter adapter;
- Component[] adapters = this.gameObject.GetComponents<LTCGI_RuntimeAdapter>();
- #endif
-
- if (adapters == null || adapters.Length == 0)
- {
- #if UDONSHARP
- adapter = this.gameObject.AddUdonSharpComponent<LTCGI_UdonAdapter>();
- #else
- adapter = this.gameObject.AddComponent<LTCGI_RuntimeAdapter>();
- #endif
- }
- else
- {
- #if UDONSHARP
- adapter = (LTCGI_UdonAdapter)adapters[0];
- #else
- adapter = (LTCGI_RuntimeAdapter)adapters[0];
- #endif
- if (adapters.Length > 1)
- {
- for (int i = 1; i < adapters.Length; i++)
- {
- Debug.LogWarning("LTCGI: WARNING: Deleting extra *Adapter component on " + this.gameObject.name);
- DestroyImmediate(adapters[i]);
- }
- }
- }
-
- // update LTCGI_UdonAdapter proxy with new data
- #pragma warning disable 618
- adapter.UpdateProxy();
- #pragma warning restore 618
- adapter._Renderers = cachedMeshRenderers.Where(cm => !IsEditorOnly(cm.gameObject)).ToArray();
- adapter._LTCGI_DefaultLightmap = DefaultLightmap;
- adapter._LTCGI_Lightmaps = cachedMeshRenderers
- .Select(r => {
- if (_LTCGI_Lightmaps == null) return DefaultLightmap;
- if (_LTCGI_LightmapData_key == null) return DefaultLightmap;
- var lidx2 = Array.IndexOf(_LTCGI_LightmapData_key, r);
- if (lidx2 < 0) return DefaultLightmap;
- var lidx = _LTCGI_LightmapIndex_val[lidx2];
- return lidx != 0xFFFE && lidx >= 0 && lidx < _LTCGI_Lightmaps.Length ?
- _LTCGI_Lightmaps[lidx] : DefaultLightmap;
- })
- .ToArray();
- adapter._LTCGI_LightmapMult = _LTCGI_LightmapMult;
- adapter._LTCGI_LightmapST = cachedMeshRenderers.Select(r => {
- if (_LTCGI_LightmapData_key == null) return Vector4.zero;
- var idx = Array.IndexOf(_LTCGI_LightmapData_key, r);
- return idx < 0 ? Vector4.zero : _LTCGI_LightmapOffsets_val[idx];
- }).ToArray();
- var mask2d = cachedMeshRenderers.Select(x => GetMaskForRenderer(screens, x)).ToArray();
- // float[][] doesn't serialize in normal Unity, so linearize it
- adapter._LTCGI_Mask =
- Enumerable.Range(0, adapter._Renderers.Length)
- .SelectMany(i => mask2d[i])
- .ToArray();
- // mask is reversed! 1 = not visible, 0 = visible
- var avatarMask = screens.Select(x => x.AffectAvatars ? 0.0f : 1.0f);
- adapter._LTCGI_MaskAvatars = avatarMask.ToArray();
- adapter._Screens = screens.Select(x => x?.gameObject).ToArray();
- adapter._LTCGI_LODs = new Texture[4];
- adapter._LTCGI_LODs[0] = VideoTexture;
- adapter._LTCGI_LODs[1] = LOD1;
- adapter._LTCGI_LODs[2] = LOD2;
- adapter._LTCGI_LODs[3] = LOD3;
- if (_LTCGI_LOD_arrays != null)
- {
- adapter._LTCGI_Static_LODs_0 = _LTCGI_LOD_arrays[0];
- adapter._LTCGI_Static_LODs_1 = _LTCGI_LOD_arrays[1];
- adapter._LTCGI_Static_LODs_2 = _LTCGI_LOD_arrays[2];
- adapter._LTCGI_Static_LODs_3 = _LTCGI_LOD_arrays[3];
- }
- else
- {
- adapter._LTCGI_Static_LODs_0 = null;
- adapter._LTCGI_Static_LODs_1 = null;
- adapter._LTCGI_Static_LODs_2 = null;
- adapter._LTCGI_Static_LODs_3 = null;
- }
- adapter._LTCGI_lut1 = LUT1;
- adapter._LTCGI_lut2 = LUT2;
- adapter._LTCGI_ScreenTransforms = _LTCGI_ScreenTransforms;
- adapter._LTCGI_Vertices_0 = _LTCGI_Vertices_0;
- adapter._LTCGI_Vertices_1 = _LTCGI_Vertices_1;
- adapter._LTCGI_Vertices_2 = _LTCGI_Vertices_2;
- adapter._LTCGI_Vertices_3 = _LTCGI_Vertices_3;
- adapter._LTCGI_ExtraData = _LTCGI_ExtraData;
- adapter._LTCGI_static_uniforms = staticUniformTex;
- adapter._LTCGI_ScreenCount = screens.Length;
- adapter._LTCGI_ScreenCountDynamic = screenCountDynamic;
- // masked counts must include all masked screens up to the last non-masked one!
- adapter._LTCGI_ScreenCountMasked =
- mask2d.Select(mask =>
- Math.Max(adapter._LTCGI_ScreenCountDynamic,
- Array.FindLastIndex(mask, m => m == 0.0f) + 1)).ToArray();
- adapter._LTCGI_ScreenCountMaskedAvatars = Array.FindLastIndex(screens, x => x.AffectAvatars) + 1;
- adapter.BlurCRTInput = LOD1s;
-
- #pragma warning disable 618
- adapter.ApplyProxyModifications();
- #pragma warning restore 618
-
- if (screens.Length > 0)
- adapter._Initialize();
-
- #if DEBUG_LOG
- Debug.Log("LTCGI: updated UdonSharp adapter");
- #endif
- }
-
- #if DEBUG_LOG
- Debug.Log("LTCGI: writing auto-config file");
- #endif
- LTCGI_ControllerEditor.RecalculateAutoConfig(this);
-
- #if DEBUG_LOG
- Debug.Log("LTCGI: updating video player adapters");
- #endif
- LTCGI_Controller.DetectAndEnableAdaptersForAvailableVideoplayers();
-
- #if DEBUG_LOG
- Debug.Log("LTCGI: update done!");
- #endif
- }
-
- private static Texture2D staticUniformTemp = null;
- private Texture2D WriteStaticUniform(LTCGI_Screen[] screens, bool fast, LTCGI_Screen fastScreen = null)
- {
- var curscene = EditorSceneManager.GetActiveScene().name;
- var path = @"Assets\LTCGI-Generated\StaticUniform-" + curscene + ".exr";
-
- if (staticUniformTemp == null)
- {
- staticUniformTemp = new Texture2D(6, MAX_SOURCES, UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16B16A16_SFloat, UnityEngine.Experimental.Rendering.TextureCreationFlags.None);
- fast = false;
- }
-
- for (int i = 0; i < MAX_SOURCES; i++)
- {
- if (fast && fastScreen != null && i < screens.Length && screens[i] != fastScreen)
- continue;
- if (i >= screens.Length)
- {
- for (int w = 0; w < staticUniformTemp.width; w++)
- {
- staticUniformTemp.SetPixel(w, i, Color.black);
- }
- }
- else
- {
- staticUniformTemp.SetPixel(0, i, (Color)_LTCGI_Vertices_0t[i]);
- staticUniformTemp.SetPixel(1, i, (Color)_LTCGI_Vertices_1t[i]);
- staticUniformTemp.SetPixel(2, i, (Color)_LTCGI_Vertices_2t[i]);
- staticUniformTemp.SetPixel(3, i, (Color)_LTCGI_Vertices_3t[i]);
- if (_LTCGI_UVs[i] != null && _LTCGI_UVs[i].Length == 4)
- {
- staticUniformTemp.SetPixel(4, i, (Color)new Vector4(
- _LTCGI_UVs[i][0].x, _LTCGI_UVs[i][0].y, _LTCGI_UVs[i][1].x, _LTCGI_UVs[i][1].y));
- staticUniformTemp.SetPixel(5, i, (Color)new Vector4(
- _LTCGI_UVs[i][2].x, _LTCGI_UVs[i][2].y, _LTCGI_UVs[i][3].x, _LTCGI_UVs[i][3].y));
- }
- }
- }
-
- staticUniformTemp.Apply();
-
- if (fast)
- {
- return staticUniformTemp;
- }
-
- if (!AssetDatabase.IsValidFolder("Assets/LTCGI-Generated"))
- AssetDatabase.CreateFolder("Assets", "LTCGI-Generated");
- var exr = staticUniformTemp.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat);
-
- var existed = File.Exists(path);
- byte[] prev = new byte[0];
- if (existed)
- {
- prev = File.ReadAllBytes(path);
- }
-
- File.WriteAllBytes(path, exr);
- AssetDatabase.Refresh();
-
- var asset = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
- string assetPath = AssetDatabase.GetAssetPath(asset);
- var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
- if (importer != null && (!prev.SequenceEqual(exr) || importer.npotScale != TextureImporterNPOTScale.None))
- {
- importer.mipmapEnabled = false;
- importer.textureCompression = TextureImporterCompression.Uncompressed;
- importer.crunchedCompression = false;
- importer.sRGBTexture = false;
- importer.maxTextureSize = 8192;
- importer.alphaSource = TextureImporterAlphaSource.FromInput;
- importer.alphaIsTransparency = true;
- importer.npotScale = TextureImporterNPOTScale.None;
- importer.SaveAndReimport();
- }
-
- #if DEBUG_LOG
- Debug.Log("LTCGI: updated static uniform declarations");
- #endif
-
- return asset;
- }
-
-
-
- // Debug stuff, plz ignore...
- private static (float[], float[], int) ReadLookupFile()
- {
- float[] ltc_1, ltc_2;
- int n;
-
- using (var reader = new StreamReader("Packages\\at.pimaker.ltcgi\\Lookup Tables\\ltc_3.inc"))
- {
- n = int.Parse(reader.ReadLine().Trim());
- ltc_1 = new float[n*n*4];
- ltc_2 = new float[n*n*4];
-
- var line = reader.ReadLine().Trim();
- var i = 0;
- while (line != "}")
- {
- var s = line.Split(',');
- var a = s[0] == "nan" || s[0] == "-nan" ? float.NaN : float.Parse(s[0]);
- var b = s[1] == "nan" || s[1] == "-nan" ? float.NaN : float.Parse(s[1]);
- var c = s[2] == "nan" || s[2] == "-nan" ? float.NaN : float.Parse(s[2]);
- var d = s[3] == "nan" || s[3] == "-nan" ? float.NaN : float.Parse(s[3]);
- ltc_1[i + 0] = a;
- ltc_1[i + 1] = b;
- ltc_1[i + 2] = c;
- ltc_1[i + 3] = d;
- i += 4;
- line = reader.ReadLine().Trim();
- }
-
- /*i = 0;
- line = reader.ReadLine().Trim();
- while (line != "}")
- {
- var s = line.Split(',');
- var a = float.Parse(s[0]);
- var b = float.Parse(s[1]);
- var c = float.Parse(s[2]);
- var d = float.Parse(s[3]);
- ltc_2[i + 0] = a;
- ltc_2[i + 1] = b;
- ltc_2[i + 2] = c;
- ltc_2[i + 3] = d;
- i += 4;
- line = reader.ReadLine().Trim();
- }*/
- }
-
- Debug.Log("LTCGI: Read texture with size " + n);
- return (ltc_1, ltc_2, n);
- }
-
- [MenuItem("Tools/LTCGI/Encode Lookup Textures into EXR")]
- public static void EncodeLookups()
- {
- var (g_ltc_mat_f, g_ltc_mag_f, n) = ReadLookupFile();
-
- var tex = new Texture2D(n, n, UnityEngine.Experimental.Rendering.GraphicsFormat.R32G32B32A32_SFloat, 0);
- tex.SetPixelData(g_ltc_mat_f, 0);
- System.IO.File.WriteAllBytes("Packages\\at.pimaker.ltcgi\\Lookup Tables\\ltc_mat_hdr_3.exr", tex.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat));
-
- var tex2 = new Texture2D(n, n, UnityEngine.Experimental.Rendering.GraphicsFormat.R32G32B32A32_SFloat, 0);
- tex2.SetPixelData(g_ltc_mag_f, 0);
- System.IO.File.WriteAllBytes("Packages\\at.pimaker.ltcgi\\Lookup Tables\\ltc_mag_hdr_3.exr", tex2.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat));
-
- GameObject.DestroyImmediate(tex);
- GameObject.DestroyImmediate(tex2);
- AssetDatabase.Refresh();
- }
- }
-#endif
-}
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerAutoSetup.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerAutoSetup.cs
deleted file mode 100644
index 726edbc..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerAutoSetup.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using UnityEditor;
-using UnityEngine;
-#if UDONSHARP
-using UdonSharp;
-using UdonSharpEditor;
-#endif
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- public partial class LTCGI_Controller
- {
- public GameObject ConfiguredAdapter;
-
- private const string PROTV_ADAPTER_VERSION = "1.0.0";
- private const string UDONSHARP_ADAPTER_VERSION = "1.0.0";
-
- internal static List<ILTCGI_AutoSetup> wizards;
- internal static List<ILTCGI_AutoSetup> Wizards
- {
- get
- {
- if (wizards != null) return wizards;
- wizards = new List<ILTCGI_AutoSetup>();
-
- var asms = System.AppDomain.CurrentDomain.GetAssemblies();
- Assembly asm = Assembly.GetExecutingAssembly();
- foreach (var a in asms)
- {
- if (a.FullName.Contains("Assembly-CSharp-Editor"))
- {
- asm = a;
- break;
- }
- }
-
- foreach (var wizard in asm.GetTypes()
- .Where(x => x.IsClass && !x.IsAbstract && typeof(ILTCGI_AutoSetup).IsAssignableFrom(x)))
- {
- var instance = Activator.CreateInstance(wizard) as ILTCGI_AutoSetup;
- if (instance != null)
- {
- //Debug.Log("LTCGI: Found AutoSetup wizard: " + wizard.Name);
- wizards.Add(instance);
- }
- }
-
- return wizards;
- }
- }
-
- internal static void DrawAutoSetupEditor(LTCGI_Controller my)
- {
- // we have one configured, only allow un-setup
- if (my.ConfiguredAdapter != null)
- {
- EditorGUILayout.LabelField("Configured Adapter: " + my.ConfiguredAdapter.name);
- if (GUILayout.Button("Un-Configure"))
- {
- DestroyImmediate(my.ConfiguredAdapter);
- my.ConfiguredAdapter = null;
- LTCGI_Controller.Singleton.UpdateMaterials();
- }
- return;
- }
-
- // try to detect auto-setupable video players
- foreach (var wizard in Wizards)
- {
- var set = wizard.AutoSetupEditor(my);
- if (set != null)
- {
- my.ConfiguredAdapter = set;
- LTCGI_Controller.Singleton.UpdateMaterials();
- return;
- }
- }
- }
-
- internal static void DetectAndEnableAdaptersForAvailableVideoplayers()
- {
-#if UDONSHARP
- if (!AssetDatabase.IsValidFolder("Assets/_pi_"))
- AssetDatabase.CreateFolder("Assets", "_pi_");
- if (!AssetDatabase.IsValidFolder("Assets/_pi_/_LTCGI-Adapters"))
- AssetDatabase.CreateFolder("Assets/_pi_", "_LTCGI-Adapters");
- if (!AssetDatabase.IsValidFolder("Assets/_pi_/_LTCGI-Adapters/Editor"))
- AssetDatabase.CreateFolder("Assets/_pi_/_LTCGI-Adapters", "Editor");
-
- var changed = false;
-
- // ProTv
- if (AssetDatabase.IsValidFolder("Assets/ArchiTechAnon/ProTV") && (!System.IO.File.Exists("Assets/_pi_/_LTCGI-Adapters/protv_adapter_version.txt") || System.IO.File.ReadAllText("Assets/_pi_/_LTCGI-Adapters/protv_adapter_version.txt") != PROTV_ADAPTER_VERSION))
- {
- EditorUtility.DisplayDialog("LTCGI", "ProTv detected, enabling ProTv adapter.", "OK");
-
- System.IO.File.WriteAllText("Assets/_pi_/_LTCGI-Adapters/protv_adapter_version.txt", PROTV_ADAPTER_VERSION);
-
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_ProTvAdapter.cs_disabled", "Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.cs", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_ProTvAdapter.cs_disabled.meta", "Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.cs.meta", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_ProTvAdapter.asset_disabled", "Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.asset", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_ProTvAdapter.asset_disabled.meta", "Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.asset.meta", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/Editor/LTCGI_ProTvAdapterAutoSetup.cs_disabled", "Assets/_pi_/_LTCGI-Adapters/Editor/LTCGI_ProTvAdapterAutoSetup.cs", true);
-
- AssetDatabase.ImportAsset("Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.asset", ImportAssetOptions.ForceSynchronousImport);
- AssetDatabase.Refresh();
-
- UdonSharpProgramAsset adapter = AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>("Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.asset");
- adapter.sourceCsScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/_pi_/_LTCGI-Adapters/LTCGI_ProTvAdapter.cs");
- adapter.ApplyProgram();
- EditorUtility.SetDirty(adapter);
-
- changed = true;
- }
-
- // USharpVideo
- if (AssetDatabase.IsValidFolder("Assets/USharpVideo") && (!System.IO.File.Exists("Assets/_pi_/_LTCGI-Adapters/usharpvideo_adapter_version.txt") || System.IO.File.ReadAllText("Assets/_pi_/_LTCGI-Adapters/usharpvideo_adapter_version.txt") != UDONSHARP_ADAPTER_VERSION))
- {
- EditorUtility.DisplayDialog("LTCGI", "USharpVideo detected, enabling USharpVideo adapter.", "OK");
-
- System.IO.File.WriteAllText("Assets/_pi_/_LTCGI-Adapters/usharpvideo_adapter_version.txt", UDONSHARP_ADAPTER_VERSION);
-
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_USharpVideoAdapter.cs_disabled", "Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.cs", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_USharpVideoAdapter.cs_disabled.meta", "Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.cs.meta", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_USharpVideoAdapter.asset_disabled", "Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.asset", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/LTCGI_USharpVideoAdapter.asset_disabled.meta", "Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.asset.meta", true);
- System.IO.File.Copy("Packages/at.pimaker.ltcgi/Adapters/Editor/LTCGI_USharpVideoAdapterAutoSetup.cs_disabled", "Assets/_pi_/_LTCGI-Adapters/Editor/LTCGI_USharpVideoAdapterAutoSetup.cs", true);
-
- AssetDatabase.ImportAsset("Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.asset", ImportAssetOptions.ForceSynchronousImport);
- AssetDatabase.Refresh();
-
- UdonSharpProgramAsset adapter = AssetDatabase.LoadAssetAtPath<UdonSharpProgramAsset>("Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.asset");
- adapter.sourceCsScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/_pi_/_LTCGI-Adapters/LTCGI_USharpVideoAdapter.cs");
- adapter.ApplyProgram();
- EditorUtility.SetDirty(adapter);
-
- changed = true;
- }
-
- if (changed)
- {
- AssetDatabase.SaveAssets();
- UdonSharp.Compiler.UdonSharpCompilerV1.CompileSync();
- }
-#endif
- }
- }
-
- public interface ILTCGI_AutoSetup
- {
- // returns value if set up
- GameObject AutoSetupEditor(LTCGI_Controller controller);
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerBake.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerBake.cs
deleted file mode 100644
index 11d9eab..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerBake.cs
+++ /dev/null
@@ -1,484 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEditor;
-using UnityEditor.SceneManagement;
-using UnityEngine;
-using UnityEngine.Rendering;
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- public partial class LTCGI_Controller
- {
- [Header("Lightmap Baking Cache (do not edit!)")]
- [SerializeField] internal List<Material> bakeMaterialReset_key;
- [SerializeField] private List<MaterialGlobalIlluminationFlags> bakeMaterialReset_val;
- [SerializeField] public bool bakeInProgress;
- [SerializeField] private LightingDataAsset prevLightmapData;
- [SerializeField] private Texture2D[] prevLightmaps0;
- [SerializeField] private Texture2D[] prevLightmaps1;
- [SerializeField] private Texture2D[] prevLightmaps2;
- [SerializeField] private Texture2D[] prevLightmaps3;
- [SerializeField] private LightmapsMode prevLightmapMode;
-
- [SerializeField] private Texture2D[] _LTCGI_Lightmaps;
- [SerializeField] private Renderer[] _LTCGI_LightmapData_key;
- [SerializeField] private Vector4[] _LTCGI_LightmapOffsets_val;
- [SerializeField] private int[] _LTCGI_LightmapIndex_val;
-
- [SerializeField] private bool followupWithRealBake;
- [SerializeField] private bool followupBakery;
-
- public bool HasLightmapData() => _LTCGI_Lightmaps != null && _LTCGI_Lightmaps.Length > 0;
- public void ClearLightmapData()
- {
- _LTCGI_Lightmaps = null;
- _LTCGI_LightmapData_key = null;
- _LTCGI_LightmapOffsets_val = null;
- _LTCGI_LightmapIndex_val = null;
- }
-
- [MenuItem("Tools/LTCGI/Bake Shadowmap")]
- public static void BakeLightmap()
- {
- var bakery = false;
- #if BAKERY_INCLUDED
- bakery = EditorUtility.DisplayDialog("LTCGI", "Bakery has been detected in your project. Do you want to bake the lightmap with Bakery?", "Yes, use Bakery", "No, use built-in");
- #endif
- LTCGI_Controller.Singleton.BakeLightmap(bakery, false);
- }
-
- [MenuItem("Tools/LTCGI/Bake Shadowmap and Normal Lightmap")]
- public static void BakeLightmapFollowup()
- {
- var bakery = false;
- #if BAKERY_INCLUDED
- bakery = EditorUtility.DisplayDialog("LTCGI", "Bakery has been detected in your project. Do you want to bake the lightmap with Bakery?", "Yes, use Bakery", "No, use built-in");
- #endif
- LTCGI_Controller.Singleton.BakeLightmap(bakery, true);
- }
-
- internal void BakeLightmap(bool bakery, bool followup)
- {
- if (Lightmapping.isRunning
- #if BAKERY_INCLUDED
- || ftRenderLightmap.bakeInProgress
- #endif
- ) {
- Debug.Log("A lightmapping job is already running. Try again when it is done.");
- return;
- }
-
- #if !BAKERY_INCLUDED
- bakery = false;
- #endif
-
- followupWithRealBake = followup;
- followupBakery = bakery;
-
- LTCGI_Controller.Singleton.UpdateMaterials();
- Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
-
- EditorUtility.DisplayProgressBar("Preparing LTCGI bake", "Disabling all external GI contributors", 0.0f);
-
- bakeMaterialReset_key = new List<Material>();
- bakeMaterialReset_val = new List<MaterialGlobalIlluminationFlags>();
-
- // disable all other contributors
- var allRenderers = GameObject.FindObjectsOfType<Renderer>();
- foreach (var renderer in allRenderers)
- {
- foreach (var m in renderer.sharedMaterials)
- {
- if (m != null && !bakeMaterialReset_key.Contains(m))
- {
- bakeMaterialReset_key.Add(m);
- bakeMaterialReset_val.Add(m.globalIlluminationFlags);
- m.globalIlluminationFlags = MaterialGlobalIlluminationFlags.None;
- }
- }
- }
-
- var bakeResets = new Dictionary<GameObject, LTCGI_BakeReset>();
- LTCGI_BakeReset resetter(GameObject obj)
- {
- if (bakeResets.ContainsKey(obj)) return bakeResets[obj];
- var bakeReset = obj.gameObject.AddComponent<LTCGI_BakeReset>();
- bakeResets.Add(obj, bakeReset);
- return bakeReset;
- }
-
- var allLights = GameObject.FindObjectsOfType<Light>();
- foreach (var light in allLights)
- {
- if (light.gameObject.activeSelf)
- {
- light.gameObject.SetActive(false);
- var r = resetter(light.gameObject);
- r.Reenable = true;
- }
- }
-
- #if BAKERY_INCLUDED
- var allBakeryLights =
- GameObject.FindObjectsOfType<BakerySkyLight>().Select(x => x.gameObject)
- .Concat(GameObject.FindObjectsOfType<BakeryPointLight>().Select(x => x.gameObject))
- .Concat(GameObject.FindObjectsOfType<BakeryLightMesh>().Select(x => x.gameObject))
- .Concat(GameObject.FindObjectsOfType<BakeryDirectLight>().Select(x => x.gameObject));
- foreach (var light in allBakeryLights)
- {
- if (light.activeSelf && (!light.TryGetComponent<BakeryLightMesh>(out _) || !light.TryGetComponent<LTCGI_Screen>(out _)))
- {
- light.SetActive(false);
- var r = resetter(light.gameObject);
- r.Reenable = true;
- }
- }
- #endif
-
- var allReflProbes = GameObject.FindObjectsOfType<ReflectionProbe>();
- foreach (var reflProbe in allReflProbes)
- {
- if (reflProbe.gameObject.activeSelf)
- {
- reflProbe.gameObject.SetActive(false);
- var r = resetter(reflProbe.gameObject);
- r.Reenable = true;
- }
- }
-
- EditorUtility.DisplayProgressBar("Preparing LTCGI bake", "Making LTCGI_Screens emissive", 0.5f);
-
- // make screen emissive
- var allScreens = GameObject.FindObjectsOfType<LTCGI_Screen>();
- foreach (var scr in allScreens)
- {
- if (scr.LightmapChannel == 0 || !scr.enabled) continue;
- var intens = LightmapIntensity * scr.LightmapIntensity;
- var mat = new Material(Shader.Find("Standard"));
- var col = scr.LightmapChannel == 1 ? new Color(intens, 0, 0, 1) : (
- scr.LightmapChannel == 2 ? new Color(0, intens, 0, 1) : (
- scr.LightmapChannel == 3 ? new Color(0, 0, intens, 1) :
- new Color(0, 0, 0, 1)));
- mat.SetColor("_EmissionColor", col);
- mat.EnableKeyword("_EMISSION");
- mat.doubleSidedGI = true; // scr.DoubleSided ??
- mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
-
- Action<Renderer> handleRenderer = (rend) => {
- var flags = GameObjectUtility.GetStaticEditorFlags(rend.gameObject);
- var r = resetter(rend.gameObject);
- #if BAKERY_INCLUDED
- if (rend.TryGetComponent(out BakeryLightMesh lightMesh))
- {
- rend.gameObject.SetActive(true);
- r.ResetLightMesh = true;
- r.lightMeshColor = lightMesh.color;
- r.lightMeshIntensity = lightMesh.intensity;
- lightMesh.color = new Color(col.r / intens, col.g / intens, col.b / intens, 1);
- lightMesh.intensity = intens;
- }
- else
- #endif
- {
- r.ResetData = true;
- r.Materials = rend.sharedMaterials;
- r.Flags = flags;
- r.ShadowCastingMode = rend.shadowCastingMode;
- if (rend.shadowCastingMode == ShadowCastingMode.Off || rend.shadowCastingMode == ShadowCastingMode.ShadowsOnly)
- {
- rend.shadowCastingMode = ShadowCastingMode.On;
- }
- rend.sharedMaterials = new Material[] { mat };
- GameObjectUtility.SetStaticEditorFlags(rend.gameObject, flags | StaticEditorFlags.ContributeGI);
- }
-
- if (!rend.enabled)
- {
- Debug.LogWarning("LTCGI: An object with an LTCGI_Screen component has a disabled renderer, it will be forcibly enabled for the bake", rend.gameObject);
- rend.enabled = true;
- r.DisableRendererComponents = new Renderer[] { rend };
- }
- };
-
- LTCGI_Emitter emitter;
- if ((emitter = scr as LTCGI_Emitter) != null)
- {
- foreach (var rend in emitter.EmissiveRenderers)
- {
- handleRenderer(rend);
- }
- }
- else
- {
- if (scr.gameObject.TryGetComponent<MeshRenderer>(out MeshRenderer rend))
- {
- handleRenderer(rend);
- }
- else
- {
- /* There is no mesh renderer on this object */
- Debug.LogWarning("LTCGI: An object with an LTCGI_Screen component has no mesh renderer, it will not contribute shadows to this bake", scr.gameObject);
- }
- }
- }
-
- bakeInProgress = true;
- EditorSceneManager.MarkSceneDirty(gameObject.scene);
- EditorSceneManager.SaveOpenScenes();
- EditorUtility.ClearProgressBar();
-
- if (!AssetDatabase.IsValidFolder("Assets/LTCGI-Generated"))
- AssetDatabase.CreateFolder("Assets", "LTCGI-Generated");
-
- /*prevLightmapData = Lightmapping.lightingDataAsset;
- Lightmapping.lightingDataAsset = null;
- LightmapSettings.lightmaps = null;
- prevLightmapMode = LightmapSettings.lightmapsMode;
- prevLightmaps0 = new Texture2D[LightmapSettings.lightmaps.Length];
- prevLightmaps1 = new Texture2D[LightmapSettings.lightmaps.Length];
- prevLightmaps2 = new Texture2D[LightmapSettings.lightmaps.Length];
- prevLightmaps3 = new Texture2D[LightmapSettings.lightmaps.Length];
- for (int i = 0; i < LightmapSettings.lightmaps.Length; i++)
- {
- prevLightmaps0[i] = LightmapSettings.lightmaps[i].lightmapColor;
- prevLightmaps1[i] = LightmapSettings.lightmaps[i].lightmapDir;
- #pragma warning disable 0618
- prevLightmaps2[i] = LightmapSettings.lightmaps[i].lightmapLight;
- #pragma warning restore 0618
- prevLightmaps3[i] = LightmapSettings.lightmaps[i].shadowMask;
- }*/
-
- UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
-
- Debug.Log("LTCGI: Shadowmap bake started");
-
- //EditorUtility.DisplayDialog("LTCGI bake", "Bake your lightmap now using either the integrated Unity lightmap baking tools or Bakery, and when finished another message should come up. If not, go back to the Controller object and manually click 'Semi-Auto Bake Shadowmap FINISH'.", "OK");
-
- if (!bakery)
- {
- Lightmapping.bakeCompleted += BakeCompleteEvent;
- EditorUtility.DisplayDialog("LTCGI", "Please don't touch the scene during async bake.", "I promise!");
- Lightmapping.BakeAsync();
- }
-
- #if BAKERY_INCLUDED
- if (bakery)
- {
- ftRenderLightmap.OnFinishedFullRender += BakeCompleteEvent;
- var b = ftRenderLightmap.instance;
- if (b == null)
- {
- b = ftRenderLightmap.instance = ftRenderLightmap.CreateInstance<ftRenderLightmap>();
- //EditorUtility.DisplayDialog("LTCGI", "Bakery instance not found, please bake lightmaps manually now.", "OK");
- }
- //else
- {
- b.Show();
- b.SaveRenderSettings();
- b.LoadRenderSettings();
- // "Asset UV processing" = "Don't change"
- ftBuildGraphics.unwrapUVs = false;
- ftBuildGraphics.forceDisableUnwrapUVs = false;
- b.SaveRenderSettings();
- EditorApplication.delayCall += () => {
- b.RenderButton(false);
- };
- }
- }
- #endif
- }
-
- private static void BakeCompleteEvent()
- {
- var obj = GameObject.FindObjectOfType<LTCGI_Controller>();
-
- if (!obj.bakeInProgress) return;
-
- Lightmapping.bakeCompleted -= BakeCompleteEvent;
- #if BAKERY_INCLUDED
- ftRenderLightmap.OnFinishedFullRender -= BakeCompleteEvent;
- #endif
-
- EditorApplication.delayCall += obj.BakeComplete;
- }
- private static void BakeCompleteEvent(object a, EventArgs b) => BakeCompleteEvent();
- internal void BakeComplete()
- {
- try
- {
- BakeCompleteProg();
- }
- finally
- {
- followupWithRealBake = false;
-
- // avoid stuck progress bar
- EditorUtility.ClearProgressBar();
-
- // I think this should be safe, and avoid some issues with data not being reset
- ResetConfiguration();
- }
- }
- internal void BakeCompleteProg()
- {
- //EditorUtility.DisplayDialog("LTCGI bake", "Lightmap baking has finished, LTCGI will now apply the generated configuration.", "OK");
-
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Copying calculated lightmaps", 0.0f);
-
- // move away calculated lightmap assets
- var curscene = EditorSceneManager.GetActiveScene().name;
- AssetDatabase.DeleteAsset("Assets/LTCGI-Generated/Lightmaps-" + curscene);
- AssetDatabase.CreateFolder("Assets/LTCGI-Generated", "Lightmaps-" + curscene);
- for (int i = 0; i < LightmapSettings.lightmaps.Length; i++)
- {
- LightmapData lm = LightmapSettings.lightmaps[i];
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Copying calculated lightmaps", i/((float)LightmapSettings.lightmaps.Length-1.0f));
- var tex = lm.lightmapColor;
- var path = AssetDatabase.GetAssetPath(tex);
- AssetDatabase.CopyAsset(path, "Assets/LTCGI-Generated/Lightmaps-" + curscene + "/" + System.IO.Path.GetFileName(path));
- }
- AssetDatabase.Refresh();
-
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Caching lightmaps", 0.0f);
-
- // Copy data to LTCGI buffer, so that other bakes don't influence it
- _LTCGI_Lightmaps = new Texture2D[LightmapSettings.lightmaps.Length];
- for (int i = 0; i < LightmapSettings.lightmaps.Length; i++)
- {
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Caching lightmaps", i/((float)LightmapSettings.lightmaps.Length-1.0f));
- var tex = LightmapSettings.lightmaps[i].lightmapColor;
- var path = AssetDatabase.GetAssetPath(tex);
- var tex2 = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/LTCGI-Generated/Lightmaps-" + curscene + "/" + System.IO.Path.GetFileName(path));
- SetTextureImporterToLightmap(tex2);
- _LTCGI_Lightmaps[i] = tex2;
- }
-
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Applying indexed lightmaps to renderers", 0.0f);
-
- var renderers = GameObject.FindObjectsOfType<Renderer>();
- var rkey = new List<Renderer>();
- var rval = new List<Vector4>();
- var rival = new List<int>();
- for (int i = 0; i < renderers.Length; i++)
- {
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Applying indexed lightmaps to renderers", i/((float)renderers.Length-1.0f));
- var r = renderers[i];
- if (GameObjectUtility.AreStaticEditorFlagsSet(r.gameObject, StaticEditorFlags.ContributeGI))
- {
- rkey.Add(r);
- rval.Add(r.lightmapScaleOffset);
- rival.Add(r.lightmapIndex);
-
- foreach (var m in r.sharedMaterials)
- {
- if (MatLTCGIenabled(m))
- {
- // Disable static batching for all objects we double-lightmap, as
- // otherwise Unity bakes unity_LightmapST into the UV channels and
- // breaks our custom offsets.
- var flags = GameObjectUtility.GetStaticEditorFlags(r.gameObject);
- flags &= ~StaticEditorFlags.BatchingStatic;
- GameObjectUtility.SetStaticEditorFlags(r.gameObject, flags);
- break;
- }
- }
- }
- }
- _LTCGI_LightmapData_key = rkey.ToArray();
- _LTCGI_LightmapOffsets_val = rval.ToArray();
- _LTCGI_LightmapIndex_val = rival.ToArray();
-
- EditorUtility.DisplayProgressBar("Finishing LTCGI bake", "Resetting configuration", 1.0f);
- bakeInProgress = false;
- ResetConfiguration();
-
- /*Lightmapping.lightingDataAsset = prevLightmapData;
- LightmapSettings.lightmapsMode = prevLightmapMode;
- LightmapSettings.lightmaps = new LightmapData[prevLightmaps0.Length];
- for (int i = 0; i < LightmapSettings.lightmaps.Length; i++)
- {
- var data = new LightmapData();
- data.lightmapColor = prevLightmaps0[i];
- data.lightmapDir = prevLightmaps1[i];
- #pragma warning disable 0618
- data.lightmapLight = prevLightmaps2[i];
- #pragma warning restore 0618
- data.shadowMask = prevLightmaps3[i];
- LightmapSettings.lightmaps[i] = data;
- }*/
-
- EditorUtility.ClearProgressBar();
- LTCGI_Controller.Singleton.UpdateMaterials();
-
- Debug.Log("LTCGI: Shadowmap bake complete!");
-
- if (followupWithRealBake)
- {
- followupWithRealBake = false;
-
- #if BAKERY_INCLUDED
- if (followupBakery)
- {
- EditorApplication.delayCall += () => {
- var b = ftRenderLightmap.instance;
- b.RenderButton(false);
- };
- }
- else
- #endif
- {
- EditorApplication.delayCall += () => {
- Lightmapping.BakeAsync();
- };
- }
- }
- }
-
- // includes ones on hidden/disabled objects
- private List<LTCGI_BakeReset> GetAllBakeResets()
- {
- List<LTCGI_BakeReset> found = new List<LTCGI_BakeReset>();
- foreach (LTCGI_BakeReset br in Resources.FindObjectsOfTypeAll(typeof(LTCGI_BakeReset)) as LTCGI_BakeReset[])
- {
- if (!EditorUtility.IsPersistent(br.gameObject.transform.root.gameObject) &&
- !(br.gameObject.hideFlags == HideFlags.NotEditable || br.gameObject.hideFlags == HideFlags.HideAndDontSave))
- {
- found.Add(br);
- }
- }
- return found;
- }
-
- [MenuItem("Tools/LTCGI/Force Settings Reset after Bake")]
- public static void ResetConfigurationMenu() => LTCGI_Controller.Singleton.ResetConfiguration();
- public void ResetConfiguration()
- {
- if (bakeMaterialReset_key != null)
- {
- for (int i = 0; i < bakeMaterialReset_key.Count; i++)
- {
- bakeMaterialReset_key[i].globalIlluminationFlags = bakeMaterialReset_val[i];
- }
- }
-
- var resetters = GetAllBakeResets();
- foreach (LTCGI_BakeReset r in resetters)
- {
- if (r)
- {
- r.ApplyReset();
- DestroyImmediate(r);
- }
- }
-
- AssetDatabase.SaveAssets();
- EditorSceneManager.MarkAllScenesDirty();
- EditorSceneManager.SaveOpenScenes();
- }
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerExternal.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerExternal.cs
deleted file mode 100644
index ce9e07d..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerExternal.cs
+++ /dev/null
@@ -1,512 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEditor;
-using UnityEngine;
-using UnityEditor.Build.Reporting;
-#if VRC_SDK_VRCSDK2 || UDONSHARP
-using VRC.SDKBase.Editor.BuildPipeline;
-#endif
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- [CustomEditor(typeof(LTCGI_Controller))]
- public class LTCGI_ControllerEditor : Editor
- {
- const string VERSION = "v1.0.2";
-
- private static readonly string[] CONFIGURATION_PROPS = new[] {
- "StaticTextures",
- "DynamicRenderers",
- "CustomBlurChain",
- "LightmapIntensity",
- "LightmapMultiplier"
- };
-
- private static Texture Logo;
-
- private bool debugFoldout = false;
-
- private static string configPath;
-
- private static Dictionary<string, object> configChangedValues = new Dictionary<string, object>();
-
- private enum ConfigType
- {
- Boolean,
- Float,
- }
-
- public void OnEnable()
- {
- Logo = Resources.Load("LTCGI-LogoController") as Texture;
-
- if (configChangedValues != null)
- {
- configChangedValues.Clear();
- }
- }
-
- private bool _configChanged = false;
-
- public override void OnInspectorGUI()
- {
- GUIStyle style = new GUIStyle(EditorStyles.label);
- style.alignment = TextAnchor.MiddleCenter;
- style.fixedHeight = 150;
- GUI.Box(GUILayoutUtility.GetRect(300, 150, style), Logo, style);
-
- var rightAlignedLabel = new GUIStyle(EditorStyles.label);
- rightAlignedLabel.alignment = TextAnchor.MiddleRight;
- GUILayout.Label(VERSION, rightAlignedLabel);
-
-
- bool applyButtonPressed = false;
- bool revertButtonPressed = false;
-
- var resetCol = GUI.backgroundColor;
-
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Getting%20Started/Setup/Controller");
-
- if (PrefabUtility.IsPartOfPrefabAsset(target))
- {
- var large = new GUIStyle(EditorStyles.wordWrappedLabel);
- large.fontSize = 32;
- GUILayout.Label("Please put exactly 1 instance of this prefab into your scene!", large);
- return;
- }
-
- #if !UDONSHARP
- if (LTCGI_Controller.RuntimeMode == LTCGI_Controller.LTCGIRuntimeMode.VRChatWorld)
- {
- const string msg = "LTCGI for VRChat requires at least UdonSharp 1.0 to be installed in your project!";
- Debug.LogError(msg);
- EditorGUILayout.HelpBox(msg, MessageType.Error);
- }
- #endif
-
- serializedObject.Update();
-
- if (GUILayout.Button("Force Update"))
- {
- LTCGI_Controller.Singleton.UpdateMaterials();
- }
-
- if (GUILayout.Button("Precompute Static Textures"))
- {
- LTCGI_Controller.Singleton.CreateLODTextureArrays();
- }
- EditorGUILayout.PropertyField(serializedObject.FindProperty("PrecomputeOnBuild"));
-
- EditorGUILayout.Separator();
-
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Advanced/Shadowmaps", "Shadowmap Baking");
-
- if (!LTCGI_Controller.Singleton.bakeInProgress && GUILayout.Button("Bake Shadowmap"))
- {
- LTCGI_Controller.BakeLightmap();
- }
- else if (!LTCGI_Controller.Singleton.bakeInProgress && GUILayout.Button("Bake Shadowmap and Normal Lightmap"))
- {
- LTCGI_Controller.BakeLightmapFollowup();
- }
- if (LTCGI_Controller.Singleton.bakeInProgress && GUILayout.Button("Bake Shadowmap - FORCE FINISH"))
- {
- LTCGI_Controller.Singleton.BakeComplete();
- }
-
- GUI.backgroundColor = Color.red;
- if (LTCGI_Controller.Singleton.bakeMaterialReset_key != null && GUILayout.Button("DEBUG: Force Settings Reset after Bake"))
- {
- LTCGI_Controller.Singleton.ResetConfiguration();
- }
-
- if (!LTCGI_Controller.Singleton.bakeInProgress && LTCGI_Controller.Singleton.HasLightmapData() &&
- GUILayout.Button("Clear Baked Data"))
- {
- LTCGI_Controller.Singleton.ResetConfiguration();
- LTCGI_Controller.Singleton.ClearLightmapData();
- LTCGI_Controller.Singleton.UpdateMaterials();
- }
- GUI.backgroundColor = resetCol;
-
- EditorGUILayout.Space(); EditorGUILayout.Space();
-
- LTCGI_Controller.DrawAutoSetupEditor(LTCGI_Controller.Singleton);
-
- EditorGUILayout.Space(); EditorGUILayout.Space();
-
- if (LTCGI_Controller.Singleton.cachedMeshRenderers != null && LTCGI_Controller.Singleton._LTCGI_ScreenTransforms != null)
- {
- EditorGUILayout.HelpBox(
-$@"Affected Renderers Total: {LTCGI_Controller.Singleton.cachedMeshRenderers.Length}
-LTCGI_Screen Components: {LTCGI_Controller.Singleton._LTCGI_ScreenTransforms.Count(x => x != null)} / {LTCGI_Controller.MAX_SOURCES}
-AudioLink: {(LTCGI_Controller.AudioLinkAvailable == LTCGI_Controller.AudioLinkAvailability.Unavailable ? "Not Detected" : (LTCGI_Controller.AudioLinkAvailable == LTCGI_Controller.AudioLinkAvailability.AvailableAsset ? "Detected (Asset)" : "Detected (Package)"))}",
- MessageType.Info, true
- );
-
- if (LTCGI_Controller.AudioLinkAvailable == LTCGI_Controller.AudioLinkAvailability.Unavailable)
- {
- if (GUILayout.Button("Re-Detect AudioLink"))
- {
- LTCGI_Controller.audioLinkAvailable = LTCGI_Controller.AudioLinkAvailability.NeedsCheck;
- var _ignored = LTCGI_Controller.AudioLinkAvailable;
- }
- }
- }
- else
- {
- EditorGUILayout.HelpBox("Hit \"Force Update\" or CTRL-S to calculate info!", MessageType.Info);
- }
-
- EditorGUILayout.Space(); EditorGUILayout.Space();
- var header = new GUIStyle(EditorStyles.boldLabel);
- header.fontSize += 4;
- GUILayout.Label("LTCGI Configuration", header);
- EditorGUILayout.Space();
-
- var vidTex = serializedObject.FindProperty("VideoTexture");
- EditorGUILayout.PropertyField(vidTex, true);
- if (vidTex.objectReferenceValue == null)
- {
- EditorGUILayout.HelpBox("Video Texture is not set! This means video player will not reflect their screen. use Auto-Configure options above or refer to documentation on how to set this up if required.", MessageType.Warning);
- }
-
- foreach (var prop in CONFIGURATION_PROPS)
- {
- EditorGUILayout.PropertyField(serializedObject.FindProperty(prop), true);
- }
-
- // multiplier clamp, negative light go brrr
- var lmm = serializedObject.FindProperty("LightmapMultiplier");
- lmm.vector3Value = new Vector3(Mathf.Max(0.0f, lmm.vector3Value.x), Mathf.Max(0.0f, lmm.vector3Value.y), Mathf.Max(0.0f, lmm.vector3Value.z));
-
- EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();
- GUILayout.Label("Global Shader Options", header);
- EditorGUILayout.Space();
-
- if (_configChanged)
- {
- using (new GUILayout.HorizontalScope())
- {
- var bigButton = new GUIStyle(GUI.skin.button);
- bigButton.fixedHeight = 40.0f;
- bigButton.fontStyle = FontStyle.Bold;
- bigButton.fontSize = 18;
- bigButton.normal.textColor = Color.white;
- bigButton.hover.textColor = Color.white;
- resetCol = GUI.backgroundColor;
- GUI.backgroundColor = Color.red;
- if (GUILayout.Button("Apply", bigButton))
- {
- applyButtonPressed = true;
- }
- GUI.backgroundColor = Color.blue;
- if (GUILayout.Button("Revert", bigButton))
- {
- revertButtonPressed = true;
- }
- GUI.backgroundColor = resetCol;
- }
- }
-
- RecalculateAutoConfig(target as LTCGI_Controller);
-
- var config = File.ReadAllLines(configPath);
- var description = "";
- var resetDesc = false;
- for (int i = 0; i < config.Length; i++)
- {
- string lineRaw = config[i];
- var line = lineRaw.Trim();
- if (string.IsNullOrEmpty(line)) continue;
-
- if (line.StartsWith("///"))
- {
- if (resetDesc)
- {
- description = "";
- resetDesc = false;
- }
- else if (!string.IsNullOrEmpty(description))
- {
- description += Environment.NewLine;
- }
- description += line.Substring(3).Trim();
- }
- else if (description != "" && (line.StartsWith("//#define") || line.StartsWith("#define")))
- {
- var name = line.Substring(line.IndexOf(' ') + 1);
- var nextSpace = name.IndexOf(' ');
- if (nextSpace < 0) nextSpace = name.Length;
- name = name.Substring(0, nextSpace);
-
- object ccvValue;
- var existsInCcv = configChangedValues.TryGetValue(name, out ccvValue);
-
- var debug = description.StartsWith("[DEBUG]");
- description = description.Replace(Environment.NewLine, " ");
-
- var type = line.Count(char.IsWhiteSpace) > 1 ? ConfigType.Float : ConfigType.Boolean;
-
- if (type == ConfigType.Boolean)
- {
- var enabledInConfig = line.StartsWith("#");
- var enabled = (existsInCcv && (bool)ccvValue) || (!existsInCcv && enabledInConfig);
-
- var toggleStyle = new GUIStyle(GUI.skin.toggle);
- if (debug)
- {
- toggleStyle.normal.textColor = Color.gray;
- toggleStyle.hover.textColor = Color.gray;
- }
- var set = GUILayout.Toggle(enabled, name, toggleStyle);
-
- EditorGUILayout.HelpBox(description, MessageType.None, true);
- EditorGUILayout.Space();
-
- if (set != enabledInConfig)
- {
- configChangedValues[name] = set;
- if (set)
- {
- config[i] = config[i].Substring(2);
- }
- else
- {
- config[i] = "//" + config[i];
- }
- }
- else
- {
- configChangedValues.Remove(name);
- }
- }
- else if (type == ConfigType.Float)
- {
- var valueInConfig = float.Parse(line.Substring(line.LastIndexOf(' ')).Replace('f', ' '), System.Globalization.CultureInfo.InvariantCulture);
- var value = existsInCcv ? (float)ccvValue : valueInConfig;
-
- var labelStyle = new GUIStyle(GUI.skin.label);
- if (debug)
- {
- labelStyle.normal.textColor = Color.gray;
- labelStyle.hover.textColor = Color.gray;
- }
- float set;
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label(name, labelStyle);
- set = EditorGUILayout.FloatField(value);
- }
-
- EditorGUILayout.HelpBox(description, MessageType.None, true);
- EditorGUILayout.Space();
-
- if (set != valueInConfig)
- {
- configChangedValues[name] = set;
- config[i] = $"#define {name} {set}";
- }
- else
- {
- configChangedValues.Remove(name);
- }
- }
-
- resetDesc = true;
- }
- }
-
- _configChanged = configChangedValues.Count > 0;
-
- if (applyButtonPressed)
- {
- File.WriteAllLines(configPath, config);
- AssetDatabase.Refresh();
- configChangedValues = new Dictionary<string, object>();
- }
- else if (revertButtonPressed)
- {
- configChangedValues = new Dictionary<string, object>();
- }
-
- EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();
- if ((debugFoldout = EditorGUILayout.Foldout(debugFoldout, "[ Debug Menu (Default Inspector) ]")))
- {
- DrawDefaultInspector();
- }
-
- var update = serializedObject.hasModifiedProperties;
- serializedObject.ApplyModifiedProperties();
-
- if (update)
- {
- LTCGI_Controller.Singleton.UpdateMaterials();
- }
- }
-
- public static void RecalculateAutoConfig(LTCGI_Controller controller)
- {
- if (configPath == null || !File.Exists(configPath))
- {
- configPath = AssetDatabase.GUIDToAssetPath("01c8aa443e7001b45b28cfe65d1c6786");
- if (string.IsNullOrEmpty(configPath))
- {
- Debug.LogError("LTCGI: Could not find config file! Please don't change the GUID or move the meta file!");
- return;
- }
- }
-
- var config = File.ReadAllLines(configPath);
- var changed = false;
- for (int i = 0; i < config.Length; i++)
- {
- string lineRaw = config[i];
- var line = lineRaw.Trim();
- if (string.IsNullOrEmpty(line)) continue;
-
- if (line.EndsWith("#define LTCGI_AUDIOLINK"))
- {
- var enabledInConfig = !line.StartsWith("//");
- var available = LTCGI_Controller.AudioLinkAvailable != LTCGI_Controller.AudioLinkAvailability.Unavailable;
- if (enabledInConfig != available)
- {
- config[i] = (available ? "" : "//") + "#define LTCGI_AUDIOLINK";
- changed = true;
- }
- }
- if (line.StartsWith("#include")) // cursed, but audiolink is the only include for now
- {
- var newConfig = (LTCGI_Controller.AudioLinkAvailable != LTCGI_Controller.AudioLinkAvailability.Unavailable ? (
- LTCGI_Controller.AudioLinkAvailable == LTCGI_Controller.AudioLinkAvailability.AvailableAsset ?
- "#include \"Assets/AudioLink/Shaders/AudioLink.cginc\"" :
- "#include \"Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.cginc\""
- ) : "#include \"not-available\"");
- if (config[i] != newConfig)
- {
- config[i] = newConfig;
- changed = true;
- }
- }
-
- if (controller != null)
- {
- if (line.EndsWith("#define LTCGI_STATIC_UNIFORMS"))
- {
- var enabledInConfig = !line.StartsWith("//");
- var available = !controller.HasDynamicScreens;
- if (enabledInConfig != available)
- {
- config[i] = (available ? "" : "//") + "#define LTCGI_STATIC_UNIFORMS";
- changed = true;
- }
- }
-
- if (line.EndsWith("#define LTCGI_CYLINDER"))
- {
- var enabledInConfig = !line.StartsWith("//");
- var available = controller.HasCylinders;
- if (enabledInConfig != available)
- {
- config[i] = (available ? "" : "//") + "#define LTCGI_CYLINDER";
- changed = true;
- }
- }
- }
-
- if (line.EndsWith("#define LTCGI_AVATAR_MODE"))
- {
- var enabledInConfig = !line.StartsWith("//");
- var enabledByProject = LTCGI_Controller.RuntimeMode == LTCGI_Controller.LTCGIRuntimeMode.VRChatAvatar;
- if (enabledInConfig != enabledByProject)
- {
- config[i] = (enabledByProject ? "" : "//") + "#define LTCGI_AVATAR_MODE";
- changed = true;
- }
- }
- }
- if (changed)
- {
- File.WriteAllLines(configPath, config);
- AssetDatabase.Refresh();
- }
- }
- }
-
- public static class LTCGIDocsHelper
- {
- public static void DrawHelpButton(string url, string name = "Help &")
- {
- EditorGUILayout.Space();
- var bigButton = new GUIStyle(GUI.skin.button);
- bigButton.fixedHeight = 30.0f;
- bigButton.fontStyle = FontStyle.Bold;
- bigButton.fontSize = 14;
- bigButton.normal.textColor = Color.white;
- bigButton.hover.textColor = Color.white;
- var resetCol = GUI.backgroundColor;
- GUI.backgroundColor = Color.blue;
- if (GUILayout.Button($"Open {name} Documentation", bigButton))
- {
- System.Diagnostics.Process.Start(url);
- }
- GUI.backgroundColor = resetCol;
- EditorGUILayout.Space();
- }
- }
-
- // automatic callbacks
- public class ShaderPostprocessLTCGI : AssetPostprocessor
- {
- static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
- {
- if (LTCGI_Controller.Singleton != null)
- {
- EditorApplication.delayCall += LTCGI_Controller.Singleton.UpdateMaterials;
- }
- }
- }
-
- #if UDONSHARP
- public class VRCSDKHookLTCGI : IVRCSDKBuildRequestedCallback
- {
- public int callbackOrder => 68;
-
- public bool OnBuildRequested(VRCSDKRequestedBuildType requestedBuildType)
- {
- if (LTCGI_Controller.Singleton != null)
- {
- LTCGI_Controller.Singleton.UpdateMaterials();
- if (LTCGI_Controller.Singleton.PrecomputeOnBuild)
- {
- LTCGI_Controller.Singleton.CreateLODTextureArrays();
- }
- }
- return true;
- }
- }
- #else
- public class PostBuildCallbackLTCGI : UnityEditor.Build.IPreprocessBuildWithReport
- {
- public int callbackOrder => 68;
-
- public void OnPreprocessBuild(BuildReport report)
- {
- if (LTCGI_Controller.Singleton != null)
- {
- LTCGI_Controller.Singleton.UpdateMaterials();
- if (LTCGI_Controller.Singleton.PrecomputeOnBuild)
- {
- LTCGI_Controller.Singleton.CreateLODTextureArrays();
- }
- }
- }
- }
- #endif
- #endif
-}
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerHelpers.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerHelpers.cs
deleted file mode 100644
index 26ee25b..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerHelpers.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEditor;
-using UnityEngine;
-using UnityEngine.Rendering;
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- public partial class LTCGI_Controller
- {
- public enum AudioLinkAvailability
- {
- NeedsCheck,
- Unavailable,
- AvailableAsset,
- AvailablePackage,
- }
- internal static AudioLinkAvailability audioLinkAvailable = AudioLinkAvailability.NeedsCheck;
- public static AudioLinkAvailability AudioLinkAvailable {
- get {
- if (audioLinkAvailable == AudioLinkAvailability.NeedsCheck)
- {
- if (System.IO.File.Exists("Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.cginc"))
- {
- audioLinkAvailable = AudioLinkAvailability.AvailablePackage;
- }
- else if (System.IO.File.Exists("Assets/AudioLink/Shaders/AudioLink.cginc"))
- {
- audioLinkAvailable = AudioLinkAvailability.AvailableAsset;
- }
- else
- {
- audioLinkAvailable = AudioLinkAvailability.Unavailable;
- }
- }
- return audioLinkAvailable;
- }
- }
-
- public enum LTCGIRuntimeMode
- {
- Standalone,
- VRChatWorld,
- VRChatAvatar,
- }
- public static LTCGIRuntimeMode RuntimeMode
- {
- get
- {
- #if VRC_SDK_VRCSDK3
- if (System.IO.Directory.Exists("Packages\\com.vrchat.avatars"))
- return LTCGIRuntimeMode.VRChatAvatar;
- else
- return LTCGIRuntimeMode.VRChatWorld;
- #else
- return LTCGIRuntimeMode.Standalone;
- #endif
- }
- }
-
- private float[] GetMaskForRenderer(LTCGI_Screen[] screens, Renderer r)
- {
- // mask is reversed! 1 = not visible, 0 = visible
- Func<bool, float> b = cond => cond ? 1.0f : 0.0f;
- return Enumerable.Range(0, screens.Length)
- .Select(si => {
- switch (screens[si].RendererMode)
- {
- case RendererMode.OnlyListed:
- return b(!screens[si].RendererList.Contains(r));
- case RendererMode.ExcludeListed:
- return b(screens[si].RendererList.Contains(r));
- case RendererMode.Distance:
- var screenPos = screens[si].transform.position;
- var point = r.bounds.ClosestPoint(screenPos);
- var dist = Vector3.Distance(point, screenPos);
- return b(dist > screens[si].RendererDistance);
- default: // RendererMode.All
- return b(false);
- }
- })
- .ToArray();
- }
-
- private void SetTextureImporterToLightmap(Texture2D texture)
- {
- if (null == texture) return;
- string assetPath = AssetDatabase.GetAssetPath(texture);
- var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
- if (importer != null && importer.textureType != TextureImporterType.Lightmap)
- {
- importer.textureType = TextureImporterType.Lightmap;
- importer.mipmapEnabled = false;
- importer.SaveAndReimport();
- AssetDatabase.Refresh();
- }
- }
-
- private void SetMeshImporterFormat(Mesh mesh, bool readable)
- {
- if (mesh == null) return;
- string assetPath = AssetDatabase.GetAssetPath(mesh);
- if (string.IsNullOrEmpty(assetPath)) return;
- var importer = AssetImporter.GetAtPath(assetPath) as ModelImporter;
- if (importer != null && importer.isReadable != readable)
- {
- importer.isReadable = readable;
- Debug.Log("LTCGI: Read/Write set for Model " + assetPath);
- importer.SaveAndReimport();
- }
- }
-
- private void SetTextureImporterFormat(Texture2D texture, bool readable)
- {
- if (texture == null) return;
- string assetPath = AssetDatabase.GetAssetPath(texture);
- var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
- if (importer != null && importer.isReadable != readable)
- {
- importer.isReadable = readable;
- Debug.Log("LTCGI: Read/Write set for Texture " + assetPath);
- importer.SaveAndReimport();
- }
- }
-
- private Texture2D ReadIntoTexture2D(RenderTexture renderTex)
- {
- Texture2D tex = new Texture2D(renderTex.width, renderTex.height, TextureFormat.RGBA32, false, true);
- RenderTexture.active = renderTex;
- tex.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
- tex.Apply();
- RenderTexture.active = null;
- return tex;
- }
-
- private bool IsEditorOnly(GameObject obj)
- {
- return obj.tag == "EditorOnly";
- }
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerLOD.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerLOD.cs
deleted file mode 100644
index f241e72..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_ControllerLOD.cs
+++ /dev/null
@@ -1,148 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEditor;
-using UnityEditor.SceneManagement;
-using UnityEngine;
-using UnityEngine.Rendering;
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- public partial class LTCGI_Controller
- {
- public bool PrecomputeOnBuild = true;
- private Texture2D[] CreateLODs(Texture2D input, int width, int height)
- {
- var result = new Texture2D[4];
-
- // apply gamma to lod0 too and resize it
- var rt0 = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
- rt0.wrapMode = TextureWrapMode.Clamp;
- Graphics.Blit(input, rt0);
- result[0] = ReadIntoTexture2D(rt0);
- RenderTexture.DestroyImmediate(rt0);
-
- var CustomRenderTextureCenters = new Vector4[1];
- CustomRenderTextureCenters[0] = new Vector4(0.5f, 0.5f, 0, 0);
- LOD1.material.SetVectorArray("CustomRenderTextureCenters", CustomRenderTextureCenters);
- var CustomRenderTextureSizesAndRotations = new Vector4[1];
- CustomRenderTextureSizesAndRotations[0] = new Vector4(1, 1, 0, 0);
- LOD1.material.SetVectorArray("CustomRenderTextureSizesAndRotations", CustomRenderTextureSizesAndRotations);
-
- for (int i = 0; i < 3; i++)
- {
- var crt = new CustomRenderTexture[] { LOD1, LOD2, LOD3 } [i];
- var crtS = new CustomRenderTexture[] { LOD1s, LOD2s, LOD3s } [i];
- var origTex = crt.material.GetTexture("_MainTex");
- var origTexS = crtS.material.GetTexture("_MainTex");
- crtS.material.SetTexture("_MainTex", result[i]);
- var rt = new RenderTexture(width/Mathf.NextPowerOfTwo((i+1)*2), height/Mathf.NextPowerOfTwo((i+1)*2), 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
- rt.wrapMode = TextureWrapMode.Clamp;
- Graphics.Blit(result[i], rt, crtS.material, 0);
- var rt2 = new RenderTexture(rt.width, rt.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
- rt.wrapMode = TextureWrapMode.Clamp;
- crt.material.SetTexture("_MainTex", rt);
- Graphics.Blit(rt, rt2, crt.material, 1);
- result[i + 1] = ReadIntoTexture2D(rt2);
- crt.material.SetTexture("_MainTex", origTex);
- crtS.material.SetTexture("_MainTex", origTexS);
- RenderTexture.DestroyImmediate(rt);
- RenderTexture.DestroyImmediate(rt2);
- }
- return result;
- }
-
- [MenuItem("Tools/LTCGI/Precompute Static Textures")]
- public static void CreateLODTextureArraysMenu() => LTCGI_Controller.Singleton?.CreateLODTextureArrays();
-
- public void CreateLODTextureArrays()
- {
- var curscene = EditorSceneManager.GetActiveScene().name;
-
- if (StaticTextures == null || StaticTextures.Length == 0)
- {
- for (int lod = 0; lod < 4; lod++)
- {
- try
- {
- AssetDatabase.DeleteAsset("Assets/LTCGI-Generated/lod-" + curscene + "-" + lod + ".asset");
- }
- catch {}
- }
- return;
- }
-
- EditorUtility.DisplayProgressBar("LTCGI: Precomputing Static Textures", "Calculating LODs...", 0.0f);
-
- try
- {
- // Create LODs by applying blur shader
- var inputLods = new Texture2D[StaticTextures.Length, 4];
- var width = Mathf.ClosestPowerOfTwo(StaticTextures.Max(x => x.width));
- var height = Mathf.ClosestPowerOfTwo(StaticTextures.Max(x => x.height));
- for (int i = 0; i < StaticTextures.Length; i++)
- {
- var lods = CreateLODs(StaticTextures[i], width, height);
- inputLods[i, 0] = lods[0];
- inputLods[i, 1] = lods[1];
- inputLods[i, 2] = lods[2];
- inputLods[i, 3] = lods[3];
-
- EditorUtility.DisplayProgressBar("LTCGI: Precomputing Static Textures", "Calculating LODs...", 0.5f * ((float)i / (float)StaticTextures.Length));
- }
-
- EditorUtility.DisplayProgressBar("LTCGI: Precomputing Static Textures", "Generating Texture Arrays...", 0.5f);
-
- // Fill into compressed Texture2DArrays
- for (int lod = 0; lod < 4; lod++)
- {
- Texture2DArray texture2DArray = new Texture2DArray(
- inputLods[0, lod].width,
- inputLods[0, lod].height,
- StaticTextures.Length,
- TextureFormat.BC7, true, false);
- texture2DArray.wrapMode = TextureWrapMode.Clamp;
-
- for (int i = 0; i < StaticTextures.Length; i++)
- {
- SetTextureImporterFormat(inputLods[i, lod], true);
- Texture2D temp = new Texture2D(texture2DArray.width, texture2DArray.height, TextureFormat.RGBA32, true, true);
- temp.wrapMode = TextureWrapMode.Clamp;
- temp.SetPixels32(inputLods[i, lod].GetPixels32(0));
- temp.Apply();
- EditorUtility.CompressTexture(temp, TextureFormat.BC7, UnityEditor.TextureCompressionQuality.Best);
- temp.Apply();
- for (int mip = 0; mip < temp.mipmapCount; mip++) {
- Graphics.CopyTexture(temp, 0, mip, texture2DArray, i, mip);
- }
- Texture2D.DestroyImmediate(temp);
- }
-
- // Save as asset
- if (!AssetDatabase.IsValidFolder("Assets/LTCGI-Generated"))
- AssetDatabase.CreateFolder("Assets", "LTCGI-Generated");
- AssetDatabase.CreateAsset(texture2DArray, "Assets/LTCGI-Generated/lod-" + curscene + "-" + lod + ".asset");
-
- EditorUtility.DisplayProgressBar("LTCGI: Precomputing Static Textures", "Generating Texture Arrays...", 0.5f + 0.5f * (lod / 3.0f));
- }
-
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();
- }
- catch (Exception ex)
- {
- Debug.LogError(ex);
- }
- finally
- {
- EditorUtility.ClearProgressBar();
- }
-
- UpdateMaterials();
- }
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Emitter.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Emitter.cs
deleted file mode 100644
index 9dec710..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Emitter.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using UnityEditor;
-using UnityEngine;
-#endif
-
-namespace pi.LTCGI
-{
- #if UNITY_EDITOR
- [ExecuteInEditMode]
- public class LTCGI_Emitter : LTCGI_Screen
- {
- public Renderer[] EmissiveRenderers;
-
- [HideInInspector] public bool Initialized = false;
-
- public LTCGI_Emitter()
- {
- // static values for emitters
- this.Cylinder = false;
- this.Diffuse = true;
- this.DiffuseFromLm = true;
- this.DoubleSided = true;
- this.Dynamic = false;
- this.FlipUV = false;
- this.Specular = false;
- }
- }
-
- [CustomEditor(typeof(LTCGI_Emitter))]
- [CanEditMultipleObjects]
- public class LTCGI_EmitterEditor : LTCGI_ScreenEditor
- {
- public override void OnInspectorGUI()
- {
- GUIStyle style = new GUIStyle(EditorStyles.label);
- style.alignment = TextAnchor.MiddleCenter;
- style.fixedHeight = 150;
- GUI.Box(GUILayoutUtility.GetRect(300, 150, style), Logo, style);
-
- var emitter = (LTCGI_Emitter)target;
-
- if (!emitter.enabled || !emitter.gameObject.activeInHierarchy)
- {
- EditorGUILayout.Space();
- EditorGUILayout.HelpBox("This component is disabled, or the GameObject not active! This will cause it to not bake a lightmap, and can cause issues at runtime. If you want this renderer to start disabled, set it's color to Black (0,0,0) or visit https://ltcgi.dev/ to see how you can toggle LTCGI globally.", MessageType.Error, true);
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Getting%20Started/Setup/Basic_Toggle", "LTCGI Toggle");
- EditorGUILayout.Space();
- }
-
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Advanced/LTCGI_Emitter");
-
- serializedObject.Update();
-
- var emissiveRenderers = serializedObject.FindProperty("EmissiveRenderers");
-
- if (!emitter.Initialized)
- {
- serializedObject.FindProperty("Initialized").boolValue = true;
- lmProp.intValue = 1;
- emissiveRenderers.InsertArrayElementAtIndex(0);
- emissiveRenderers.GetArrayElementAtIndex(0).objectReferenceValue = emitter.GetComponent<Renderer>();
- }
-
- EditorGUILayout.HelpBox("This is an emitter component. It can only produce diffuse, untextured light. It can however apply to multiple objects and is a lot cheaper to use.", MessageType.Info);
- EditorGUILayout.Space();
-
- DrawColorSelector(emitter);
- EditorGUILayout.Space();
- DrawColorModeSelector(false);
- EditorGUILayout.Space();
- DrawRendererModeSelector();
- EditorGUILayout.Space();
- DrawLmChannelSelector();
-
- if (lmProp.intValue == 0)
- {
- EditorGUILayout.HelpBox("This emitter is not using a lightmap channel. It will not look correct.", MessageType.Warning);
- }
-
- EditorGUILayout.Space();
- EditorGUILayout.Space();
-
- EditorGUILayout.LabelField("List all emissive renderers below:", EditorStyles.boldLabel);
- EditorGUILayout.PropertyField(emissiveRenderers, true);
-
- if (serializedObject.hasModifiedProperties)
- {
- serializedObject.ApplyModifiedProperties();
- LTCGI_Controller.Singleton?.UpdateMaterials();
- }
- }
- }
- #endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Include.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Include.cs
deleted file mode 100644
index 3070a03..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Include.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-#if UNITY_EDITOR
-
-// based on similar script from Bakery
-
-using System;
-using UnityEngine;
-using UnityEditor;
-using UnityEditor.Build;
-
-[InitializeOnLoad]
-public class LTCGI_Define : IActiveBuildTargetChanged
-{
- public int callbackOrder => 0;
-
- static void AddDefine()
- {
- var platform = EditorUserBuildSettings.selectedBuildTargetGroup;
- var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform);
- if (!defines.Contains("LTCGI_INCLUDED"))
- {
- if (defines.Length > 0)
- {
- defines += ";";
- }
- defines += "LTCGI_INCLUDED";
- PlayerSettings.SetScriptingDefineSymbolsForGroup(platform, defines);
- }
- }
-
- static LTCGI_Define()
- {
- AddDefine();
- pi.LTCGI.LTCGI_Controller.MigratoryBirdsDontMigrateAsMuchAsWeDoButThisFunctionWillTakeCareOfItNonetheless();
- }
-
- public void OnActiveBuildTargetChanged(BuildTarget prev, BuildTarget cur)
- {
- AddDefine();
- }
-}
-
-#endif
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Screen.cs b/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Screen.cs
deleted file mode 100644
index a8df773..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/LTCGI_Screen.cs
+++ /dev/null
@@ -1,452 +0,0 @@
-#if UNITY_EDITOR
-using System;
-using UnityEditor;
-using UnityEngine;
-#endif
-
-namespace pi.LTCGI
-{
-#if UNITY_EDITOR
- [ExecuteInEditMode]
- public class LTCGI_Screen : MonoBehaviour
- {
- public Color Color = Color.white;
-
- public bool DoubleSided = false;
-
- [Tooltip("If enabled, allows moving the screen GameObject during runtime. Has CPU performance overhead (Udon).")]
- public bool Dynamic;
-
- public int TextureIndex;
-
- [Tooltip("Specular and Diffuse are the two types of lighting that LTCGI calculates. For performance, try disabling Diffuse and see if the result is visually similar, in which case you should leave it off.")]
- public bool Diffuse = true, Specular = true;
- public bool DiffuseFromLm;
- [SerializeField] private int diffMode;
-
- public int LightmapChannel;
- public float LightmapIntensity = 1.0f;
-
- public ColorMode ColorMode;
-
- public Vector2 SingleUV;
-
- [Range(0, 3)]
- public int AudioLinkBand;
-
- [Tooltip("Workaround for some Blender imports. Try to enable it if you notice your reflection is sideways.")]
- public bool FlipUV;
-
- public RendererMode RendererMode = RendererMode.Distance;
- public MeshRenderer[] RendererList;
- [Min(0.0f)] public float RendererDistance = 15.0f;
-
- public bool Cylinder;
- public Vector3 CylinderBase;
- public float CylinderHeight = 1.0f;
- public float CylinderRadius = 1.0f;
- [Range(0.0f, Mathf.PI*0.5f)]
- public float CylinderSize = Mathf.PI*0.5f;
- [Range(0.0f, Mathf.PI*2.0f)]
- public float CylinderAngle;
-
- [Tooltip("If this renderer should affect avatars that use a supported LTCGI shader.")]
- public bool AffectAvatars = true;
-
- private Vector3 prevPos, prevScale, prevRot;
-
- private bool update = false;
-
- private static readonly Color[] GIZMO_COLORS = new Color[]
- {
- Color.white,
- Color.red,
- Color.green,
- Color.blue,
- };
-
- public void Update()
- {
- // don't mess with Udon emulation
- if (EditorApplication.isPlaying)
- return;
-
- if (this.prevPos != this.transform.position ||
- this.prevRot != this.transform.rotation.eulerAngles ||
- this.prevScale != this.transform.lossyScale)
- {
- this.prevPos = this.transform.position;
- this.prevRot = this.transform.rotation.eulerAngles;
- this.prevScale = this.transform.lossyScale;
- update = true;
- }
- if (update && LTCGI_Controller.Singleton != null)
- {
- LTCGI_Controller.Singleton.UpdateMaterials(true, this);
- update = false;
- }
- }
-
- void OnDrawGizmos()
- {
- Gizmos.color = GIZMO_COLORS[this.LightmapChannel];
- Gizmos.DrawIcon(transform.position, "LTCGI_Screen_Gizmo.png", true, Gizmos.color);
- }
-
- private static Mesh cylMesh = null;
- void OnDrawGizmosSelected()
- {
- if (RendererMode == RendererMode.Distance)
- {
- Gizmos.color = Color.cyan;
- Gizmos.DrawWireSphere(transform.position, RendererDistance);
- }
-
- if (Cylinder)
- {
- if (cylMesh == null)
- {
- cylMesh = Resources.GetBuiltinResource<Mesh>("Cylinder.fbx");
- }
-
- Gizmos.color = new Color(0, 1, 1, 0.2f);
- Gizmos.DrawMesh(cylMesh, 0,
- transform.position + CylinderBase - Vector3.up * 0.5f + Vector3.up * CylinderHeight,
- Quaternion.AngleAxis(Mathf.Rad2Deg * CylinderAngle, Vector3.up),
- new Vector3(CylinderRadius, CylinderHeight, CylinderRadius) * 1.01f);
- }
- }
- }
-
- public enum ColorMode
- {
- Static = 0,
- Texture = 1,
- SingleUV = 2,
- AudioLink = 3,
- }
-
- public enum RendererMode
- {
- All = 0,
- ExcludeListed = 1,
- OnlyListed = 2,
- Distance = 3,
- }
-
- [CustomEditor(typeof(LTCGI_Screen))]
- [CanEditMultipleObjects]
- public class LTCGI_ScreenEditor : Editor
- {
- protected SerializedProperty colorProp, sidedProp, dynamicProp, indexProp, colormodeProp, specProp, diffProp, lmProp, singleUVProp, rendererModeProp, rendererListProp, rendererDistProp, diffModeProp, diffuseFromLmProp, flipProp, lmIntensProp, alBandProp, affectAvatarsProp;
- protected SerializedProperty cylProp, cylBaseProp, cylHeightProp, cylAngleProp, cylRadiusProp, cylSizeProp;
-
- protected static Texture Logo;
-
- protected enum LMChannel
- {
- Off = 0,
- Red = 1,
- Green = 2,
- Blue = 3,
- }
-
- protected enum DiffMode
- {
- NoDiffuse = 0,
- LTCDiffuse = 1,
- LightmapDiffuse = 2,
- }
-
- void OnEnable()
- {
- colorProp = serializedObject.FindProperty("Color");
- sidedProp = serializedObject.FindProperty("DoubleSided");
- dynamicProp = serializedObject.FindProperty("Dynamic");
- indexProp = serializedObject.FindProperty("TextureIndex");
- colormodeProp = serializedObject.FindProperty("ColorMode");
- specProp = serializedObject.FindProperty("Specular");
- diffProp = serializedObject.FindProperty("Diffuse");
- lmProp = serializedObject.FindProperty("LightmapChannel");
- singleUVProp = serializedObject.FindProperty("SingleUV");
- rendererModeProp = serializedObject.FindProperty("RendererMode");
- rendererListProp = serializedObject.FindProperty("RendererList");
- rendererDistProp = serializedObject.FindProperty("RendererDistance");
- diffModeProp = serializedObject.FindProperty("diffMode");
- diffuseFromLmProp = serializedObject.FindProperty("DiffuseFromLm");
- lmIntensProp = serializedObject.FindProperty("LightmapIntensity");
- flipProp = serializedObject.FindProperty("FlipUV");
- alBandProp = serializedObject.FindProperty("AudioLinkBand");
- affectAvatarsProp = serializedObject.FindProperty("AffectAvatars");
-
- cylProp = serializedObject.FindProperty("Cylinder");
- cylAngleProp = serializedObject.FindProperty("CylinderAngle");
- cylBaseProp = serializedObject.FindProperty("CylinderBase");
- cylHeightProp = serializedObject.FindProperty("CylinderHeight");
- cylRadiusProp = serializedObject.FindProperty("CylinderRadius");
- cylSizeProp = serializedObject.FindProperty("CylinderSize");
-
- Logo = Resources.Load("LTCGI-Logo") as Texture;
- }
-
- public override void OnInspectorGUI()
- {
- GUIStyle style = new GUIStyle(EditorStyles.label);
- style.alignment = TextAnchor.MiddleCenter;
- style.fixedHeight = 150;
- GUI.Box(GUILayoutUtility.GetRect(300, 150, style), Logo, style);
-
- var screen = (LTCGI_Screen)target;
-
- if (!screen.enabled || !screen.gameObject.activeInHierarchy)
- {
- EditorGUILayout.Space();
- EditorGUILayout.HelpBox("This component is disabled, or the GameObject not active! This will cause it to not bake a lightmap, and can cause issues at runtime. If you want this renderer to start disabled, set it's color to Black (0,0,0) or visit https://ltcgi.dev/ to see how you can toggle LTCGI globally.", MessageType.Error, true);
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Getting%20Started/Setup/Basic_Toggle", "LTCGI Toggle");
- EditorGUILayout.Space();
- }
-
- LTCGIDocsHelper.DrawHelpButton("https://ltcgi.dev/Getting%20Started/Setup/LTCGI_Screen");
-
- serializedObject.Update();
-
- GUILayout.Label("Area light shape:");
- var isCylinder = cylProp.boolValue;
- using (var hor = new EditorGUILayout.HorizontalScope())
- {
- var leftStyle = EditorStyles.miniButtonLeft;
- var midStyle = EditorStyles.miniButtonMid;
- var rightStyle = EditorStyles.miniButtonRight;
- var toggleMesh = GUILayout.Toggle(!isCylinder, "Quad/Triangle", leftStyle);
- var toggleCyl = GUILayout.Toggle(isCylinder, "Cylinder", rightStyle);
-
- if ((toggleMesh && isCylinder) || (!toggleMesh && !isCylinder))
- {
- isCylinder = cylProp.boolValue = !toggleMesh;
- }
- else if ((toggleCyl && !isCylinder) || (!toggleCyl && isCylinder))
- {
- isCylinder = cylProp.boolValue = toggleCyl;
- }
- }
- EditorGUILayout.Space();
- EditorGUILayout.Space();
-
- if (!isCylinder)
- {
- var mesh = screen.gameObject.GetComponent<MeshFilter>()?.sharedMesh;
- string error = "";
- if (mesh == null)
- {
- error = "No mesh or mesh filter assigned!";
- }
- else if (!mesh.isReadable)
- {
- error = "Mesh is not readable!";
- }
- else if (mesh.vertexCount != 4 && mesh.vertexCount != 3)
- {
- error = "Mesh does not have exactly 3 or 4 vertices!";
- }
- if (error != "")
- {
- EditorGUILayout.Space();
- EditorGUILayout.HelpBox(error, MessageType.Error, true);
- EditorGUILayout.Space();
- }
- }
-
- if (isCylinder)
- {
- EditorGUILayout.PropertyField(cylBaseProp);
- EditorGUILayout.PropertyField(cylHeightProp);
- EditorGUILayout.PropertyField(cylRadiusProp);
- EditorGUILayout.PropertyField(cylAngleProp);
- EditorGUILayout.PropertyField(cylSizeProp);
- if (GUILayout.Button("Try cylinder auto-detect"))
- {
- var coll = screen.gameObject.GetComponent<Collider>();
- if (coll != null)
- {
- cylBaseProp.vector3Value = new Vector3(0, -coll.bounds.extents.y / 2.0f, 0);
- cylHeightProp.floatValue = coll.bounds.extents.y;
- cylRadiusProp.floatValue = Mathf.Max(coll.bounds.extents.x, coll.bounds.extents.z);
- }
- else
- {
- cylHeightProp.floatValue = screen.transform.localScale.y;
- cylRadiusProp.floatValue = screen.transform.localScale.x / 2.0f;
- }
- }
-
- EditorGUILayout.Separator();
- }
-
- DrawColorSelector(screen);
-
- EditorGUILayout.Space();
- EditorGUILayout.Separator();
-
- var dm = (DiffMode)EditorGUILayout.EnumPopup("Diffuse Mode", (DiffMode)diffModeProp.intValue);
- if (diffModeProp.intValue != (int)dm)
- {
- diffModeProp.intValue = (int)dm;
- diffProp.boolValue = dm != DiffMode.NoDiffuse;
- diffuseFromLmProp.boolValue = dm == DiffMode.LightmapDiffuse;
- }
-
- if (diffuseFromLmProp.boolValue && lmProp.intValue == 0)
- {
- EditorGUILayout.HelpBox("You have \"Lightmap Diffuse\" enabled but no lightmap channel selected - this is probably not what you want.", MessageType.Warning, true);
- }
-
- EditorGUILayout.PropertyField(specProp);
- EditorGUILayout.PropertyField(dynamicProp);
- if (isCylinder)
- {
- sidedProp.boolValue = false;
- }
- else
- {
- EditorGUILayout.PropertyField(sidedProp);
- }
- EditorGUILayout.PropertyField(flipProp);
- EditorGUILayout.PropertyField(affectAvatarsProp);
-
- EditorGUILayout.Separator();
- DrawColorModeSelector(true);
- EditorGUILayout.Separator();
- DrawRendererModeSelector();
- EditorGUILayout.Separator();
- DrawLmChannelSelector();
-
- if (serializedObject.hasModifiedProperties)
- {
- serializedObject.ApplyModifiedProperties();
- LTCGI_Controller.Singleton?.UpdateMaterials();
- }
- }
-
- protected void DrawColorSelector(LTCGI_Screen screen)
- {
- var newCol = EditorGUILayout.ColorField(new GUIContent("Color"), colorProp.colorValue, true, false, true);
- if (colorProp.colorValue != newCol)
- {
- colorProp.colorValue = newCol;
- }
-
- if (colorProp.colorValue.maxColorComponent == 0.0f)
- {
- EditorGUILayout.HelpBox("Screen is disabled with color black!", MessageType.Warning, true);
- }
-
- if (GUILayout.Button("Try get Color from Material"))
- {
- var ren = screen.gameObject.GetComponent<Renderer>();
- if (ren != null)
- {
- var mat = ren.sharedMaterial;
- if (mat != null)
- {
- var col = mat.GetColor("_Color");
- if (col != null)
- {
- colorProp.colorValue = col;
- }
- }
- }
- }
- }
-
- protected void DrawColorModeSelector(bool allowTextured)
- {
- var texmode = (ColorMode)EditorGUILayout.EnumPopup("Color Mode", (ColorMode)colormodeProp.intValue);
- if (colormodeProp.intValue != (int)texmode)
- {
- colormodeProp.intValue = (int)texmode;
- }
- if (targets.Length == 1)
- {
- Action texSelect = () =>
- {
- EditorGUILayout.IntSlider(indexProp, 0,
- LTCGI_Controller.Singleton == null && LTCGI_Controller.Singleton.StaticTextures != null ? 2 :
- LTCGI_Controller.Singleton.StaticTextures.Length);
-
- if (LTCGI_Controller.Singleton != null)
- {
- if (indexProp.intValue == 0)
- {
- EditorGUILayout.HelpBox("Texture: [Live Video]", MessageType.None, false);
- }
- else
- {
- EditorGUILayout.HelpBox("Texture: " + LTCGI_Controller.Singleton.StaticTextures[indexProp.intValue - 1].name, MessageType.None, false);
- }
- }
- };
- switch (texmode)
- {
- case ColorMode.Static:
- indexProp.intValue = 0;
- break;
- case ColorMode.Texture:
- if (allowTextured)
- {
- texSelect();
- }
- else
- {
- EditorGUILayout.HelpBox("Texture mode is not allowed for emitters! Falling back to static color.", MessageType.Error, true);
- }
- break;
- case ColorMode.SingleUV:
- EditorGUILayout.HelpBox("This will always use LOD0 of the video texture as its input.", MessageType.Info);
- singleUVProp.vector2Value = EditorGUILayout.Vector2Field("Texture UV", singleUVProp.vector2Value);
- break;
- case ColorMode.AudioLink:
- EditorGUILayout.PropertyField(alBandProp);
- string[] bandNames = new[] {"Bass", "Low Mids", "High Mids", "Treble"};
- EditorGUILayout.HelpBox($"Selected Band: {bandNames[alBandProp.intValue]}", MessageType.None, false);
- break;
- }
- }
- else
- {
- EditorGUILayout.HelpBox("(cannot multi-edit 'Color Mode' settings)", MessageType.None, false);
- }
- }
-
- protected void DrawRendererModeSelector()
- {
- var rendererMode = (RendererMode)EditorGUILayout.EnumPopup("Affected Renderers", (RendererMode)rendererModeProp.intValue);
- if (rendererModeProp.intValue != (int)rendererMode)
- {
- rendererModeProp.intValue = (int)rendererMode;
- }
- if (rendererMode != RendererMode.All && rendererMode != RendererMode.Distance)
- {
- EditorGUILayout.PropertyField(rendererListProp, new GUIContent("Renderer List"), true);
- }
- else if (rendererMode == RendererMode.Distance)
- {
- EditorGUILayout.PropertyField(rendererDistProp);
- }
- }
-
- protected void DrawLmChannelSelector()
- {
- var lmch = (LMChannel)EditorGUILayout.EnumPopup("Lightmap Channel", (LMChannel)lmProp.intValue);
- if (lmProp.intValue != (int)lmch)
- {
- lmProp.intValue = (int)lmch;
- }
-
- if (lmch != LMChannel.Off)
- {
- EditorGUILayout.PropertyField(lmIntensProp);
- }
- }
- }
-#endif
-} \ No newline at end of file
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-Logo.png b/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-Logo.png
deleted file mode 100644
index 1634673..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-Logo.png
+++ /dev/null
Binary files differ
diff --git a/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-LogoController.png b/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-LogoController.png
deleted file mode 100644
index c00aa2e..0000000
--- a/Third_Party/at.pimaker.ltcgi/Editor/Resources/LTCGI-LogoController.png
+++ /dev/null
Binary files differ