Does HDRP have a shader replacement rendering like URP for assignment to a 2ond camera?

Hi,

Does HDRP have a shader replacement rendering like URP with RenderObjects renderer feature, that can be assigned to a 2ond camera ?

Thanks

I think you looking for Custom Pass in HDRP
https://github.com/alelievr/HDRP-Custom-Passes
Oh and btw in HDRP you forced to use only one Camera, the second one will drain 50% of your fps

thanks, interesting, sounds very limiting

e.g how can do effects like top down rendering for various use cases, like mini map, scene depth etc from another camera view ?

It’s a shame i dont know how to use “code block” in this new forum :smiley:

CustomPass code for minimap
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering.RendererUtils;

namespace BOYAREngineFramework.CustomPasses.Map
{
    public class MapCustomPass : CustomPass
    {
        [SerializeField] private Camera _mapCamera;
        [SerializeField] private RenderTexture _mapRT;
        [SerializeField] private LayerMask _layerMask = ~0;
        [Space]
        [SerializeField] private float _updateInterval;
        
        private float _timer;
        
        private ShaderTagId[] _shaderTags;
        private RenderStateBlock _depthTestOverride;
        private RendererListDesc _result;
        private ProfilingSampler _renderFromCameraSampler;
        private float _aspectRatio;
        
        protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
        {
            _shaderTags = new ShaderTagId[]
            {
                HDShaderPassNames.s_ForwardName,
                HDShaderPassNames.s_ForwardOnlyName,
                HDShaderPassNames.s_SRPDefaultUnlitName
            };
            
            _depthTestOverride = new RenderStateBlock(RenderStateMask.Depth)
            {
                depthState = new DepthState(true, CompareFunction.LessEqual),
                blendState = BlendState.defaultValue
            };
            
            _renderFromCameraSampler = new ProfilingSampler("Render From Camera");
        }

        protected override void Execute(CustomPassContext ctx)
        {
            if (_mapCamera == null)
                return;
            if (ctx.hdCamera.camera.cameraType == CameraType.SceneView)
                return;
            if (_mapRT == null) 
                return;
            
            if (_timer > _updateInterval)
            {
                _timer = 0;
                
                _mapCamera.TryGetCullingParameters(out var cullingParameters);
                var cullingResults = ctx.renderContext.Cull(ref cullingParameters);
                ctx.cullingResults = cullingResults;
            
                CoreUtils.SetRenderTarget(ctx.cmd, _mapRT.colorBuffer, clearFlags);

                _aspectRatio = _mapRT.width / (float)_mapRT.height;

                _result = new RendererListDesc(_shaderTags, cullingResults, ctx.hdCamera.camera)
                {
                    rendererConfiguration = PerObjectData.None,
                    renderQueueRange = RenderQueueRange.all,
                    sortingCriteria = SortingCriteria.RenderQueue,
                    excludeObjectMotionVectors = false,
                    overrideShader = null,
                    overrideShaderPassIndex = 0,
                    layerMask = _layerMask,
                    stateBlock = _depthTestOverride,
                };
            
                using (new CustomPassUtils.DisableSinglePassRendering(ctx))
                {
                    using (new CustomPassUtils.OverrideCameraRendering(ctx, _mapCamera, _aspectRatio))
                    {
                        using (new ProfilingScope(ctx.cmd, _renderFromCameraSampler))
                            CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(_result));
                    }
                }
            }
            else
            {
                _timer += Time.deltaTime;
            }
        }

        public void RefreshTimer()
        {
            _timer = _updateInterval;
        }
    }
}

I am also no near expert in CustomPass in HDRP but it should give you basic idea how you can use one camera for all your needs.
Basically manual rendering in CustomPass
Which btw using the second camera actually but it MUST be disabled and used only for transform and for copy basic settings for rendering to the main camera. It does not render anything itself

1 Like

I see, thanks, very useful :slight_smile:

About code block, i think is three ` (one in tilde button) to enclose the code in

e.g.

code = code
1 Like

Thanks!
Fixed my reply to keep code on this forum

1 Like