| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  | using System; | 
					
						
							|  |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | using UnityEngine.Rendering; | 
					
						
							|  |  |  | using UnityEngine.Rendering.Universal; | 
					
						
							|  |  |  | using Debug = UnityEngine.Debug; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public class GlitchFeature : ScriptableRendererFeature | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     [Serializable] | 
					
						
							|  |  |  |     public class Settings | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         public RenderTexture glitchTex; | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |         public RenderTexture stencilTex; | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |         public RenderTexture blendTex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public Material blendMat; | 
					
						
							|  |  |  |         public Material fadeMat; | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |         public Material stencilMat; | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |          | 
					
						
							|  |  |  |         public float sample; | 
					
						
							|  |  |  |         public float fadeStrength; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [SerializeField] private Settings _settings = new Settings(); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     private GlitchPass _glitchPass; | 
					
						
							|  |  |  |     private BlendPass _blendPass; | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |     private GlitchStencilPass _stencilPass; | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |      | 
					
						
							|  |  |  |     public override void Create() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |         _blendPass = new BlendPass(_settings); | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |         _glitchPass = new GlitchPass(); | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |         _stencilPass = new GlitchStencilPass(_settings); | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  |         // get glitch stencil information | 
					
						
							|  |  |  |         _stencilPass.renderPassEvent = RenderPassEvent.AfterRendering; | 
					
						
							|  |  |  |         renderer.EnqueuePass(_stencilPass); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |         _blendPass.renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing; | 
					
						
							|  |  |  |         renderer.EnqueuePass(_blendPass); | 
					
						
							| 
									
										
										
										
											2021-04-25 23:44:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // _glitchPass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques; | 
					
						
							|  |  |  |         // _glitchPass.Settings = _settings; | 
					
						
							|  |  |  |         // renderer.EnqueuePass(_glitchPass); | 
					
						
							| 
									
										
										
										
											2021-04-24 02:06:03 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |