├── .gitignore ├── Editor.meta ├── Editor ├── Analytics.meta ├── Analytics │ ├── AmbientOcclusionInfo.cs │ ├── AmbientOcclusionInfo.cs.meta │ ├── EnlightenInfo.cs │ ├── EnlightenInfo.cs.meta │ ├── LightProbeInfo.cs │ ├── LightProbeInfo.cs.meta │ ├── LightmapInfo.cs │ ├── LightmapInfo.cs.meta │ ├── LightmappingAnalyticsData.cs │ ├── LightmappingAnalyticsData.cs.meta │ ├── LightsInfo.cs │ ├── LightsInfo.cs.meta │ ├── MemoryInfo.cs │ ├── MemoryInfo.cs.meta │ ├── ProgressiveLightmapperInfo.cs │ ├── ProgressiveLightmapperInfo.cs.meta │ ├── SceneInfo.cs │ └── SceneInfo.cs.meta ├── AssemblyPostProcessor.cs ├── AssemblyPostProcessor.cs.meta ├── LightProbes.meta ├── LightProbes │ ├── LightProbeData.cs │ ├── LightProbeData.cs.meta │ ├── LightProbeOcclusion.cs │ ├── LightProbeOcclusion.cs.meta │ ├── Matrix3x4f.cs │ ├── Matrix3x4f.cs.meta │ ├── Pair.cs │ ├── Pair.cs.meta │ ├── ProbeSetIndex.cs │ ├── ProbeSetIndex.cs.meta │ ├── ProbeSetTetrahedralization.cs │ ├── ProbeSetTetrahedralization.cs.meta │ ├── ScriptableLightProbes.cs │ ├── ScriptableLightProbes.cs.meta │ ├── Tetrahedron.cs │ └── Tetrahedron.cs.meta ├── LightingData.meta ├── LightingData │ ├── EnlightenRendererInformation.cs │ ├── EnlightenRendererInformation.cs.meta │ ├── EnlightenSceneMapping.cs │ ├── EnlightenSceneMapping.cs.meta │ ├── EnlightenSystemAtlasInformation.cs │ ├── EnlightenSystemAtlasInformation.cs.meta │ ├── EnlightenSystemInformation.cs │ ├── EnlightenSystemInformation.cs.meta │ ├── EnlightenTerrainChunksInformation.cs │ ├── EnlightenTerrainChunksInformation.cs.meta │ ├── SceneObjectIdentifier.cs │ ├── SceneObjectIdentifier.cs.meta │ ├── ScriptableLightingData.LightBakingOutput.cs │ ├── ScriptableLightingData.LightBakingOutput.cs.meta │ ├── ScriptableLightingData.LightmapData.cs │ ├── ScriptableLightingData.LightmapData.cs.meta │ ├── ScriptableLightingData.RendererData.cs │ ├── ScriptableLightingData.RendererData.cs.meta │ ├── ScriptableLightingData.cs │ └── ScriptableLightingData.cs.meta ├── LightmappingInternal.cs ├── LightmappingInternal.cs.meta ├── MetadataNameAttribute.cs ├── MetadataNameAttribute.cs.meta ├── NewBlood.LightingInternals.asmdef ├── NewBlood.LightingInternals.asmdef.meta ├── ObjectFactoryInternal.cs └── ObjectFactoryInternal.cs.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd32bf1ff6a4c024693cbae724806311 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Analytics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db5cc53affeb4cf44a0bf804f817c2ec 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Analytics/AmbientOcclusionInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct AmbientOcclusionInfo 9 | { 10 | public bool enabled; 11 | public float maxDistance; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Editor/Analytics/AmbientOcclusionInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 741dff74897a73a478a8ffdda7d79f92 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/EnlightenInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct EnlightenInfo 9 | { 10 | public FinalGatherInfo finalGather; 11 | 12 | [Serializable] 13 | public struct FinalGatherInfo 14 | { 15 | public bool enabled; 16 | public int rayCount; 17 | public bool denoise; 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Editor/Analytics/EnlightenInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fecc9fbae4e52f41a253bae89a8d60c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/LightProbeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct LightProbeInfo 9 | { 10 | public uint lightProbeGroupCount; 11 | public ulong lightProbeCount; 12 | public uint contributingLightProbeLitInstanceCount; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Editor/Analytics/LightProbeInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9949f1f5249e78f46b29ca1d57f05519 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/LightmapInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct LightmapInfo 9 | { 10 | public ulong occupiedTexels; 11 | public uint lightmapCount; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Editor/Analytics/LightmapInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 552e4a5eca22bf641933ebac76131a9e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/LightmappingAnalyticsData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | [Serializable] 6 | public partial struct LightmappingAnalyticsData 7 | { 8 | public bool autoGenerate; 9 | public string bakeBackend; 10 | public bool computeRealtime; 11 | public bool computeBaked; 12 | public float indirectResolution; 13 | public float lightmapResolution; 14 | public AmbientOcclusionInfo ambientOcclusion; 15 | public int lightmapCompression; 16 | public int lightmapSize; 17 | public EnlightenInfo enlighten; 18 | public ProgressiveLightmapperInfo progressive; 19 | public LightmapInfo lightmaps; 20 | public SceneInfo scene; 21 | public LightsInfo lights; 22 | public LightProbeInfo lightProbes; 23 | public MemoryInfo memory; 24 | public string outcome; 25 | public string fallback; 26 | public string sourceView; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Editor/Analytics/LightmappingAnalyticsData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36ce1c124cce8ec4fb66efa1077f342c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/LightsInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct LightsInfo 9 | { 10 | public string mixedBakeMode; 11 | public uint bakedLightCount; 12 | public uint mixedLightCount; 13 | public uint shadowCastingLightCount; 14 | public uint cookieLightCount; 15 | public uint uniqueCookieCount; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Editor/Analytics/LightsInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e86345c1e86968b429c9fbd7cb88bb20 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/MemoryInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct MemoryInfo 9 | { 10 | public uint maxTilingModeDuringBake; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Editor/Analytics/MemoryInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0bb79cffef358a47b395de561e04a78 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/ProgressiveLightmapperInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct ProgressiveLightmapperInfo 9 | { 10 | public int directSamples; 11 | public int indirectSamples; 12 | public int bounces; 13 | public bool prioritizeView; 14 | public int minBounces; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Editor/Analytics/ProgressiveLightmapperInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e3592ef829e7414ab8161231eec78b7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Analytics/SceneInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | public partial struct LightmappingAnalyticsData 6 | { 7 | [Serializable] 8 | public struct SceneInfo 9 | { 10 | public uint contributingInstanceCount; 11 | public uint meshCount; 12 | public ulong totalTriangleCount; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Editor/Analytics/SceneInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 595fe323b749a574ca47769dc2c87236 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/AssemblyPostProcessor.cs: -------------------------------------------------------------------------------- 1 | using Mono.Cecil; 2 | using UnityEditor; 3 | using UnityEditor.Compilation; 4 | 5 | namespace NewBlood 6 | { 7 | [InitializeOnLoad] 8 | static class AssemblyPostProcessor 9 | { 10 | static AssemblyPostProcessor() 11 | { 12 | CompilationPipeline.compilationFinished += OnCompilationFinished; 13 | } 14 | 15 | static void OnCompilationFinished(object context) 16 | { 17 | bool modified = false; 18 | EditorApplication.LockReloadAssemblies(); 19 | 20 | try 21 | { 22 | var parameters = new ReaderParameters { ReadWrite = true }; 23 | using var assembly = AssemblyDefinition.ReadAssembly(typeof(AssemblyPostProcessor).Assembly.Location, parameters); 24 | 25 | foreach (ModuleDefinition module in assembly.Modules) 26 | { 27 | foreach (TypeDefinition type in module.Types) 28 | { 29 | foreach (FieldDefinition field in type.Fields) 30 | { 31 | foreach (CustomAttribute attribute in field.CustomAttributes) 32 | { 33 | if (attribute.AttributeType.Name != nameof(MetadataNameAttribute)) 34 | continue; 35 | 36 | modified = true; 37 | field.Name = attribute.ConstructorArguments[0].Value.ToString(); 38 | field.CustomAttributes.Remove(attribute); 39 | break; 40 | } 41 | } 42 | } 43 | } 44 | 45 | if (modified) 46 | { 47 | assembly.Write(); 48 | EditorApplication.delayCall += EditorUtility.RequestScriptReload; 49 | } 50 | } 51 | finally 52 | { 53 | EditorApplication.UnlockReloadAssemblies(); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Editor/AssemblyPostProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf1ad9bc8289915459990293c741e955 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a4a5558f292c9b49a4aaff6d93e6b0b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/LightProbes/LightProbeData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public sealed class LightProbeData 8 | { 9 | [SerializeField] 10 | ProbeSetTetrahedralization m_Tetrahedralization; 11 | 12 | [SerializeField] 13 | ProbeSetIndex[] m_ProbeSets; 14 | 15 | [SerializeField] 16 | bool[] m_DeringSettings; 17 | 18 | [SerializeField] 19 | Vector3[] m_Positions; 20 | 21 | [SerializeField] 22 | Pair[] m_NonTetrahedralizedProbeSetIndexMap; 23 | 24 | public ProbeSetTetrahedralization tetrahedralization 25 | { 26 | get => m_Tetrahedralization; 27 | set => m_Tetrahedralization = value; 28 | } 29 | 30 | public ProbeSetIndex[] probeSets 31 | { 32 | get => m_ProbeSets; 33 | set => m_ProbeSets = value; 34 | } 35 | 36 | public bool[] deringSettings 37 | { 38 | get => m_DeringSettings; 39 | set => m_DeringSettings = value; 40 | } 41 | 42 | public Vector3[] positions 43 | { 44 | get => m_Positions; 45 | set => m_Positions = value; 46 | } 47 | 48 | public Pair[] nonTetrahedralizedProbeSetIndexMap 49 | { 50 | get => m_NonTetrahedralizedProbeSetIndexMap; 51 | set => m_NonTetrahedralizedProbeSetIndexMap = value; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Editor/LightProbes/LightProbeData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce08f18a77b771d43836d2d775b0f88b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/LightProbeOcclusion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using UnityEngine; 4 | 5 | namespace NewBlood 6 | { 7 | [Serializable] 8 | [StructLayout(LayoutKind.Explicit)] 9 | public unsafe struct LightProbeOcclusion 10 | { 11 | [NonSerialized] 12 | [FieldOffset(0)] 13 | public fixed int probeOcclusionLightIndex[4]; 14 | 15 | [SerializeField] 16 | [FieldOffset(0)] 17 | fixed int m_ProbeOcclusionLightIndex[4]; 18 | 19 | [NonSerialized] 20 | [FieldOffset(16)] 21 | public fixed float occlusion[4]; 22 | 23 | [SerializeField] 24 | [FieldOffset(16)] 25 | fixed float m_Occlusion[4]; 26 | 27 | [NonSerialized] 28 | [FieldOffset(32)] 29 | public fixed byte occlusionMaskChannel[4]; 30 | 31 | [SerializeField] 32 | [FieldOffset(32)] 33 | fixed byte m_OcclusionMaskChannel[4]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Editor/LightProbes/LightProbeOcclusion.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62fe3112780e3aa4aa6df4796216ea6a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/Matrix3x4f.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public struct Matrix3x4f 8 | { 9 | public float e00; 10 | public float e01; 11 | public float e02; 12 | public float e03; 13 | public float e10; 14 | public float e11; 15 | public float e12; 16 | public float e13; 17 | public float e20; 18 | public float e21; 19 | public float e22; 20 | public float e23; 21 | 22 | public static implicit operator Matrix4x4(Matrix3x4f matrix) 23 | { 24 | return new Matrix4x4 25 | { 26 | m00 = matrix.e00, m01 = matrix.e01, m02 = matrix.e02, m03 = matrix.e03, 27 | m10 = matrix.e10, m11 = matrix.e11, m12 = matrix.e12, m13 = matrix.e13, 28 | m20 = matrix.e20, m21 = matrix.e21, m22 = matrix.e22, m23 = matrix.e23 29 | }; 30 | } 31 | 32 | public static explicit operator Matrix3x4f(Matrix4x4 matrix) 33 | { 34 | return new Matrix3x4f 35 | { 36 | e00 = matrix.m00, e01 = matrix.m01, e02 = matrix.m02, e03 = matrix.m03, 37 | e10 = matrix.m10, e11 = matrix.m11, e12 = matrix.m12, e13 = matrix.m13, 38 | e20 = matrix.m20, e21 = matrix.m21, e22 = matrix.m22, e23 = matrix.m23 39 | }; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Editor/LightProbes/Matrix3x4f.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0633599843ea5a94185a9bae362f495e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/Pair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | [Serializable] 6 | public struct Pair 7 | { 8 | public T1 first; 9 | 10 | public T2 second; 11 | 12 | public Pair(T1 first, T2 second) 13 | { 14 | this.first = first; 15 | this.second = second; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Editor/LightProbes/Pair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab76602a2b0a661459a7ff89f1985530 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/ProbeSetIndex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public struct ProbeSetIndex 8 | { 9 | [SerializeField] 10 | Hash128 m_Hash; 11 | 12 | [SerializeField] 13 | int m_Offset; 14 | 15 | [SerializeField] 16 | int m_Size; 17 | 18 | public Hash128 hash 19 | { 20 | get => m_Hash; 21 | set => m_Hash = value; 22 | } 23 | 24 | public int offset 25 | { 26 | get => m_Offset; 27 | set => m_Offset = value; 28 | } 29 | 30 | public int size 31 | { 32 | get => m_Size; 33 | set => m_Size = value; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Editor/LightProbes/ProbeSetIndex.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ab4bad7e9f700b47ab100bc6213ddca 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/ProbeSetTetrahedralization.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public sealed class ProbeSetTetrahedralization 8 | { 9 | [SerializeField] 10 | Tetrahedron[] m_Tetrahedra; 11 | 12 | [SerializeField] 13 | Vector3[] m_HullRays; 14 | 15 | public Tetrahedron[] tetrahedra 16 | { 17 | get => m_Tetrahedra; 18 | set => m_Tetrahedra = value; 19 | } 20 | 21 | public Vector3[] hullRays 22 | { 23 | get => m_HullRays; 24 | set => m_HullRays = value; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Editor/LightProbes/ProbeSetTetrahedralization.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f436a21d6f663e40ad18d084b866194 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/ScriptableLightProbes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | 6 | namespace NewBlood 7 | { 8 | public sealed class ScriptableLightProbes : ScriptableObject 9 | { 10 | [SerializeField] 11 | LightProbesRoot m_Root = new LightProbesRoot(); 12 | 13 | public LightProbeData data 14 | { 15 | get => m_Root.LightProbes.m_Data; 16 | set => m_Root.LightProbes.m_Data = value; 17 | } 18 | 19 | public SphericalHarmonicsL2[] bakedCoefficients 20 | { 21 | get => m_Root.LightProbes.m_BakedCoefficients; 22 | set => m_Root.LightProbes.m_BakedCoefficients = value; 23 | } 24 | 25 | public LightProbeOcclusion[] bakedLightOcclusion 26 | { 27 | get => m_Root.LightProbes.m_BakedLightOcclusion; 28 | set => m_Root.LightProbes.m_BakedLightOcclusion = value; 29 | } 30 | 31 | public void Read(LightProbes source) 32 | { 33 | var json = EditorJsonUtility.ToJson(source); 34 | EditorJsonUtility.FromJsonOverwrite(json, m_Root); 35 | EditorUtility.SetDirty(this); 36 | } 37 | 38 | public void Write(LightProbes destination) 39 | { 40 | var json = EditorJsonUtility.ToJson(m_Root); 41 | EditorJsonUtility.FromJsonOverwrite(json, destination); 42 | EditorUtility.SetDirty(destination); 43 | } 44 | 45 | public static LightProbes CreateAsset() 46 | { 47 | return ObjectFactoryInternal.CreateDefaultInstance(); 48 | } 49 | 50 | [Serializable] 51 | sealed class LightProbesRoot 52 | { 53 | public SerializedData LightProbes; 54 | 55 | [Serializable] 56 | public struct SerializedData 57 | { 58 | public LightProbeData m_Data; 59 | public SphericalHarmonicsL2[] m_BakedCoefficients; 60 | public LightProbeOcclusion[] m_BakedLightOcclusion; 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Editor/LightProbes/ScriptableLightProbes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef8fbb65e810d974c8a91f230703c6a6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightProbes/Tetrahedron.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using UnityEngine; 4 | 5 | namespace NewBlood 6 | { 7 | [Serializable] 8 | [StructLayout(LayoutKind.Explicit)] 9 | public unsafe struct Tetrahedron 10 | { 11 | [NonSerialized] 12 | [FieldOffset(0)] 13 | public fixed int indices[4]; 14 | 15 | [SerializeField] 16 | [FieldOffset(0)] 17 | [MetadataName("indices[0]")] 18 | int indices0; 19 | 20 | [SerializeField] 21 | [FieldOffset(4)] 22 | [MetadataName("indices[1]")] 23 | int indices1; 24 | 25 | [SerializeField] 26 | [FieldOffset(8)] 27 | [MetadataName("indices[2]")] 28 | int indices2; 29 | 30 | [SerializeField] 31 | [FieldOffset(12)] 32 | [MetadataName("indices[3]")] 33 | int indices3; 34 | 35 | [NonSerialized] 36 | [FieldOffset(16)] 37 | public fixed int neighbors[4]; 38 | 39 | [SerializeField] 40 | [FieldOffset(16)] 41 | [MetadataName("neighbors[0]")] 42 | int neighbors0; 43 | 44 | [SerializeField] 45 | [FieldOffset(20)] 46 | [MetadataName("neighbors[1]")] 47 | int neighbors1; 48 | 49 | [SerializeField] 50 | [FieldOffset(24)] 51 | [MetadataName("neighbors[2]")] 52 | int neighbors2; 53 | 54 | [SerializeField] 55 | [FieldOffset(28)] 56 | [MetadataName("neighbors[3]")] 57 | int neighbors3; 58 | 59 | [FieldOffset(32)] 60 | public Matrix3x4f matrix; 61 | 62 | [FieldOffset(80)] 63 | public bool isValid; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Editor/LightProbes/Tetrahedron.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 284f453485ab4f3439cebb84ba6d924a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 928f7065cb000264a89aa91d06fef038 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenRendererInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using Object = UnityEngine.Object; 4 | 5 | namespace NewBlood 6 | { 7 | [Serializable] 8 | public struct EnlightenRendererInformation 9 | { 10 | public Object renderer; 11 | public Vector4 dynamicLightmapSTInSystem; 12 | public int systemId; 13 | public Hash128 instanceHash; 14 | public Hash128 geometryHash; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenRendererInformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b54ea173ad51f7d40a81f805b657e608 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSceneMapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public sealed class EnlightenSceneMapping 8 | { 9 | [SerializeField] 10 | EnlightenRendererInformation[] m_Renderers; 11 | 12 | [SerializeField] 13 | EnlightenSystemInformation[] m_Systems; 14 | 15 | [SerializeField] 16 | Hash128[] m_Probesets; 17 | 18 | [SerializeField] 19 | EnlightenSystemAtlasInformation[] m_SystemAtlases; 20 | 21 | [SerializeField] 22 | EnlightenTerrainChunksInformation[] m_TerrainChunks; 23 | 24 | public EnlightenRendererInformation[] renderers 25 | { 26 | get => m_Renderers; 27 | set => m_Renderers = value; 28 | } 29 | 30 | public EnlightenSystemInformation[] systems 31 | { 32 | get => m_Systems; 33 | set => m_Systems = value; 34 | } 35 | 36 | public Hash128[] probesets 37 | { 38 | get => m_Probesets; 39 | set => m_Probesets = value; 40 | } 41 | 42 | public EnlightenSystemAtlasInformation[] systemAtlases 43 | { 44 | get => m_SystemAtlases; 45 | set => m_SystemAtlases = value; 46 | } 47 | 48 | public EnlightenTerrainChunksInformation[] terrainChunks 49 | { 50 | get => m_TerrainChunks; 51 | set => m_TerrainChunks = value; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSceneMapping.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0985230125d9c7743b21934ff29c9fd5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSystemAtlasInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public struct EnlightenSystemAtlasInformation 8 | { 9 | public int atlasSize; 10 | public Hash128 atlasHash; 11 | public int firstSystemId; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSystemAtlasInformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c568fc01c55b2e458317d502640ca14 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSystemInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | [Serializable] 7 | public struct EnlightenSystemInformation 8 | { 9 | public int rendererIndex; 10 | public int rendererSize; 11 | public int atlasIndex; 12 | public int atlasOffsetX; 13 | public int atlasOffsetY; 14 | public Hash128 inputSystemHash; 15 | public Hash128 radiositySystemHash; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenSystemInformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d09a06086bda7964e96c2d3974f23533 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenTerrainChunksInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | [Serializable] 6 | public struct EnlightenTerrainChunksInformation 7 | { 8 | public int firstSystemId; 9 | public int numChunksInX; 10 | public int numChunksInY; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Editor/LightingData/EnlightenTerrainChunksInformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e81441f4baff3543821b98f74efefc1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/SceneObjectIdentifier.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine.SceneManagement; 4 | using Object = UnityEngine.Object; 5 | 6 | namespace NewBlood 7 | { 8 | [Serializable] 9 | public struct SceneObjectIdentifier : IEquatable 10 | { 11 | public long targetObject; 12 | 13 | public long targetPrefab; 14 | 15 | public SceneObjectIdentifier(GlobalObjectId id) 16 | { 17 | if (id.identifierType != 2) 18 | throw new ArgumentException("GlobalObjectId must refer to a scene object.", nameof(id)); 19 | 20 | targetObject = unchecked((long)id.targetObjectId); 21 | targetPrefab = unchecked((long)id.targetPrefabId); 22 | } 23 | 24 | public bool Equals(SceneObjectIdentifier other) 25 | { 26 | return targetObject == other.targetObject && targetPrefab == other.targetPrefab; 27 | } 28 | 29 | public GlobalObjectId ToGlobalObjectId(SceneAsset scene) 30 | { 31 | return ToGlobalObjectId(AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(scene))); 32 | } 33 | 34 | public GlobalObjectId ToGlobalObjectId(Scene scene) 35 | { 36 | return ToGlobalObjectId(AssetDatabase.GUIDFromAssetPath(scene.path)); 37 | } 38 | 39 | public GlobalObjectId ToGlobalObjectId(GUID sceneGuid) 40 | { 41 | GlobalObjectId id; 42 | GlobalObjectId.TryParse($"GlobalObjectId_V1-2-{sceneGuid}-{unchecked((ulong)targetObject)}-{unchecked((ulong)targetPrefab)}", out id); 43 | return id; 44 | } 45 | 46 | public static Object SceneObjectIdentifierToObjectSlow(SceneAsset scene, SceneObjectIdentifier id) 47 | { 48 | return SceneObjectIdentifierToObjectSlow(AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(scene)), id); 49 | } 50 | 51 | public static Object SceneObjectIdentifierToObjectSlow(Scene scene, SceneObjectIdentifier id) 52 | { 53 | return SceneObjectIdentifierToObjectSlow(AssetDatabase.GUIDFromAssetPath(scene.path), id); 54 | } 55 | 56 | public static Object SceneObjectIdentifierToObjectSlow(GUID sceneGuid, SceneObjectIdentifier id) 57 | { 58 | return GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id.ToGlobalObjectId(sceneGuid)); 59 | } 60 | 61 | public static void SceneObjectIdentifiersToObjectsSlow(SceneAsset scene, SceneObjectIdentifier[] identifiers, Object[] outputObjects) 62 | { 63 | SceneObjectIdentifiersToObjectsSlow(AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(scene)), identifiers, outputObjects); 64 | } 65 | 66 | public static void SceneObjectIdentifiersToObjectsSlow(Scene scene, SceneObjectIdentifier[] identifiers, Object[] outputObjects) 67 | { 68 | SceneObjectIdentifiersToObjectsSlow(AssetDatabase.GUIDFromAssetPath(scene.path), identifiers, outputObjects); 69 | } 70 | 71 | public static void SceneObjectIdentifiersToObjectsSlow(GUID sceneGuid, SceneObjectIdentifier[] identifiers, Object[] outputObjects) 72 | { 73 | var globalIdentifiers = new GlobalObjectId[identifiers.Length]; 74 | 75 | for (int i = 0; i < identifiers.Length; i++) 76 | globalIdentifiers[i] = identifiers[i].ToGlobalObjectId(sceneGuid); 77 | 78 | GlobalObjectId.GlobalObjectIdentifiersToObjectsSlow(globalIdentifiers, outputObjects); 79 | } 80 | 81 | public static void GetSceneObjectIdentifiersSlow(Object[] objects, SceneObjectIdentifier[] outputIdentifiers) 82 | { 83 | var globalIdentifiers = new GlobalObjectId[outputIdentifiers.Length]; 84 | GlobalObjectId.GetGlobalObjectIdsSlow(objects, globalIdentifiers); 85 | 86 | for (int i = 0; i < outputIdentifiers.Length; i++) 87 | { 88 | outputIdentifiers[i] = new SceneObjectIdentifier(globalIdentifiers[i]); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Editor/LightingData/SceneObjectIdentifier.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bea995f1dae8ede4ba050d6f02e473ea 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.LightBakingOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | public partial class ScriptableLightingData 7 | { 8 | [Serializable] 9 | public struct LightBakingOutput 10 | { 11 | public int serializedVersion; 12 | public int probeOcclusionLightIndex; 13 | public int occlusionMaskChannel; 14 | public LightmapBakeMode lightmapBakeMode; 15 | public bool isBaked; 16 | 17 | [Serializable] 18 | public struct LightmapBakeMode 19 | { 20 | public LightmapBakeType lightmapBakeType; 21 | public MixedLightingMode mixedLightingMode; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.LightBakingOutput.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d0ea75dfad05324dba10a780890b762 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.LightmapData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | public partial class ScriptableLightingData 7 | { 8 | [Serializable] 9 | public struct LightmapData 10 | { 11 | [SerializeField] 12 | Texture2D m_Lightmap; 13 | 14 | [SerializeField] 15 | Texture2D m_DirLightmap; 16 | 17 | [SerializeField] 18 | Texture2D m_ShadowMask; 19 | 20 | public Texture2D lightmap 21 | { 22 | get => m_Lightmap; 23 | set => m_Lightmap = value; 24 | } 25 | 26 | public Texture2D dirLightmap 27 | { 28 | get => m_DirLightmap; 29 | set => m_DirLightmap = value; 30 | } 31 | 32 | public Texture2D shadowMask 33 | { 34 | get => m_ShadowMask; 35 | set => m_ShadowMask = value; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.LightmapData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8aa1ffaebe194624fa55431a463a3ecb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.RendererData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace NewBlood 5 | { 6 | public partial class ScriptableLightingData 7 | { 8 | [Serializable] 9 | public struct RendererData 10 | { 11 | public Mesh uvMesh; 12 | public Vector4 terrainDynamicUVST; 13 | public Vector4 terrainChunkDynamicUVST; 14 | public Vector4 lightmapST; 15 | public Vector4 lightmapSTDynamic; 16 | public ushort lightmapIndex; 17 | public ushort lightmapIndexDynamic; 18 | public Hash128 explicitProbeSetHash; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.RendererData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb79a1e6c44f8c0478c372b8e7dae652 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | using Object = UnityEngine.Object; 6 | 7 | namespace NewBlood 8 | { 9 | public sealed partial class ScriptableLightingData : ScriptableObject 10 | { 11 | [SerializeField] 12 | LightingDataAssetRoot m_Root = new LightingDataAssetRoot(); 13 | 14 | public int serializedVersion 15 | { 16 | get => m_Root.LightingDataAsset.serializedVersion; 17 | set => m_Root.LightingDataAsset.serializedVersion = value; 18 | } 19 | 20 | public SceneAsset scene 21 | { 22 | get => m_Root.LightingDataAsset.m_Scene; 23 | set => m_Root.LightingDataAsset.m_Scene = value; 24 | } 25 | 26 | public LightmapData[] lightmaps 27 | { 28 | get => m_Root.LightingDataAsset.m_Lightmaps; 29 | set => m_Root.LightingDataAsset.m_Lightmaps = value; 30 | } 31 | 32 | public Texture2D[] aoTextures 33 | { 34 | get => m_Root.LightingDataAsset.m_AOTextures; 35 | set => m_Root.LightingDataAsset.m_AOTextures = value; 36 | } 37 | 38 | public string[] lightmapsCacheFiles 39 | { 40 | get => m_Root.LightingDataAsset.m_LightmapsCacheFiles; 41 | set => m_Root.LightingDataAsset.m_LightmapsCacheFiles = value; 42 | } 43 | 44 | public LightProbes lightProbes 45 | { 46 | get => m_Root.LightingDataAsset.m_LightProbes; 47 | set => m_Root.LightingDataAsset.m_LightProbes = value; 48 | } 49 | 50 | public int lightmapsMode 51 | { 52 | get => m_Root.LightingDataAsset.m_LightmapsMode; 53 | set => m_Root.LightingDataAsset.m_LightmapsMode = value; 54 | } 55 | 56 | public SphericalHarmonicsL2 bakedAmbientProbeInLinear 57 | { 58 | get => m_Root.LightingDataAsset.m_BakedAmbientProbeInLinear; 59 | set => m_Root.LightingDataAsset.m_BakedAmbientProbeInLinear = value; 60 | } 61 | 62 | public RendererData[] lightmappedRendererData 63 | { 64 | get => m_Root.LightingDataAsset.m_LightmappedRendererData; 65 | set => m_Root.LightingDataAsset.m_LightmappedRendererData = value; 66 | } 67 | 68 | public SceneObjectIdentifier[] lightmappedRendererDataIDs 69 | { 70 | get => m_Root.LightingDataAsset.m_LightmappedRendererDataIDs; 71 | set => m_Root.LightingDataAsset.m_LightmappedRendererDataIDs = value; 72 | } 73 | 74 | public EnlightenSceneMapping enlightenSceneMapping 75 | { 76 | get => m_Root.LightingDataAsset.m_EnlightenSceneMapping; 77 | set => m_Root.LightingDataAsset.m_EnlightenSceneMapping = value; 78 | } 79 | 80 | public SceneObjectIdentifier[] enlightenSceneMappingRendererIDs 81 | { 82 | get => m_Root.LightingDataAsset.m_EnlightenSceneMappingRendererIDs; 83 | set => m_Root.LightingDataAsset.m_EnlightenSceneMappingRendererIDs = value; 84 | } 85 | 86 | public SceneObjectIdentifier[] lights 87 | { 88 | get => m_Root.LightingDataAsset.m_Lights; 89 | set => m_Root.LightingDataAsset.m_Lights = value; 90 | } 91 | 92 | public LightBakingOutput[] lightBakingOutputs 93 | { 94 | get => m_Root.LightingDataAsset.m_LightBakingOutputs; 95 | set => m_Root.LightingDataAsset.m_LightBakingOutputs = value; 96 | } 97 | 98 | public string[] bakedReflectionProbeCubemapCacheFiles 99 | { 100 | get => m_Root.LightingDataAsset.m_BakedReflectionProbeCubemapCacheFiles; 101 | set => m_Root.LightingDataAsset.m_BakedReflectionProbeCubemapCacheFiles = value; 102 | } 103 | 104 | public Texture[] bakedReflectionProbeCubemaps 105 | { 106 | get => m_Root.LightingDataAsset.m_BakedReflectionProbeCubemaps; 107 | set => m_Root.LightingDataAsset.m_BakedReflectionProbeCubemaps = value; 108 | } 109 | 110 | public SceneObjectIdentifier[] bakedReflectionProbes 111 | { 112 | get => m_Root.LightingDataAsset.m_BakedReflectionProbes; 113 | set => m_Root.LightingDataAsset.m_BakedReflectionProbes = value; 114 | } 115 | 116 | public byte[] enlightenData 117 | { 118 | get => m_Root.LightingDataAsset.m_EnlightenData; 119 | set => m_Root.LightingDataAsset.m_EnlightenData = value; 120 | } 121 | 122 | public int enlightenDataVersion 123 | { 124 | get => m_Root.LightingDataAsset.m_EnlightenDataVersion; 125 | set => m_Root.LightingDataAsset.m_EnlightenDataVersion = value; 126 | } 127 | 128 | public void Read(LightingDataAsset source) 129 | { 130 | var json = EditorJsonUtility.ToJson(source); 131 | EditorJsonUtility.FromJsonOverwrite(json, m_Root); 132 | EditorUtility.SetDirty(this); 133 | } 134 | 135 | public void Write(LightingDataAsset destination) 136 | { 137 | var json = EditorJsonUtility.ToJson(m_Root); 138 | EditorJsonUtility.FromJsonOverwrite(json, destination); 139 | EditorUtility.SetDirty(destination); 140 | } 141 | 142 | public void UpdateScene() 143 | { 144 | // Assign the lightmap settings values. 145 | LightmapSettings.lightmapsMode = (LightmapsMode)lightmapsMode; 146 | LightmapSettings.lightProbes = lightProbes; 147 | 148 | // Build the lightmap texture array 149 | if (lightmaps == null) 150 | LightmapSettings.lightmaps = null; 151 | else 152 | { 153 | var lightmaps = new UnityEngine.LightmapData[this.lightmaps.Length]; 154 | 155 | for (int i = 0; i < lightmaps.Length; i++) 156 | { 157 | lightmaps[i] = new UnityEngine.LightmapData 158 | { 159 | lightmapColor = this.lightmaps[i].lightmap, 160 | lightmapDir = this.lightmaps[i].dirLightmap, 161 | shadowMask = this.lightmaps[i].shadowMask 162 | }; 163 | } 164 | 165 | LightmapSettings.lightmaps = lightmaps; 166 | } 167 | 168 | if (scene == null) 169 | return; 170 | 171 | if (lightBakingOutputs != null && lights != null) 172 | { 173 | var lights = new Light[this.lights.Length]; 174 | SceneObjectIdentifier.SceneObjectIdentifiersToObjectsSlow(scene, this.lights, lights); 175 | 176 | for (int i = 0, n = Mathf.Min(lights.Length, lightBakingOutputs.Length); i < n; i++) 177 | { 178 | var lightBakingOutput = lightBakingOutputs[i]; 179 | 180 | if (lights[i] == null) 181 | continue; 182 | 183 | lights[i].bakingOutput = new UnityEngine.LightBakingOutput 184 | { 185 | probeOcclusionLightIndex = lightBakingOutput.probeOcclusionLightIndex, 186 | occlusionMaskChannel = lightBakingOutput.occlusionMaskChannel, 187 | lightmapBakeType = (LightmapBakeType)lightBakingOutput.lightmapBakeMode.lightmapBakeType, 188 | mixedLightingMode = (MixedLightingMode)lightBakingOutput.lightmapBakeMode.mixedLightingMode, 189 | isBaked = lightBakingOutput.isBaked, 190 | }; 191 | } 192 | } 193 | 194 | if (lightmappedRendererData != null && lightmappedRendererDataIDs != null) 195 | { 196 | var renderers = new Object[lightmappedRendererDataIDs.Length]; 197 | SceneObjectIdentifier.SceneObjectIdentifiersToObjectsSlow(scene, lightmappedRendererDataIDs, renderers); 198 | 199 | for (int i = 0, n = Mathf.Min(renderers.Length, lightmappedRendererData.Length); i < n; i++) 200 | { 201 | var rendererData = lightmappedRendererData[i]; 202 | 203 | if (renderers[i] is MeshRenderer renderer && renderer != null) 204 | { 205 | renderer.lightmapIndex = rendererData.lightmapIndex; 206 | renderer.realtimeLightmapIndex = rendererData.lightmapIndexDynamic; 207 | renderer.lightmapScaleOffset = rendererData.lightmapST; 208 | renderer.realtimeLightmapScaleOffset = rendererData.lightmapSTDynamic; 209 | renderer.enlightenVertexStream = rendererData.uvMesh; 210 | } 211 | else if (renderers[i] is Terrain terrain && terrain != null) 212 | { 213 | terrain.lightmapIndex = rendererData.lightmapIndex; 214 | terrain.realtimeLightmapIndex = rendererData.lightmapIndexDynamic; 215 | terrain.lightmapScaleOffset = rendererData.lightmapST; 216 | terrain.realtimeLightmapScaleOffset = rendererData.lightmapSTDynamic; 217 | 218 | var root = new TerrainRoot 219 | { 220 | Terrain = new TerrainRoot.SerializedData 221 | { 222 | m_DynamicUVST = rendererData.terrainDynamicUVST, 223 | m_ChunkDynamicUVST = rendererData.terrainChunkDynamicUVST, 224 | m_ExplicitProbeSetHash = rendererData.explicitProbeSetHash 225 | } 226 | }; 227 | 228 | var json = EditorJsonUtility.ToJson(root); 229 | EditorJsonUtility.FromJsonOverwrite(json, terrain); 230 | } 231 | } 232 | } 233 | } 234 | 235 | public static LightingDataAsset CreateAsset() 236 | { 237 | // Unfortunately, ObjectFactory.CreateDefaultInstance is not public, so we need to reflect into it. 238 | var asset = ObjectFactoryInternal.CreateDefaultInstance(); 239 | 240 | // We have to use FromJsonOverwrite instead of SerializedObject, because the latter will call the 241 | // native LightingDataAsset::CheckConsistency method, which will check the enlighten data version 242 | // and produce a warning if it does not match the expected value. 243 | EditorJsonUtility.FromJsonOverwrite("{ \"LightingDataAsset\": { \"m_EnlightenDataVersion\": 112 } }", asset); 244 | return asset; 245 | } 246 | 247 | [Serializable] 248 | sealed class LightingDataAssetRoot 249 | { 250 | public SerializedData LightingDataAsset; 251 | 252 | [Serializable] 253 | public struct SerializedData 254 | { 255 | public int serializedVersion; 256 | public SceneAsset m_Scene; 257 | public LightmapData[] m_Lightmaps; 258 | public Texture2D[] m_AOTextures; 259 | public string[] m_LightmapsCacheFiles; 260 | public LightProbes m_LightProbes; 261 | public int m_LightmapsMode; 262 | public SphericalHarmonicsL2 m_BakedAmbientProbeInLinear; 263 | public RendererData[] m_LightmappedRendererData; 264 | public SceneObjectIdentifier[] m_LightmappedRendererDataIDs; 265 | public EnlightenSceneMapping m_EnlightenSceneMapping; 266 | public SceneObjectIdentifier[] m_EnlightenSceneMappingRendererIDs; 267 | public SceneObjectIdentifier[] m_Lights; 268 | public LightBakingOutput[] m_LightBakingOutputs; 269 | public string[] m_BakedReflectionProbeCubemapCacheFiles; 270 | public Texture[] m_BakedReflectionProbeCubemaps; 271 | public SceneObjectIdentifier[] m_BakedReflectionProbes; 272 | public byte[] m_EnlightenData; 273 | public int m_EnlightenDataVersion; 274 | } 275 | } 276 | 277 | [Serializable] 278 | sealed class TerrainRoot 279 | { 280 | public SerializedData Terrain; 281 | 282 | [Serializable] 283 | public struct SerializedData 284 | { 285 | public Vector4 m_DynamicUVST; 286 | public Vector4 m_ChunkDynamicUVST; 287 | public Hash128 m_ExplicitProbeSetHash; 288 | } 289 | } 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /Editor/LightingData/ScriptableLightingData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f36c903e6bbc2284285dd7eb83611dca 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/LightmappingInternal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using UnityEditor; 4 | 5 | namespace NewBlood 6 | { 7 | public static class LightmappingInternal 8 | { 9 | static readonly object[] s_BakeAnalyticsParameters = new object[1]; 10 | 11 | static readonly EventInfo s_BakeAnalytics = typeof(Lightmapping).GetEvent("bakeAnalytics", BindingFlags.NonPublic | BindingFlags.Static); 12 | 13 | public static bool bakeAnalyticsSupported => s_BakeAnalytics != null; 14 | 15 | public static event Action bakeAnalytics 16 | { 17 | add 18 | { 19 | s_BakeAnalyticsParameters[0] = value; 20 | s_BakeAnalytics?.AddMethod?.Invoke(null, s_BakeAnalyticsParameters); 21 | } 22 | 23 | remove 24 | { 25 | s_BakeAnalyticsParameters[0] = value; 26 | s_BakeAnalytics?.RemoveMethod?.Invoke(null, s_BakeAnalyticsParameters); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Editor/LightmappingInternal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 251407f9c9f748343b57bf2bc48ea89c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MetadataNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewBlood 4 | { 5 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] 6 | sealed class MetadataNameAttribute : Attribute 7 | { 8 | public string Name { get; } 9 | 10 | public MetadataNameAttribute(string name) 11 | { 12 | Name = name; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Editor/MetadataNameAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db043af3ae81bc642895a9f7c8e6f65c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NewBlood.LightingInternals.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NewBlood.LightingInternals", 3 | "rootNamespace": "", 4 | "references": [], 5 | "includePlatforms": [ 6 | "Editor" 7 | ], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": true, 10 | "overrideReferences": true, 11 | "precompiledReferences": [ 12 | "Mono.Cecil.dll" 13 | ], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Editor/NewBlood.LightingInternals.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80fd4d055bc59fb46a7cfe952d8d1428 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ObjectFactoryInternal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using UnityEditor; 4 | using Object = UnityEngine.Object; 5 | 6 | namespace NewBlood 7 | { 8 | static class ObjectFactoryInternal 9 | { 10 | static readonly MethodInfo s_CreateDefaultInstance = typeof(ObjectFactory).GetMethod("CreateDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static); 11 | 12 | static readonly Func s_CreateDefaultInstanceFunc = (Func)s_CreateDefaultInstance.CreateDelegate(typeof(Func)); 13 | 14 | public static Object CreateDefaultInstance(Type type) 15 | { 16 | return s_CreateDefaultInstanceFunc(type); 17 | } 18 | 19 | public static T CreateDefaultInstance() 20 | where T : Object 21 | { 22 | return (T)s_CreateDefaultInstanceFunc(typeof(T)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Editor/ObjectFactoryInternal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27ed8548aa50b174d8bf4f37d0bdc46e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 New Blood Interactive 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c124797c856bcf45ab2585ed2700dbc 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lighting Internals Package 2 | Provides access to internal lighting APIs. 3 | 4 | # `ScriptableLightingData` 5 | Provides access to the information contained in the `LightingDataAsset` class. To use it, create a new instance and call `Read`: 6 | ```cs 7 | var data = ScriptableObject.CreateInstance(); 8 | data.Read(Lightmapping.lightingDataAsset); 9 | ``` 10 | In order to save your changes back to the `LightingDataAsset`, use the `Write` method: 11 | ```cs 12 | data.Write(Lightmapping.lightingDataAsset); 13 | ``` 14 | 15 | # `ScriptableLightProbes` 16 | Provides access to the information contained in the `LightProbes` class. To use it, create a new instance and call `Read`: 17 | ```cs 18 | var probes = ScriptableObject.CreateInstance(); 19 | probes.Read(LightmapSettings.lightProbes); 20 | ``` 21 | In order to save your changes back to the `LightProbes`, use the `Write` method: 22 | ```cs 23 | probes.Write(LightmapSettings.lightProbes); 24 | ``` 25 | 26 | # `LightmappingInternal` 27 | Provides access to the `bakeAnalytics` callback, which receives detailed information about lightmap bakes. This comes in the form of a JSON string, which can be deserialized through the `LightmappingAnalyticsData` type. 28 | 29 | ```cs 30 | LightmappingInternal.bakeAnalytics += OnBakeAnalytics; 31 | 32 | // ... 33 | 34 | static void OnBakeAnalytics(string json) 35 | { 36 | switch (JsonUtility.FromJson(json).outcome) 37 | { 38 | case "success": 39 | // Bake completed successfully 40 | break; 41 | case "cancelled": 42 | case "forcestop": 43 | case "interrupted": 44 | // Bake completed unsuccessfully 45 | break; 46 | } 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b298cd925d33594995b1896a93978bb 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.newblood.lighting-internals", 3 | "displayName": "Lighting Internals", 4 | "description": "Provides access to internal lighting APIs.", 5 | "version": "1.0.0", 6 | "type": "library", 7 | "dependencies": 8 | { 9 | "com.unity.nuget.mono-cecil": "1.10.2" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3792fd26ca07c3f47af4a023d23a2c3c 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------