IDataProvider.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Collections.Generic;
  2. namespace UnityEngine.Rendering.LookDev
  3. {
  4. /// <summary>
  5. /// Interface that Scriptable Render Pipelines should implement to be able to use LookDev window
  6. /// </summary>
  7. public interface IDataProvider
  8. {
  9. /// <summary>Additional configuration required by this SRP on LookDev's scene creation</summary>
  10. /// <param name="stage">Access element of the LookDev's scene</param>
  11. void FirstInitScene(StageRuntimeInterface stage);
  12. /// <summary>Notify the SRP that sky have changed in LookDev</summary>
  13. /// <param name="camera">The camera of the LookDev's scene</param>
  14. /// <param name="sky">The new Sky informations</param>
  15. /// <param name="stage">Access element of the LookDev's scene</param>
  16. void UpdateSky(Camera camera, Sky sky, StageRuntimeInterface stage);
  17. /// <summary>Notify the LookDev about what debug view mode are available in this SRP</summary>
  18. /// <returns>The list of the mode, None is not required.</returns>
  19. IEnumerable<string> supportedDebugModes { get; }
  20. /// <summary>Notify the SRP about a change in the DebugMode used</summary>
  21. /// <param name="debugIndex">
  22. /// -1: None
  23. /// Others: map the result of <see cref="supportedDebugModes()"/>
  24. /// </param>
  25. void UpdateDebugMode(int debugIndex);
  26. /// <summary>
  27. /// Compute the shadow mask in SRP for LookDev sun simulation
  28. /// </summary>
  29. /// <param name="output">The computed ShadowMask</param>
  30. /// <param name="stage">Access element of the LookDev's scene</param>
  31. void GetShadowMask(ref RenderTexture output, StageRuntimeInterface stage);
  32. /// <summary>
  33. /// Callback called at the beginning of LookDev rendering.
  34. /// </summary>
  35. /// <param name="stage">Access element of the LookDev's scene</param>
  36. void OnBeginRendering(StageRuntimeInterface stage);
  37. /// <summary>
  38. /// Callback called at the beginning of LookDev rendering.
  39. /// </summary>
  40. /// <param name="stage">Access element of the LookDev's scene</param>
  41. void OnEndRendering(StageRuntimeInterface stage);
  42. }
  43. /// <summary>
  44. /// Runtime container representing Sky data given to the scriptable render pipeline for rendering
  45. /// </summary>
  46. public struct Sky
  47. {
  48. /// <summary>The cubemap representing this sky</summary>
  49. public Cubemap cubemap;
  50. /// <summary>The longitude offset to rotate this cubemap</summary>
  51. public float longitudeOffset;
  52. /// <summary>The sky exposure</summary>
  53. public float exposure;
  54. }
  55. /// <summary>Runtime link to reflect some Stage functionality for SRP editing</summary>
  56. public class StageRuntimeInterface
  57. {
  58. System.Func<bool, GameObject> m_AddGameObject;
  59. System.Func<Camera> m_GetCamera;
  60. System.Func<Light> m_GetSunLight;
  61. /// <summary>Construct a StageRuntimeInterface</summary>
  62. /// <param name="AddGameObject">Callback to call when adding a GameObject</param>
  63. /// <param name="GetCamera">Callback to call for getting the Camera</param>
  64. /// <param name="GetSunLight">Callback to call for getting the sun Light</param>
  65. public StageRuntimeInterface(
  66. System.Func<bool, GameObject> AddGameObject,
  67. System.Func<Camera> GetCamera,
  68. System.Func<Light> GetSunLight)
  69. {
  70. m_AddGameObject = AddGameObject;
  71. m_GetCamera = GetCamera;
  72. m_GetSunLight = GetSunLight;
  73. }
  74. /// <summary>Create a gameObject in the stage</summary>
  75. /// <param name="persistent">
  76. /// [OPTIONAL] If true, the object is not recreated with the scene update.
  77. /// Default value: false.
  78. /// </param>
  79. /// <returns></returns>
  80. public GameObject AddGameObject(bool persistent = false)
  81. => m_AddGameObject?.Invoke(persistent);
  82. /// <summary>Get the camera used in the stage</summary>
  83. public Camera camera => m_GetCamera?.Invoke();
  84. /// <summary>Get the sun used in the stage</summary>
  85. public Light sunLight => m_GetSunLight?.Invoke();
  86. /// <summary>Custom data pointer for convenience</summary>
  87. public object SRPData;
  88. }
  89. }