运动模糊,代码如下:
1 using UnityEngine; 2 3 public class MotionBlurRenderer : PostEffectRenderer 4 { 5 [Range(0.1f, 0.9f)] 6 [SerializeField] 7 float m_blurAmount = 0.1f; 8 9 RenderTexture m_accumulationTexture; 10 11 void OnDisable() 12 { 13 DestroyImmediate(m_accumulationTexture); 14 } 15 16 protected override void OnRenderImage(RenderTexture src, RenderTexture dest) 17 { 18 if (!m_accumulationTexture || m_accumulationTexture.width != src.width || m_accumulationTexture.height != src.height) 19 { 20 DestroyImmediate(m_accumulationTexture); 21 m_accumulationTexture = new RenderTexture(src.width, src.height, 0); 22 //m_accumulationTexture.hideFlags = HideFlags.HideAndDontSave; 23 Graphics.Blit(src, m_accumulationTexture); 24 } 25 26 //m_accumulationTexture.MarkRestoreExpected(); 27 28 Mat.SetFloat("_BlurAmount", m_blurAmount); 29 30 Graphics.Blit(src, m_accumulationTexture, Mat); 31 Graphics.Blit(m_accumulationTexture, dest); 32 33 base.OnRenderImage(src, dest); 34 } 35 36 protected override string ShaderName 37 { 38 get { return "Custom/Study/Motion Shader"; } 39 } 40 }