Beispiel #1
0
        public static void RenderLights(this IRenderPass2D pass, RenderingData renderingData, CommandBuffer cmd, int layerToRender, ref LayerBatch layerBatch, ref RenderTextureDescriptor rtDesc)
        {
            var blendStyles = pass.rendererData.lightBlendStyles;

            for (var i = 0; i < blendStyles.Length; ++i)
            {
                if ((layerBatch.lightStats.blendStylesUsed & (uint)(1 << i)) == 0)
                {
                    continue;
                }

                var sampleName = blendStyles[i].name;
                cmd.BeginSample(sampleName);

                if (!Light2DManager.GetGlobalColor(layerToRender, i, out var clearColor))
                {
                    clearColor = Color.black;
                }

                var anyLights = (layerBatch.lightStats.blendStylesWithLights & (uint)(1 << i)) != 0;

                var desc = rtDesc;
                if (!anyLights) // No lights -- create tiny texture
                {
                    desc.width = desc.height = 4;
                }
                var identifier = layerBatch.GetRTId(cmd, desc, i);

                cmd.SetRenderTarget(identifier,
                                    RenderBufferLoadAction.DontCare,
                                    RenderBufferStoreAction.Store,
                                    RenderBufferLoadAction.DontCare,
                                    RenderBufferStoreAction.DontCare);
                cmd.ClearRenderTarget(false, true, clearColor);

                if (anyLights)
                {
                    RenderLightSet(
                        pass, renderingData,
                        i,
                        cmd,
                        layerToRender,
                        identifier,
                        pass.rendererData.lightCullResult.visibleLights
                        );
                }

                cmd.EndSample(sampleName);
            }
        }
Beispiel #2
0
        static public void RenderLights(Camera camera, CommandBuffer cmdBuffer, int layerToRender, uint blendStylesUsed)
        {
            for (int i = 0; i < s_BlendStyles.Length; ++i)
            {
                if ((blendStylesUsed & (uint)(1 << i)) == 0)
                {
                    continue;
                }

                string sampleName = s_BlendStyles[i].name;
                cmdBuffer.BeginSample(sampleName);

                cmdBuffer.SetRenderTarget(s_LightRenderTargets[i].Identifier());

                bool  rtDirty = false;
                Color clearColor;
                if (!Light2DManager.GetGlobalColor(layerToRender, i, out clearColor))
                {
                    clearColor = Color.black;
                }
                else
                {
                    rtDirty = true;
                }

                if (s_LightRenderTargetsDirty[i] || rtDirty)
                {
                    cmdBuffer.ClearRenderTarget(false, true, clearColor);
                }

                rtDirty |= RenderLightSet(
                    camera,
                    i,
                    cmdBuffer,
                    layerToRender,
                    s_LightRenderTargets[i].Identifier(),
                    Light2D.GetLightsByBlendStyle(i)
                    );

                s_LightRenderTargetsDirty[i] = rtDirty;

                cmdBuffer.EndSample(sampleName);
            }
        }