protected override void OnUpdate()
        {
            if (m_StatIndex < 0 || HasSingleton <ThinClientComponent>())
            {
                return;
            }
            uint currentTick = (m_ClientSimulationSystemGroup != null) ? m_ClientSimulationSystemGroup.ServerTick : m_ServerSimulationSystemGroup.ServerTick;

            if (currentTick != m_CollectionTick)
            {
                BeginCollection(currentTick);
            }
            if (m_ClientSimulationSystemGroup == null)
            {
                return;
            }
            var ack        = GetSingleton <NetworkSnapshotAckComponent>();
            var timeSample = new TimeSample
            {
                sampleFraction      = m_ClientSimulationSystemGroup.ServerTickFraction,
                timeScale           = m_NetworkTimeSystem.GetAverageTimeScale(),
                interpolationOffset = m_NetworkTimeSystem.currentInterpolationFrames,
                commandAge          = ack.ServerCommandAge / 256f,
                rtt            = ack.EstimatedRTT,
                jitter         = ack.DeviationRTT,
                snapshotAgeMin = m_SnapshotTickMax != 0?(currentTick - m_SnapshotTickMax):0,
                snapshotAgeMax = m_SnapshotTickMin != 0?(currentTick - m_SnapshotTickMin):0,
            };

            if (m_TimeSamples.Length < 255)
            {
                m_TimeSamples.Add(timeSample);
            }
        }
Esempio n. 2
0
        private void RenderObstracles(ref ScriptableRenderContext context)
        {
            var obstracleTime = TimeSample.Sample("Obstracles Sample");
            int width, height;

            GetLightingResolution(out width, out height);

            var cmdBuf = CmdBufferPool.Get("Obstracles");

            cmdBuf.GetTemporaryRT(obstracle, width, height, asset.GetDepthBits());
            SetRT(cmdBuf, obstracleRT, cWite.linear, true, true);
            context.ExecuteCommandBuffer(cmdBuf);
            CmdBufferPool.Release(cmdBuf);

            var opaqueDrawSettings = new DrawRendererSettings(m_CurrCamera, m_NormalsLitPassName);

            opaqueDrawSettings.SetShaderPassName(1, m_NormalsLitPassName);
            opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;

            var opaqueFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.opaque,
            };

            context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);
            asset.ObstraclesRenderTime = obstracleTime.Result();
        }
Esempio n. 3
0
        private static (long TotalProcessorTimeTicks, long TimeTicks) TryGetProcessTimesForLinux()
        {
            if (PlatformDetails.RunningOnLinux == false)
            {
                return(0, 0);
            }

            try
            {
                long timeTicks;
                long tmsStime;
                long tmsUtime;

                if (PlatformDetails.Is32Bits == false)
                {
                    var timeSample = new TimeSample();
                    timeTicks = Syscall.times(ref timeSample);
                    tmsStime  = timeSample.tms_stime;
                    tmsUtime  = timeSample.tms_utime;
                }
                else
                {
                    var timeSample = new TimeSample_32bit();
                    timeTicks = Syscall.times(ref timeSample);
                    tmsStime  = timeSample.tms_stime;
                    tmsUtime  = timeSample.tms_utime;
                }

                if (timeTicks == -1)
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info("Got overflow time using the times system call " + Marshal.GetLastWin32Error());
                    }

                    return(0, 0);
                }

                return(TotalProcessorTimeTicks : tmsUtime + tmsStime, TimeTicks : timeTicks);
            }
            catch (Exception e)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Failure to get process times for linux, error: {e.Message}", e);
                }

                return(0, 0);
            }
        }
Esempio n. 4
0
        private void RenderUnlit(ref ScriptableRenderContext context, bool clear)
        {
            var time = TimeSample.Sample("Unlit Sample");

            if (clear)
            {
                CommandBuffer cmd = CmdBufferPool.Get("Unlit");
                SetRT(cmd, BuiltinRenderTextureType.CameraTarget, m_CurrCamera.backgroundColor.linear, true, true);
                context.ExecuteCommandBuffer(cmd);
                CmdBufferPool.Release(cmd);
            }

            var opaqueDrawSettings = new DrawRendererSettings(m_CurrCamera, m_DrawUnlt);

            opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;

            var opaqueFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.opaque,
            };

            context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);
            asset.UnlitRenderTime = time.Result();
        }
Esempio n. 5
0
        /// <summary>
        /// Returns the value from the given timesample that corresponds
        /// to the given object and axis request.
        /// </summary>
        /// <param name="isXValue">True if should use xaxis, else uses yaxis</param>
        /// <param name="aktObjectNr">The index of the used object</param>
        /// <param name="sample">The time sample with the raw data</param>
        /// <returns>The nullable <see cref="double"/> with the value, if there is one found.</returns>
        private double?GetValueFromSample(bool isXValue, int aktObjectNr, TimeSample sample)
        {
            double?value = null;

            if (sample.Object[aktObjectNr] == null)
            {
                return(null);
            }

            switch (isXValue ? Viana.Project.CurrentFilterData.AxisX.Axis : Viana.Project.CurrentFilterData.AxisY.Axis)
            {
            case AxisType.I:
                value = sample.Framenumber;
                break;

            case AxisType.T:
                value = sample.Object[aktObjectNr].Time;
                break;

            case AxisType.X:
                value = sample.Object[aktObjectNr].PixelX;
                break;

            case AxisType.Y:
                value = sample.Object[aktObjectNr].PixelY;
                break;

            case AxisType.PX:
                value = sample.Object[aktObjectNr].PositionX;
                break;

            case AxisType.PY:
                value = sample.Object[aktObjectNr].PositionY;
                break;

            case AxisType.D:
                value = sample.Object[aktObjectNr].Distance;
                break;

            case AxisType.DX:
                value = sample.Object[aktObjectNr].DistanceX;
                break;

            case AxisType.DY:
                value = sample.Object[aktObjectNr].DistanceY;
                break;

            case AxisType.S:
                value = sample.Object[aktObjectNr].Length;
                break;

            case AxisType.SX:
                value = sample.Object[aktObjectNr].LengthX;
                break;

            case AxisType.SY:
                value = sample.Object[aktObjectNr].LengthY;
                break;

            case AxisType.V:
                value = sample.Object[aktObjectNr].Velocity;
                break;

            case AxisType.VX:
                value = sample.Object[aktObjectNr].VelocityX;
                break;

            case AxisType.VY:
                value = sample.Object[aktObjectNr].VelocityY;
                break;

            case AxisType.A:
                value = sample.Object[aktObjectNr].Acceleration;
                break;

            case AxisType.AX:
                value = sample.Object[aktObjectNr].AccelerationX;
                break;

            case AxisType.AY:
                value = sample.Object[aktObjectNr].AccelerationY;
                break;
            }

            return(value);
        }
Esempio n. 6
0
        private void RenderLights(ref ScriptableRenderContext context)
        {
            var lightsTime = TimeSample.Sample("Lights Sample");
            int width, height;

            GetLightingResolution(out width, out height);

            var ColorRT = BuiltinRenderTextureType.CameraTarget;

            Vector2 downSampleTexelSize = new Vector2(1F / width, 1F / height);
            Vector2 texel                    = new Vector2(1F / m_CurrCamera.pixelWidth, 1F / m_CurrCamera.pixelHeight);
            float   LightPixelSize           = m_CurrCamera.orthographicSize * 2f / m_CurrCamera.pixelHeight;
            float   lightPixelsPerUnityMeter = 1F / LightPixelSize;
            Vector3 mainPos                  = m_CurrCamera.transform.position;
            Vector3 gridPos                  = new Vector3(
                Mathf.Round(mainPos.x * lightPixelsPerUnityMeter) / lightPixelsPerUnityMeter,
                Mathf.Round(mainPos.y * lightPixelsPerUnityMeter) / lightPixelsPerUnityMeter,
                Mathf.Round(mainPos.z * lightPixelsPerUnityMeter) / lightPixelsPerUnityMeter);
            Vector3 posDiff = gridPos - mainPos;
            Vector3 pos     = posDiff + mainPos;
            Vector2 offset  = Vector2.Scale(texel, -posDiff * (lightPixelsPerUnityMeter));

            Matrix4x4 view = Matrix4x4.Inverse(Matrix4x4.TRS(pos, m_CurrCamera.transform.rotation, new Vector3(1, 1, -1)));
            Matrix4x4 proj = GL.GetGPUProjectionMatrix(m_CurrCamera.projectionMatrix, true);
            Matrix4x4 gPos = proj * view;

            var cmdBuf = CmdBufferPool.Get("Lights");

            cmdBuf.SetGlobalMatrix(GridPosMatrix, gPos);
            cmdBuf.GetTemporaryRT(ambient, width, height, 0);
            cmdBuf.GetTemporaryRT(lights, width, height, 0);
            SetRT(cmdBuf, lightsRT, Color.clear, true, false);;
            cmdBuf.SetGlobalTexture(envObstracleTex, obstracleRT);
            context.ExecuteCommandBuffer(cmdBuf);

            var opaqueDrawSettings = new DrawRendererSettings(m_CurrCamera, m_DrawLights);

            opaqueDrawSettings.SetShaderPassName(1, m_DrawLights);
            opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;

            var opaqueFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.opaque,
            };

            context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);

            if (asset.Mode == FlatLightRPAsset.DrawMode.Lights)
            {
                cmdBuf.Clear();
                cmdBuf.Blit(lights, ColorRT);
                context.ExecuteCommandBuffer(cmdBuf);
                CmdBufferPool.Release(cmdBuf);
                asset.LightsRenderTime = lightsTime.Result();
                return;
            }

            asset.LightsRenderTime = lightsTime.Result();
            var compositeTime = TimeSample.Sample("Composite Sample");

            // composite
            LightsComposite.SetVector(TexelSize, downSampleTexelSize);
            LightsComposite.SetVector(ENVLightOffset, offset);
            LightsComposite.SetColor(Ambient, asset.GetAmbientColor());
            LightsComposite.SetFloat(EmissionBlend, asset.GetEmissionBlend());
            LightsComposite.SetFloat(SampleDistBlur, asset.GetSampleDistBlur());

            cmdBuf.Clear();

            if (asset.BlurLights && asset.BlurLightsIterations > 0)
            {
                cmdBuf.GetTemporaryRT(blurLights, width, height, 0);
                RenderTargetIdentifier dst   = blurLightsRT;
                RenderTargetIdentifier src   = lightsRT;
                RenderTargetIdentifier final = src;
                for (int i = 0; i < asset.BlurLightsIterations; ++i)
                {
                    cmdBuf.Blit(src, dst, LightsComposite, LIGHT_BLUR_PASS);
                    RenderTargetIdentifier tmp = dst;
                    final = dst;
                    dst   = src;
                    src   = tmp;
                }
                if (asset.AmbientPass)
                {
                    cmdBuf.Blit(final, ambientRT, LightsComposite, AMBIENT_PASS);
                    cmdBuf.SetGlobalTexture(envLightsTex, ambientRT);
                }
                else
                {
                    cmdBuf.SetGlobalTexture(envLightsTex, final);
                }
            }
            else if (asset.AmbientPass)
            {
                cmdBuf.Blit(lightsRT, ambientRT, LightsComposite, AMBIENT_PASS);
                cmdBuf.SetGlobalTexture(envLightsTex, ambientRT);
            }
            else
            {
                cmdBuf.SetGlobalTexture(envLightsTex, lightsRT);
            }

            if (asset.AmbientPass)
            {
                if (asset.Mode == FlatLightRPAsset.DrawMode.Ambient)
                {
                    cmdBuf.Blit(ambientRT, ColorRT);
                    context.ExecuteCommandBuffer(cmdBuf);
                    CmdBufferPool.Release(cmdBuf);
                    asset.CompositeRenderTime = compositeTime.Result();
                    return;
                }

                cmdBuf.Blit(screenColorRT, BuiltinRenderTextureType.CameraTarget, LightsComposite, COMPOSITE_PASS);
            }
            else
            {
                cmdBuf.Blit(screenColorRT, BuiltinRenderTextureType.CameraTarget, LightsComposite, COMPOSITE_AMBIENT_PASS);
            }

            context.ExecuteCommandBuffer(cmdBuf);
            CmdBufferPool.Release(cmdBuf);
            asset.CompositeRenderTime = compositeTime.Result();
        }
Esempio n. 7
0
        private void RenderOpaquesAndTransparent(ref ScriptableRenderContext context)
        {
            int opaque_width  = m_CurrCamera.pixelWidth / asset.GetDownsample(FlatLightRPAsset.FLTechnique.Opaques);
            int opaque_height = m_CurrCamera.pixelHeight / asset.GetDownsample(FlatLightRPAsset.FLTechnique.Opaques);

            if (asset.GroundIsRenderedSeparately)
            {
                var           groundTime    = TimeSample.Sample("Ground Sample");
                int           ground_width  = m_CurrCamera.pixelWidth / asset.GetDownsample(FlatLightRPAsset.FLTechnique.Ground);
                int           ground_height = m_CurrCamera.pixelHeight / asset.GetDownsample(FlatLightRPAsset.FLTechnique.Ground);
                CommandBuffer cmd           = CmdBufferPool.Get("SetCameraRenderTarget(Ground)");
                cmd.GetTemporaryRT(ground, ground_width, ground_height, asset.GetDepthBits());
                ClearAndSetRT(cmd, groundRT);
                context.ExecuteCommandBuffer(cmd);

                var groundDrawSettings = new DrawRendererSettings(m_CurrCamera, m_DrawGround);
                groundDrawSettings.SetShaderPassName(1, m_DrawGround);
                groundDrawSettings.sorting.flags = SortFlags.CommonOpaque;

                var groundFilterSettings = new FilterRenderersSettings(true)
                {
                    renderQueueRange = RenderQueueRange.opaque,
                };

                if (m_CurrCamera.clearFlags == CameraClearFlags.Skybox)
                {
                    context.DrawSkybox(m_CurrCamera);
                }

                context.DrawRenderers(m_CullResults.visibleRenderers, ref groundDrawSettings, groundFilterSettings);

                cmd.Clear();
                cmd.GetTemporaryRT(screenColor, opaque_width, opaque_height, asset.GetDepthBits());
                SetRT(cmd, screenColorRT, m_CurrCamera.backgroundColor.linear, false, true);
                cmd.Blit(groundRT, screenColorRT);
                cmd.ReleaseTemporaryRT(ground);
                context.ExecuteCommandBuffer(cmd);
                CmdBufferPool.Release(cmd);
                asset.GroundRenderTime = groundTime.Result();
            }
            else
            {
                CommandBuffer cmd = CmdBufferPool.Get("SetCameraRenderTarget");
                cmd.GetTemporaryRT(screenColor, opaque_width, opaque_height, asset.GetDepthBits());
                ClearAndSetRT(cmd, screenColorRT);
                context.ExecuteCommandBuffer(cmd);
                CmdBufferPool.Release(cmd);

                if (m_CurrCamera.clearFlags == CameraClearFlags.Skybox)
                {
                    context.DrawSkybox(m_CurrCamera);
                }
            }

            var opTime             = TimeSample.Sample("Opaques And Transparent Sample");
            var opaqueDrawSettings = new DrawRendererSettings(m_CurrCamera, m_LitPassName);

            opaqueDrawSettings.SetShaderPassName(1, m_LitPassName);
            opaqueDrawSettings.sorting.flags = SortFlags.CommonOpaque;

            var opaqueFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.opaque,
            };

            context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);

            var transparentSettings = new DrawRendererSettings(m_CurrCamera, m_LitPassName);

            transparentSettings.SetShaderPassName(1, m_LitPassName);
            transparentSettings.sorting.flags = SortFlags.CommonTransparent;

            var transparentFilterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.transparent
            };

            context.DrawRenderers(m_CullResults.visibleRenderers, ref transparentSettings, transparentFilterSettings);
            asset.OpaquesAndTransparentRenderTime = opTime.Result();
        }