Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.67 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3.  
  4. [Serializable]
  5. public class CycleParameters
  6. {
  7. public float TimeOfDay = 12f; // [ 0, 24 ] Hour of the day
  8. public float JulianDate = 180f; // [ 1, 365 ] Day of the year, going from Jan 1st [=1] to Dec 31st [=365]
  9. public float Latitude = 0f; // [ -90, 90 ] Horizontal earth lines, 0 is located at the equator
  10. public float Longitude = 0f; // [ -180, 180 ] Vertical earth lines, 0 is located at Greenwich, England
  11. }
  12.  
  13. [Serializable]
  14. public class DayParameters
  15. {
  16. public float RayleighMultiplier = 1.0f;
  17. public float MieMultiplier = 0.1f;
  18. public float Brightness = 10.0f;
  19. public float Haziness = 0.5f;
  20. public Color Color = Color.black;
  21. }
  22.  
  23. [Serializable]
  24. public class NightParameters
  25. {
  26. public float Haziness = 0.5f;
  27. public Color Color = Color.black;
  28. public Color HazeColor = Color.black;
  29. public Color CloudColor = Color.clear;
  30. }
  31.  
  32. [Serializable]
  33. public class SunParameters
  34. {
  35. public float LightIntensity = 0.75f;
  36. public float Falloff = 1.25f;
  37. public float Coloring = 0.25f;
  38. }
  39.  
  40. [Serializable]
  41. public class MoonParameters
  42. {
  43. public float LightIntensity = 0.05f;
  44. public float Phase = 0.0f;
  45. public Color HaloColor = Color.black;
  46. }
  47.  
  48. [Serializable]
  49. public class CloudParameters
  50. {
  51. public float Tone = 1.5f;
  52. public float Shading = 0.5f;
  53. public float Density = 1.0f;
  54. public float Sharpness = 1.0f;
  55. public float Speed1 = 0.5f;
  56. public float Speed2 = 1.0f;
  57. public float Scale1 = 3.0f;
  58. public float Scale2 = 7.0f;
  59. }
  60.  
  61. [ExecuteInEditMode]
  62. public class Sky : MonoBehaviour
  63. {
  64. // Component references
  65. // These are already setup in the prefab
  66. public GameObject SunInstance = null;
  67. public GameObject MoonInstance = null;
  68. public GameObject AtmosphereInstance = null;
  69. public GameObject CloudInstance = null;
  70.  
  71. // Color space (can be linear or gamma)
  72. // This has to be set by the user
  73. public bool LinearLighting = false;
  74.  
  75. // Dome parameters
  76. public CycleParameters Cycle = null;
  77. public DayParameters Day = null;
  78. public NightParameters Night = null;
  79. public SunParameters Sun = null;
  80. public MoonParameters Moon = null;
  81. public CloudParameters Clouds = null;
  82.  
  83. // Shader parameters
  84. private Vector3 betaRayleigh;
  85. private Vector3 betaRayleighTheta;
  86. private Vector3 betaMie;
  87. private Vector3 betaMieTheta;
  88. private Vector3 henyeyGreenstein;
  89.  
  90. // Component pointers for faster access
  91. internal Transform DomeTransform;
  92. internal Material AtmosphereShader;
  93. internal Material CloudShader;
  94. internal Transform SunTransform;
  95. internal Renderer SunRenderer;
  96. internal Material SunShader;
  97. internal Material SunHalo;
  98. internal Light SunLight;
  99. internal Transform MoonTransform;
  100. internal Renderer MoonRenderer;
  101. internal Material MoonShader;
  102. internal Material MoonHalo;
  103. internal Light MoonLight;
  104.  
  105. // Property and state accessors
  106. public bool IsDay // ранее был internal
  107. {
  108. get { return SunLight.enabled; }
  109. }
  110. internal bool IsNight
  111. {
  112. get { return MoonLight.enabled; }
  113. }
  114. internal float OrbitRadius
  115. {
  116. get { return DomeTransform.localScale.x; }
  117. }
  118. internal float Gamma
  119. {
  120. get { return LinearLighting ? 1.0f : 2.2f; }
  121. }
  122. internal float OneOverGamma
  123. {
  124. get { return LinearLighting ? 1.0f/1.0f : 1.0f/2.2f; }
  125. }
  126.  
  127. // Red wavelength
  128. const float lambda_r1 = 700.0e-9f;
  129. const float lambda_r2 = lambda_r1 * lambda_r1;
  130. const float lambda_r4 = lambda_r2 * lambda_r2;
  131.  
  132. // Green wavelength
  133. const float lambda_g1 = 575.0e-9f;
  134. const float lambda_g2 = lambda_g1 * lambda_g1;
  135. const float lambda_g4 = lambda_g2 * lambda_g2;
  136.  
  137. // Blue wavelength
  138. const float lambda_b1 = 450.0e-9f;
  139. const float lambda_b2 = lambda_b1 * lambda_b1;
  140. const float lambda_b4 = lambda_b2 * lambda_b2;
  141.  
  142. // Powers of PI
  143. const float pi = Mathf.PI;
  144. const float pi2 = pi*pi;
  145. const float pi3 = pi*pi2;
  146. const float pi4 = pi2*pi2;
  147.  
  148. // Unity: OnEnable
  149. protected void OnEnable()
  150. {
  151. DomeTransform = transform;
  152.  
  153. if (AtmosphereInstance)
  154. {
  155. AtmosphereShader = AtmosphereInstance.GetComponent<Renderer>().sharedMaterial;
  156. }
  157.  
  158. if (CloudInstance)
  159. {
  160. CloudShader = CloudInstance.GetComponent<Renderer>().sharedMaterial;
  161. }
  162.  
  163. if (SunInstance)
  164. {
  165. SunTransform = SunInstance.transform;
  166. SunRenderer = SunInstance.GetComponent<Renderer>();
  167. SunShader = SunRenderer.sharedMaterial;
  168. SunLight = SunInstance.GetComponent<Light>();
  169.  
  170. if (SunRenderer.sharedMaterials.Length > 1)
  171. SunHalo = SunRenderer.sharedMaterials[1];
  172. }
  173. else
  174. {
  175. Debug.LogError("Sun instance reference not set. Disabling script.");
  176. this.enabled = false;
  177. }
  178.  
  179. if (MoonInstance)
  180. {
  181. MoonTransform = MoonInstance.transform;
  182. MoonRenderer = MoonInstance.GetComponent<Renderer>();
  183. MoonShader = MoonRenderer.sharedMaterial;
  184. MoonLight = MoonInstance.GetComponent<Light>();
  185.  
  186. if (MoonRenderer.sharedMaterials.Length > 1)
  187. MoonHalo = MoonRenderer.sharedMaterials[1];
  188. }
  189. else
  190. {
  191. Debug.LogError("Moon instance reference not set. Disabling script.");
  192. this.enabled = false;
  193. }
  194. }
  195.  
  196. // Unity: Update
  197. protected void Update()
  198. {
  199. ValidateScriptParameters();
  200. SetupRayleighScattering();
  201. SetupMieScattering();
  202. SetupHenyeyGreensteinPhaseFunction();
  203. SetupSunAndMoon();
  204. SetupShaderParameters();
  205. }
  206.  
  207. private void SetupShaderParameters()
  208. {
  209. Vector3 objSpaceSunDir = DomeTransform.InverseTransformDirection(SunTransform.forward);
  210.  
  211. Color sunColorGamma = AdjustColorGamma(SunLight.color);
  212. Color dayColorGamma = AdjustColorGamma(Day.Color * Day.Color.a);
  213. Color nightColorGamma = AdjustColorGamma(Night.Color * Night.Color.a);
  214. Color nightHazeColorGamma = AdjustColorGamma(Night.HazeColor * Night.HazeColor.a);
  215. Color nightCloudColorGamma = AdjustColorGamma(Night.CloudColor);
  216.  
  217. Color sunHaloColor = SunLight.color;
  218. sunHaloColor.a *= SunLight.intensity / Sun.LightIntensity;
  219.  
  220. Color moonHaloColor = Moon.HaloColor;
  221. moonHaloColor.a *= MoonLight.intensity / Moon.LightIntensity;
  222.  
  223. if (AtmosphereShader != null)
  224. {
  225. AtmosphereShader.SetColor("_SunColor", sunColorGamma);
  226. AtmosphereShader.SetVector("_SunDirection", objSpaceSunDir);
  227.  
  228. AtmosphereShader.SetFloat("_OneOverGamma", OneOverGamma);
  229. AtmosphereShader.SetFloat("_DayBrightness", Day.Brightness);
  230. AtmosphereShader.SetFloat("_DayHaziness", Day.Haziness);
  231. AtmosphereShader.SetFloat("_NightHaziness", Night.Haziness);
  232. AtmosphereShader.SetColor("_DayColor", dayColorGamma);
  233. AtmosphereShader.SetColor("_NightColor", nightColorGamma);
  234. AtmosphereShader.SetColor("_NightHazeColor", nightHazeColorGamma);
  235. AtmosphereShader.SetVector("_BetaRayleigh", betaRayleigh);
  236. AtmosphereShader.SetVector("_BetaRayleighTheta", betaRayleighTheta);
  237. AtmosphereShader.SetVector("_BetaMie", betaMie);
  238. AtmosphereShader.SetVector("_BetaMieTheta", betaMieTheta);
  239. AtmosphereShader.SetVector("_HenyeyGreenstein", henyeyGreenstein);
  240. }
  241.  
  242. if (CloudShader != null)
  243. {
  244. CloudShader.SetColor("_LightColor", Color.Lerp(nightCloudColorGamma, sunColorGamma, sunColorGamma.a));
  245. CloudShader.SetVector("_LightDirection", objSpaceSunDir);
  246.  
  247. CloudShader.SetFloat("_OneOverGamma", OneOverGamma);
  248. CloudShader.SetFloat("_CloudTone", Clouds.Tone);
  249. CloudShader.SetFloat("_CloudDensity", Clouds.Density);
  250. CloudShader.SetFloat("_CloudSharpness", Clouds.Sharpness);
  251. CloudShader.SetFloat("_CloudShading", Clouds.Shading);
  252. CloudShader.SetFloat("_CloudSpeed1", Clouds.Speed1);
  253. CloudShader.SetFloat("_CloudSpeed2", Clouds.Speed2);
  254. CloudShader.SetFloat("_CloudScale1", Clouds.Scale1);
  255. CloudShader.SetFloat("_CloudScale2", Clouds.Scale2);
  256. }
  257.  
  258. if (MoonShader != null)
  259. {
  260. MoonShader.SetFloat("_Phase", Moon.Phase);
  261. }
  262.  
  263. if (MoonHalo != null)
  264. {
  265. MoonHalo.SetColor("_Color", moonHaloColor);
  266. }
  267.  
  268. if (SunShader != null)
  269. {
  270. SunShader.SetColor("_Color", sunHaloColor);
  271. }
  272.  
  273. if (SunHalo != null)
  274. {
  275. SunHalo.SetColor("_Color", sunHaloColor);
  276. }
  277. }
  278.  
  279. // Henyey Greenstein phase function - may vary with viewer height at some point in the future
  280. private void SetupHenyeyGreensteinPhaseFunction()
  281. {
  282. const float g = 0.55f; // Directionality factor
  283.  
  284. // See [2] page 27
  285. henyeyGreenstein.x = 1-g*g;
  286. henyeyGreenstein.y = 1+g*g;
  287. henyeyGreenstein.z = 2*g;
  288. }
  289.  
  290. // Rayleigh scattering
  291. private void SetupRayleighScattering()
  292. {
  293. const float n = 1.0003000f; // Refractive index of air in the visible spectrum
  294. const float N = 2.5450e25f; // Number of molecules per unit volume
  295.  
  296. // See [1] page 23
  297. // See [2] page 24 equation (2.2)
  298. betaRayleigh.x = Day.RayleighMultiplier * 8*pi3 * (n*n-1)*(n*n-1) / (3*N*lambda_r4);
  299. betaRayleigh.y = Day.RayleighMultiplier * 8*pi3 * (n*n-1)*(n*n-1) / (3*N*lambda_g4);
  300. betaRayleigh.z = Day.RayleighMultiplier * 8*pi3 * (n*n-1)*(n*n-1) / (3*N*lambda_b4);
  301.  
  302. // See [1] page 23
  303. // See [2] page 24 equation (2.1)
  304. betaRayleighTheta.x = Day.RayleighMultiplier * pi2 * (n*n-1)*(n*n-1) / (2*N*lambda_r4);
  305. betaRayleighTheta.y = Day.RayleighMultiplier * pi2 * (n*n-1)*(n*n-1) / (2*N*lambda_g4);
  306. betaRayleighTheta.z = Day.RayleighMultiplier * pi2 * (n*n-1)*(n*n-1) / (2*N*lambda_b4);
  307. }
  308.  
  309. // Mie scattering
  310. private void SetupMieScattering()
  311. {
  312. const float t = 1.0f; // Turbidity
  313. const float c = (0.6544f * t - 0.6510f) * 1e-16f; // Concentration factor
  314.  
  315. // Wavelength-dependent constants
  316. const float k_r = 0.687112f;
  317. const float k_g = 0.679802f;
  318. const float k_b = 0.665996f;
  319.  
  320. // See [1] page 23
  321. // See [2] page 26 equation (2.5)
  322. betaMie.x = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_r2 * k_r * pi;
  323. betaMie.y = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_g2 * k_g * pi;
  324. betaMie.z = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_b2 * k_b * pi;
  325.  
  326. // See [1] page 23
  327. // See [2] page 25 equation (2.3)
  328. betaMieTheta.x = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_r2 * 0.5f;
  329. betaMieTheta.y = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_g2 * 0.5f;
  330. betaMieTheta.z = Day.MieMultiplier * 0.434f*c * 4f*pi2 / lambda_b2 * 0.5f;
  331. }
  332.  
  333. // Calculate sun and moon position
  334. // See [1] page 26
  335. private void SetupSunAndMoon()
  336. {
  337. // Solar latitude
  338. float latitudeRadians = Mathf.Deg2Rad * Cycle.Latitude;
  339. float latitudeRadiansSin = Mathf.Sin(latitudeRadians);
  340. float latitudeRadiansCos = Mathf.Cos(latitudeRadians);
  341.  
  342. // Solar longitude
  343. float longitudeRadians = Mathf.Deg2Rad * Cycle.Longitude;
  344.  
  345. // Solar declination - constant for the whole globe at any given day
  346. float solarDeclination = 0.4093f * Mathf.Sin(2f*pi/368f * (Cycle.JulianDate-81f));
  347. float solarDeclinationSin = Mathf.Sin(solarDeclination);
  348. float solarDeclinationCos = Mathf.Cos(solarDeclination);
  349.  
  350. // Solar time
  351. float timeZone = (int)(Cycle.Longitude/15f);
  352. float meridian = Mathf.Deg2Rad * 15f * timeZone;
  353. float solarTime = Cycle.TimeOfDay
  354. + 0.170f * Mathf.Sin(4f*pi/373f * (Cycle.JulianDate-80f))
  355. - 0.129f * Mathf.Sin(2f*pi/355f * (Cycle.JulianDate-8f))
  356. + 12f/pi * (meridian - longitudeRadians);
  357. float solarTimeRadians = pi/12f * solarTime;
  358. float solarTimeSin = Mathf.Sin(solarTimeRadians);
  359. float solarTimeCos = Mathf.Cos(solarTimeRadians);
  360.  
  361. // Solar altitude angle - angle between the sun and the horizon
  362. float solarAltitudeSin = latitudeRadiansSin * solarDeclinationSin
  363. - latitudeRadiansCos * solarDeclinationCos * solarTimeCos;
  364. float solarAltitude = Mathf.Asin(solarAltitudeSin);
  365.  
  366. // Solar azimuth angle - angle of the sun around the horizon
  367. float solarAzimuthY = - solarDeclinationCos * solarTimeSin;
  368. float solarAzimuthX = latitudeRadiansCos * solarDeclinationSin
  369. - latitudeRadiansSin * solarDeclinationCos * solarTimeCos;
  370. float solarAzimuth = Mathf.Atan2(solarAzimuthY, solarAzimuthX);
  371.  
  372. // Convert solar angles to spherical coordinates
  373. float theta = pi/2 - solarAltitude;
  374. float phi = solarAzimuth;
  375.  
  376. // Update sun position
  377. SunTransform.position = DomeTransform.position
  378. + DomeTransform.rotation * SphericalToCartesian(OrbitRadius, theta, phi);
  379. SunTransform.LookAt(DomeTransform.position);
  380.  
  381. // Update moon position
  382. // The following calculation is not physically correct and might be changed at some point in the future
  383. // However, as most people don't pay attention to the moon position this should be a decent workaround for now
  384. MoonTransform.position = DomeTransform.position
  385. + DomeTransform.rotation * SphericalToCartesian(OrbitRadius, theta + pi, phi);
  386. MoonTransform.LookAt(DomeTransform.position);
  387.  
  388. // Update sun and fog color according to the new position of the sun
  389. SetupSunAndMoonColor(theta);
  390. }
  391.  
  392. // Calculate sun and moon color
  393. // See [1] page 21
  394. private void SetupSunAndMoonColor(float theta)
  395. {
  396. // Relative optical mass (air mass coefficient approximated by a spherical shell)
  397. // See http://en.wikipedia.org/wiki/Air_mass_(solar_energy)
  398. float cosTheta = Mathf.Cos(theta * Mathf.Pow(Mathf.Abs(theta/pi), 1/Sun.Falloff));
  399. float m = Mathf.Sqrt(708f*708f * cosTheta*cosTheta + 2*708f + 1) - 708f*cosTheta;
  400.  
  401. // Wavelengths in micrometers
  402. const float lambda_r = lambda_r1*1e6f; // [um]
  403. const float lambda_g = lambda_g1*1e6f; // [um]
  404. const float lambda_b = lambda_b1*1e6f; // [um]
  405.  
  406. // Transmitted sun color
  407. float r = 1, g = 1, b = 1, a = 1;
  408.  
  409. // 1. Transmittance due to Rayleigh scattering of air molecules
  410. const float rayleigh_beta = 0.008735f;
  411. const float rayleigh_alpha = 4.08f;
  412. r *= Mathf.Exp(-rayleigh_beta * Mathf.Pow(lambda_r, -rayleigh_alpha * m));
  413. g *= Mathf.Exp(-rayleigh_beta * Mathf.Pow(lambda_g, -rayleigh_alpha * m));
  414. b *= Mathf.Exp(-rayleigh_beta * Mathf.Pow(lambda_b, -rayleigh_alpha * m));
  415.  
  416. // 2. Angstrom's turbididty formula for aerosal (does not improve anything visually)
  417. //const float aerosol_turbidity = 1.0f;
  418. //const float aerosal_beta = 0.04608f * aerosol_turbidity - 0.04586f;
  419. //const float aerosal_alpha = 1.3f;
  420. //r *= Mathf.Exp(-aerosal_beta * Mathf.Pow(lambda_r, -aerosal_alpha * m));
  421. //g *= Mathf.Exp(-aerosal_beta * Mathf.Pow(lambda_g, -aerosal_alpha * m));
  422. //b *= Mathf.Exp(-aerosal_beta * Mathf.Pow(lambda_b, -aerosal_alpha * m));
  423.  
  424. // 3. Transmittance due to ozone absorption (does not improve anything visually)
  425. //const float ozone_l = 0.350f; // [cm]
  426. //const float ozone_kr = 0.067f; // [1/cm]
  427. //const float ozone_kg = 0.040f; // [1/cm]
  428. //const float ozone_kb = 0.009f; // [1/cm]
  429. //r *= Mathf.Exp(-ozone_kr * Mathf.Pow(lambda_r, -ozone_l * m));
  430. //g *= Mathf.Exp(-ozone_kg * Mathf.Pow(lambda_g, -ozone_l * m));
  431. //b *= Mathf.Exp(-ozone_kb * Mathf.Pow(lambda_b, -ozone_l * m));
  432.  
  433. // Make sure rgb values are valid and calculate sun alpha value
  434. // These checks are required as it appears that there is in fact such thing as negative (or NaN) colors!
  435. r = r > 0 ? r : 0;
  436. g = g > 0 ? g : 0;
  437. b = b > 0 ? b : 0;
  438. a = Mathf.Max(Mathf.Max(r, g), b);
  439.  
  440. // Set sun and fog color
  441. Color sun_aaaa = new Color(a, a, a, a);
  442. Color sun_rgba = new Color(r, g, b, a);
  443. SunLight.color = RenderSettings.fogColor = Color.Lerp(sun_aaaa, sun_rgba, Sun.Coloring);
  444.  
  445. // Sun altitude and intensity dropoff angle
  446. float altitude = pi/2 - theta;
  447. float altitude_abs = Mathf.Abs(altitude);
  448. float dropoff_rad = 10 * Mathf.Deg2Rad;
  449.  
  450. // Set sun and moon intensity
  451. if (altitude > 0)
  452. {
  453. // Disable moon
  454. MoonLight.enabled = MoonRenderer.enabled = false;
  455. MoonLight.intensity = 0;
  456.  
  457. // Enable sun
  458. SunLight.enabled = SunRenderer.enabled = true;
  459. float sunIntensityMax = Sun.LightIntensity;
  460. if (altitude_abs < dropoff_rad)
  461. {
  462. SunLight.intensity = Mathf.Lerp(0, sunIntensityMax, altitude_abs / dropoff_rad);
  463. }
  464. else SunLight.intensity = sunIntensityMax;
  465. }
  466. else
  467. {
  468. // Disable sun
  469. SunLight.enabled = SunRenderer.enabled = false;
  470. SunLight.intensity = 0;
  471.  
  472. // Enable moon
  473. MoonLight.enabled = MoonRenderer.enabled = true;
  474. float moonIntensityMax = Moon.LightIntensity * Mathf.Clamp01(1 - Mathf.Abs(Moon.Phase));
  475. if (altitude_abs < dropoff_rad)
  476. {
  477. MoonLight.intensity = Mathf.Lerp(0, moonIntensityMax, altitude_abs / dropoff_rad);
  478. }
  479. else MoonLight.intensity = moonIntensityMax;
  480. }
  481. }
  482.  
  483. // Make the parameters stay within some sort of reasonable range
  484. private void ValidateScriptParameters()
  485. {
  486. // Cycle
  487. Cycle.TimeOfDay = Mathf.Repeat(Cycle.TimeOfDay, 24);
  488. Cycle.JulianDate = Mathf.Repeat(Cycle.JulianDate - 1, 365) + 1;
  489. Cycle.Longitude = Mathf.Clamp(Cycle.Longitude, -180, 180);
  490. Cycle.Latitude = Mathf.Clamp(Cycle.Latitude, -90, 90);
  491.  
  492. // Day
  493. #if UNITY_EDITOR
  494. Day.MieMultiplier = Mathf.Max(0, Day.MieMultiplier);
  495. Day.RayleighMultiplier = Mathf.Max(0, Day.RayleighMultiplier);
  496. Day.Brightness = Mathf.Max(0, Day.Brightness);
  497. Day.Haziness = Mathf.Max(0, Day.Haziness);
  498. #endif
  499.  
  500. // Night
  501. #if UNITY_EDITOR
  502. Night.Haziness = Mathf.Max(0, Night.Haziness);
  503. #endif
  504.  
  505. // Sun
  506. #if UNITY_EDITOR
  507. Sun.LightIntensity = Mathf.Max(0, Sun.LightIntensity);
  508. Sun.Falloff = Mathf.Max(0, Sun.Falloff);
  509. Sun.Coloring = Mathf.Max(0, Sun.Coloring);
  510. #endif
  511.  
  512. // Moon
  513. #if UNITY_EDITOR
  514. Moon.LightIntensity = Mathf.Max(0, Moon.LightIntensity);
  515. Moon.Phase = Mathf.Clamp(Moon.Phase, -1, +1);
  516. #endif
  517.  
  518. // Clouds
  519. #if UNITY_EDITOR
  520. Clouds.Tone = Mathf.Max(0, Clouds.Tone);
  521. Clouds.Shading = Mathf.Max(0, Clouds.Shading);
  522. Clouds.Density = Mathf.Max(0, Clouds.Density);
  523. Clouds.Sharpness = Mathf.Max(0, Clouds.Sharpness);
  524. #endif
  525. }
  526.  
  527. // Convert spherical coordinates to cartesian coordinates
  528. private Vector3 SphericalToCartesian(float radius, float theta, float phi)
  529. {
  530. Vector3 res;
  531.  
  532. float sinTheta = Mathf.Sin(theta);
  533. float cosTheta = Mathf.Cos(theta);
  534. float sinPhi = Mathf.Sin(phi);
  535. float cosPhi = Mathf.Cos(phi);
  536.  
  537. res.x = radius * sinTheta * cosPhi;
  538. res.y = radius * cosTheta;
  539. res.z = radius * sinTheta * sinPhi;
  540.  
  541. return res;
  542. }
  543.  
  544. // Adjust a color according to the current color space
  545. private Color AdjustColorGamma(Color c)
  546. {
  547. if (LinearLighting) return c;
  548. return new Color(Mathf.Pow(c.r, Gamma), Mathf.Pow(c.g, Gamma), Mathf.Pow(c.b, Gamma), Mathf.Pow(c.a, Gamma));
  549. }
  550. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement