Skip to content

Commit

Permalink
Merge pull request #8009 from Unity-Technologies/internal/2023.2/staging
Browse files Browse the repository at this point in the history
Internal/2023.2/staging
  • Loading branch information
UnityAljosha authored Jan 2, 2024
2 parents 75c55eb + a061507 commit 9f5ae1a
Show file tree
Hide file tree
Showing 779 changed files with 20,623 additions and 1,964 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace UnityEditor.Rendering
/// </example>
public class HierarchicalBox
{
const float k_HandleSizeCoef = 0.05f;
const float k_HandleSizeCoef = 0.07f;
static Material k_Material_Cache;
static Material k_Material => (k_Material_Cache == null || k_Material_Cache.Equals(null) ? (k_Material_Cache = new Material(Shader.Find("Hidden/UnlitTransparentColored"))) : k_Material_Cache);
static Mesh k_MeshQuad_Cache;
Expand Down Expand Up @@ -492,6 +492,6 @@ public void DrawHandle()
}
}

Color GetHandleColor(NamedFace name) => monoHandle ? m_MonochromeHandleColor : m_PolychromeHandleColor[(int)name];
Color GetHandleColor(NamedFace name) => monoHandle ? m_MonochromeHandleColor : GizmoUtility.GetHandleColor(m_PolychromeHandleColor[(int)name]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void CreateRayTracingResources()

m_RayTracingContext = new RayTracingContext(backend, resources);
m_RayTracingShader = m_RayTracingContext.CreateRayTracingShader("Editor/Lighting/ProbeVolume/VirtualOffset/TraceVirtualOffset", fileLoader);
m_RayTracingAccelerationStructure = m_RayTracingContext.CreateAccelerationStructure(new AccelerationStructureOptions());
m_RayTracingAccelerationStructure = m_RayTracingContext.CreateAccelerationStructure(new AccelerationStructureOptions{buildFlags = BuildFlags.PreferFastBuild}); // Use PreferFastBuild to avoid bug triggered with big meshes (UUM-52552)

_Probes = Shader.PropertyToID("_Probes");
_Offsets = Shader.PropertyToID("_Offsets");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ static void OnBakeStarted()

using (new BakingSetupProfiling(BakingSetupProfiling.Stages.PlaceProbes))
{

Vector3[] positions = RunPlacement();
UnityEditor.Experimental.Lightmapping.SetAdditionalBakedProbes(m_BakingBatch.index, positions);
}
Expand Down Expand Up @@ -1183,12 +1184,6 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,

m_BakingBatchIndex = 0;

// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
var prevSHBands = ProbeReferenceVolume.instance.shBands;
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);
// Don't use Disk streaming to avoid having to wait for it when doing dilation.
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);

PrepareCellsForWriting(isBakingSceneSubset);

using var writeScope = new BakingCompleteProfiling(BakingCompleteProfiling.Stages.WriteBakedData);
Expand All @@ -1209,6 +1204,16 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,
// Reset internal structures depending on current bake.
probeRefVolume.EnsureCurrentBakingSet(m_BakingSet);

// This subsequent block needs to happen AFTER we call WriteBakingCells.
// Otherwise in cases where we change the spacing between probes, we end up loading cells with a certain layout in ForceSHBand
// And then we unload cells using the wrong layout in PerformDilation (after WriteBakingCells updates the baking set object) which leads to a broken internal state.

// Don't use Disk streaming to avoid having to wait for it when doing dilation.
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);
// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
var prevSHBands = ProbeReferenceVolume.instance.shBands;
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);

// TODO Discuss: Not nice to do this here, shouldn't reloading the asset also resolve cell data?
// Would still need to reload common shared data like bricks as they are separately handled by the baking set itself.
// Load common shared data (bricks + debug)
Expand Down Expand Up @@ -1744,6 +1749,7 @@ unsafe static void WriteBakingCells(BakingCell[] bakingCells)

m_BakingSet.validityMaskChunkSize = validityMaskChunkSize;


// Brick data
using var bricks = new NativeArray<Brick>(m_TotalCellCounts.bricksCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

Expand Down Expand Up @@ -2163,7 +2169,7 @@ public static ProbeSubdivisionResult BakeBricks(ProbeSubdivisionContext ctx)
// Calculate valid renderers to avoid unnecessary work (a renderer needs to overlap a probe volume and match the layer)
var filteredContributors = ctx.contributors.Filter(ctx.bakingSet, cell.bounds, overlappingProbeVolumes);

if (overlappingProbeVolumes.Count == 0 && filteredContributors.Count == 0)
if (filteredContributors.Count == 0 && !overlappingProbeVolumes.Any(v => v.component.fillEmptySpaces))
continue;

var bricks = ProbePlacement.SubdivideCell(cell.bounds, ctx, gpuResources, filteredContributors, overlappingProbeVolumes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static class Styles
public static readonly string msgProbeFreeze = "Some scene(s) in this Baking Set are not currently loaded in the Hierarchy. Set Probe Positions to Don't Recalculate to not break compatibility with already baked scenarios.";
public static readonly GUIContent maxDistanceBetweenProbes = new GUIContent("Max Probe Spacing", "Maximum distance between probes, in meters. Determines the number of bricks in a streamable unit.");
public static readonly GUIContent minDistanceBetweenProbes = new GUIContent("Min Probe Spacing", "Minimum distance between probes, in meters.");
public static readonly string simplificationLevelsHighWarning = "A high number of brick size causes a big memory overhead, this is not recommended except for testing purposes.";
public static readonly string simplificationLevelsHighWarning = " Using this many brick sizes will result in high memory usage and can cause instabilities.";
public static readonly GUIContent indexDimensions = new GUIContent("Index Dimensions", "The dimensions of the index buffer.");
public static readonly GUIContent minRendererVolumeSize = new GUIContent("Min Renderer Size", "The smallest Renderer size to consider when placing probes.");
public static readonly GUIContent renderersLayerMask = new GUIContent("Layer Mask", "Specify Layers to use when generating probe positions.");
Expand Down Expand Up @@ -159,11 +159,11 @@ void ProbePlacementGUI()

int levels = ProbeVolumeBakingSet.GetMaxSubdivision(m_SimplificationLevels.intValue);
MessageType helpBoxType = MessageType.Info;
string helpBoxText = $"Baked data will contain up to {levels} different size of bricks.";
string helpBoxText = $"Baked Probe Volume data will contain up-to {levels} different sizes of Brick.";
if (levels == 6)
{
helpBoxType = MessageType.Warning;
helpBoxText += "\n" + Styles.simplificationLevelsHighWarning;
helpBoxText += Styles.simplificationLevelsHighWarning;
}
EditorGUILayout.HelpBox(helpBoxText, helpBoxType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static class Styles
public static readonly GUIContent bakeBox = new GUIContent("", "Controls if Probe Volumes in this scene are baked when Generating Lighting.");
public static readonly GUIContent warnings = new GUIContent("Warnings");

public static readonly string[] bakingModeOptions = new string[] { "Single Scene", "Baking Sets (Advanced)" };
public static readonly string[] bakingModeOptions = new string[] { "Single Scene", "Baking Set" };

public static readonly GUIContent iconEnableAll = new GUIContent("", CoreEditorStyles.GetMessageTypeIcon(MessageType.Info), "The Scene is loaded but is currently not enabled for Baking. It will therefore not be considered when generating lighting data.");
public static readonly GUIContent iconLoadForBake = new GUIContent("", CoreEditorStyles.GetMessageTypeIcon(MessageType.Warning), "The Scene is currently enabled for baking but is unloaded in the Hierarchy. This may result in incomplete lighting data being generated.\nLoad the Scene in the Hierarchy, or use the shortcuts below to fix the issue.");
Expand Down Expand Up @@ -261,13 +261,18 @@ public override void OnGUI()
EditorGUILayout.Space();
}

public override bool HasHelpGUI()
{
return true;
}

public override void OnHeaderSettingsGUI()
{
var iconSize = EditorStyles.iconButton.CalcSize(Styles.helpIcon);

if (GUI.Button(GUILayoutUtility.GetRect(iconSize.x, iconSize.y), Styles.helpIcon, EditorStyles.iconButton))
Help.BrowseURL(DocumentationInfo.GetPageLink("com.unity.render-pipelines.high-definition", documentationURL));

iconSize = EditorStyles.iconButton.CalcSize(Styles.settingsIcon);
var rect = GUILayoutUtility.GetRect(iconSize.x, iconSize.y);
if (EditorGUI.DropdownButton(rect, Styles.settingsIcon, FocusType.Passive, EditorStyles.iconButton))
EditorUtility.DisplayCustomMenu(rect, new[] { EditorGUIUtility.TrTextContent("Open Rendering Debugger") }, -1, OpenProbeVolumeDebugPanel, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ public class AdditionalGIBakeRequestsManager
/// </summary>
public static AdditionalGIBakeRequestsManager instance { get { return s_Instance; } }

internal void Init()
{
SubscribeOnBakeStarted();
}

internal void Cleanup()
{
UnsubscribeOnBakeStarted();
}

const float kInvalidSH = 1f;
const float kValidSHThresh = 0.33f;

Expand Down Expand Up @@ -109,18 +99,6 @@ public void UpdatePositionForRequest(int probeInstanceID, Vector3 newPosition)
}
}

private void SubscribeOnBakeStarted()
{
UnsubscribeOnBakeStarted();
Lightmapping.bakeStarted += AddRequestsToLightmapper;
}

private void UnsubscribeOnBakeStarted()
{
Lightmapping.bakeStarted -= AddRequestsToLightmapper;
RemoveRequestsFromLightmapper();
}

internal void AddRequestsToLightmapper()
{
UnityEditor.Experimental.Lightmapping.SetAdditionalBakedProbes(s_BakingID, (new List<Vector3>(m_RequestPositions.Values)).ToArray());
Expand All @@ -129,11 +107,6 @@ internal void AddRequestsToLightmapper()
Lightmapping.bakeCompleted += OnAdditionalProbesBakeCompleted;
}

private void RemoveRequestsFromLightmapper()
{
UnityEditor.Experimental.Lightmapping.SetAdditionalBakedProbes(s_BakingID, null);
}

private void OnAdditionalProbesBakeCompleted()
{
Lightmapping.bakeCompleted -= OnAdditionalProbesBakeCompleted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ static int DefragComparer(Cell a, Cell b)

void StartIndexDefragmentation()
{
// We can end up here during baking (dilation) when trying to load all cells even without supporting GPU streaming.
if (!m_SupportGPUStreaming)
return;

m_IndexDefragmentationInProgress = true;

// Prepare the list of cells.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ public void Initialize(in ProbeVolumeSystemParameters parameters)
#if UNITY_EDITOR
if (sceneData != null)
UnityEditor.SceneManagement.EditorSceneManager.sceneSaving += sceneData.OnSceneSaving;
AdditionalGIBakeRequestsManager.instance.Init();
#endif
m_EnabledBySRP = true;

Expand Down Expand Up @@ -954,7 +953,6 @@ public void Cleanup()
if (!m_ProbeReferenceVolumeInit) return;

#if UNITY_EDITOR
AdditionalGIBakeRequestsManager.instance.Cleanup();
if (sceneData != null)
UnityEditor.SceneManagement.EditorSceneManager.sceneSaving -= sceneData.OnSceneSaving;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public enum Mode

/// <summary>Whether spaces with no renderers need to be filled with bricks at lowest subdivision level.</summary>
[HideInInspector]
[Tooltip("Whether HDRP should fill empty space between renderers with bricks at the lowest subdivision level.")]
[Tooltip("Whether Unity should fill empty space between renderers with bricks at the lowest subdivision level.")]
public bool fillEmptySpaces = false;

#if UNITY_EDITOR
Expand Down Expand Up @@ -214,11 +214,16 @@ void OnDisable()
return true;
cellSizeInMeters = profile.cellSizeInMeters;
}
Camera activeCamera = Camera.current;
#if UNITY_EDITOR
if (activeCamera == null)
activeCamera = UnityEditor.SceneView.lastActiveSceneView.camera;
#endif

if (Camera.current == null)
if (activeCamera == null)
return true;

var cameraTransform = Camera.current.transform;
var cameraTransform = activeCamera.transform;

Vector3 cellCenterWS = cellPosition * cellSizeInMeters + originWS + Vector3.one * (cellSizeInMeters / 2.0f);

Expand All @@ -228,7 +233,7 @@ void OnDisable()
if (roundedDownDist > ProbeReferenceVolume.instance.probeVolumeDebug.subdivisionViewCullingDistance)
return true;

var frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.current);
var frustumPlanes = GeometryUtility.CalculateFrustumPlanes(activeCamera);
var volumeAABB = new Bounds(cellCenterWS, cellSizeInMeters * Vector3.one);

return !GeometryUtility.TestPlanesAABB(frustumPlanes, volumeAABB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class ProbeVolumesOptions : VolumeComponent
/// Noise to be applied to the sampling position. It can hide seams issues between subdivision levels, but introduces noise.
/// </summary>
[Tooltip("Noise to be applied to the sampling position. It can hide seams issues between subdivision levels, but introduces noise.")]
public ClampedFloatParameter samplingNoise = new ClampedFloatParameter(0.1f, 0.0f, 0.5f);
public ClampedFloatParameter samplingNoise = new ClampedFloatParameter(0.1f, 0.0f, 1.0f);


/// <summary>
Expand All @@ -66,7 +66,6 @@ public sealed class ProbeVolumesOptions : VolumeComponent
[Tooltip("The minimum value that the dot product between the sample position normal and the vector to contributing probe need to have to have the probe considered.")]
public ClampedFloatParameter minValidDotProductValue = new ClampedFloatParameter(0.1f, -1.0f, 0.33f);


/// <summary>
/// When enabled, reflection probe normalization can only decrease the reflections intensity.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ static public float ShapeAttenuationAreaDiscLight(Vector3 forward, Vector3 wo)
return ShapeAttenuateForwardLight(forward, wo);
}

static bool IsLensFlareSRPHidden(Camera cam, LensFlareComponentSRP comp, LensFlareDataSRP data)
{
if (!comp.enabled ||
!comp.gameObject.activeSelf ||
!comp.gameObject.activeInHierarchy ||
data == null ||
data.elements == null ||
data.elements.Length == 0 ||
comp.intensity <= 0.0f ||
((cam.cullingMask & (1 << comp.gameObject.layer)) == 0))
return true;

return false;
}

/// <summary>
/// Compute internal parameters needed to render single flare
/// </summary>
Expand Down Expand Up @@ -502,15 +517,9 @@ static public bool IsCloudLayerOpacityNeeded(Camera cam)
LensFlareComponentSRP comp = info.comp;
LensFlareDataSRP data = comp.lensFlareData;

if (!comp.enabled ||
!comp.gameObject.activeSelf ||
!comp.gameObject.activeInHierarchy ||
data == null ||
data.elements == null ||
data.elements.Length == 0 ||
if (IsLensFlareSRPHidden(cam, comp, data) ||
!comp.useOcclusion ||
(comp.useOcclusion && comp.sampleCount == 0) ||
comp.intensity <= 0.0f)
(comp.useOcclusion && comp.sampleCount == 0))
continue;

if (comp.useBackgroundCloudOcclusion)
Expand Down Expand Up @@ -701,13 +710,7 @@ static public void ComputeOcclusion(Material lensFlareShader, Camera cam,
LensFlareComponentSRP comp = info.comp;
LensFlareDataSRP data = comp.lensFlareData;

if (!comp.enabled ||
!comp.gameObject.activeSelf ||
!comp.gameObject.activeInHierarchy ||
data == null ||
data.elements == null ||
data.elements.Length == 0 ||
comp.intensity <= 0.0f ||
if (IsLensFlareSRPHidden(cam, comp, data) ||
!comp.useOcclusion ||
(comp.useOcclusion && comp.sampleCount == 0))
continue;
Expand Down Expand Up @@ -960,13 +963,7 @@ static public void DoLensFlareDataDrivenCommon(Material lensFlareShader, Camera
LensFlareComponentSRP comp = info.comp;
LensFlareDataSRP data = comp.lensFlareData;

if (!comp.enabled ||
!comp.gameObject.activeSelf ||
!comp.gameObject.activeInHierarchy ||
data == null ||
data.elements == null ||
data.elements.Length == 0 ||
comp.intensity <= 0.0f)
if (IsLensFlareSRPHidden(cam, comp, data))
continue;

#if UNITY_EDITOR
Expand Down
19 changes: 15 additions & 4 deletions Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,22 @@ float3 ApplyLut2D(TEXTURE2D_PARAM(tex, samplerTex), float3 uvw, float3 scaleOffs
// params = (lut_height, 0.5 / lut_width, 0.5 / lut_height, lut_height / lut_height - 1)
float3 GetLutStripValue(float2 uv, float4 params)
{
uv -= params.yz;
// scale up x from [0,1] to [0,lut_height], so that x is an integer at LUT boundaries (arranged in a strip)
uv.x *= params.x;

// make x vary between 0 and 1 within its LUT
float lutBase = floor(uv.x);
uv.x -= lutBase;

// get the LUT index as value between 0 and (lut_height - 1)/lut_height
float lutBaseU = lutBase * 2.0 * params.z;

// shift the UV to vary between 0 and (lut_height - 1)/lut_height, arrange as color
float3 color;
color.r = frac(uv.x * params.x);
color.b = uv.x - color.r / params.x;
color.g = uv.y;
color.rg = uv - params.zz;
color.b = lutBaseU;

// scale to vary between 0 and 1
return color * params.w;
}

Expand Down
Loading

0 comments on commit 9f5ae1a

Please sign in to comment.