Skip to content

Fixing nans related to reflection probes in ray tracing and potentially instabilities. #1307

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 4 commits into from
Jul 16, 2020
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
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 @@ -736,6 +736,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with duplicate names in newly created sub-layers in the graphics compositor (case 1263093).
- Remove MSAA debug mode when renderpipeline asset has no MSAA
- Fixed some post processing using motion vectors when they are disabled
- Fixed the multiplier of the environement lights being overriden with a wrong value for ray tracing (1260311).

### Changed
- Improve MIP selection for decals on Transparents
Expand Down Expand Up @@ -898,6 +899,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Shutter speed can now be changed by dragging the mouse over the UI label (case 1245007).
- Remove the 'Point Cube Size' for cookie, use the Cubemap size directly.
- Only building the RTAS if there is an effect that will require it (1262217).
- Fixed the first ray tracing frame not having the light cluster being set up properly (1260311).

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ The PCF algorithm applies a fixed size blur. PCSS applies a different blur size

Use these settings to enable or disable settings relating to lighting in HDRP.

| **Property** | **Description** |
| --------------------------------- | ------------------------------------------------------------ |
| **Maximum Directional On Screen** | The maximum number of Directional Lights HDRP can manage on screen at once. |
| **Maximum Punctual On Screen** | The maximum number of [Point and Spot Lights](Glossary.html#PunctualLight) HDRP can manage on screen at once. |
| **Maximum Area On Screen** | The maximum number of area Lights HDRP can manage on screen at once. |
| **Property** | **Description** |
| ----------------------------------------- | ------------------------------------------------------------ |
| **Maximum Directional On Screen** | The maximum number of Directional Lights HDRP can manage on screen at once. |
| **Maximum Punctual On Screen** | The maximum number of [Point and Spot Lights](Glossary.html#PunctualLight) HDRP can manage on screen at once. |
| **Maximum Area On Screen** | The maximum number of area Lights HDRP can manage on screen at once. |
| **Maximum Lights Per Cell (Ray Tracing)** | The maximum number of Lights that an individual grid cell in a [Light Cluster](Ray-Tracing-Light-Cluster.md) can store. |

## Material

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ For ray tracing, HDRP builds an axis-aligned grid which, in each cell, stores th

## Properties

| **Property** | **Description** |
| --------------------------- | ------------------------------------------------------------ |
| **Maximum Lights Per Cell** | Sets the maximum number of Lights that an individual cell can store. |
| **Camera Cluster Range** | Sets the range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. |
| **Property** | **Description** |
| ------------------------ | ------------------------------------------------------------ |
| **Camera Cluster Range** | The range of the cluster grid. The cluster grid itself has its center on the Camera's position and extends in all directions because an intersection may occur outside of the Camera frustum. |

Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public class GeneralSection
public static readonly GUIContent maxAreaContent = EditorGUIUtility.TrTextContent("Maximum Area on Screen", "Sets the maximum number of area Lights HDRP can handle on screen at once.");
public static readonly GUIContent maxEnvContent = EditorGUIUtility.TrTextContent("Maximum Reflection Probes on Screen", "Sets the maximum number of Planar and Reflection Probes HDRP can handle on screen at once.");
public static readonly GUIContent maxDecalContent = EditorGUIUtility.TrTextContent("Maximum Clustered Decals on Screen", "Sets the maximum number of decals that can affect transparent GameObjects on screen.");
public static readonly GUIContent maxLightPerCellContent = EditorGUIUtility.TrTextContent("Maximum Lights per Cell (Ray Tracing)", "Sets the maximum number of lights HDRP can handle in each cell of the ray tracing light cluster.");

public static readonly GUIContent resolutionContent = EditorGUIUtility.TrTextContent("Resolution", "Specifies the resolution of the shadow Atlas.");
public static readonly GUIContent cachedShadowAtlasResolution = EditorGUIUtility.TrTextContent("Cached Shadow Atlas Resolution", "Specifies the resolution of the shadow Atlas that contains the cached shadow maps.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ static void Drawer_SectionLightLoop(SerializedHDRenderPipelineAsset serialized,
EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen, Styles.maxAreaContent);
if (EditorGUI.EndChangeCheck())
serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen.intValue = Mathf.Clamp(serialized.renderPipelineSettings.lightLoopSettings.maxAreaLightsOnScreen.intValue, 1, HDRenderPipeline.k_MaxAreaLightsOnScreen);

EditorGUI.BeginChangeCheck();
EditorGUILayout.DelayedIntField(serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell, Styles.maxLightPerCellContent);
if (EditorGUI.EndChangeCheck())
serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell.intValue = Mathf.Clamp(serialized.renderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell.intValue, 1, HDRenderPipeline.k_MaxLightsPerClusterCell);
}

static void Drawer_SectionDynamicResolutionSettings(SerializedHDRenderPipelineAsset serialized, Editor owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SerializedGlobalLightLoopSettings
public SerializedProperty maxEnvLightsOnScreen;
public SerializedProperty maxDecalsOnScreen;
public SerializedProperty maxPlanarReflectionOnScreen;
public SerializedProperty maxLightsPerClusterCell;

public SerializedGlobalLightLoopSettings(SerializedProperty root)
{
Expand Down Expand Up @@ -56,6 +57,7 @@ public SerializedGlobalLightLoopSettings(SerializedProperty root)
maxEnvLightsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxEnvLightsOnScreen);
maxDecalsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxDecalsOnScreen);
maxPlanarReflectionOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxPlanarReflectionOnScreen);
maxLightsPerClusterCell = root.Find((GlobalLightLoopSettings s) => s.maxLightsPerClusterCell);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public struct GlobalLightLoopSettings
maxEnvLightsOnScreen = 64,
maxDecalsOnScreen = 512,
maxPlanarReflectionOnScreen = 16,
maxLightsPerClusterCell = 8,
};

/// <summary>Cookie atlas resolution.</summary>
Expand Down Expand Up @@ -181,5 +182,7 @@ public struct GlobalLightLoopSettings
public int maxDecalsOnScreen;
/// <summary>Maximum number of planar reflections at the same time on screen.</summary>
public int maxPlanarReflectionOnScreen;
/// <summary>Maximum number of lights per ray tracing light cluster cell.</summary>
public int maxLightsPerClusterCell;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public partial class HDRenderPipeline
internal const int k_MaxDecalsOnScreen = 2048;
internal const int k_MaxLightsOnScreen = k_MaxDirectionalLightsOnScreen + k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen + k_MaxEnvLightsOnScreen;
internal const int k_MaxEnvLightsOnScreen = 1024;
internal const int k_MaxLightsPerClusterCell = 24;
internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f;

#if UNITY_SWITCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ internal class HDRaytracingLightCluster
public static readonly int _ClusterCenterPosition = Shader.PropertyToID("_ClusterCenterPosition");
public static readonly int _ClusterDimension = Shader.PropertyToID("_ClusterDimension");

// Temporary variables
// Temporary variables
// This value is now fixed for every HDRP asset
int m_NumLightsPerCell = 0;

// These values are overriden for every light cluster that is built
Vector3 minClusterPos = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 maxClusterPos = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 clusterCellSize = new Vector3(0.0f, 0.0f, 0.0f);
Expand All @@ -68,7 +72,6 @@ internal class HDRaytracingLightCluster
int areaLightCount = 0;
int envLightCount = 0;
int totalLightCount = 0;
int numLightsPerCell = 0;
Bounds bounds = new Bounds();
Vector3 minBounds = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
Vector3 maxBounds = new Vector3(-float.MaxValue, -float.MaxValue, -float.MaxValue);
Expand Down Expand Up @@ -98,6 +101,11 @@ public void Initialize(HDRenderPipeline renderPipeline)
m_LightDataGPUArray = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
m_EnvLightDataGPUArray = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));

// Allocate the light cluster buffer at the right size
m_NumLightsPerCell = renderPipeline.asset.currentPlatformRenderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell;
int bufferSize = 64 * 64 * 32 * (renderPipeline.asset.currentPlatformRenderPipelineSettings.lightLoopSettings.maxLightsPerClusterCell + 4);
ResizeClusterBuffer(bufferSize);

// Create the material required for debug
m_DebugMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineRayTracingResources.lightClusterDebugS);
}
Expand Down Expand Up @@ -434,16 +442,6 @@ void BuildLightCluster(HDCamera hdCamera, CommandBuffer cmd)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingBuildCluster)))
{
var lightClusterSettings = hdCamera.volumeStack.GetComponent<LightCluster>();
numLightsPerCell = lightClusterSettings.maxNumLightsPercell.value;

// Make sure the Cluster buffer has the right size
int bufferSize = 64 * 64 * 32 * (numLightsPerCell + 4);
if (m_LightCluster.count != bufferSize)
{
ResizeClusterBuffer(bufferSize);
}

// Grab the kernel
ComputeShader lightClusterCS = m_RenderPipelineRayTracingResources.lightClusterBuildCS;
int lightClusterKernel = lightClusterCS.FindKernel(m_LightClusterKernelName);
Expand Down Expand Up @@ -691,7 +689,7 @@ public int GetEnvLightCount()

public int GetLightPerCellCount()
{
return numLightsPerCell;
return m_NumLightsPerCell;
}

void InvalidateCluster()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace UnityEngine.Rendering.HighDefinition
[Serializable, VolumeComponentMenu("Ray Tracing/Light Cluster (Preview)")]
public sealed class LightCluster : VolumeComponent
{
/// <summary>
/// Controls the maximal number lights in a cell.
/// </summary>
[Tooltip("Controls the maximal number lights in a cell.")]
public ClampedIntParameter maxNumLightsPercell = new ClampedIntParameter(10, 0, 24);

/// <summary>
/// Controls the range of the cluster around the camera.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro

// Evaluate the complete lighting
LightLoopOutput lightLoopOutput;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput);
LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 1.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput);

// Alias
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
Expand Down Expand Up @@ -183,7 +183,7 @@ void RaytracingDiffuseDeferred(uint3 dispatchThreadId : SV_DispatchThreadID, uin

// Evaluate lighting
LightLoopOutput lightLoopOutput;
LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput);
LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, 0.0, 1.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), lightLoopOutput);

// Alias
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
#else
EnvLightData envLightData = _EnvLightDatasRT[envLightIdx];
#endif
envLightData.multiplier = _EnvLightDatas[envLightIdx].multiplier;

if (reflectionHierarchyWeight < 1.0)
{
Expand Down