Skip to content

Commit

Permalink
Merge pull request #8109 from Unity-Technologies/internal/6000.0/staging
Browse files Browse the repository at this point in the history
Internal/6000.0/staging
  • Loading branch information
UnityAljosha authored Nov 1, 2024
2 parents 828256b + eb2b453 commit 6a723ff
Show file tree
Hide file tree
Showing 1,391 changed files with 35,082 additions and 30,396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public HierarchicalSphere(Color baseColor, HierarchicalSphere parent = null)
/// <param name="filled">If true, also draw the surface of the hull's sphere</param>
public void DrawHull(bool filled)
{
if (Event.current.type != EventType.Repaint)
return;

Color wireframeColor = m_HandleColor;
wireframeColor.a = 0.8f;
using (new Handles.DrawingScope(m_WireframeColor, Matrix4x4.TRS((Vector3)Handles.matrix.GetColumn(3) + center, Quaternion.identity, Vector3.one)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,16 @@ static void FixSeams(NativeArray<int> positionRemap, NativeArray<Vector3> positi
// The idea is to find first them and do a kind of dilation to smooth the values on the boundary
// the dilation process consits in doing a trilinear sample of the higher subdivision brick and override the lower subdiv with that
// We have to mark the probes on the boundary as valid otherwise leak reduction at runtime will interfere with this method
// This isn't perfect and also doesn't work on cell boundary, but could easily be fix if it's an issue



// Use an indirection structure to ensure mem usage stays reasonable
VoxelToBrickCache cache = new VoxelToBrickCache();

// Create a map from cell position to index for fast lookup across cells
var cellPositionToIndex = new Dictionary<Vector3Int, int>();
for (int i = 0; i < m_BakingBatch.cells.Count; i++)
cellPositionToIndex[m_BakingBatch.cells[i].position] = i;

for (int c = 0; c < m_BakingBatch.cells.Count; c++)
{
var cell = m_BakingBatch.cells[c];
Expand All @@ -1265,7 +1269,32 @@ static void FixSeams(NativeArray<int> positionRemap, NativeArray<Vector3> positi
Vector3Int voxel = Vector3Int.FloorToInt((pos - sampleOffset) / minBrickSize);
int hashCode = m_BakingBatch.GetBrickPositionHash(voxel);
if (!voxelToBrick.TryGetValue(hashCode, out var brick))
continue;
{
// If the brick was not found in the current cell, find it in the neighbouring cells
Vector3Int GetCellPositionFromVoxel(Vector3Int voxelToLookup, int cellSizeInBricks)
{
return new Vector3Int(
FloorDivide(voxelToLookup.x, cellSizeInBricks),
FloorDivide(voxelToLookup.y, cellSizeInBricks),
FloorDivide(voxelToLookup.z, cellSizeInBricks)
);
int FloorDivide(int a, int b) => a >= 0 ? a / b : (a - b + 1) / b;
}

// Find the position of the neighbouring cell that would contain the voxel
bool foundInOtherCell = false;
var cellToLookupPos = GetCellPositionFromVoxel(voxel, m_ProfileInfo.cellSizeInBricks);
if(cellPositionToIndex.TryGetValue(cellToLookupPos, out var cellIndex))
{
var currentCell = m_BakingBatch.cells[cellIndex];
var voxelToBrickNeighbouringCell = cache.GetMap(currentCell);
if (voxelToBrickNeighbouringCell.TryGetValue(hashCode, out brick))
foundInOtherCell = true;
}

if(!foundInOtherCell)
continue;
}

if (brick.subdivisionLevel > maxSubdiv)
largestBrick = brick;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ void UseTemporaryBakingSet(string sceneGUID, ProbeVolumeBakingSet set = null)
{
set = ScriptableObject.CreateInstance<ProbeVolumeBakingSet>();
set.SetDefaults();

ProbeReferenceVolume.instance.AddPendingSceneRemoval(sceneGUID);
}

EditorUtility.SetDirty(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void JumpFlooding(uint3 id : SV_DispatchThreadID)
o.x += (o.x < 0) ? _Size.x : 0;
o.y += (o.y < 0) ? _Size.x : 0;
o.z += (o.z < 0) ? _Size.x : 0;
float4 n1 = _Output[o];
float4 n1 = _Input[o];

// Discard invalid samples
if (n1.w < 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static Rect GetRect(MaterialProperty prop)
public static void IntShaderProperty(this MaterialEditor editor, MaterialProperty prop, GUIContent label, System.Func<int, int> transform = null)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = prop.hasMixedValue;
Expand All @@ -92,6 +93,7 @@ public static void IntShaderProperty(this MaterialEditor editor, MaterialPropert
prop.floatValue = newValue;
}

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
}

Expand All @@ -118,6 +120,7 @@ public static void IntSliderShaderProperty(this MaterialEditor editor, MaterialP
public static void IntSliderShaderProperty(this MaterialEditor editor, MaterialProperty prop, int min, int max, GUIContent label)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = prop.hasMixedValue;
Expand All @@ -129,6 +132,7 @@ public static void IntSliderShaderProperty(this MaterialEditor editor, MaterialP
prop.floatValue = newValue;
}

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
}

Expand All @@ -142,6 +146,7 @@ public static void IntSliderShaderProperty(this MaterialEditor editor, MaterialP
public static void MinFloatShaderProperty(this MaterialEditor editor, MaterialProperty prop, GUIContent label, float min)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = prop.hasMixedValue;
Expand All @@ -151,6 +156,7 @@ public static void MinFloatShaderProperty(this MaterialEditor editor, MaterialPr
if (EditorGUI.EndChangeCheck())
prop.floatValue = newValue;

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
}

Expand All @@ -163,6 +169,7 @@ public static void MinFloatShaderProperty(this MaterialEditor editor, MaterialPr
public static void Vector3ShaderProperty(this MaterialEditor editor, MaterialProperty prop, GUIContent label)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = prop.hasMixedValue;
Expand All @@ -171,6 +178,7 @@ public static void Vector3ShaderProperty(this MaterialEditor editor, MaterialPro
if (EditorGUI.EndChangeCheck())
prop.vectorValue = vector;

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
}

Expand All @@ -185,6 +193,7 @@ public static void Vector3ShaderProperty(this MaterialEditor editor, MaterialPro
public static int PopupShaderProperty(this MaterialEditor editor, MaterialProperty prop, GUIContent label, string[] displayedOptions)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

int val = (int)prop.floatValue;

Expand All @@ -198,6 +207,7 @@ public static int PopupShaderProperty(this MaterialEditor editor, MaterialProper
prop.floatValue = val = newValue;
}

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();

return val;
Expand All @@ -215,6 +225,7 @@ public static int PopupShaderProperty(this MaterialEditor editor, MaterialProper
public static int IntPopupShaderProperty(this MaterialEditor editor, MaterialProperty prop, string label, string[] displayedOptions, int[] optionValues)
{
MaterialEditor.BeginProperty(prop);
editor.BeginAnimatedCheck(prop);

int val = (int)prop.floatValue;

Expand All @@ -228,6 +239,7 @@ public static int IntPopupShaderProperty(this MaterialEditor editor, MaterialPro
prop.floatValue = val = newValue;
}

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();

return val;
Expand All @@ -246,6 +258,8 @@ public static void MinMaxShaderProperty(this MaterialEditor editor, MaterialProp
{
MaterialEditor.BeginProperty(min);
MaterialEditor.BeginProperty(max);
editor.BeginAnimatedCheck(min);
editor.BeginAnimatedCheck(max);

float minValue = min.floatValue;
float maxValue = max.floatValue;
Expand All @@ -257,6 +271,8 @@ public static void MinMaxShaderProperty(this MaterialEditor editor, MaterialProp
max.floatValue = maxValue;
}

editor.EndAnimatedCheck();
editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
MaterialEditor.EndProperty();
}
Expand All @@ -272,6 +288,7 @@ public static void MinMaxShaderProperty(this MaterialEditor editor, MaterialProp
public static void MinMaxShaderProperty(this MaterialEditor editor, MaterialProperty remapProp, float minLimit, float maxLimit, GUIContent label)
{
MaterialEditor.BeginProperty(remapProp);
editor.BeginAnimatedCheck(remapProp);

Vector2 remap = remapProp.vectorValue;

Expand All @@ -280,6 +297,7 @@ public static void MinMaxShaderProperty(this MaterialEditor editor, MaterialProp
if (EditorGUI.EndChangeCheck())
remapProp.vectorValue = remap;

editor.EndAnimatedCheck();
MaterialEditor.EndProperty();
}
#endregion
Expand Down
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 @@ -174,7 +174,7 @@ void OnEnable()

if (m_PreviewTexture == null)
{
m_PreviewTexture = RTHandles.Alloc(Styles.thumbnailSizeWidth, Styles.thumbnailSizeHeight, colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB);
m_PreviewTexture = RTHandles.Alloc(Styles.thumbnailSizeWidth, Styles.thumbnailSizeHeight, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_SRGB);
}
if (m_PreviewTextureCache == null)
{
Expand Down
Loading

0 comments on commit 6a723ff

Please sign in to comment.