Fog.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. namespace UnityEngine.Rendering.PostProcessing
  3. {
  4. /// <summary>
  5. /// This class holds settings for the Fog effect with the deferred rendering path.
  6. /// </summary>
  7. [Serializable]
  8. public sealed class Fog
  9. {
  10. /// <summary>
  11. /// If <c>true</c>, enables the internal deferred fog pass. Actual fog settings should be
  12. /// set in the Lighting panel.
  13. /// </summary>
  14. [Tooltip("Enables the internal deferred fog pass. Actual fog settings should be set in the Lighting panel.")]
  15. public bool enabled = true;
  16. /// <summary>
  17. /// Should the fog affect the skybox?
  18. /// </summary>
  19. [Tooltip("Mark true for the fog to ignore the skybox")]
  20. public bool excludeSkybox = true;
  21. internal DepthTextureMode GetCameraFlags()
  22. {
  23. return DepthTextureMode.Depth;
  24. }
  25. internal bool IsEnabledAndSupported(PostProcessRenderContext context)
  26. {
  27. return enabled
  28. && RenderSettings.fog
  29. && !RuntimeUtilities.scriptableRenderPipelineActive
  30. && context.resources.shaders.deferredFog
  31. && context.resources.shaders.deferredFog.isSupported
  32. && context.camera.actualRenderingPath == RenderingPath.DeferredShading; // In forward fog is already done at shader level
  33. }
  34. internal void Render(PostProcessRenderContext context)
  35. {
  36. var sheet = context.propertySheets.Get(context.resources.shaders.deferredFog);
  37. sheet.ClearKeywords();
  38. var fogColor = RuntimeUtilities.isLinearColorSpace ? RenderSettings.fogColor.linear : RenderSettings.fogColor;
  39. sheet.properties.SetVector(ShaderIDs.FogColor, fogColor);
  40. sheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
  41. var cmd = context.command;
  42. cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, excludeSkybox ? 1 : 0);
  43. }
  44. }
  45. }