PropertySheet.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. namespace UnityEngine.Rendering.PostProcessing
  2. {
  3. /// <summary>
  4. /// The post-processing stack is entirely built around the use of <see cref="CommandBuffer"/>
  5. /// and as such requires the use of <see cref="MaterialPropertyBlock"/> to properly deal with
  6. /// the deferred nature of <see cref="CommandBuffer"/>.
  7. /// This wrapper abstracts the creation and destruction of <see cref="MaterialPropertyBlock"/>
  8. /// and <see cref="Material"/> to make the process easier.
  9. /// </summary>
  10. /// <seealso cref="PropertySheetFactory"/>
  11. public sealed class PropertySheet
  12. {
  13. /// <summary>
  14. /// The actual <see cref="MaterialPropertyBlock"/> to fill.
  15. /// </summary>
  16. public MaterialPropertyBlock properties { get; private set; }
  17. internal Material material { get; private set; }
  18. internal PropertySheet(Material material)
  19. {
  20. this.material = material;
  21. properties = new MaterialPropertyBlock();
  22. }
  23. /// <summary>
  24. /// Clears all keywords set on the source material.
  25. /// </summary>
  26. public void ClearKeywords()
  27. {
  28. material.shaderKeywords = null;
  29. }
  30. /// <summary>
  31. /// Enableds a given keyword on the source material.
  32. /// </summary>
  33. /// <param name="keyword">The keyword to enable</param>
  34. public void EnableKeyword(string keyword)
  35. {
  36. material.EnableKeyword(keyword);
  37. }
  38. /// <summary>
  39. /// Disables a given keyword on the source material.
  40. /// </summary>
  41. /// <param name="keyword">The keyword to disable</param>
  42. public void DisableKeyword(string keyword)
  43. {
  44. material.DisableKeyword(keyword);
  45. }
  46. internal void Release()
  47. {
  48. RuntimeUtilities.Destroy(material);
  49. material = null;
  50. }
  51. }
  52. }