Skip to content

Commit

Permalink
Merge pull request #8099 from Unity-Technologies/internal/2022.3/staging
Browse files Browse the repository at this point in the history
Internal/2022.3/staging
  • Loading branch information
UnityAljosha authored Nov 1, 2024
2 parents 76c458e + c7d5852 commit 40a072c
Show file tree
Hide file tree
Showing 104 changed files with 4,527 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using System;
using UnityEngine.Rendering;
using System.Text;

namespace UnityEditor.Rendering
{
Expand Down Expand Up @@ -64,7 +65,6 @@ public string NewShaderPath
List<string> m_TexturesToRemove = new List<string>();
Dictionary<string, Texture> m_TexturesToSet = new Dictionary<string, Texture>();


class KeywordFloatRename
{
public string keyword;
Expand Down Expand Up @@ -357,6 +357,72 @@ static bool ShouldUpgradeShader(Material material, HashSet<string> shaderNamesTo
return !shaderNamesToIgnore.Contains(material.shader.name);
}

/// <summary>
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
/// </summary>
/// <param name="materialGUIDs">Array of materials GUIDs.</param>
/// <param name="upgraders">List or available upgraders.</param>
static void LogMaterialVariantMessage(string[] materialGUIDs, List<MaterialUpgrader> upgraders)
{
List<Material> materials = new List<Material>();
foreach (var guid in materialGUIDs)
materials.Add(AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(guid)));

LogMaterialVariantMessage(materials, upgraders);
}

/// <summary>
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
/// </summary>
/// <param name="objects">Array of objects.</param>
/// <param name="upgraders">List or available upgraders.</param>
static void LogMaterialVariantMessage(UnityEngine.Object[] objects, List<MaterialUpgrader> upgraders)
{
Material mat;
List<Material> materials = new List<Material>();
for (int i = 0; i<objects.Length; i++)
{
mat = objects[i] as Material;
if (mat != null)
materials.Add(mat);
}

LogMaterialVariantMessage(materials, upgraders);
}

/// <summary>
/// Check if the materials in the list are variants of upgradable materials, and logs a infomative message to the user..
/// </summary>
/// <param name="materials">List of materials.</param>
/// <param name="upgraders">List or available upgraders.</param>
static void LogMaterialVariantMessage(List<Material> materials, List<MaterialUpgrader> upgraders)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Can not upgrade Material Variants, the following assets were skipped:");
bool needsLogging = false;

Material rootMaterial;

foreach (Material material in materials)
{
if (material.isVariant)
{
rootMaterial = material;
while (rootMaterial.isVariant)
rootMaterial = rootMaterial.parent;

if (GetUpgrader(upgraders, rootMaterial) != null)
{
needsLogging = true;
sb.AppendLine($"- <a href=\"{AssetDatabase.GetAssetPath(material)}\" >{material.name}</a>, variant of {material.parent.name} with shader {rootMaterial.shader.name}.");
}
}
}

if (needsLogging)
Debug.Log(sb.ToString(), null);
}


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

LogMaterialVariantMessage(materialAssets, upgraders);

foreach (var guid in materialAssets)
{
Material material = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(guid));
Expand All @@ -417,6 +485,9 @@ public static void UpgradeProjectFolder(List<MaterialUpgrader> upgraders, HashSe
if (!ShouldUpgradeShader(material, shaderNamesToIgnore))
continue;

if (material.isVariant)
continue;

Upgrade(material, upgraders, flags);

}
Expand Down Expand Up @@ -524,10 +595,13 @@ public static void UpgradeSelection(List<MaterialUpgrader> upgraders, HashSet<st
}

List<Material> selectedMaterials = new List<Material>(selection.Length);

LogMaterialVariantMessage(selection, upgraders);

for (int i = 0; i < selection.Length; ++i)
{
Material mat = selection[i] as Material;
if (mat != null)
if (mat != null && !mat.isVariant)
selectedMaterials.Add(mat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static private void DrawTriangle(CommandBuffer cmd, Material material, int shade
cmd.DrawMesh(s_TriangleMesh, Matrix4x4.identity, material, 0, shaderPass, s_PropertyBlock);
else
cmd.DrawProcedural(Matrix4x4.identity, material, shaderPass, MeshTopology.Triangles, 3, 1, s_PropertyBlock);
s_PropertyBlock.Clear();
}

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

/// <summary>
Expand Down Expand Up @@ -261,7 +263,7 @@ public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scale
s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source);
DrawTriangle(cmd, material, pass);
}

/// <summary>
/// Blit a RTHandle texture
/// </summary>
Expand Down Expand Up @@ -311,7 +313,7 @@ public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source,
cmd.SetRenderTarget(destination, loadAction, storeAction);
DrawTriangle(cmd, material, pass);
}

/// <summary>
/// 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.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void Append(Delegate del)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetFuncHashCode(Delegate del)
{
return del.Method.GetHashCode() ^ RuntimeHelpers.GetHashCode(del.Target);
return del.Method.GetHashCode() ^ (del.Target != null ? RuntimeHelpers.GetHashCode(del.Target) : 0);
}

public int value => (int)m_Hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,7 @@ class MaterialModificationProcessor : AssetModificationProcessor
static void OnWillCreateAsset(string asset)
{
if (asset.ToLowerInvariant().EndsWith(".mat"))
{
MaterialPostprocessor.s_CreatedAssets.Add(asset);
return;
}

// For .shadergraph assets, this is tricky since the callback will be for the .meta
// file only as we don't create it with AssetDatabase.CreateAsset but later AddObjectToAsset
// to the .shadergraph via the importer context.
// At the time the meta file is created, the .shadergraph is already present
// but Load*AtPAth(), GetMainAssetTypeAtPath() etc. won't find anything.
// The GUID is already present though, and we actually use those facts to infer we
// have a newly created shadergraph.

//
// HDMetaData subasset will be included after SG creation anyway so unlike for materials
// (cf .mat with AssetVersion in OnPostprocessAllAssets) we dont need to manually add a subasset.
// For adding them to MaterialPostprocessor.s_ImportedAssetThatNeedSaving for SaveAssetsToDisk()
// to make them editable (flag for checkout), we still detect those here, but not sure this is
// helpful as right now, even on re-import, a .shadergraph multijson is not rewritten, so only
// /Library side serialized data is actually changed (including the generated .shader that can
// also change which is why we run shadergraph reimports), and re-import from the same .shadergraph
// should be idempotent.
// In other words, there shouldn't be anything to checkout for the .shadergraph per se.
//
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}.meta"))
{
var sgPath = System.IO.Path.ChangeExtension(asset, null);
var importer = AssetImporter.GetAtPath(sgPath);
var guid = AssetDatabase.AssetPathToGUID(sgPath);
if (!String.IsNullOrEmpty(guid) && importer == null)
{
MaterialPostprocessor.s_CreatedAssets.Add(sgPath);
return;
}
}

// Like stated above, doesnt happen:
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}"))
{
MaterialPostprocessor.s_CreatedAssets.Add(asset);
return;
}
}
}

Expand Down Expand Up @@ -292,23 +251,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
{
foreach (var asset in importedAssets)
{
// We intercept shadergraphs just to add them to s_ImportedAssetThatNeedSaving to make them editable when we save assets
if (asset.ToLowerInvariant().EndsWith($".{ShaderGraphImporter.Extension}"))
{
bool justCreated = s_CreatedAssets.Contains(asset);

if (!justCreated)
{
s_ImportedAssetThatNeedSaving.Add(asset);
s_NeedsSavingAssets = true;
}
else
{
s_CreatedAssets.Remove(asset);
}
continue;
}
else if (!asset.EndsWith(".mat", StringComparison.OrdinalIgnoreCase))
if (!asset.ToLowerInvariant().EndsWith(".mat"))
continue;

// Materials (.mat) post processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public float clampValue
}
[SerializeField, FormerlySerializedAs("clampValue")]
[Tooltip("Controls the clamp of intensity.")]
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
private MinFloatParameter m_ClampValue = new MinFloatParameter(100.0f, 0.001f);

/// <summary>
/// Controls which version of the effect should be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_DEFERRED_LIGHTING

// Disable half-precision types in the deferred lighting pass since this causes visual corruption in some cases
#define PREFER_HALF 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ public partial class HDRenderPipeline
internal const int k_MaxLightsPerClusterCell = ShaderConfig.LightClusterMaxCellElementCount;
internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f;

#if UNITY_SWITCH
static bool k_PreferFragment = true;
#else
static bool k_PreferFragment = false;
#endif

#if !UNITY_EDITOR && UNITY_SWITCH
const bool k_HasNativeQuadSupport = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void REPROJECT_GLOBAL_ILLUMINATION(uint3 dispatchThreadId : SV_DispatchThreadID,

if((RAYMARCHINGFALLBACKHIERARCHY_SKY & _RayMarchingFallbackHierarchy) && weight < 1.0f)
{
color += SAMPLE_TEXTURECUBE_ARRAY_LOD(_SkyTexture, s_trilinear_clamp_sampler, sampleDir, 0.0, 0).xyz * (1.0 - weight);
color += EvaluateAmbientProbe(normalData.normalWS) * (1.0 - weight);
weight = 1.0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public float clampValue
}
[SerializeField, FormerlySerializedAs("clampValue")]
[Tooltip("Clamps the exposed intensity, this only affects reflections on opaque objects.")]
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
private MinFloatParameter m_ClampValue = new MinFloatParameter(100.0f, 0.001f);

/// <summary>
/// Enable denoising on the ray traced reflections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,12 @@ float EvaluateFinalTransmittance(float3 color, float transmittance)
// reverse the tone mapping
resultLuminance = resultLuminance / (1.0 - resultLuminance);

// By softening the transmittance attenuation curve for pixels adjacent to cloud boundaries when the luminance is super high,
// We can prevent sun flicker and improve perceptual blending. (https://www.desmos.com/calculator/vmly6erwdo)
float finalTransmittance = max(resultLuminance / luminance, pow(transmittance, 6));

// This approach only makes sense if the color is not black
return luminance > 0.0 ? lerp(transmittance, resultLuminance / luminance, _ImprovedTransmittanceBlend) : transmittance;
return luminance > 0.0 ? lerp(transmittance, finalTransmittance, _ImprovedTransmittanceBlend) : transmittance;
}

#endif // VOLUMETRIC_CLOUD_UTILITIES_H
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void SampleBakedGI(
// 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
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
#if (SHADERPASS == SHADERPASS_GBUFER)
#if (SHADERPASS == SHADERPASS_GBUFFER)
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
#endif
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ Shader "HDRP/LayeredLit"
// Include
//-------------------------------------------------------------------------------------

// Disable half-precision types in the lit shader since this causes visual corruption in some cases
#define PREFER_HALF 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ Shader "HDRP/LayeredLitTessellation"
// Include
//-------------------------------------------------------------------------------------

// Disable half-precision types in the lit shader since this causes visual corruption in some cases
#define PREFER_HALF 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ uint DecodeFromGBuffer(uint2 positionSS, uint tileFeatureFlags, out BSDFData bsd
bsdfData.ambientOcclusion = 1.0;

// For SSGI/RTGI/Mixed and APV not using lightmap we load the content of gbuffer3 in emissive, otherwise it is lightmap/lightprobe + emissive
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
if ((_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF && _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED)
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|| !builtinData.isLightmap
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ Shader "HDRP/Lit"
// Include
//-------------------------------------------------------------------------------------

// Disable half-precision types in the lit shader since this causes visual corruption in some cases
#define PREFER_HALF 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ Shader "HDRP/LitTessellation"
// Include
//-------------------------------------------------------------------------------------

// Disable half-precision types in the lit shader since this causes visual corruption in some cases
#define PREFER_HALF 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ internal GlobalLightingQualitySettings()
public float[] RTGIRayLength = new float[s_QualitySettingCount];
/// <summary>Controls if the effect should be computed at full resolution. The array must have one entry per scalable setting level.</summary>
public bool[] RTGIFullResolution = new bool[s_QualitySettingCount];
/// <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>
[Range(0.001f, 10.0f)]
/// <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>
[Min(0.001f)]
public float[] RTGIClampValue = new float[s_QualitySettingCount];
/// <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>
[Min(0)]
Expand All @@ -251,8 +251,8 @@ internal GlobalLightingQualitySettings()
/// <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>
[Min(0.01f)]
public float[] RTRRayLength = new float[s_QualitySettingCount];
/// <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>
[Range(0.001f, 10.0f)]
/// <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>
[Min(0.001f)]
public float[] RTRClampValue = new float[s_QualitySettingCount];
/// <summary>Controls if the effect should be computed at full resolution. The array must have one entry per scalable setting level.</summary>
public bool[] RTRFullResolution = new bool[s_QualitySettingCount];
Expand Down
Loading

0 comments on commit 40a072c

Please sign in to comment.