private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            var hdrp = (HDRenderPipeline)RenderPipelineManager.currentPipeline;

            hdrp.UpdateShaderVariablesForCamera(cmd, hd);
            context.SetupCameraProperties(hd.camera);

            var transform = hd.camera.transform;
            var rot       = transform.rotation;
            var localRot  = transform.localRotation;

            var originalProj = hd.camera.projectionMatrix;

            hd.camera.projectionMatrix = CubeProj;

            var sensor            = hd.camera.GetComponent <CameraSensorBase>();
            var renderPostprocess = sensor != null && sensor.Postprocessing != null && sensor.Postprocessing.Count > 0;

            cmd.SetInvertCulling(true); // Cubemap uses RHS standard, face culling has to be inverted

            for (var i = 0; i < 6; ++i)
            {
                // Custom face order is used for dynamic exposure - this way it will be based on forward cube face
                var faceIndex = CubemapFaceOrder[i];

                if ((target.CubeFaceMask & (1 << faceIndex)) == 0)
                {
                    continue;
                }

                transform.localRotation = localRot * Quaternion.LookRotation(CoreUtils.lookAtList[faceIndex], CoreUtils.upVectorList[faceIndex]);
                var view = hd.camera.worldToCameraMatrix;
                hdrp.SetupGlobalParamsForCubemap(cmd, view, target.ColorHandle.rt.width);

                CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)faceIndex);
                cmd.ClearRenderTarget(true, true, clearColor);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                if (hd.camera.TryGetCullingParameters(out var culling))
                {
                    var cull = context.Cull(ref culling);

                    var sorting = new SortingSettings(hd.camera);
                    var drawing = new DrawingSettings(pass, sorting);
                    var filter  = new FilteringSettings(RenderQueueRange.all);

                    context.DrawRenderers(cull, ref drawing, ref filter);

                    if (renderPostprocess)
                    {
                        var ctx = new PostProcessPassContext(cmd, hd, target);
                        SimulatorManager.Instance.Sensors.PostProcessSystem.RenderForSensor(ctx, sensor, (CubemapFace)i);
                    }
                }
            }

            cmd.SetInvertCulling(false);
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            transform.rotation         = rot;
            hd.camera.projectionMatrix = originalProj;
        }
        private static void RenderToTexture(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            var hdrp = (HDRenderPipeline)RenderPipelineManager.currentPipeline;

            hdrp.UpdateShaderVariablesForCamera(cmd, hd);
            context.SetupCameraProperties(hd.camera);

            CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle);
            cmd.ClearRenderTarget(true, true, clearColor);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            if (hd.camera.TryGetCullingParameters(out var culling))
            {
                var cull = context.Cull(ref culling);

                var sorting = new SortingSettings(hd.camera);
                var drawing = new DrawingSettings(pass, sorting);
                var filter  = new FilteringSettings(RenderQueueRange.all);

                context.DrawRenderers(cull, ref drawing, ref filter);
            }

            var sensor = hd.camera.GetComponent <CameraSensorBase>();

            if (sensor != null && sensor.Postprocessing != null && sensor.Postprocessing.Count > 0)
            {
                var ctx = new PostProcessPassContext(cmd, hd, target);
                SimulatorManager.Instance.Sensors.PostProcessSystem.RenderForSensor(ctx, sensor);
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();
            }
        }
 /// <summary>
 /// Renders objects with specified pass to given <see cref="SensorRenderTarget"/>.
 /// </summary>
 /// <param name="context">Current rendering context.</param>
 /// <param name="cmd">Command buffer for queueing commands. Will be executed and cleared.</param>
 /// <param name="hd">HD camera to use for rendering.</param>
 /// <param name="target">Render target to which image will be rendered.</param>
 /// <param name="pass">Pass to use for rendering.</param>
 /// <param name="clearColor">Color that will be used for clearing color buffer.</param>
 public static void Render(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
 {
     if (target.IsCube)
     {
         RenderToCubemap(context, cmd, hd, target, pass, clearColor);
     }
     else
     {
         RenderToTexture(context, cmd, hd, target, pass, clearColor);
     }
 }
        private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            hd.SetupGlobalParams(cmd, 0);
            context.SetupCameraProperties(hd.camera);

            var transform = hd.camera.transform;
            var r         = transform.rotation;

            var originalProj = hd.camera.projectionMatrix;

            hd.camera.projectionMatrix = CubeProj;

            var sensor            = hd.camera.GetComponent <CameraSensorBase>();
            var renderPostprocess = sensor != null && sensor.Postprocessing != null && sensor.Postprocessing.Count > 0;

            for (var i = 0; i < 6; ++i)
            {
                // Custom face order is used for dynamic exposure - this way it will be based on forward cube face
                var faceIndex = CubemapFaceOrder[i];

                if ((target.CubeFaceMask & (1 << faceIndex)) == 0)
                {
                    continue;
                }

                transform.localRotation = Quaternion.LookRotation(CoreUtils.lookAtList[faceIndex], CoreUtils.upVectorList[faceIndex]);
                var view = hd.camera.worldToCameraMatrix;
                SetupGlobalParamsForCubemap(cmd, view, target.ColorHandle.rt.width);

                CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)faceIndex);
                cmd.ClearRenderTarget(true, true, clearColor);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                if (hd.camera.TryGetCullingParameters(out var culling))
                {
                    var cull = context.Cull(ref culling);

                    var sorting = new SortingSettings(hd.camera);
                    var drawing = new DrawingSettings(pass, sorting);
                    var filter  = new FilteringSettings(RenderQueueRange.all);
                    // NOTE: This should flip culling, not hard-set it to front. SRP API does not provide this option
                    //       currently. Expected issues with front-culled geometry.
                    // TODO: investigate HDAdditionalCameraData.FlipYMode.ForceFlipY, it might be a way to solve this
                    var stateBlock = new RenderStateBlock(RenderStateMask.Raster)
                    {
                        rasterState = new RasterState
                        {
                            cullingMode = CullMode.Front
                        }
                    };
                    context.DrawRenderers(cull, ref drawing, ref filter, ref stateBlock);

                    if (renderPostprocess)
                    {
                        SimulatorManager.Instance.Sensors.PostProcessSystem.RenderForSensor(cmd, hd, sensor, target.ColorHandle, (CubemapFace)i);
                    }
                }
            }

            if (renderPostprocess)
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();
            }

            transform.rotation         = r;
            hd.camera.projectionMatrix = originalProj;
        }
Beispiel #5
0
 /// <summary>
 /// Renders objects with specified pass to given <see cref="SensorRenderTarget"/>.
 /// </summary>
 /// <param name="context">Current rendering context.</param>
 /// <param name="cmd">Command buffer for queueing commands. Will be executed and cleared.</param>
 /// <param name="hd">HD camera to use for rendering.</param>
 /// <param name="target">Render target to which image will be rendered.</param>
 /// <param name="pass">Pass to use for rendering.</param>
 /// <param name="clearColor">Color that will be used for clearing color buffer.</param>
 public static void Render(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
 {
     Render(context, cmd, hd, target, pass, clearColor, null);
 }
Beispiel #6
0
 public PostProcessPassContext(CommandBuffer cmd, HDCamera hdCamera, SensorRenderTarget target)
     : this(cmd, hdCamera, target.ColorHandle, target.DepthHandle)
 {
 }
        private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            hd.SetupGlobalParams(cmd, 0);
            context.SetupCameraProperties(hd.camera);

            var transform = hd.camera.transform;
            var r         = transform.rotation;

            var originalProj = hd.camera.projectionMatrix;

            hd.camera.projectionMatrix = CubeProj;

            for (var i = 0; i < 6; ++i)
            {
                if ((target.CubeFaceMask & (1 << i)) == 0)
                {
                    continue;
                }

                transform.localRotation = Quaternion.LookRotation(CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
                var view = hd.camera.worldToCameraMatrix;
                SetupGlobalParamsForCubemap(cmd, view);

                CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)i);
                cmd.ClearRenderTarget(true, true, clearColor);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                if (hd.camera.TryGetCullingParameters(out var culling))
                {
                    var cull = context.Cull(ref culling);

                    var sorting = new SortingSettings(hd.camera);
                    var drawing = new DrawingSettings(pass, sorting);
                    var filter  = new FilteringSettings(RenderQueueRange.all);
                    // NOTE: This should flip culling, not hard-set it to front. SRP API does not provide this option
                    //       currently. Expected issues with front-culled geometry.
                    var stateBlock = new RenderStateBlock(RenderStateMask.Raster)
                    {
                        rasterState = new RasterState
                        {
                            cullingMode = CullMode.Front
                        }
                    };
                    context.DrawRenderers(cull, ref drawing, ref filter, ref stateBlock);
                }
            }

            transform.rotation         = r;
            hd.camera.projectionMatrix = originalProj;
        }
        private static void RenderToTexture(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            hd.SetupGlobalParams(cmd, 0);
            context.SetupCameraProperties(hd.camera);

            CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle);
            cmd.ClearRenderTarget(true, true, clearColor);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            if (hd.camera.TryGetCullingParameters(out var culling))
            {
                var cull = context.Cull(ref culling);

                var sorting = new SortingSettings(hd.camera);
                var drawing = new DrawingSettings(pass, sorting);
                var filter  = new FilteringSettings(RenderQueueRange.all);

                context.DrawRenderers(cull, ref drawing, ref filter);
            }
        }