Skip to content

Commit 40a072c

Browse files
authored
Merge pull request #8099 from Unity-Technologies/internal/2022.3/staging
Internal/2022.3/staging
2 parents 76c458e + c7d5852 commit 40a072c

File tree

104 files changed

+4527
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4527
-560
lines changed

Packages/com.unity.render-pipelines.core/Editor/MaterialUpgrader.cs

+76-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine;
33
using System;
44
using UnityEngine.Rendering;
5+
using System.Text;
56

67
namespace UnityEditor.Rendering
78
{
@@ -64,7 +65,6 @@ public string NewShaderPath
6465
List<string> m_TexturesToRemove = new List<string>();
6566
Dictionary<string, Texture> m_TexturesToSet = new Dictionary<string, Texture>();
6667

67-
6868
class KeywordFloatRename
6969
{
7070
public string keyword;
@@ -357,6 +357,72 @@ static bool ShouldUpgradeShader(Material material, HashSet<string> shaderNamesTo
357357
return !shaderNamesToIgnore.Contains(material.shader.name);
358358
}
359359

360+
/// <summary>
361+
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
362+
/// </summary>
363+
/// <param name="materialGUIDs">Array of materials GUIDs.</param>
364+
/// <param name="upgraders">List or available upgraders.</param>
365+
static void LogMaterialVariantMessage(string[] materialGUIDs, List<MaterialUpgrader> upgraders)
366+
{
367+
List<Material> materials = new List<Material>();
368+
foreach (var guid in materialGUIDs)
369+
materials.Add(AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(guid)));
370+
371+
LogMaterialVariantMessage(materials, upgraders);
372+
}
373+
374+
/// <summary>
375+
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
376+
/// </summary>
377+
/// <param name="objects">Array of objects.</param>
378+
/// <param name="upgraders">List or available upgraders.</param>
379+
static void LogMaterialVariantMessage(UnityEngine.Object[] objects, List<MaterialUpgrader> upgraders)
380+
{
381+
Material mat;
382+
List<Material> materials = new List<Material>();
383+
for (int i = 0; i<objects.Length; i++)
384+
{
385+
mat = objects[i] as Material;
386+
if (mat != null)
387+
materials.Add(mat);
388+
}
389+
390+
LogMaterialVariantMessage(materials, upgraders);
391+
}
392+
393+
/// <summary>
394+
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
395+
/// </summary>
396+
/// <param name="materials">List of materials.</param>
397+
/// <param name="upgraders">List or available upgraders.</param>
398+
static void LogMaterialVariantMessage(List<Material> materials, List<MaterialUpgrader> upgraders)
399+
{
400+
StringBuilder sb = new StringBuilder();
401+
sb.AppendLine("Can not upgrade Material Variants, the following assets were skipped:");
402+
bool needsLogging = false;
403+
404+
Material rootMaterial;
405+
406+
foreach (Material material in materials)
407+
{
408+
if (material.isVariant)
409+
{
410+
rootMaterial = material;
411+
while (rootMaterial.isVariant)
412+
rootMaterial = rootMaterial.parent;
413+
414+
if (GetUpgrader(upgraders, rootMaterial) != null)
415+
{
416+
needsLogging = true;
417+
sb.AppendLine($"- <a href=\"{AssetDatabase.GetAssetPath(material)}\" >{material.name}</a>, variant of {material.parent.name} with shader {rootMaterial.shader.name}.");
418+
}
419+
}
420+
}
421+
422+
if (needsLogging)
423+
Debug.Log(sb.ToString(), null);
424+
}
425+
360426

361427
private static bool IsNotAutomaticallyUpgradable(List<MaterialUpgrader> upgraders, Material material)
362428
{
@@ -407,6 +473,8 @@ public static void UpgradeProjectFolder(List<MaterialUpgrader> upgraders, HashSe
407473
var materialAssets = AssetDatabase.FindAssets($"t:{nameof(Material)} glob:\"**/*.mat\"");
408474
int materialIndex = 0;
409475

476+
LogMaterialVariantMessage(materialAssets, upgraders);
477+
410478
foreach (var guid in materialAssets)
411479
{
412480
Material material = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(guid));
@@ -417,6 +485,9 @@ public static void UpgradeProjectFolder(List<MaterialUpgrader> upgraders, HashSe
417485
if (!ShouldUpgradeShader(material, shaderNamesToIgnore))
418486
continue;
419487

488+
if (material.isVariant)
489+
continue;
490+
420491
Upgrade(material, upgraders, flags);
421492

422493
}
@@ -524,10 +595,13 @@ public static void UpgradeSelection(List<MaterialUpgrader> upgraders, HashSet<st
524595
}
525596

526597
List<Material> selectedMaterials = new List<Material>(selection.Length);
598+
599+
LogMaterialVariantMessage(selection, upgraders);
600+
527601
for (int i = 0; i < selection.Length; ++i)
528602
{
529603
Material mat = selection[i] as Material;
530-
if (mat != null)
604+
if (mat != null && !mat.isVariant)
531605
selectedMaterials.Add(mat);
532606
}
533607

Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blitter.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static private void DrawTriangle(CommandBuffer cmd, Material material, int shade
190190
cmd.DrawMesh(s_TriangleMesh, Matrix4x4.identity, material, 0, shaderPass, s_PropertyBlock);
191191
else
192192
cmd.DrawProcedural(Matrix4x4.identity, material, shaderPass, MeshTopology.Triangles, 3, 1, s_PropertyBlock);
193+
s_PropertyBlock.Clear();
193194
}
194195

195196
static internal void DrawQuad(CommandBuffer cmd, Material material, int shaderPass)
@@ -198,6 +199,7 @@ static internal void DrawQuad(CommandBuffer cmd, Material material, int shaderPa
198199
cmd.DrawMesh(s_QuadMesh, Matrix4x4.identity, material, 0, shaderPass, s_PropertyBlock);
199200
else
200201
cmd.DrawProcedural(Matrix4x4.identity, material, shaderPass, MeshTopology.Quads, 4, 1, s_PropertyBlock);
202+
s_PropertyBlock.Clear();
201203
}
202204

203205
/// <summary>
@@ -261,7 +263,7 @@ public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scale
261263
s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source);
262264
DrawTriangle(cmd, material, pass);
263265
}
264-
266+
265267
/// <summary>
266268
/// Blit a RTHandle texture
267269
/// </summary>
@@ -311,7 +313,7 @@ public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source,
311313
cmd.SetRenderTarget(destination, loadAction, storeAction);
312314
DrawTriangle(cmd, material, pass);
313315
}
314-
316+
315317
/// <summary>
316318
/// Blit a Texture with a given Material. Unity uses the reference name `_BlitTexture` to bind the input texture. Set the destination parameter before using this method.
317319
/// </summary>

Packages/com.unity.render-pipelines.core/Runtime/Utilities/HashFNV1A32.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void Append(Delegate del)
112112
[MethodImpl(MethodImplOptions.AggressiveInlining)]
113113
internal static int GetFuncHashCode(Delegate del)
114114
{
115-
return del.Method.GetHashCode() ^ RuntimeHelpers.GetHashCode(del.Target);
115+
return del.Method.GetHashCode() ^ (del.Target != null ? RuntimeHelpers.GetHashCode(del.Target) : 0);
116116
}
117117

118118
public int value => (int)m_Hash;

Packages/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs

+1-58
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,7 @@ class MaterialModificationProcessor : AssetModificationProcessor
2020
static void OnWillCreateAsset(string asset)
2121
{
2222
if (asset.ToLowerInvariant().EndsWith(".mat"))
23-
{
24-
MaterialPostprocessor.s_CreatedAssets.Add(asset);
25-
return;
26-
}
27-
28-
// For .shadergraph assets, this is tricky since the callback will be for the .meta
29-
// file only as we don't create it with AssetDatabase.CreateAsset but later AddObjectToAsset
30-
// to the .shadergraph via the importer context.
31-
// At the time the meta file is created, the .shadergraph is already present
32-
// but Load*AtPAth(), GetMainAssetTypeAtPath() etc. won't find anything.
33-
// The GUID is already present though, and we actually use those facts to infer we
34-
// have a newly created shadergraph.
35-
36-
//
37-
// HDMetaData subasset will be included after SG creation anyway so unlike for materials
38-
// (cf .mat with AssetVersion in OnPostprocessAllAssets) we dont need to manually add a subasset.
39-
// For adding them to MaterialPostprocessor.s_ImportedAssetThatNeedSaving for SaveAssetsToDisk()
40-
// to make them editable (flag for checkout), we still detect those here, but not sure this is
41-
// helpful as right now, even on re-import, a .shadergraph multijson is not rewritten, so only
42-
// /Library side serialized data is actually changed (including the generated .shader that can
43-
// also change which is why we run shadergraph reimports), and re-import from the same .shadergraph
44-
// should be idempotent.
45-
// In other words, there shouldn't be anything to checkout for the .shadergraph per se.
46-
//
47-
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}.meta"))
48-
{
49-
var sgPath = System.IO.Path.ChangeExtension(asset, null);
50-
var importer = AssetImporter.GetAtPath(sgPath);
51-
var guid = AssetDatabase.AssetPathToGUID(sgPath);
52-
if (!String.IsNullOrEmpty(guid) && importer == null)
53-
{
54-
MaterialPostprocessor.s_CreatedAssets.Add(sgPath);
55-
return;
56-
}
57-
}
58-
59-
// Like stated above, doesnt happen:
60-
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}"))
61-
{
6223
MaterialPostprocessor.s_CreatedAssets.Add(asset);
63-
return;
64-
}
6524
}
6625
}
6726

@@ -292,23 +251,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
292251
{
293252
foreach (var asset in importedAssets)
294253
{
295-
// We intercept shadergraphs just to add them to s_ImportedAssetThatNeedSaving to make them editable when we save assets
296-
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}"))
297-
{
298-
bool justCreated = s_CreatedAssets.Contains(asset);
299-
300-
if (!justCreated)
301-
{
302-
s_ImportedAssetThatNeedSaving.Add(asset);
303-
s_NeedsSavingAssets = true;
304-
}
305-
else
306-
{
307-
s_CreatedAssets.Remove(asset);
308-
}
309-
continue;
310-
}
311-
else if (!asset.EndsWith(".mat", StringComparison.OrdinalIgnoreCase))
254+
if (!asset.ToLowerInvariant().EndsWith(".mat"))
312255
continue;
313256

314257
// Materials (.mat) post processing

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIllumination.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public float clampValue
206206
}
207207
[SerializeField, FormerlySerializedAs("clampValue")]
208208
[Tooltip("Controls the clamp of intensity.")]
209-
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
209+
private MinFloatParameter m_ClampValue = new MinFloatParameter(100.0f, 0.001f);
210210

211211
/// <summary>
212212
/// Controls which version of the effect should be used.

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
5656
#define SHADERPASS SHADERPASS_DEFERRED_LIGHTING
5757

58+
// Disable half-precision types in the deferred lighting pass since this causes visual corruption in some cases
59+
#define PREFER_HALF 0
60+
5861
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
5962

6063

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs

-4
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ public partial class HDRenderPipeline
271271
internal const int k_MaxLightsPerClusterCell = ShaderConfig.LightClusterMaxCellElementCount;
272272
internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f;
273273

274-
#if UNITY_SWITCH
275-
static bool k_PreferFragment = true;
276-
#else
277274
static bool k_PreferFragment = false;
278-
#endif
279275

280276
#if !UNITY_EDITOR && UNITY_SWITCH
281277
const bool k_HasNativeQuadSupport = true;

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceGlobalIllumination.compute

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void REPROJECT_GLOBAL_ILLUMINATION(uint3 dispatchThreadId : SV_DispatchThreadID,
307307

308308
if((RAYMARCHINGFALLBACKHIERARCHY_SKY & _RayMarchingFallbackHierarchy) && weight < 1.0f)
309309
{
310-
color += SAMPLE_TEXTURECUBE_ARRAY_LOD(_SkyTexture, s_trilinear_clamp_sampler, sampleDir, 0.0, 0).xyz * (1.0 - weight);
310+
color += EvaluateAmbientProbe(normalData.normalWS) * (1.0 - weight);
311311
weight = 1.0;
312312
}
313313
}

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ScreenSpaceReflection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public float clampValue
261261
}
262262
[SerializeField, FormerlySerializedAs("clampValue")]
263263
[Tooltip("Clamps the exposed intensity, this only affects reflections on opaque objects.")]
264-
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
264+
private MinFloatParameter m_ClampValue = new MinFloatParameter(100.0f, 0.001f);
265265

266266
/// <summary>
267267
/// Enable denoising on the ray traced reflections.

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricClouds/VolumetricCloudsUtilities.hlsl

+5-1
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,12 @@ float EvaluateFinalTransmittance(float3 color, float transmittance)
819819
// reverse the tone mapping
820820
resultLuminance = resultLuminance / (1.0 - resultLuminance);
821821

822+
// By softening the transmittance attenuation curve for pixels adjacent to cloud boundaries when the luminance is super high,
823+
// We can prevent sun flicker and improve perceptual blending. (https://www.desmos.com/calculator/vmly6erwdo)
824+
float finalTransmittance = max(resultLuminance / luminance, pow(transmittance, 6));
825+
822826
// This approach only makes sense if the color is not black
823-
return luminance > 0.0 ? lerp(transmittance, resultLuminance / luminance, _ImprovedTransmittanceBlend) : transmittance;
827+
return luminance > 0.0 ? lerp(transmittance, finalTransmittance, _ImprovedTransmittanceBlend) : transmittance;
824828
}
825829

826830
#endif // VOLUMETRIC_CLOUD_UTILITIES_H

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void SampleBakedGI(
145145
// We prevent to read GI only if we are not raytrace pass that are used to fill the RTGI/Mixed buffer need to be executed normaly
146146
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
147147
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
148-
#if (SHADERPASS == SHADERPASS_GBUFER)
148+
#if (SHADERPASS == SHADERPASS_GBUFFER)
149149
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
150150
#endif
151151
)

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader

+3
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ Shader "HDRP/LayeredLit"
580580
// Include
581581
//-------------------------------------------------------------------------------------
582582

583+
// Disable half-precision types in the lit shader since this causes visual corruption in some cases
584+
#define PREFER_HALF 0
585+
583586
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
584587
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
585588
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader

+3
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ Shader "HDRP/LayeredLitTessellation"
610610
// Include
611611
//-------------------------------------------------------------------------------------
612612

613+
// Disable half-precision types in the lit shader since this causes visual corruption in some cases
614+
#define PREFER_HALF 0
615+
613616
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
614617
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
615618
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ uint DecodeFromGBuffer(uint2 positionSS, uint tileFeatureFlags, out BSDFData bsd
964964
bsdfData.ambientOcclusion = 1.0;
965965

966966
// For SSGI/RTGI/Mixed and APV not using lightmap we load the content of gbuffer3 in emissive, otherwise it is lightmap/lightprobe + emissive
967-
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
967+
if ((_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF && _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED)
968968
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
969969
|| !builtinData.isLightmap
970970
#endif

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader

+3
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ Shader "HDRP/Lit"
352352
// Include
353353
//-------------------------------------------------------------------------------------
354354

355+
// Disable half-precision types in the lit shader since this causes visual corruption in some cases
356+
#define PREFER_HALF 0
357+
355358
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
356359
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
357360
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"

Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader

+3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ Shader "HDRP/LitTessellation"
368368
// Include
369369
//-------------------------------------------------------------------------------------
370370

371+
// Disable half-precision types in the lit shader since this causes visual corruption in some cases
372+
#define PREFER_HALF 0
373+
371374
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
372375
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
373376
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ internal GlobalLightingQualitySettings()
225225
public float[] RTGIRayLength = new float[s_QualitySettingCount];
226226
/// <summary>Controls if the effect should be computed at full resolution. The array must have one entry per scalable setting level.</summary>
227227
public bool[] RTGIFullResolution = new bool[s_QualitySettingCount];
228-
/// <summary>Clamp value used to reduce the variance in the integration signal. The array must have one entry per scalable setting level, and elements must be between 0.001 and 10.</summary>
229-
[Range(0.001f, 10.0f)]
228+
/// <summary>Clamp value used to reduce the variance in the integration signal. The array must have one entry per scalable setting level, and elements must be above 0.001.</summary>
229+
[Min(0.001f)]
230230
public float[] RTGIClampValue = new float[s_QualitySettingCount];
231231
/// <summary>Controls the number of ray steps for hybrid tracing. The array must have one entry per scalable setting level, and elements must above 0.</summary>
232232
[Min(0)]
@@ -251,8 +251,8 @@ internal GlobalLightingQualitySettings()
251251
/// <summary>Controls the length of ray traced reflection rays. The array must have one entry per scalable setting level, and elements must above 0.01.</summary>
252252
[Min(0.01f)]
253253
public float[] RTRRayLength = new float[s_QualitySettingCount];
254-
/// <summary>Clamp value used to reduce the variance in the integration signal. The array must have one entry per scalable setting level, and elements must be between 0.001 and 10.</summary>
255-
[Range(0.001f, 10.0f)]
254+
/// <summary>Clamp value used to reduce the variance in the integration signal. The array must have one entry per scalable setting level, and elements must be above 0.001.</summary>
255+
[Min(0.001f)]
256256
public float[] RTRClampValue = new float[s_QualitySettingCount];
257257
/// <summary>Controls if the effect should be computed at full resolution. The array must have one entry per scalable setting level.</summary>
258258
public bool[] RTRFullResolution = new bool[s_QualitySettingCount];

0 commit comments

Comments
 (0)