Hi,
what would be the best way to render some objects (either by layer or with a list of objects) to a render texture in HDRP?
The goal is to is the result to make some special image effect using a volume.
Thanks!
Hi,
what would be the best way to render some objects (either by layer or with a list of objects) to a render texture in HDRP?
The goal is to is the result to make some special image effect using a volume.
Thanks!
Hello,
I think that HDRP Custom passes are exactly what you need
They allow you to draw a list of objects (defined by a layer and a render queue) to either the camera buffers or the HDRP custom buffer.
Here is the documentation of the feature: https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@7.1/manual/Custom-Pass.html
And an example repository that shows how to use this feature: GitHub - alelievr/HDRP-Custom-Passes: A bunch of custom passes made for HDRP
Is is possible to prepare different cull results / different view in custom pass?
Yes it’s possible, there is an example here that captures a depth from a different view: https://github.com/alelievr/HDRP-Custom-Passes/blob/master/Assets/CustomPasses/Tests/CameraDepthBake.cs. But right now it’s kind of hacky, there will be an API to do it in a clean way in a future version of HDRP (maybe 2020.1)
Thank you for pointing this out!
I can’t seem to understand how to do it. I get only a white rendertexture, what am I missing?
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Profiling;
class SimpleCustomPass : CustomPass
{
public LayerMask maskLayer = 0;
private RTHandle _rt;
private ShaderTagId[] _shaderTags;
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
_rt = RTHandles.Alloc(
Vector2.one, TextureXR.slices, dimension: TextureXR.dimension,
colorFormat: GraphicsFormat.B10G11R11_UFloatPack32, // no alpha
useDynamicScale: true, name: "myRenderBuffer"
);
_shaderTags = new ShaderTagId[5]
{
new ShaderTagId("GBuffer"),
new ShaderTagId("Forward"),
new ShaderTagId("ForwardOnly"),
new ShaderTagId("SRPDefaultUnlit"),
new ShaderTagId("FirstPass")
};
}
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera camera, CullingResults cullingResult)
{
var result = new RendererListDesc(_shaderTags, cullingResult, camera.camera)
{
rendererConfiguration = PerObjectData.None,
renderQueueRange = RenderQueueRange.all,
sortingCriteria = SortingCriteria.BackToFront,
excludeObjectMotionVectors = false,
layerMask = maskLayer
};
CoreUtils.SetRenderTarget(cmd, _rt, ClearFlag.Color);
HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(result));
}
protected override void Cleanup()
{
// Cleanup code
_rt.Release();
}
}
I’m trying to modify the CameraDepthBake.cs example to unwrap all renderers in the BakingCamera view to a texture map (I’m setting positionOS.xy to be uv0.uv. I confirm that this part works after premultiplying the positionOS with inverse model matrix).
So instead of setting the projection matrix to be the Baking camera’s perspective projection, I’m setting it to an orthographic projection matrix so that I can render the vertices to a flattened texture in a custom shader:
var p = GL.GetGPUProjectionMatrix(Matrix4x4.Ortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 100.0f), true);
I don’t see anything as a result. I suspect my geometry is being culled out because when I increase my orthographic camera size I can see geometry. So is there a way to set the renderers into my RenderListDesc from the list of renderers visible from another camera? Is there a better way to unwrap geometry into a texture UV space in HDRP?