using System;
using System.Collections.Generic;

namespace UnityEngine.Rendering.Universal
{
    public class EnvironmentUrp : ScriptableRendererFeature
    {
        VolumetricFogPass m_volumetricFogPass = null;
        //RainOcclusionPass m_RainOcclusionPass = null;
        AtomsphericScatteringPass m_AtomsphricScatteringPass = null;
        DrawFoliagePass m_RenderTransparentFoliagePass = null;
        DrawFoliagePass m_RenderTransparentNeedDepthAndFogPass = null;

        public override void Create()
        {
            m_volumetricFogPass = new VolumetricFogPass(RenderPassEvent.BeforeRenderingOpaques);
            //m_RainOcclusionPass = new RainOcclusionPass();

            StencilStateData stencilData = new StencilStateData();  // TODO : copy from ForwardRender
            LayerMask transparentLayerMask = -1;    // TODO : copy from ForwardRender
            m_RenderTransparentFoliagePass = new DrawFoliagePass("Transparents Foliage", "FoliageForward", false, 
                RenderPassEvent.BeforeRenderingSkybox + 1, 
                RenderQueueRange.transparent, transparentLayerMask, StencilState.defaultValue, stencilData.stencilReference);
            m_RenderTransparentNeedDepthAndFogPass = new DrawFoliagePass("Transparents Depth & Fog", "TransparentDepthFog", false, 
                RenderPassEvent.AfterRenderingSkybox + 10, 
                RenderQueueRange.transparent, transparentLayerMask, StencilState.defaultValue, stencilData.stencilReference);

            m_AtomsphricScatteringPass = new AtomsphericScatteringPass(RenderPassEvent.AfterRenderingSkybox + 30);


        }

        public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            
            m_volumetricFogPass.Setup(ref renderingData.cameraData.cameraTargetDescriptor, renderer.cameraColorTarget, renderer.cameraDepth);
            renderer.EnqueuePass(m_volumetricFogPass);

            //if (m_RainOcclusionPass.Setup(ref renderingData))
            //{
            //    renderer.EnqueuePass(m_RainOcclusionPass);
            //}


            renderer.EnqueuePass(m_RenderTransparentFoliagePass);
            renderer.EnqueuePass(m_RenderTransparentNeedDepthAndFogPass);
            m_AtomsphricScatteringPass.Setup(ref renderingData.cameraData.cameraTargetDescriptor, renderer.cameraColorTarget, renderer.cameraDepth);
            renderer.EnqueuePass(m_AtomsphricScatteringPass);





        }
    }

}
