Skip to content

Commit

Permalink
Merge pull request Unity-Technologies#7660 from Unity-Technologies/in…
Browse files Browse the repository at this point in the history
…ternal/master

Internal/master
  • Loading branch information
UnityAljosha committed Sep 22, 2022
2 parents 0bac831 + d3ee8a6 commit 86cdbd1
Show file tree
Hide file tree
Showing 526 changed files with 29,989 additions and 2,722 deletions.
1 change: 1 addition & 0 deletions Packages/com.unity.render-pipelines.core/.buginfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
area: RP Workflow

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using JetBrains.Annotations;
using System.Diagnostics.CodeAnalysis;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEngine.Analytics;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering.Analytics
{
internal class BuildTargetAnalytic : IPostprocessBuildWithReport
{
public int callbackOrder => int.MaxValue;

const int k_MaxEventsPerHour = 10;
const int k_MaxNumberOfElements = 1000;
const string k_VendorKey = "unity.srp";

[System.Diagnostics.DebuggerDisplay("{render_pipeline_asset_type} - {quality_levels}/{total_quality_levels_on_project}")]
internal struct BuildTargetAnalyticData
{
internal const string k_EventName = "uBuildTargetAnalytic";

// Naming convention for analytics data
public string build_target;
public string render_pipeline_asset_type;
public int quality_levels;
public int total_quality_levels_on_project;
};

void IPostprocessBuildWithReport.OnPostprocessBuild(BuildReport _)
{
if (!EditorAnalytics.enabled || EditorAnalytics.RegisterEventWithLimit(BuildTargetAnalyticData.k_EventName, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey) != AnalyticsResult.Ok)
return;

if (!TryGatherData(out var data, out var warning))
Debug.Log(warning);

EditorAnalytics.SendEventWithLimit(BuildTargetAnalyticData.k_EventName, data);
}

[MustUseReturnValue]
static bool TryGatherData([NotNullWhen(true)] out BuildTargetAnalyticData data, [NotNullWhen(false)] out string warning)
{
var activeBuildTarget = EditorUserBuildSettings.activeBuildTarget;
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(activeBuildTarget);
var activeBuildTargetGroupName = activeBuildTargetGroup.ToString();

warning = string.Empty;

var assetType = GraphicsSettings.currentRenderPipeline == null ? "Built-In Render Pipeline" : GraphicsSettings.currentRenderPipeline.GetType().ToString();

data = new BuildTargetAnalyticData()
{
build_target = activeBuildTarget.ToString(),
quality_levels = QualitySettings.GetActiveQualityLevelsForPlatformCount(activeBuildTargetGroupName),
render_pipeline_asset_type = assetType,
total_quality_levels_on_project = QualitySettings.count
};

return true;
}

[MenuItem("internal:Edit/Rendering/Analytics/Send BuildTargetAnalytic ", priority = 0)]
static void SendAnalyitic()
{
if (!TryGatherData(out var data, out var warning))
Debug.Log(warning);
}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
area: HD RP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
area: HD RP
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,139 @@ static void ComputeValidityMasks(BakingCell bakingCell)

probeHasEmptySpaceInGrid.Dispose();
}

internal static void RecomputeValidityAfterBake()
{
// We need to start from scratch, so reset this.
s_ForceInvalidatedProbesAndTouchupVols.Clear();
var prv = ProbeReferenceVolume.instance;

var touchupVolumes = GameObject.FindObjectsOfType<ProbeTouchupVolume>();
var touchupVolumesAndBounds = new List<(ProbeReferenceVolume.Volume obb, Bounds aabb, ProbeTouchupVolume touchupVolume)>(touchupVolumes.Length);
foreach (var touchup in touchupVolumes)
{
m_BakingProfile = prv.sceneData.GetProfileForScene(touchup.gameObject.scene); // We need to grab a profile. The last one will have to do.
if (touchup.isActiveAndEnabled)
{
touchup.GetOBBandAABB(out var obb, out var aabb);
touchupVolumesAndBounds.Add((obb, aabb, touchup));

}
}

float cellSize = prv.MaxBrickSize();
var chunkSizeInProbes = ProbeBrickPool.GetChunkSizeInProbeCount();
Vector3Int locSize = ProbeBrickPool.ProbeCountToDataLocSize(chunkSizeInProbes);

List<BakingCell> bakingCells = new List<BakingCell>();

// Then for each cell we need to convert to baking cell and repeat the invalidation scheme.
foreach (var cellInfo in prv.cells)
{
var cell = cellInfo.Value.cell;
var bakingCell = ConvertCellToBakingCell(cell);
var position = cell.position;
var posWS = new Vector3(position.x * cellSize, position.y * cellSize, position.z * cellSize);

Bounds cellBounds = new Bounds();
cellBounds.min = posWS;
cellBounds.max = posWS + (Vector3.one * cellSize);

// Find the subset of touchup volumes that will be considered for this cell.
// Capacity of the list to cover the worst case.
var localTouchupVolumes = new List<(ProbeReferenceVolume.Volume obb, Bounds aabb, ProbeTouchupVolume touchupVolume)>(touchupVolumes.Length);
foreach (var touchup in touchupVolumesAndBounds)
{
if (touchup.aabb.Intersects(cellBounds))
localTouchupVolumes.Add(touchup);
}

for (int i=0; i< bakingCell.probePositions.Length; ++i)
{
var probePos = bakingCell.probePositions[i];
// Restore validity modified by the touchup volume before going forward.
bool wasForceInvalidated = bakingCell.touchupVolumeInteraction[i] > 0.0f && bakingCell.touchupVolumeInteraction[i] <= 1;
if (wasForceInvalidated)
{
bakingCell.validity[i] = 0.0f;
}

var probeValidity = bakingCell.validity[i];
bakingCell.touchupVolumeInteraction[i] = 0.0f; // Reset as we don't force write it and we might have stale data from previous.

bool invalidatedProbe = false;
foreach (var touchup in localTouchupVolumes)
{
var touchupBound = touchup.aabb;
var touchupVolume = touchup.touchupVolume;

// We check a small box around the probe to give some leniency (a couple of centimeters).
var probeBounds = new Bounds(bakingCell.probePositions[i], new Vector3(0.02f, 0.02f, 0.02f));
if (ProbeVolumePositioning.OBBAABBIntersect(touchup.obb, probeBounds, touchupBound))
{
if (touchupVolume.mode == ProbeTouchupVolume.Mode.InvalidateProbes)
{
invalidatedProbe = true;
// We check as below 1 but bigger than 0 in the debug shader, so any value <1 will do to signify touched up.
bakingCell.touchupVolumeInteraction[i] = 0.5f;

if (probeValidity < 0.05f) // We just want to add probes that were not already invalid or close to.
{
s_ForceInvalidatedProbesAndTouchupVols[bakingCell.probePositions[i]] = touchupBound;
}
break;
}
}
}

float currValidity = invalidatedProbe ? 1.0f : probeValidity;
byte currValidityNeighbourMask = 255;
bakingCell.validity[i] = currValidity;
bakingCell.validityNeighbourMask[i] = currValidityNeighbourMask;
}
ComputeValidityMasks(bakingCell);

bakingCells.Add(bakingCell);
}

// Unload it all as we are gonna load back with newly written cells.
foreach (var sceneData in prv.perSceneDataList)
{
prv.AddPendingAssetRemoval(sceneData.asset);
}

// Make sure unloading happens.
prv.PerformPendingOperations();


// We now need to make sure we find for each PerSceneData
foreach (var data in prv.perSceneDataList)
{
List<BakingCell> newCells = new List<BakingCell>();
// This is a bit naive now. Should be fine tho.
for (int i=0; i<data.asset.cells.Length; ++i)
{
var currCell = data.asset.cells[i];
var bc = bakingCells.Find(x => x.index == currCell.index);
newCells.Add(bc);
}

// Write bake the assets.
WriteBakingCells(data, newCells);
data.ResolveCells();
}


// We can now finally reload.
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

foreach (var sceneData in prv.perSceneDataList)
{
prv.AddPendingAssetLoading(sceneData.asset);
}

prv.PerformPendingOperations();
}
}
}
Loading

0 comments on commit 86cdbd1

Please sign in to comment.