Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a modified version of a Scriptable Render Pass written by Harry Heath.
- // Twitter: https://twitter.com/harryh___h/status/1328024692431540224
- // Pastebin: https://pastebin.com/LstBHRZF
- // The original code was used in a recreation of a Mako illustration:
- // https://twitter.com/harryh___h/status/1328006632102526976
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Rendering.Universal;
- public class FullscreenQuadRenderer : ScriptableRenderPass
- {
- string m_ProfilerTag;
- private Material _material;
- private ScriptableRenderer _renderer;
- private bool _isDepth;
- int textureId = -1;
- RenderTargetIdentifier _texture;
- bool _newTexture;
- public FullscreenQuadRenderer(string name)
- {
- renderPassEvent = RenderPassEvent.BeforeRenderingTransparents;
- m_ProfilerTag = name;
- }
- public void Init(Material initMaterial, ScriptableRenderer newRenderer, bool depth)
- {
- _material = initMaterial;
- _renderer = newRenderer;
- textureId = -1;
- _isDepth = depth;
- }
- public void Init(Material initMaterial, string textureName, bool newTexture)
- {
- _material = initMaterial;
- textureId = Shader.PropertyToID(textureName);
- _texture = new RenderTargetIdentifier(textureId);
- _renderer = null;
- _newTexture = newTexture;
- }
- public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
- {
- if (textureId != -1 && _newTexture)
- {
- cmd.GetTemporaryRT(textureId, cameraTextureDescriptor.width, cameraTextureDescriptor.height, 24, FilterMode.Point,
- RenderTextureFormat.ARGBFloat);
- }
- else if (textureId == -1)
- {
- _texture = _isDepth ? _renderer.cameraDepthTarget : _renderer.cameraColorTarget;
- }
- ConfigureTarget(_texture);
- if (_newTexture) ConfigureClear(ClearFlag.All, Color.black);
- }
- public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
- {
- if (_material == null) return;
- CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
- Camera camera = renderingData.cameraData.camera;
- cmd.SetGlobalTexture("_MainTex", _texture);
- cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
- cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, _material);
- cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
- context.ExecuteCommandBuffer(cmd);
- CommandBufferPool.Release(cmd);
- }
- public override void FrameCleanup(CommandBuffer cmd)
- {
- if (textureId != -1 && _newTexture) cmd.ReleaseTemporaryRT(textureId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement