Skip to content

Commit 2579bdd

Browse files
Fixed LOD mesh stripping and LOD Group UI (#2072)
* Current LOD bias and max values for scene view rendering is now using the default frame settings. This makes LODGroup UI consistent with what is happening on screen. * LOD Meshes are now properly stripped depending on the Max LOD value stored in all HDRP assets of a build. * Added a section about LOD management in the feature comparison with builtin to explain the differences and that the QualitySettings lod APIs aren't supported anymore. * Update changelog * Updated doc with review feedback. Co-authored-by: sebastienlagarde <[email protected]>
1 parent 0e1eec1 commit 2579bdd

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
123123
- Fixed accumulation on DX11
124124
- Fixed issue with screen space UI not drawing on the graphics compositor (case 1279272).
125125
- Fixed error Maximum allowed thread group count is 65535 when resolution is very high.
126+
- LOD meshes are now properly stripped based on the maximum lod value parameters contained in the HDRP asset.
127+
- Fixed an inconsistency in the LOD group UI where LOD bias was not the right one.
126128

127129
### Changed
128130
- Preparation pass for RTSSShadows to be supported by render graph.

com.unity.render-pipelines.high-definition/Documentation~/Feature-Comparison.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ The tables that follow provide an overview of the **Features** that the High Def
210210
| Hair | Not supported | Yes |
211211
| Fabric | Not supported | Yes |
212212

213+
## LOD Management
214+
In the Built-in Render Pipeline, you manage levels of detail (LOD) from the QualitySettings. Each quality setting defines a LOD Bias and a Maximum LOD value. As such, they are global to the quality setting and you cannot change them on a per camera basis. In HDRP, there are scalability settings that allow you to change the LOD settings per camera by using either predetermined values contained in the HDRP Asset of the current quality level or overridden values. For more information, see [HDRP Asset](HDRP-Asset.md) and [Frame Settings](Frame-Settings.md).
215+
216+
Managing LOD in this way has two consequences:
217+
- Default LOD settings for a quality level are now stored in the HDRP Asset instead of the Quality Settings.
218+
- Built-in APIs such as QualitySettings.lodBias or QualitySettings.maximumLODLevel no longer work. Instead, you need to change these properties through the camera Frame Settings. If you use the Built-in APIs, they have no effect at all.
219+
213220
## Render Pipeline Hooks
214221

215222
| **Feature** | **Built-in Render Pipeline** | **High Definition Render Pipeline (HDRP)** |

com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessBuild.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ class HDRPPreprocessBuild : IPreprocessBuildWithReport
1010
{
1111
public int callbackOrder { get { return 0; } }
1212

13+
int GetMinimumMaxLoDValue(HDRenderPipelineAsset asset)
14+
{
15+
int minimumMaxLoD = int.MaxValue;
16+
var maxLoDs = asset.currentPlatformRenderPipelineSettings.maximumLODLevel;
17+
var schema = ScalableSettingSchema.GetSchemaOrNull(maxLoDs.schemaId);
18+
for (int lod = 0; lod < schema.levelCount; ++lod)
19+
{
20+
if (maxLoDs.TryGet(lod, out int maxLoD))
21+
minimumMaxLoD = Mathf.Min(minimumMaxLoD, maxLoD);
22+
}
23+
24+
if (minimumMaxLoD != int.MaxValue)
25+
return minimumMaxLoD;
26+
else
27+
return 0;
28+
}
29+
1330
public void OnPreprocessBuild(BuildReport report)
1431
{
1532
// Detect if the users forget to assign an HDRP Asset
@@ -38,16 +55,35 @@ public void OnPreprocessBuild(BuildReport report)
3855

3956
// If platform is supported all good
4057
GraphicsDeviceType unsupportedGraphicDevice = GraphicsDeviceType.Null;
41-
if (HDUtils.AreGraphicsAPIsSupported(report.summary.platform, out unsupportedGraphicDevice)
58+
bool supported = HDUtils.AreGraphicsAPIsSupported(report.summary.platform, out unsupportedGraphicDevice)
4259
&& HDUtils.IsSupportedBuildTarget(report.summary.platform)
43-
&& HDUtils.IsOperatingSystemSupported(SystemInfo.operatingSystem))
44-
return;
60+
&& HDUtils.IsOperatingSystemSupported(SystemInfo.operatingSystem);
4561

46-
unsupportedGraphicDevice = (unsupportedGraphicDevice == GraphicsDeviceType.Null) ? SystemInfo.graphicsDeviceType : unsupportedGraphicDevice;
47-
string msg = "The platform " + report.summary.platform.ToString() + " with the graphic API " + unsupportedGraphicDevice + " is not supported with High Definition Render Pipeline";
62+
if (!supported)
63+
{
64+
unsupportedGraphicDevice = (unsupportedGraphicDevice == GraphicsDeviceType.Null) ? SystemInfo.graphicsDeviceType : unsupportedGraphicDevice;
65+
string msg = "The platform " + report.summary.platform.ToString() + " with the graphic API " + unsupportedGraphicDevice + " is not supported with High Definition Render Pipeline";
4866

49-
// Throw an exception to stop the build
50-
throw new BuildFailedException(msg);
67+
// Throw an exception to stop the build
68+
throw new BuildFailedException(msg);
69+
}
70+
71+
// Update all quality levels with the right max lod so that meshes can be stripped.
72+
// We don't take lod bias into account because it can be overridden per camera.
73+
int qualityLevelCount = QualitySettings.names.Length;
74+
for (int i = 0; i < qualityLevelCount; ++i)
75+
{
76+
QualitySettings.SetQualityLevel(i, false);
77+
var renderPipeline = QualitySettings.renderPipeline as HDRenderPipelineAsset;
78+
if (renderPipeline != null)
79+
{
80+
QualitySettings.maximumLODLevel = GetMinimumMaxLoDValue(renderPipeline);
81+
}
82+
else
83+
{
84+
QualitySettings.maximumLODLevel = GetMinimumMaxLoDValue(hdPipelineAsset);
85+
}
86+
}
5187
}
5288
}
5389
}

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau
383383

384384
SetRenderingFeatures();
385385

386+
// Initialize lod settings with the default frame settings. This will pull LoD values from the current quality level HDRP asset if necessary.
387+
// This will make the LoD Group UI consistent with the scene view camera like it is for builtin pipeline.
388+
QualitySettings.lodBias = m_Asset.GetDefaultFrameSettings(FrameSettingsRenderType.Camera).GetResolvedLODBias(m_Asset);
389+
QualitySettings.maximumLODLevel = m_Asset.GetDefaultFrameSettings(FrameSettingsRenderType.Camera).GetResolvedMaximumLODLevel(m_Asset);
390+
386391
// The first thing we need to do is to set the defines that depend on the render pipeline settings
387392
m_RayTracingSupported = GatherRayTracingSupport(m_Asset.currentPlatformRenderPipelineSettings);
388393

0 commit comments

Comments
 (0)