RenderObjects.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Generic;
  2. using UnityEngine.Rendering.Universal;
  3. using UnityEngine.Rendering;
  4. using UnityEngine.Scripting.APIUpdating;
  5. namespace UnityEngine.Experimental.Rendering.Universal
  6. {
  7. [MovedFrom("UnityEngine.Experimental.Rendering.LWRP")]public enum RenderQueueType
  8. {
  9. Opaque,
  10. Transparent,
  11. }
  12. [MovedFrom("UnityEngine.Experimental.Rendering.LWRP")]public class RenderObjects : ScriptableRendererFeature
  13. {
  14. [System.Serializable]
  15. public class RenderObjectsSettings
  16. {
  17. public string passTag = "RenderObjectsFeature";
  18. public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques;
  19. public FilterSettings filterSettings = new FilterSettings();
  20. public Material overrideMaterial = null;
  21. public int overrideMaterialPassIndex = 0;
  22. public bool overrideDepthState = false;
  23. public CompareFunction depthCompareFunction = CompareFunction.LessEqual;
  24. public bool enableWrite = true;
  25. public StencilStateData stencilSettings = new StencilStateData();
  26. public CustomCameraSettings cameraSettings = new CustomCameraSettings();
  27. }
  28. [System.Serializable]
  29. public class FilterSettings
  30. {
  31. // TODO: expose opaque, transparent, all ranges as drop down
  32. public RenderQueueType RenderQueueType;
  33. public LayerMask LayerMask;
  34. public string[] PassNames;
  35. public FilterSettings()
  36. {
  37. RenderQueueType = RenderQueueType.Opaque;
  38. LayerMask = 0;
  39. }
  40. }
  41. [System.Serializable]
  42. public class CustomCameraSettings
  43. {
  44. public bool overrideCamera = false;
  45. public bool restoreCamera = true;
  46. public Vector4 offset;
  47. public float cameraFieldOfView = 60.0f;
  48. }
  49. public RenderObjectsSettings settings = new RenderObjectsSettings();
  50. RenderObjectsPass renderObjectsPass;
  51. public override void Create()
  52. {
  53. FilterSettings filter = settings.filterSettings;
  54. renderObjectsPass = new RenderObjectsPass(settings.passTag, settings.Event, filter.PassNames,
  55. filter.RenderQueueType, filter.LayerMask, settings.cameraSettings);
  56. renderObjectsPass.overrideMaterial = settings.overrideMaterial;
  57. renderObjectsPass.overrideMaterialPassIndex = settings.overrideMaterialPassIndex;
  58. if (settings.overrideDepthState)
  59. renderObjectsPass.SetDetphState(settings.enableWrite, settings.depthCompareFunction);
  60. if (settings.stencilSettings.overrideStencilState)
  61. renderObjectsPass.SetStencilState(settings.stencilSettings.stencilReference,
  62. settings.stencilSettings.stencilCompareFunction, settings.stencilSettings.passOperation,
  63. settings.stencilSettings.failOperation, settings.stencilSettings.zFailOperation);
  64. }
  65. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  66. {
  67. renderer.EnqueuePass(renderObjectsPass);
  68. }
  69. }
  70. }