Skip to content

[HDRP] Backport misc PRs #6412

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 5 commits into from
Nov 28, 2021
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
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Fixed potentially conflicting runtime Rendering Debugger UI command by adding an option to disable runtime UI altogether (1345783).
- Fixed issue when changing volume profiles at runtime with a script (case 1364256).

## [10.7.0] - 2021-07-02

Expand Down
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.core/Editor/Volume/VolumeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void RefreshEffectListEditor(VolumeProfile asset)
{
m_ComponentList.Clear();

asset.Sanitize();

if (asset != null)
m_ComponentList.Init(asset, new SerializedObject(asset));
}
Expand Down
10 changes: 10 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,15 @@ internal int GetComponentListHashCode()
return hash;
}
}

/// <summary>
/// Removes any components that were destroyed externally from the iternal list of components
/// </summary>
internal void Sanitize()
{
for (int i = components.Count - 1; i >= 0; i--)
if (components[i] == null)
components.RemoveAt(i);
}
}
}
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed screen space reflection PBR Accumulation
- Fixed and optimize distance shadowmask fade.
- Fixed HDRP Decals performances when they use different materials (~5x improvement in the decal update loop code).
- Fixed light unit conversion after changing mid gray value.
- Fixed stencil buffer resolve when MSAA is enabled so that OR operator is used instead of picking the last sample.

### Changed
- MaterialReimporter.ReimportAllMaterials and MaterialReimporter.ReimportAllHDShaderGraphs now batch the asset database changes to improve performance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the High Definition Render Pipeline (HDRP), there are two parts to environmen
Essentially, you use the visual environment to control how the sky looks in your Scene and use the lighting environment to control how the sky contributes to indirect ambient lighting.

## Visual Environment
The Visual Environment is a Volume override that tells HDRP what type of [sky](HDRP-Features.md#sky) and [fog](HDRP-Features.md#fog) you want to see through Cameras that the Volume affects. For information on how to customize Visual Environments, see the [Visual Environment](Override-Visual-Environment.md) documentation.
The Visual Environment is a Volume override that tells HDRP what type of [sky](HDRP-Features.md#sky) you want to see through Cameras that the Volume affects. For information on how to customize Visual Environments, see the [Visual Environment](Override-Visual-Environment.md) documentation.

Your Unity Project’s [HDRP Asset](HDRP-Asset.md) has the following properties that also affect all Visual Environments:

Expand Down Expand Up @@ -65,7 +65,15 @@ HDRP uses the ambient Light Probe as the final fallback for indirect diffuse lig
- Mesh Renderers that have their **Light Probe Mode** set to **Off**
- Volumetric fog if the Global Light Probe dimmer is set to a value above 0

The ambient Light Probe can be static (generated only once) or dynamic (updated at runtime).**Note**: If there is a **Light Probe group** in your Scene and you have computed indirect ambient lighting, then the Ambient Light Probe only affects Mesh Renderers that have their **Light Probe Mode** set to **Off**, and that have **Volumetric fog** (if it’s enabled in the Scene).
The ambient Light Probe can be static (generated only once from the static lighting sky set in the HDRP **Environment (HDRP)**panel) or dynamic (updated at runtime from the sky currently in use).

***\*Note\****: If there is a ***\*Light Probe group\**** in your Scene and you have computed indirect ambient lighting, then the Ambient Light Probe only affects Mesh Renderers that have their ***\*Light Probe Mode\**** set to ***\*Off\****, and that have ***\*Volumetric fog\**** (if it’s enabled in the Scene).

### Limitation of Dynamic Ambient mode

The Ambient Light Probe always affects your scene one frame late after HDRP calculates it. This is because HDRP calculates Ambient Light Probes on the GPU and then uses asynchronous readback on the CPU.

As a result, the ambient lighting might not match the actual lighting and cause visual artifacts. This can happen when you use the dynamic ambient mode and use reflection probes that update on demand.

## Ambient Reflection Probe

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ When building your custom shaders using shader graph, some nodes are incompatibl
- DDX, DDY and DDXY nodes.
- All the nodes under Inputs > Geometry (Position, View Direction, Normal, etc.) in View Space mode.
- Checkerboard node.
Furthermore, Shader Graphs that use [Custom Interpolators](../../com.unity.shadergraph/Documentation~/Custom-Interpolators.md) are not supported in ray tracing.

### Unsupported features of path tracing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ HDRP path tracing in Unity 2020.2 has the following limitations:
- If a Mesh in your scene has a Material assigned that does not have the `HDRenderPipeline` tag, the mesh will not appear in your scene. For more information, see [Ray tracing and Meshes](Ray-Tracing-Getting-Started.md#RayTracingMeshes).
- Does not support 3D Text and TextMeshPro.
- Does not support Shader Graph nodes that use derivatives (for example, a normal map that derives from a texture).
- Does not support Shader Graphs that use [Custom Interpolators](../../com.unity.shadergraph/Documentation~/Custom-Interpolators.md).
- Does not support decals.
- Does not support tessellation.
- Does not support Tube and Disc-shaped Area Lights.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace UnityEditor.Rendering.HighDefinition
{
class EmissionUIBlock : MaterialUIBlock
{
static float s_MaxEvValue = Mathf.Floor(LightUtils.ConvertLuminanceToEv(float.MaxValue));
// Max EV Value. Equals to LightUtils.ConvertLuminanceToEv(float.MaxValue)
// Literal value to avoid precision issue with max float and to be independent of ColorUtils.s_LightMeterCalibrationConstant.
static float s_MaxEvValue = 130.0f;

[Flags]
public enum Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ internal static class Styles
public static GUIContent receivesSSRTransparentText = new GUIContent("Receive SSR Transparent", "When enabled, this Material can receive screen space reflections.");

public static GUIContent opaqueCullModeText = new GUIContent("Cull Mode", "For opaque objects, change the cull mode of the object.");

public static string afterPostProcessZTestInfoBox = "After post-process material wont be ZTested. Enable the \"ZTest For After PostProcess\" checkbox in the Frame Settings to force the depth-test if the TAA is disabled.";
public static string afterPostProcessInfoBox = "If After post-process objects don't render, make sure to enable \"After Post-process\" in the frame settings.\nAfter post-process material wont be ZTested. Enable the \"ZTest For After PostProcess\" checkbox in the Frame Settings to force the depth-test if the TAA is disabled.";
}

// Properties common to Unlit and Lit
Expand Down Expand Up @@ -581,7 +581,7 @@ void DrawSurfaceGUI()

void ShowAfterPostProcessZTestInfoBox()
{
EditorGUILayout.HelpBox(Styles.afterPostProcessZTestInfoBox, MessageType.Info);
EditorGUILayout.HelpBox(Styles.afterPostProcessInfoBox, MessageType.Info);
}

void SurfaceTypePopup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace UnityEngine.Rendering.HighDefinition
/// </summary>
class LightUtils
{
static float s_LuminanceToEvFactor = Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant, 2);
static float s_EvToLuminanceFactor = -Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant, 2);
static float s_LuminanceToEvFactor => Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant, 2);
static float s_EvToLuminanceFactor => -Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant, 2);

// Physical light unit helper
// All light unit are in lumen (Luminous power)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ static class HDShaderIDs
public static readonly int _SpaceEmissionTexture = Shader.PropertyToID("_SpaceEmissionTexture");
public static readonly int _SpaceEmissionMultiplier = Shader.PropertyToID("_SpaceEmissionMultiplier");

public static readonly int _RenderSunDisk = Shader.PropertyToID("_RenderSunDisk");
public static readonly int _RenderSunDisk = Shader.PropertyToID("_RenderSunDisk");
public static readonly int _SunDiskCosines = Shader.PropertyToID("_SunDiskCosines");

public static readonly int _ColorSaturation = Shader.PropertyToID("_ColorSaturation");
public static readonly int _AlphaSaturation = Shader.PropertyToID("_AlphaSaturation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID,
{
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadID.z);

// The best shot at resolving is being overly conservative, hence the OR operator. This is by nature inaccurate.
// The best shot at resolving is being overly conservative, hence the OR operator. This is by nature inaccurate, but there is no way to blend MSAA sub-samples properly and we need to pick the lesser evil.
uint resolvedStencil = 0;

if (dispatchThreadID.x < (uint)_ScreenSize.x && dispatchThreadID.y < (uint)_ScreenSize.y)
Expand All @@ -61,7 +61,7 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID,
#else
sampledStencil = LOAD_TEXTURE2D_X_MSAA(_StencilTexture, dispatchThreadID.xy, i);
#endif
resolvedStencil = GetStencilValue(sampledStencil);
resolvedStencil |= GetStencilValue(sampledStencil); // In not MSAA cases the | is the same as assigning given that NUM_SAMPLES is 1
}
}
#ifdef RESOLVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Shader "Hidden/HDRP/Sky/PbrSky"

#pragma vertex Vert

// #pragma enable_d3d11_debug_symbols
#pragma editor_sync_compilation
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
Expand All @@ -26,6 +25,13 @@ Shader "Hidden/HDRP/Sky/PbrSky"
float _GroundEmissionMultiplier;
float _SpaceEmissionMultiplier;

// Inner and outer cosine computed as:
// float radInner = 0.5 * light.angularDiameter
// float cosInner = cos(radInner); // (In _SunDiskCosines.x)
// float cosOuter = cos(radInner + light.flareSize); // (In _SunDiskCosines.y)
// We need to pass it over instead of computing it here because on some vendors trigonometry has very bad precision, so we precompute what we can on CPU to have better precision.
float4 _SunDiskCosines;

// Sky framework does not set up global shader variables (even per-view ones),
// so they can contain garbage. It's very difficult to not include them, however,
// since the sky framework includes them internally in many header files.
Expand Down Expand Up @@ -111,8 +117,9 @@ Shader "Hidden/HDRP/Sky/PbrSky"
float LdotV = -dot(L, V);
float rad = acos(LdotV);
float radInner = 0.5 * light.angularDiameter;
float cosInner = cos(radInner);
float cosOuter = cos(radInner + light.flareSize);

float cosInner = _SunDiskCosines.x;
float cosOuter = _SunDiskCosines.y;

float solidAngle = TWO_PI * (1 - cosInner);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo
}
s_PbrSkyMaterialProperties.SetInt(HDShaderIDs._HasSpaceEmissionTexture, hasSpaceEmissionTexture);

// We need to pass it over instead of computing it here because on some vendors trigonometry has very bad precision, so we precompute what we can on CPU to have better precision.
// We can safely retrieve HDAdditionalLightData as for PBR sky the sunlight is always going to be an HDRP light.
var lightData = builtinParams.sunLight.gameObject.GetComponent<HDAdditionalLightData>();
float radInner = 0.5f * lightData.angularDiameter * Mathf.Deg2Rad;
float cosInner = Mathf.Cos(radInner);
float cosOuter = Mathf.Cos(radInner + lightData.flareSize);
s_PbrSkyMaterialProperties.SetVector(HDShaderIDs._SunDiskCosines, new Vector4(cosInner, cosOuter, 0, 0));

s_PbrSkyMaterialProperties.SetInt(HDShaderIDs._RenderSunDisk, renderSunDisk ? 1 : 0);

int pass = (renderForCubemap ? 0 : 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ struct CachedSkyContext

public void Reset()
{
// We keep around the renderer and the rendering context to avoid useless allocation if they get reused.
// We keep around the rendering context to avoid useless allocation if they get reused.
hash = 0;
refCount = 0;
if (renderingContext != null)
renderingContext.Reset();
}

public void Cleanup()
Expand Down Expand Up @@ -760,14 +762,15 @@ public void UpdateEnvironment(HDCamera hdCamera,
// Debug.Log("Update Sky Lighting");
RenderSkyToCubemap(skyContext);

if (updateAmbientProbe)
if (updateAmbientProbe&& !renderingContext.computeAmbientProbeRequested)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpdateSkyAmbientProbe)))
{
cmd.SetComputeBufferParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeOutputBufferParam, renderingContext.ambientProbeResult);
cmd.SetComputeTextureParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeInputCubemap, renderingContext.skyboxCubemapRT);
cmd.DispatchCompute(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, 1, 1, 1);
cmd.RequestAsyncReadback(renderingContext.ambientProbeResult, renderingContext.OnComputeAmbientProbeDone);
renderingContext.computeAmbientProbeRequested = true;

// When the profiler is enabled, we don't want to submit the render context because
// it will break all the profiling sample Begin() calls issued previously, which leads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class SkyRenderingContext
public bool supportsConvolution { get; private set; } = false;

internal bool ambientProbeIsReady = false;
public bool computeAmbientProbeRequested = false;

public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name)
{
Expand All @@ -40,6 +41,12 @@ public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvoluti
}
}

public void Reset()
{
ambientProbeIsReady = false;
computeAmbientProbeRequested = false;
}

public void Cleanup()
{
RTHandles.Release(skyboxCubemapRT);
Expand Down