Hi I am trying to understand the custom pass in HDRP step by step.
I would like to write a custom pass that simply gives out the acutal main camera to a RT - here is the script:
public RenderTexture _rt;
public LayerMask renderingMask3 = -1;
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
There is a custom pass script to output the camera color in a RenderTexture in my reply also
Note that we typically use CustomPassUtils.RenderFromCamera for rendering from a different camera than the current, and also that it renders a certain subset of objects in the camera view (i.e. you can’t get the camera color just with this function).
Hello,
thank you very much - it worked! - I had a look to the HDRP-Custom-Passes on git
I have new problem. - I want to render all objects from a certain layer to an RT, give the objects a diffent material which works so far in my code. But I want to give it a new color defined in the custom pass script (I dont want to use the click solution in the selection examples - I want to do i by code). I am setting the material property color to black or any other. - The problem is the objects are always in blue color and don’t use the new color. - What could be the solution?
public LayerMask outlineLayer = 0;
[ColorUsage(false, true)]
public Color outlineColor = Color.black;
public float threshold = 1;
public RenderTexture _rt;
[SerializeField, HideInInspector]
public Material _unlit_mat;
I think you forgot the override material pass index parameter of CustomPassUtils.DrawRenderers. Without that param you don’t know which pass the draw will take from the shader. There are also example of this in the custom pass repo.
I’m sorry to revive this one, but I’m really baffled. I tried to follow along above, but there seems to be no clear answer, with regards to how to actually render directly to a render texture, in a custom pass.
I don’t wish to render to the built-in Custom Buffer (or Camera Color Buffer) and then copy it to RT. I need to simply render to the RT like this:
Is there a simple answer (Yes or No) whether or not this is possible? And if possible, does anyone know how my lines of code might be tweaked to make it work?
I’m just looking for some direct assistance rather than being sent off into the void of the “various custom passes” sample, or some other thread this doesn’t answer the question directly
One possible issue that you can encounter while doing this kind of effect is that the rendered objects need the camera depth buffer to render properly (this is for opaque objects). This is because we expect that there is a depth prepass in HDRP.
If you want to render objects with a clear depth buffer, you need to override the depth settings in the DrawRenderers, this can be done by providing the overrideRenderState parameter to the function. I have an example of this here: HDRP-Custom-Passes/Assets/Scenes/CameraDepthBaking/CameraDepthBake.cs at c1e6f31317fca4960780525fcf35016a3e63f460 · alelievr/HDRP-Custom-Passes · GitHub
I’m sorry for reviving this post once again, but I’m struggling with a similar thing right now. I’m trying to optimize rendering from multiple points of view with a custom pass using: CustomPassUtils.RenderFromCamera()
There was a problem of duplicated lighting, but it was solved by overriding this value: CameraRelativeRendering = 0
The problem is that shadows and lighting are still computed/culled with respect to the pose of the initial camera of the pass. I’ve been wondering if it’s possible to recalculate shadows and lights culling with respect to the new camera because it is quite far from the initial camera.
The RenderFromCamera API was mainly designed to render objects from any camera in the scene using a custom shader that doesn’t rely on HDRP camera features or to render objects within the camera view (for example FPS foreground objects with fixed FoV).
If you need all the lighting/shadow features of HDRP for your additional cameras, then it can’t be achieved with this API and you’ll need to use a real camera. You can still try to optimize the cost of this camera by tweaking the frame settings and disabling everything you don’t need, scaling the output resolution down, or even making your camera render every other frame.