Esempio n. 1
0
        static public void Setup(RenderingData renderingData, Renderer2DData renderer2DData)
        {
            s_Renderer2DData = renderer2DData;
            s_BlendStyles    = renderer2DData.lightBlendStyles;
            s_RenderingData  = renderingData;

            if (s_LightRenderTargets == null)
            {
                s_LightRenderTargets = new RenderTargetHandle[s_BlendStyles.Length];
                s_LightRenderTargets[0].Init("_ShapeLightTexture0");
                s_LightRenderTargets[1].Init("_ShapeLightTexture1");
                s_LightRenderTargets[2].Init("_ShapeLightTexture2");
                s_LightRenderTargets[3].Init("_ShapeLightTexture3");

                s_LightRenderTargetsDirty = new bool[s_BlendStyles.Length];
            }

            if (s_NormalsTarget.id == 0)
            {
                s_NormalsTarget.Init("_NormalMap");
            }

            if (s_ShadowsRenderTarget.id == 0)
            {
                s_ShadowsRenderTarget.Init("_ShadowTex");
            }

            // The array size should be determined by the number of 'feature bit' the material index has. See GetLightMaterialIndex().
            // Not all slots must be filled because certain combinations of the feature bits don't make sense (e.g. sprite bit on + shape bit off).
            if (s_LightMaterials == null)
            {
                s_LightMaterials = new Material[k_NumberOfLightMaterials];
            }

            // This really needs to be deleted and replaced with a material block
            const int totalMaterials = 256;

            if (s_ShadowMaterials == null)
            {
                s_ShadowMaterials = new Material[totalMaterials];
            }

            if (s_RemoveSelfShadowMaterials == null)
            {
                s_RemoveSelfShadowMaterials = new Material[totalMaterials];
            }
        }
Esempio n. 2
0
        public Renderer2D(Renderer2DData data) : base(data)
        {
            m_BlitMaterial = CoreUtils.CreateEngineMaterial(data.blitShader);

            m_ColorGradingLutPass  = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, data.postProcessData);
            m_Render2DLightingPass = new Render2DLightingPass(data);
            m_PostProcessPass      = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData);
            m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, data.postProcessData);
            m_FinalBlitPass        = new FinalBlitPass(RenderPassEvent.AfterRendering, m_BlitMaterial);

            m_UseDepthStencilBuffer = data.useDepthStencilBuffer;

            m_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture");
            m_ColorGradingLutHandle.Init("_InternalGradingLut");

            m_Renderer2DData = data;
        }
Esempio n. 3
0
        private static Material CreateLightMaterial(Renderer2DData rendererData, Light2D light, bool isVolume)
        {
            var      isPoint = light.isPointLight;
            Material material;

            if (isVolume)
            {
                material = CoreUtils.CreateEngineMaterial(isPoint ? rendererData.pointLightVolumeShader : rendererData.shapeLightVolumeShader);
            }
            else
            {
                material = CoreUtils.CreateEngineMaterial(isPoint ? rendererData.pointLightShader : rendererData.shapeLightShader);

                if (light.overlapOperation == Light2D.OverlapOperation.Additive)
                {
                    SetBlendModes(material, BlendMode.One, BlendMode.One);
                    material.EnableKeyword(k_UseAdditiveBlendingKeyword);
                }
                else
                {
                    SetBlendModes(material, BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);
                }
            }

            if (light.lightType == Light2D.LightType.Sprite)
            {
                material.EnableKeyword(k_SpriteLightKeyword);
            }

            if (isPoint && light.lightCookieSprite != null && light.lightCookieSprite.texture != null)
            {
                material.EnableKeyword(k_UsePointLightCookiesKeyword);
            }

            if (isPoint && light.normalMapQuality == Light2D.NormalMapQuality.Fast)
            {
                material.EnableKeyword(k_LightQualityFastKeyword);
            }

            if (light.normalMapQuality != Light2D.NormalMapQuality.Disabled)
            {
                material.EnableKeyword(k_UseNormalMap);
            }

            return(material);
        }
Esempio n. 4
0
        public Renderer2D(Renderer2DData data) : base(data)
        {
            Material blitMaterial = CoreUtils.CreateEngineMaterial(data.blitShader);

            m_ColorGradingLutPass  = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, data.postProcessData);
            m_Render2DLightingPass = new Render2DLightingPass(data);
            m_PostProcessPass      = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData, blitMaterial);
            m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, data.postProcessData, blitMaterial);
            m_FinalBlitPass        = new FinalBlitPass(RenderPassEvent.AfterRendering, CoreUtils.CreateEngineMaterial(data.blitShader));

#if POST_PROCESSING_STACK_2_0_0_OR_NEWER
            m_PostProcessPassCompat = new PostProcessPassCompat(RenderPassEvent.BeforeRenderingPostProcessing);
#endif

            m_UseDepthStencilBuffer = data.useDepthStencilBuffer;

            m_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture");
            m_ColorGradingLutHandle.Init("_InternalGradingLut");

            m_Renderer2DData = data;
        }
Esempio n. 5
0
        public Renderer2D(Renderer2DData data) : base(data)
        {
            m_BlitMaterial     = CoreUtils.CreateEngineMaterial(data.blitShader);
            m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.samplingShader);

            m_Render2DLightingPass = new Render2DLightingPass(data, m_BlitMaterial, m_SamplingMaterial);
            m_FinalBlitPass        = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial);

            UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

#pragma warning disable 618 // Obsolete warning
            PostProcessData postProcessData = data.postProcessData ? data.postProcessData : urpAsset.postProcessData;
#pragma warning restore 618 // Obsolete warning
            if (postProcessData != null)
            {
                m_ColorGradingLutPass  = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, postProcessData);
                m_PostProcessPass      = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, postProcessData, m_BlitMaterial);
                m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, postProcessData, m_BlitMaterial);
                k_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture");
                k_ColorGradingLutHandle.Init("_InternalGradingLut");
            }

            m_UseDepthStencilBuffer = data.useDepthStencilBuffer;

            // We probably should declare these names in the base class,
            // as they must be the same across all ScriptableRenderer types for camera stacking to work.
            k_ColorTextureHandle.Init("_CameraColorTexture");
            k_DepthTextureHandle.Init("_CameraDepthAttachment");

            m_Renderer2DData = data;

            supportedRenderingFeatures = new RenderingFeatures()
            {
                cameraStacking = true,
            };

            m_LightCullResult = new Light2DCullResult();
            m_Renderer2DData.lightCullResult = m_LightCullResult;
        }
Esempio n. 6
0
 public Render2DLightingPass(Renderer2DData rendererData, Material blitMaterial, Material samplingMaterial)
 {
     m_Renderer2DData   = rendererData;
     m_BlitMaterial     = blitMaterial;
     m_SamplingMaterial = samplingMaterial;
 }
Esempio n. 7
0
 public Render2DLightingPass(Renderer2DData rendererData)
 {
     m_Renderer2DData = rendererData;
 }
Esempio n. 8
0
 public Renderer2D(Renderer2DData data) : base(data)
 {
     m_Render2DLightingPass = new Render2DLightingPass(data);
     //m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing);
     m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering, CoreUtils.CreateEngineMaterial(data.blitShader));
 }