Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Rendering.Universal;
- namespace HexagonSurvive.RenderFeatures.Environment
- {
- public class CloudsRenderFeature : ScriptableRendererFeature
- {
- private class CloudsPass : ScriptableRenderPass
- {
- private Mesh _planeMesh;
- private RTHandle _cameraHandle;
- private RTHandle _tempHandle;
- private Material _cloudMaterial;
- private CloudsSettings _settings;
- private static readonly int CameraTex = Shader.PropertyToID("_MainTex");
- public CloudsPass(CloudsSettings settings, RenderPassEvent ev)
- {
- _settings = settings;
- renderPassEvent = ev;
- _tempHandle = RTHandles.Alloc(Screen.width, Screen.height);
- profilingSampler = new ProfilingSampler("Clouds");
- }
- public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
- {
- ConfigureTarget(_cameraHandle);
- ConfigureClear(ClearFlag.All, Color.black);
- }
- public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
- {
- RenderingUtils.ReAllocateIfNeeded(ref _tempHandle, renderingData.cameraData.cameraTargetDescriptor);
- }
- public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
- {
- if (_cloudMaterial == null)
- return;
- CommandBuffer cmd = CommandBufferPool.Get("Clouds");
- context.ExecuteCommandBuffer(cmd);
- cmd.Clear();
- cmd.SetGlobalTexture(CameraTex, _cameraHandle);
- Blitter.BlitCameraTexture(cmd, _cameraHandle, _tempHandle, _cloudMaterial, 0);
- Blitter.BlitCameraTexture(cmd, _tempHandle, _cameraHandle);
- context.ExecuteCommandBuffer(cmd);
- cmd.Clear();
- CommandBufferPool.Release(cmd);
- }
- public void Setup(RTHandle color, Material cloudMaterial)
- {
- _cameraHandle = color;
- _cloudMaterial = cloudMaterial;
- }
- }
- [System.Serializable]
- public class CloudsSettings
- {
- public Vector4 boundsMax;
- public Vector4 boundsMin;
- }
- public Material cloudMaterial;
- public RenderPassEvent renderPassEvent;
- public CloudsSettings settings;
- private CloudsPass _cloudsPass;
- public override void Create()
- {
- _cloudsPass = new CloudsPass(settings, renderPassEvent);
- }
- public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
- {
- if (renderingData.cameraData.isPreviewCamera)
- return;
- renderer.EnqueuePass(_cloudsPass);
- }
- public override void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData)
- {
- _cloudsPass.Setup(renderer.cameraColorTargetHandle, cloudMaterial);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement