Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class VolumetricSphere : MonoBehaviour
  6. {
  7. #region Public Members
  8. [Header("Parameters")]
  9. [Tooltip("The radius of the sphere")]
  10. [Range(0.0f,50.0f)]public float radius = 3.0f;
  11. [Tooltip("The density of the sphere")]
  12. [Range(0.0f,10.0f)]public float density = 1.0f;
  13. [Tooltip("The curve of the fade-out")]
  14. [Range(0.2f,5.0f)]public float exponent = 1.0f/3.0f;
  15. [Tooltip("The maximum pixelization size")]
  16. [Range(1,10)]public int maxPixelizationLevel = 5;
  17. [Tooltip("Enabled the interpolation between the layers of different pixels size")]
  18. public bool enableLayersInterpolation = true;
  19. [Header("Debug")]
  20. [Tooltip("Outputs the sphere mask")]
  21. public bool debugSphere = false;
  22. #endregion
  23. #region Functions
  24. void Update()
  25. {
  26. Shader.SetGlobalVector("_SpherePosition", transform.position);
  27. Shader.SetGlobalFloat("_SphereRadius", radius);
  28. Shader.SetGlobalFloat("_MaskDensity", density);
  29. Shader.SetGlobalFloat("_MaskExponent", exponent);
  30. Shader.SetGlobalInt("_MaxPixelizationLevel", maxPixelizationLevel);
  31. if (enableLayersInterpolation)
  32. {
  33. Shader.EnableKeyword("_INTERPOLATE_LAYERS_ON");
  34. }
  35. else
  36. {
  37. Shader.DisableKeyword("_INTERPOLATE_LAYERS_ON");
  38. }
  39. if (debugSphere)
  40. {
  41. Shader.EnableKeyword("_DEBUG_MASK_ON");
  42. }
  43. else
  44. {
  45. Shader.DisableKeyword("_DEBUG_MASK_ON");
  46. }
  47. }
  48. //void OnDrawGizmos()
  49. //{
  50. // Color color = Color.green;
  51. // color.a = 0.35f;
  52. // Gizmos.color = color;
  53. // Gizmos.DrawWireSphere(transform.position, radius);
  54. //}
  55. void OnDrawGizmosSelected()
  56. {
  57. Gizmos.color = Color.green;
  58. Gizmos.DrawWireSphere(transform.position, radius);
  59. }
  60. #endregion
  61. }