IESObject.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace UnityEditor.Rendering
  5. {
  6. /// <summary>
  7. /// Various possible type for IES, in HDRP for Rectangular light we use spot version
  8. /// </summary>
  9. public enum IESLightType
  10. {
  11. /// <summary>
  12. /// Point for the IES
  13. /// </summary>
  14. Point,
  15. /// <summary>
  16. /// Spot for IES (compatible with Area Light)
  17. /// </summary>
  18. Spot,
  19. }
  20. /// <summary>
  21. /// Possible values for the IES Size.
  22. /// </summary>
  23. public enum IESResolution
  24. {
  25. /// <summary>Size 16</summary>
  26. IESResolution16 = 16,
  27. /// <summary>Size 32</summary>
  28. IESResolution32 = 32,
  29. /// <summary>Size 64</summary>
  30. IESResolution64 = 64,
  31. /// <summary>Size 128</summary>
  32. IESResolution128 = 128,
  33. /// <summary>Size 256</summary>
  34. IESResolution256 = 256,
  35. /// <summary>Size 512</summary>
  36. IESResolution512 = 512,
  37. /// <summary>Size 1024</summary>
  38. IESResolution1024 = 1024,
  39. /// <summary>Size 2048</summary>
  40. IESResolution2048 = 2048,
  41. /// <summary>Size 4096</summary>
  42. IESResolution4096 = 4096
  43. }
  44. /// <summary>
  45. /// Common class to store metadata of an IES file
  46. /// </summary>
  47. [System.Serializable]
  48. public class IESMetaData
  49. {
  50. /// <summary>
  51. /// Version of the IES File
  52. /// </summary>
  53. public string FileFormatVersion;
  54. /// <summary>
  55. /// Total light intensity (in Lumens) stored on the file, usage of it is optional (through the prefab subasset inside the IESObject)
  56. /// </summary>
  57. public string IESPhotometricType;
  58. /// <summary>
  59. /// IES Max Intensity depends on the various information stored on the IES file
  60. /// </summary>
  61. public float IESMaximumIntensity;
  62. /// <summary>
  63. /// Unit used to measure the IESMaximumIntensity
  64. /// </summary>
  65. public string IESMaximumIntensityUnit;
  66. // IES luminaire product information.
  67. /// <summary>
  68. /// Manufacturer of the current IES file
  69. /// </summary>
  70. public string Manufacturer; // IES keyword MANUFAC
  71. /// <summary>
  72. /// Luninaire Catalog Number
  73. /// </summary>
  74. public string LuminaireCatalogNumber; // IES keyword LUMCAT
  75. /// <summary>
  76. /// Luminaire Description
  77. /// </summary>
  78. public string LuminaireDescription; // IES keyword LUMINAIRE
  79. /// <summary>
  80. /// Lamp Catalog Number
  81. /// </summary>
  82. public string LampCatalogNumber; // IES keyword LAMPCAT
  83. /// <summary>
  84. /// Lamp Description
  85. /// </summary>
  86. public string LampDescription; // IES keyword LAMP
  87. /// <summary>
  88. /// Prefab Light Type (optional to generate the texture used by the renderer)
  89. /// </summary>
  90. public IESLightType PrefabLightType = IESLightType.Point;
  91. /// <summary>
  92. /// Spot angle used for the Gnomonic projection of the IES. This parameter will be responsible of the pixel footprint in the 2D Texture
  93. /// https://en.wikipedia.org/wiki/Gnomonic_projection
  94. /// </summary>
  95. [Range(1f, 179f)]
  96. public float SpotAngle = 120f;
  97. /// <summary>
  98. /// IES Size of the texture used (same parameter for Point and Spot)
  99. /// </summary>
  100. public IESResolution iesSize = IESResolution.IESResolution128;
  101. /// <summary>
  102. /// Enable attenuation used for Spot recommanded to be true, particulary with large angle of "SpotAngle" (cf. Gnomonic Projection)
  103. /// </summary>
  104. public bool ApplyLightAttenuation = true;
  105. /// <summary>
  106. /// Enable max intensity for the texture generation
  107. /// </summary>
  108. public bool UseIESMaximumIntensity = true;
  109. /// <summary>
  110. /// Compression used to generate the texture (CompressedHQ by default (BC7))
  111. /// </summary>
  112. public TextureImporterCompression CookieCompression = TextureImporterCompression.CompressedHQ;
  113. /// <summary>
  114. /// Internally we use 2D projection, we have to choose one axis to project the IES propertly
  115. /// </summary>
  116. [Range(-180f, 180f)]
  117. public float LightAimAxisRotation = -90f;
  118. /// <summary>
  119. /// Get Hash describing an unique IES
  120. /// </summary>
  121. /// <returns>The Hash of the IES Object</returns>
  122. public override int GetHashCode()
  123. {
  124. int hash = base.GetHashCode();
  125. hash = hash * 23 + FileFormatVersion.GetHashCode();
  126. hash = hash * 23 + IESPhotometricType.GetHashCode();
  127. hash = hash * 23 + IESMaximumIntensity.GetHashCode();
  128. hash = hash * 23 + IESMaximumIntensityUnit.GetHashCode();
  129. hash = hash * 23 + Manufacturer.GetHashCode();
  130. hash = hash * 23 + LuminaireCatalogNumber.GetHashCode();
  131. hash = hash * 23 + LuminaireDescription.GetHashCode();
  132. hash = hash * 23 + LampCatalogNumber.GetHashCode();
  133. hash = hash * 23 + LampDescription.GetHashCode();
  134. hash = hash * 23 + PrefabLightType.GetHashCode();
  135. hash = hash * 23 + SpotAngle.GetHashCode();
  136. hash = hash * 23 + iesSize.GetHashCode();
  137. hash = hash * 23 + ApplyLightAttenuation.GetHashCode();
  138. hash = hash * 23 + UseIESMaximumIntensity.GetHashCode();
  139. return hash;
  140. }
  141. }
  142. /// <summary>
  143. /// IESObject manipulated internally (in the UI)
  144. /// </summary>
  145. [System.Serializable]
  146. public class IESObject : ScriptableObject
  147. {
  148. /// <summary>
  149. /// Metadata of the IES file
  150. /// </summary>
  151. public IESMetaData iesMetaData = new IESMetaData();
  152. }
  153. }