Skip to content

[HDRP] Backport various PRs #7054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
905 changes: 613 additions & 292 deletions TestProjects/HDRP_RuntimeTests/Assets/Scenes/006-Compositor.unity

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,38 @@ The Light Anchor can help to place light sources around subjects, in relation to

## Using the Light Anchor Component

To use the Light Anchor, you must set the Tag of at least one Camera to "MainCamera". By default, the Anchor's position will be the same as the position of the GameObject the Light Anchor Component is attached to.
To add a Light Anchor component to a GameObject in your Scene:

1. Select a Light GameObject in the hierarchy to open its Inspector window.
2. Go to **Add Component** > **Rendering** > **Light Anchor**

By default, the Anchor's position is the same as the position of the GameObject the Light Anchor Component is attached to.

**Note**: To use the Light Anchor, you must set the Tag of at least one Camera to "MainCamera".

Use the **Orbit** and **Elevation** to control the orientation of the light, in degrees, relative to the main Camera's and Anchor's positions. If the Light has a Cookie or an IES Profile, use the **Roll** to change their orientation. Use the **Distance** to control how far from the anchor, in meters, you want to place the Light.

Using the **Anchor Position Override**, you can provide a custom GameObject as an anchor point for the light. This is useful if you want the light to follow a specific GameObject in the Scene.
You can use the **Anchor Position Override** to provide a GameObject’s [Transform](https://docs.unity3d.com/ScriptReference/Transform.html) as an anchor point for the Light. This is useful if you want the Light to follow a specific GameObject in the Scene.

![](Images/LightAnchorAnimation.gif)

**Note**: The above example uses the Main Camera as the reference Camera that adjusts the light rotation. The Common presets might create a different result in the Scene View if your view isn't aligned with the Main Camera.

You can set a **Position Offset** for this custom Anchor. This is useful if the Transform position of the custom Anchor isn't centered appropriately for the light to orbit correctly around the custom Anchor.

![](Images/view-lighting-tool-light-anchor0.png)
![](Images/LightAnchor0.png)


The Light Anchor component also includes a list of **Presets** that you can use to set the Light's orientation relative to the main Camera.

## Properties

| **Property** | **Description** |
| --------------- | ------------------------------------------------------------ |
| **Orbit** | Use the left icon to control the Orbit of the light. This tool becomes green when you move the icon. |
| **Elevation** | Use the middle icon to control the Elevation of the light. This tool becomes blue when you move the icon. |
| **Roll** | Use the right icon to control the Roll of the light. This tool becomes gray when you move the icon. This is useful if the light has an IES or a Cookie. |
| **Distance** | Controls the distance between the light and its anchor in world space. |
| **Up Direction** | Defines the space of the up direction of the anchor. When you set this value to Local, the Up Direction is relative to the Camera. |
| **Anchor Position Override** | Allows you to use a GameObject's [Transform](https://docs.unity3d.com/ScriptReference/Transform.html) as anchor position instead of the LightAnchor's Transform. When the Transform of the GameObject you assigned to this property changes, the Light Anchor's Transform also changes. |
| **Common** | Assigns a preset to the light component based on the behavior of studio lights. |
14 changes: 14 additions & 0 deletions com.unity.render-pipelines.core/Documentation~/whats-new-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ In practice, this means that the initialization APIs no longer require MSAA rela
### New API to disable runtime Rendering Debugger UI

It is now possible to disable the Rendering Debugger UI at runtime by using [DebugManager.enableRuntimeUI](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@latest/api/UnityEngine.Rendering.DebugManager.html#UnityEngine_Rendering_DebugManager_enableRuntimeUI).

## Added

### High performance sorting algorithms in CoreUnsafeUtils

New high performance sorting algorithms in the CoreUnsafeUtils helper methods. The new sorting algorithms include:

* RadixSort - ideal for very large lists, more then 512 elements.
* MergeSort (non recursive) - ideal for mid size lists, less than 512 elements.
* InsertionSort - ideal for very small lists, less than 32 elements.

The sorting algorithms only work on uint elements. They include methods that support standard c# arrays, NativeArray objects or raw pointers.
RadixSort and MergeSort require support array data, which can be allocated by the user, or allocated automatically via ref parameter passing. InsertionSort is in-place and does not require support data.
These algorithms are compatible with burst kernels when using raw pointers or NativeArray. Currently HDRP utilizes them to sort lights in the CPU lightloop.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public sealed class DebugUIDrawerHistoryEnumField : DebugUIDrawer
public override bool OnGUI(DebugUI.Widget widget, DebugState state)
{
var w = Cast<DebugUI.HistoryEnumField>(widget);
var s = Cast<DebugStateInt>(state);
var s = Cast<DebugStateEnum>(state);

if (w.indexes == null)
w.InitIndexes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,11 @@ void OnExecutionUnregistered(RenderGraph graph, string name)

void OnEnable()
{
// For some reason, when entering playmode, CreateGUI is not called again so we need to rebuild the UI because all references are lost.
// Apparently it was not the case a while ago.
if (m_Root == null)
RebuildUI();

for (int i = 0; i < (int)RenderGraphResourceType.Count; ++i)
m_ResourceElementsInfo[i] = new DynamicArray<ResourceElementInfo>();

Expand Down
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed performance penalty when hardware DRS was used between multiple views like editor or other gameviews (case 1354382)
- Fixed PBR Dof using the wrong resolution for COC min/max filter, and also using the wrong parameters when running post TAAU stabilization. (case 1388961)
- Fixed RTGI potentially reading from outside the half res pixels due to missing last pixel during the upscale pass (case 1400310).
- Fixed various issues with render graph viewer when entering playmode.
- Fixed issue with Final Image Histogram displaying a flat histogram on certain GPUs and APIs.
- Fixed HDRP camera debug panel rendering foldout.

## [12.1.4] - 2021-12-07

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
## Multiframe rendering and accumulation

Some rendering techniques, such as [path tracing](Ray-Tracing-Path-Tracing.md) and accumulation motion blur, combine information from multiple intermediate sub-frames to create a final "converged" frame. Each intermediate sub-frame can correspond to a slightly different point in time, effectively computing physically-based accumulation motion blur, which properly takes into account object rotations, deformations, material or lighting changes.
Some rendering techniques, such as [path tracing](Ray-Tracing-Path-Tracing.md) and accumulation motion blur, combine information from multiple intermediate sub-frames to create a final "converged" frame. Each intermediate sub-frame can correspond to a slightly different point in time, effectively computing physically based accumulation motion blur, which properly takes into account object rotations, deformations, material or lighting changes.

The High Definition Render Pipeline (HDRP) provides a scripting API that allows you to control the creation of sub-frames and the convergence of multi-frame rendering effects. In particular, the API allows you to control the number of intermediate sub-frames (samples) and the points in time that correspond to each one of them. Furthermore, you can use a shutter profile to control the weights of each sub-frame. A shutter profile describes how fast the physical camera opens and closes its shutter.

This API is particularly useful when recording path-traced movies. Normally, when editing a Scene, the convergence of path tracing restarts every time the Scene changes, to provide artists an interactive editing workflow that allows them to quickly visualize their changes. However such behavior is not desirable during recording.
This API is particularly useful when recording path-traced movies. Normally, when editing a Scene, the convergence of path tracing restarts every time the Scene changes, to provide artists an interactive editing workflow that allows them to quickly visualize their changes. However such behavior isn't desirable during recording.

The following image shows a rotating GameObject with path tracing and accumulation motion blur, recorded using the multi-frame recording API.

![](Images/path_tracing_recording.png)

## API overview
The recording API is available in HDRP and has three calls:
- **BeginRecording**: Call this when you want to start a multi-frame render.
- **PrepareNewSubFrame**: Call this before rendering a new subframe.
- **EndRecording**: Call this when you want to stop the multi-frame render.
- `BeginRecording`: Call this when you want to start a multi-frame render.
- `PrepareNewSubFrame`: Call this before rendering a new subframe.
- `EndRecording`: Call this when you want to stop the multi-frame render.

The only call that takes any parameters is **BeginRecording**. Here is an explanation of the parameters:

Expand All @@ -27,7 +27,7 @@ The only call that takes any parameters is **BeginRecording**. Here is an explan
Before calling the accumulation API, the application should also set the desired Time.captureDeltaTime. The example script below demonstrates how to use these API calls.

## Scripting API example
The following example demonstrates how to use the multi-frame rendering API in your scripts to properly record converged animation sequences with path tracing and/or accumulation motion blur. To use it, attach the script to a Camera in your Scene and, in the component's context menu, click the “Start Recording” and “Stop Recording” actions.
The following example demonstrates how to use the multi-frame rendering API in your scripts to properly record converged animation sequences with path tracing or accumulation motion blur. To use it, attach the script to a Camera in your Scene and, in the component's context menu, click the “Start Recording” and “Stop Recording” actions.

```C#
using UnityEngine;
Expand Down Expand Up @@ -123,7 +123,7 @@ In all cases, the speed of the sphere is the same. The only change is the shutte

You can easily define the first three profiles without using an animation curve by setting the open, close parameters to (0,1), (1,1), and (0.25, 0.75) respectively. The last profile requires the use of an animation curve.

In this example, you can see that the slow open profile creates a motion trail appearance for the motion blur, which might be more desired for artists. On the other hand, the smooth open and close profile creates smoother animations than the slow open or uniform profiles.
In this example, you can see that the slow open profile creates a motion trail appearance for the motion blur, which might be more desired for artists. Although, the smooth open and close profile creates smoother animations than the slow open or uniform profiles.


## High Quality Anti-aliasing with Accumulation
Expand Down Expand Up @@ -243,5 +243,5 @@ public class SuperSampling : MonoBehaviour

## Limitations
The multi-frame rendering API internally changes the `Time.timeScale` of the Scene. This means that:
- You cannot have different accumulation motion blur parameters per camera.
- Projects that already modify this parameter per frame are not be compatible with this feature.
- You can't have different accumulation motion blur parameters per camera.
- Projects that already modify this parameter per frame aren't be compatible with this feature.
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Alpha Output

To maximize performance and minimize bandwidth usage, HDRP by default renders image frames in the **R11G11B10** format. However, this format does not include an alpha channel, which might be required for applications that want to composite HDRP's output over other images.
To maximize performance and minimize bandwidth usage, HDRP by default renders image frames in the **R11G11B10** format. However, this format doesn't include an alpha channel, which might be required for applications that want to composite HDRP's output over other images.

To configure HDRP to output an alpha channel, open your [HDRP Asset](HDRP-Asset.md) (menu: **Edit > Project Settings > Graphics > Scriptable Render Pipeline Asset**)), go to the **Rendering** section, and set the **Color Buffer Format** to **R16G16B16A16**. However, note that enabling this option incurs a performance overhead. In HDRP, opaque materials always output 1 in the alpha channel, unless you enable [Alpha Clipping](Alpha-Clipping.md). If you want to export the alpha of an opaque material, one solution is to enable **Alpha Clipping** and set the Threshold to 0.
To configure HDRP to output an alpha channel:

Furthermore, when post-processing is enabled, the *Buffer Format* for post-processing operations should also be set to *R16G16B16A16* in order to apply post-processing operation in the alpha channel. This can be selected from the post-processing section of the HDRP asset. If the post-processing format is set to **R11G11B10**, then HDRP will output a copy of the alpha channel without any post-processing on it.
1. Open your [HDRP Asset](HDRP-Asset.md) in the Inspector window.
2. Go to **Rendering** > **Color Buffer Format**.
3. Select **R16G16B16A16**.

**Note**: Enabling this option incurs a performance overhead.

In HDRP, opaque materials always output 1 in the alpha channel, unless you enable [Alpha Clipping](Alpha-Clipping.md). If you want to export the alpha of an opaque material, one solution is to enable **Alpha Clipping** and set the Threshold to 0.

Furthermore, when you enable post-processing, also set the Buffer Format for post-processing operations to **R16G16B16A16** to apply post-processing operation in the alpha channel. You can select this from the **Post-Processing** section of the HDRP asset. If you set the post-processing format to **R11G11B10**, HDRP outputs a copy of the alpha channel without any post-processing on it.

The following table summarizes the behavior of HDRP regarding the alpha channel of the output frames.

Expand All @@ -14,27 +22,27 @@ Rendering Buffer Format | Post-processing Buffer Format | Alpha Output
**R16G16B16A16** | **R11G11B10** | Alpha channel without post-processing (AlphaCopy)
**R16G16B16A16** | **R16G16B16A16** | Alpha channel with post-processing

Note that alpha output is also supported in [Path Tracing](Ray-Tracing-Path-Tracing.md).
**Note**: Alpha output is also supported in [Path Tracing](Ray-Tracing-Path-Tracing.md).

## DoF and Alpha Output
Another case which might require post-processing of the alpha channel is for scenes that use Depth Of Field. In this case, if the alpha is not processed, compositing will result in a sharp cut-off of an object that should appear blurred. This is better is illustrated in the images below:
Another case which might require post-processing of the alpha channel is for scenes that use Depth Of Field. In this case, if the alpha isn't processed, compositing results in a sharp cut-off of an object that appears blurred. This is better illustrated in the images below:

![](Images/DoFAlpha.png)

An out-of-focus sphere composited over a solid blue background using a *R16G16B16A16* buffer format for both rendering and post-processing. In this case, DoF is applied in the alpha channel, resulting in a proper composition (the output alpha used in the composition is shown in the image inset).
An out-of-focus sphere composited over a solid blue background using a R16G16B16A16 buffer format for both rendering and post-processing. In this case, DoF is applied in the alpha channel, resulting in a proper composition (the output alpha used in the composition is shown in the image inset).

![](Images/DoFAlphaCopy.png)

An out-of-focus sphere composited over a solid blue background using *AlphaCopy*. In this case, DoF is NOT applied in the alpha channel, resulting in a sharp outline around the composited sphere (the output alpha used in the composition is shown in the image inset).
An out-of-focus sphere composited over a solid blue background using AlphaCopy. In this case, DoF isn't applied in the alpha channel, resulting in a sharp outline around the composited sphere (the output alpha used in the composition is shown in the image inset).

## Temporal Anti-Aliasing and Alpha Output
When Temporal Anti-Aliasing (TAA) is enabled it is highly recommended to enable post-processing for the alpha channel (*R16G16B16A16* format for both rendering and post-processing). If the alpha channel is not post-processed, then the alpha mask will be jittered, as shown in the images below:
When you enable Temporal Anti-Aliasing (TAA), it's highly recommended to enable post-processing for the alpha channel (R16G16B16A16 format for both rendering and post-processing). If the alpha channel isn't post-processed, then the alpha mask is jittered, as shown in the images below:

![](Images/TAA_AlphaCopy.gif)

A sphere rendered with TAA using *AlphaCopy*, composited over a solid blue background using the alpha channel. The alpha channel is not temporally stabilized by TAA, resulting in jittering on the final image.
A sphere rendered with TAA using AlphaCopy, composited over a solid blue background using the alpha channel. The alpha channel isn't temporally stabilized by TAA, resulting in jittering on the final image.


![](Images/TAA_Alpha.gif)

A sphere rendered with TAA (*R16G16B16A16* for both rendering and post-processing), composited over a solid blue background using the alpha channel. TAA is also applied in the alpha channel, resulting in a stable composition.
A sphere rendered with TAA (R16G16B16A16 for both rendering and post-processing), composited over a solid blue background using the alpha channel. TAA is also applied in the alpha channel, resulting in a stable composition.
Loading