VolumetricFogPosT.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //------------------------------------------------------------------------------------------------------------------
  2. // Volumetric Fog & Mist
  3. // Created by Ramiro Oliva (Kronnect)
  4. //------------------------------------------------------------------------------------------------------------------
  5. using UnityEngine;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. namespace VolumetricFogAndMist
  10. {
  11. [ExecuteInEditMode]
  12. [RequireComponent(typeof(Camera), typeof(VolumetricFog))]
  13. public class VolumetricFogPosT : MonoBehaviour, IVolumetricFogRenderComponent
  14. {
  15. public VolumetricFog fog { get; set; }
  16. Material copyOpaqueMat;
  17. void OnRenderImage(RenderTexture source, RenderTexture destination)
  18. {
  19. if (fog == null || !fog.enabled)
  20. {
  21. Graphics.Blit(source, destination);
  22. return;
  23. }
  24. if (fog.transparencyBlendMode == TRANSPARENT_MODE.None)
  25. {
  26. fog.DoOnRenderImage(source, destination);
  27. } else
  28. {
  29. RenderTextureDescriptor desc = source.descriptor;
  30. RenderTexture opaqueFrame = RenderTexture.GetTemporary(desc);
  31. if (copyOpaqueMat == null)
  32. {
  33. copyOpaqueMat = new Material(Shader.Find("VolumetricFogAndMist/CopyOpaque"));
  34. }
  35. copyOpaqueMat.SetFloat("_BlendPower", fog.transparencyBlendPower);
  36. Graphics.Blit(source, destination, copyOpaqueMat, (fog.computeDepth && fog.downsampling==1) ? 1: 0);
  37. RenderTexture.ReleaseTemporary(opaqueFrame);
  38. }
  39. }
  40. public void DestroySelf()
  41. {
  42. DestroyImmediate(this);
  43. }
  44. }
  45. }