Skip to content

Commit 98d012a

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.3] Fixed Default Volume profile bugs
1 parent dd05a05 commit 98d012a

15 files changed

Lines changed: 765 additions & 66 deletions

Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,6 @@ internal void SetOverridesTo(IEnumerable<VolumeParameter> enumerable, bool state
328328
}
329329
}
330330

331-
/// <summary>
332-
/// A custom hashing function that Unity uses to compare the state of parameters.
333-
/// </summary>
334-
/// <returns>A computed hash code for the current instance.</returns>
335-
public override int GetHashCode()
336-
{
337-
unchecked
338-
{
339-
//return parameters.Aggregate(17, (i, p) => i * 23 + p.GetHash());
340-
341-
int hash = 17;
342-
343-
for (int i = 0; i < parameterList.Length; i++)
344-
hash = hash * 23 + parameterList[i].GetHashCode();
345-
346-
return hash;
347-
}
348-
}
349-
350331
/// <summary>
351332
/// Returns true if any of the volume properites has been overridden.
352333
/// </summary>

Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeManager.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,14 @@ public void Initialize(VolumeProfile globalDefaultVolumeProfile = null, VolumePr
260260
void InitializeBaseTypesArray(VolumeProfile globalDefaultVolumeProfile = null)
261261
{
262262
using var profilerScope = k_ProfilerMarkerInitializeBaseTypesArray.Auto();
263-
#if UNITY_EDITOR
264-
LoadBaseTypesByReflection(GraphicsSettings.currentRenderPipelineAssetType);
265-
#else
263+
#if !UNITY_EDITOR
266264
if (globalDefaultVolumeProfile == null)
267265
{
268266
var defaultVolumeProfileSettings = GraphicsSettings.GetRenderPipelineSettings<IDefaultVolumeProfileAsset>();
269267
globalDefaultVolumeProfile = defaultVolumeProfileSettings?.defaultVolumeProfile;
270268
}
271-
LoadBaseTypes(globalDefaultVolumeProfile);
272269
#endif
270+
LoadBaseTypes(GraphicsSettings.currentRenderPipelineAssetType, globalDefaultVolumeProfile);
273271
}
274272

275273
//This is called by test where the basetypes are tuned for the purpose of the test.
@@ -311,7 +309,7 @@ public void Deinitialize()
311309
/// <param name="profile">The VolumeProfile to use as the global default profile.</param>
312310
public void SetGlobalDefaultProfile(VolumeProfile profile)
313311
{
314-
LoadBaseTypes(profile);
312+
LoadBaseTypes(GraphicsSettings.currentRenderPipelineAssetType, profile);
315313
globalDefaultProfile = profile;
316314
EvaluateVolumeDefaultState();
317315
}
@@ -423,8 +421,9 @@ public void DestroyStack(VolumeStack stack)
423421
/// LoadBaseTypes is responsible for loading the list of VolumeComponent types that will be used to build the default state of the VolumeStack. It uses the provided global default profile to determine which component types are relevant for the current render pipeline.
424422
/// This will be called only once at runtime on app boot
425423
/// </summary>
424+
/// <param name="rpType">The Pipeline Type used to check if each VolumeComponent is supported.</param>
426425
/// <param name="globalDefaultVolumeProfile">The global default volume profile to use to build the base component type array.</param>
427-
internal void LoadBaseTypes(VolumeProfile globalDefaultVolumeProfile)
426+
internal void LoadBaseTypesByDefaultVolume(Type rpType, VolumeProfile globalDefaultVolumeProfile)
428427
{
429428
if (globalDefaultVolumeProfile == null)
430429
{
@@ -434,13 +433,13 @@ internal void LoadBaseTypes(VolumeProfile globalDefaultVolumeProfile)
434433

435434
using (ListPool<Type>.Get(out var list))
436435
{
437-
var pipelineAssetType = GraphicsSettings.currentRenderPipelineAssetType;
438436
foreach (var comp in globalDefaultVolumeProfile.components)
439437
{
440-
if (comp == null) continue;
438+
if (comp == null)
439+
continue;
441440

442441
var componentType = comp.GetType();
443-
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(componentType, pipelineAssetType))
442+
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(componentType, rpType))
444443
continue;
445444

446445
list.Add(componentType);
@@ -469,15 +468,30 @@ internal Type[] LoadBaseTypesByReflection(Type pipelineAssetType)
469468
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(t, pipelineAssetType))
470469
continue;
471470

471+
if (t.GetCustomAttribute<ObsoleteAttribute>() != null)
472+
continue;
473+
472474
list.Add(t);
473475
}
474-
475476
m_BaseComponentTypeArray = list.ToArray();
476477
}
477478

478479
return m_BaseComponentTypeArray;
479480
}
480481
#endif
482+
/// <summary>
483+
/// Helper to choose a type loading depending if we are in Editor and Standalone.
484+
/// </summary>
485+
/// <param name="pipelineAssetType">The Pipeline Type used to check if each VolumeComponent is supported.</param>
486+
/// <param name="globalDefaultVolumeProfile">The global default volume profile to use to build the base component type array.</param>
487+
void LoadBaseTypes(Type pipelineAssetType, VolumeProfile globalDefaultVolumeProfile = null)
488+
{
489+
#if UNITY_EDITOR
490+
LoadBaseTypesByReflection(pipelineAssetType);
491+
#else
492+
LoadBaseTypesByDefaultVolume(pipelineAssetType, globalDefaultVolumeProfile);
493+
#endif
494+
}
481495

482496
internal void InitializeVolumeComponents()
483497
{

Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,33 +321,16 @@ public bool TryGetAllSubclassOf<T>(Type type, List<T> result)
321321
return count != result.Count;
322322
}
323323

324-
/// <summary>
325-
/// A custom hashing function that Unity uses to compare the state of parameters.
326-
/// </summary>
327-
/// <returns>A computed hash code for the current instance.</returns>
328-
public override int GetHashCode()
329-
{
330-
unchecked
331-
{
332-
int hash = 17;
333-
334-
for (int i = 0; i < components.Count; i++)
335-
hash = hash * 23 + components[i].GetHashCode();
336-
337-
return hash;
338-
}
339-
}
340-
341324
internal int GetComponentListHashCode()
342325
{
343326
unchecked
344327
{
345-
int hash = 17;
328+
var hashCode = HashFNV1A32.Create();
346329

347330
for (int i = 0; i < components.Count; i++)
348-
hash = hash * 23 + components[i].GetType().GetHashCode();
331+
hashCode.Append(components[i].GetType().GetHashCode());
349332

350-
return hash;
333+
return hashCode.value;
351334
}
352335
}
353336

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine;
2+
using UnityEngine.Rendering;
3+
4+
namespace UnityEditor.Rendering.Tests
5+
{
6+
[HideInInspector]
7+
class VolumeComponentDecorators : VolumeComponent
8+
{
9+
[Tooltip("Increase to make the noise texture appear bigger and less")]
10+
public FloatParameter _NoiseTileSize = new FloatParameter(25.0f);
11+
12+
[InspectorName("Color")]
13+
public ColorParameter _FogColor = new ColorParameter(Color.grey);
14+
15+
[InspectorName("Size and occurrence"), Tooltip("Increase to make patches SMALLER, and frequent")]
16+
public ClampedFloatParameter _HighNoiseSpaceFreq = new ClampedFloatParameter(0.1f, 0.1f, 1f);
17+
}
18+
}

Tests/SRPTests/Projects/SRP_SmokeTest/Assets/Tests/Editor/Volumes/VolumeComponentDecorators.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SRPTests/Projects/SRP_SmokeTest/Assets/Tests/Editor/Volumes/VolumeComponentTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,6 @@ public string[] AdditionalProperties(Type volumeComponentType)
310310

311311
#region Decorators Handling Test
312312

313-
[HideInInspector]
314-
class VolumeComponentDecorators : VolumeComponent
315-
{
316-
[Tooltip("Increase to make the noise texture appear bigger and less")]
317-
public FloatParameter _NoiseTileSize = new FloatParameter(25.0f);
318-
319-
[InspectorName("Color")]
320-
public ColorParameter _FogColor = new ColorParameter(Color.grey);
321-
322-
[InspectorName("Size and occurrence"), Tooltip("Increase to make patches SMALLER, and frequent")]
323-
public ClampedFloatParameter _HighNoiseSpaceFreq = new ClampedFloatParameter(0.1f, 0.1f, 1f);
324-
}
325-
326313
readonly (string displayName, string tooltip)[] k_ExpectedResults =
327314
{
328315
(string.Empty, "Increase to make the noise texture appear bigger and less"),

0 commit comments

Comments
 (0)