Skip to content

Commit 1c1e679

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.5] Fixed Default Volume profile bugs
1 parent 5c302c1 commit 1c1e679

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
@@ -272,16 +272,14 @@ public void Initialize(VolumeProfile globalDefaultVolumeProfile = null, VolumePr
272272
void InitializeBaseTypesArray(VolumeProfile globalDefaultVolumeProfile = null)
273273
{
274274
using var profilerScope = k_ProfilerMarkerInitializeBaseTypesArray.Auto();
275-
#if UNITY_EDITOR
276-
LoadBaseTypesByReflection(GraphicsSettings.currentRenderPipelineAssetType);
277-
#else
275+
#if !UNITY_EDITOR
278276
if (globalDefaultVolumeProfile == null)
279277
{
280278
var defaultVolumeProfileSettings = GraphicsSettings.GetRenderPipelineSettings<IDefaultVolumeProfileAsset>();
281279
globalDefaultVolumeProfile = defaultVolumeProfileSettings?.defaultVolumeProfile;
282280
}
283-
LoadBaseTypes(globalDefaultVolumeProfile);
284281
#endif
282+
LoadBaseTypes(GraphicsSettings.currentRenderPipelineAssetType, globalDefaultVolumeProfile);
285283
}
286284

287285
//This is called by test where the basetypes are tuned for the purpose of the test.
@@ -323,7 +321,7 @@ public void Deinitialize()
323321
/// <param name="profile">The VolumeProfile to use as the global default profile.</param>
324322
public void SetGlobalDefaultProfile(VolumeProfile profile)
325323
{
326-
LoadBaseTypes(profile);
324+
LoadBaseTypes(GraphicsSettings.currentRenderPipelineAssetType, profile);
327325
globalDefaultProfile = profile;
328326
EvaluateVolumeDefaultState();
329327
}
@@ -435,8 +433,9 @@ public void DestroyStack(VolumeStack stack)
435433
/// 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.
436434
/// This will be called only once at runtime on app boot
437435
/// </summary>
436+
/// <param name="rpType">The Pipeline Type used to check if each VolumeComponent is supported.</param>
438437
/// <param name="globalDefaultVolumeProfile">The global default volume profile to use to build the base component type array.</param>
439-
internal void LoadBaseTypes(VolumeProfile globalDefaultVolumeProfile)
438+
internal void LoadBaseTypesByDefaultVolume(Type rpType, VolumeProfile globalDefaultVolumeProfile)
440439
{
441440
if (globalDefaultVolumeProfile == null)
442441
{
@@ -446,13 +445,13 @@ internal void LoadBaseTypes(VolumeProfile globalDefaultVolumeProfile)
446445

447446
using (ListPool<Type>.Get(out var list))
448447
{
449-
var pipelineAssetType = GraphicsSettings.currentRenderPipelineAssetType;
450448
foreach (var comp in globalDefaultVolumeProfile.components)
451449
{
452-
if (comp == null) continue;
450+
if (comp == null)
451+
continue;
453452

454453
var componentType = comp.GetType();
455-
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(componentType, pipelineAssetType))
454+
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(componentType, rpType))
456455
continue;
457456

458457
list.Add(componentType);
@@ -481,15 +480,30 @@ internal Type[] LoadBaseTypesByReflection(Type pipelineAssetType)
481480
if (!SupportedOnRenderPipelineAttribute.IsTypeSupportedOnRenderPipeline(t, pipelineAssetType))
482481
continue;
483482

483+
if (t.GetCustomAttribute<ObsoleteAttribute>() != null)
484+
continue;
485+
484486
list.Add(t);
485487
}
486-
487488
m_BaseComponentTypeArray = list.ToArray();
488489
}
489490

490491
return m_BaseComponentTypeArray;
491492
}
492493
#endif
494+
/// <summary>
495+
/// Helper to choose a type loading depending if we are in Editor and Standalone.
496+
/// </summary>
497+
/// <param name="pipelineAssetType">The Pipeline Type used to check if each VolumeComponent is supported.</param>
498+
/// <param name="globalDefaultVolumeProfile">The global default volume profile to use to build the base component type array.</param>
499+
void LoadBaseTypes(Type pipelineAssetType, VolumeProfile globalDefaultVolumeProfile = null)
500+
{
501+
#if UNITY_EDITOR
502+
LoadBaseTypesByReflection(pipelineAssetType);
503+
#else
504+
LoadBaseTypesByDefaultVolume(pipelineAssetType, globalDefaultVolumeProfile);
505+
#endif
506+
}
493507

494508
internal void InitializeVolumeComponents()
495509
{

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)