Skip to content

Commit

Permalink
Merge pull request #7998 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 Nov 21, 2023
2 parents 3868383 + 883ef69 commit e2f5fc6
Show file tree
Hide file tree
Showing 142 changed files with 7,743 additions and 35,482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static class Styles
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.");

public static readonly string msgEnableAll = "Scenes which are currently loaded are not enabled for baking.\nNo probe will be baked for these scenes when generating lighting.";
public static readonly string msgEnableAll = "Some loaded Scenes are disabled by this Baking Set. These Scenes will not contribute to the generation of probe data.";
public static readonly string msgUnloadOther = "Scene(s) not belonging to this Baking Set are currently loaded in the Hierarchy. This might result in incorrect lighting.";
public static readonly string msgLoadForBake = "Some scene(s) in this Baking Set are not currently loaded in the Hierarchy. This might result in missing or incomplete lighting.";

Expand Down Expand Up @@ -959,9 +959,16 @@ internal bool PrepareAPVBake()
}

bool createPV = m_SingleSceneMode ? !ActiveSceneHasProbeVolume() : NoSceneHasProbeVolume();
if (createPV && EditorUtility.DisplayDialog("No Probe Volume in Scene", "Probe Volumes are enabled for this Project, but none exist in the Scene.\n\n" +
if (createPV)
{
if(!activeSet.DialogNoProbeVolumeInSetShown())
{
if(EditorUtility.DisplayDialog("No Probe Volume in Scene", "Probe Volumes are enabled for this Project, but none exist in the Scene.\n\n" +
"Do you wish to add a Probe Volume to the Active Scene?", "Yes", "No"))
CreateProbeVolume();
CreateProbeVolume();
activeSet.SetDialogNoProbeVolumeInSetShown(true);
}
}
if (m_SingleSceneMode)
{
if (GetFirstProbeVolumeInNonActiveScene() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ public void Set(Material mat, int shaderId)
mat.SetConstantBuffer(shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride);
}

/// <summary>
/// Bind the constant buffer to a material property block.
/// </summary>
/// <param name="mpb">Material property block to which the constant buffer should be bound.</param>
/// <param name="shaderId">Shader porperty id to bind the constant buffer to.</param>
public void Set(MaterialPropertyBlock mpb, int shaderId)
{
mpb.SetConstantBuffer(shaderId, m_GPUConstantBuffer, 0, m_GPUConstantBuffer.stride);
}

/// <summary>
/// Update the GPU data of the constant buffer and bind it globally via a command buffer.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,53 @@ void RefreshDebug<T>(DebugUI.Field<T> field, T value)

var widgetList = new List<DebugUI.Widget>();

var subdivContainer = new DebugUI.Container() { displayName = "Subdivision Visualization" };
subdivContainer.children.Add(new DebugUI.BoolField { displayName = "Display Cells", tooltip = "Draw Cells used for loading and streaming.", getter = () => probeVolumeDebug.drawCells, setter = value => probeVolumeDebug.drawCells = value, onValueChanged = RefreshDebug });
subdivContainer.children.Add(new DebugUI.BoolField { displayName = "Display Bricks", tooltip = "Display Subdivision bricks.", getter = () => probeVolumeDebug.drawBricks, setter = value => probeVolumeDebug.drawBricks = value, onValueChanged = RefreshDebug });
var subdivContainer = new DebugUI.Container()
{
displayName = "Subdivision Visualization",
isHiddenCallback = () =>
{
#if UNITY_EDITOR
return false;
#else
return false; // Cells / Bricks visualization is not implemented in a runtime compatible way atm.
#endif
}
};
subdivContainer.children.Add(new DebugUI.BoolField
{
displayName = "Display Cells",
tooltip = "Draw Cells used for loading and streaming.",
getter = () => probeVolumeDebug.drawCells,
setter = value => probeVolumeDebug.drawCells = value,
onValueChanged = RefreshDebug
});
subdivContainer.children.Add(new DebugUI.BoolField
{
displayName = "Display Bricks",
tooltip = "Display Subdivision bricks.",
getter = () => probeVolumeDebug.drawBricks,
setter = value => probeVolumeDebug.drawBricks = value,
onValueChanged = RefreshDebug
});

#if UNITY_EDITOR
subdivContainer.children.Add(new DebugUI.BoolField { displayName = "Live Subdivision Preview", tooltip = "Enable a preview of Probe Volume data in the Scene without baking. Can impact Editor performance.", getter = () => probeVolumeDebug.realtimeSubdivision, setter = value => probeVolumeDebug.realtimeSubdivision = value, onValueChanged = RefreshDebug });
if (probeVolumeDebug.realtimeSubdivision)
if (probeVolumeDebug.drawCells || probeVolumeDebug.drawBricks)
{
var cellUpdatePerFrame = new DebugUI.IntField { displayName = "Cell Updates Per Frame", tooltip = "The number of Cells, bricks, and probe positions updated per frame. Higher numbers can impact Editor performance.", getter = () => probeVolumeDebug.subdivisionCellUpdatePerFrame, setter = value => probeVolumeDebug.subdivisionCellUpdatePerFrame = value, min = () => 1, max = () => 100 };
var delayBetweenUpdates = new DebugUI.FloatField { displayName = "Update Frequency", tooltip = "Delay in seconds between updates to Cell, Brick, and Probe positions if Live Subdivision Preview is enabled.", getter = () => probeVolumeDebug.subdivisionDelayInSeconds, setter = value => probeVolumeDebug.subdivisionDelayInSeconds = value, min = () => 0.1f, max = () => 10 };
subdivContainer.children.Add(new DebugUI.Container { children = { cellUpdatePerFrame, delayBetweenUpdates } });
subdivContainer.children.Add(new DebugUI.BoolField
{
displayName = "Live Subdivision Preview",
tooltip = "Enable a preview of Probe Volume data in the Scene without baking. Can impact Editor performance.",
getter = () => probeVolumeDebug.realtimeSubdivision,
setter = value => probeVolumeDebug.realtimeSubdivision = value,
});

var realtimeSubdivisonChildContainer = new DebugUI.Container()
{
isHiddenCallback = () => !probeVolumeDebug.realtimeSubdivision
};
realtimeSubdivisonChildContainer.children.Add(new DebugUI.IntField { displayName = "Cell Updates Per Frame", tooltip = "The number of Cells, bricks, and probe positions updated per frame. Higher numbers can impact Editor performance.", getter = () => probeVolumeDebug.subdivisionCellUpdatePerFrame, setter = value => probeVolumeDebug.subdivisionCellUpdatePerFrame = value, min = () => 1, max = () => 100 });
realtimeSubdivisonChildContainer.children.Add(new DebugUI.FloatField { displayName = "Update Frequency", tooltip = "Delay in seconds between updates to Cell, Brick, and Probe positions if Live Subdivision Preview is enabled.", getter = () => probeVolumeDebug.subdivisionDelayInSeconds, setter = value => probeVolumeDebug.subdivisionDelayInSeconds = value, min = () => 0.1f, max = () => 10 });
subdivContainer.children.Add(realtimeSubdivisonChildContainer);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ uint GetIndexData(APVResources apvRes, float3 posWS)
float3 entryPos = floor(posWS / _GlobalIndirectionEntryDim);
float3 topLeftEntryWS = entryPos * _GlobalIndirectionEntryDim;

bool isALoadedCell = all(entryPos >= _MinLoadedCellInEntries && entryPos <= _MaxLoadedCellInEntries);
bool isALoadedCell = all(entryPos >= _MinLoadedCellInEntries) && all(entryPos <= _MaxLoadedCellInEntries);

// Make sure we start from 0
int3 entryPosInt = (int3)(entryPos - _MinEntryPosition);
Expand All @@ -311,7 +311,7 @@ uint GetIndexData(APVResources apvRes, float3 posWS)
int3 localBrickIndex = floor(residualPosWS / (_MinBrickSize * stepSize));

// Out of bounds.
isValidBrick = all(localBrickIndex >= minRelativeIdx && localBrickIndex < maxRelativeIdxPlusOne);
isValidBrick = all(localBrickIndex >= minRelativeIdx) && all(localBrickIndex < maxRelativeIdxPlusOne);

int3 sizeOfValid = maxRelativeIdxPlusOne - minRelativeIdx;
// Relative to valid region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void Add(CellCounts o)

// Baking Set Data
[SerializeField] internal bool singleSceneMode = true;
[SerializeField] internal bool dialogNoProbeVolumeInSetShown = false;
[SerializeField] internal ProbeVolumeBakingProcessSettings settings;

[SerializeField] private List<string> m_SceneGUIDs = new List<string>();
Expand Down Expand Up @@ -1137,6 +1138,16 @@ public static string GetDirectory(string scenePath, string sceneName)

return assetPath;
}

public bool DialogNoProbeVolumeInSetShown()
{
return dialogNoProbeVolumeInSetShown;
}

public void SetDialogNoProbeVolumeInSetShown(bool value)
{
dialogNoProbeVolumeInSetShown = value;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2043,9 +2043,9 @@
AF4 AZolSignedF4(AF4 x){return ASatF4(x*AF4_(A_INFN_F));}
//------------------------------------------------------------------------------------------------------------------------------
AF1 AZolZeroPassF1(AF1 x,AF1 y){return AF1_AU1((AU1_AF1(x)!=AU1_(0))?AU1_(0):AU1_AF1(y));}
AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2_AU2((AU2_AF2(x)!=AU2_(0))?AU2_(0):AU2_AF2(y));}
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3_AU3((AU3_AF3(x)!=AU3_(0))?AU3_(0):AU3_AF3(y));}
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4_AU4((AU4_AF4(x)!=AU4_(0))?AU4_(0):AU4_AF4(y));}
AF2 AZolZeroPassF2(AF2 x,AF2 y){return AF2(AZolZeroPassF1(x.x, y.x), AZolZeroPassF1(x.y, y.y)); }
AF3 AZolZeroPassF3(AF3 x,AF3 y){return AF3(AZolZeroPassF1(x.x, y.x), AZolZeroPassF1(x.y, y.y), AZolZeroPassF1(x.z, y.z)); }
AF4 AZolZeroPassF4(AF4 x,AF4 y){return AF4(AZolZeroPassF1(x.x, y.x), AZolZeroPassF1(x.y, y.y), AZolZeroPassF1(x.z, y.z), AZolZeroPassF1(x.w, y.w)); }
#endif
//==============================================================================================================================
#ifdef A_HALF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ public static RenderTexture emptyUAV
}
}

static GraphicsBuffer m_EmptyBuffer;
/// <summary>
/// Empty 4-Byte buffer resource usable as a dummy.
/// </summary>
public static GraphicsBuffer emptyBuffer
{
get
{
if (m_EmptyBuffer == null || !m_EmptyBuffer.IsValid())
{
m_EmptyBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Raw, 1, sizeof(uint));
}

return m_EmptyBuffer;
}
}

static Texture3D m_BlackVolumeTexture;
/// <summary>
/// Black 3D texture.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using UnityEngine.Assertions;

// Ref: https://poniesandlight.co.uk/reflect/bitonic_merge_sort/

namespace UnityEngine.Rendering
{
/// <summary>
Expand All @@ -10,7 +12,6 @@ public partial struct GPUSort
{
private const uint kWorkGroupSize = 1024;

private string[] m_StageNames;
private LocalKeyword[] m_Keywords;

enum Stage
Expand Down Expand Up @@ -38,14 +39,6 @@ public GPUSort(SystemResources resources)
new(resources.computeAsset, "STAGE_BIG_FLIP"),
new(resources.computeAsset, "STAGE_BIG_DISPERSE")
};

m_StageNames = new[]
{
Enum.GetName(typeof(Stage), Stage.BigDisperse),
Enum.GetName(typeof(Stage), Stage.BigFlip),
Enum.GetName(typeof(Stage), Stage.LocalDisperse),
Enum.GetName(typeof(Stage), Stage.LocalBMS)
};
}

void DispatchStage(CommandBuffer cmd, Args args, uint h, Stage stage)
Expand All @@ -54,7 +47,7 @@ void DispatchStage(CommandBuffer cmd, Args args, uint h, Stage stage)
Assert.IsNotNull(resources.computeAsset);

// When the is no geometry, instead of computing the distance field, we clear it with a big value.
using (new ProfilingScope(cmd, new ProfilingSampler(m_StageNames[(int) stage])))
using (new ProfilingScope(cmd, ProfilingSampler.Get(stage)))
{
#if false
m_SortCS.enabledKeywords = new[] { keywords[(int)stage] };
Expand All @@ -66,6 +59,7 @@ void DispatchStage(CommandBuffer cmd, Args args, uint h, Stage stage)
#endif

cmd.SetComputeIntParam(resources.computeAsset, "_H", (int) h);
cmd.SetComputeIntParam(resources.computeAsset, "_Total", (int) args.count);
cmd.SetComputeBufferParam(resources.computeAsset, 0, "_KeyBuffer", args.resources.sortBufferKeys);
cmd.SetComputeBufferParam(resources.computeAsset, 0, "_ValueBuffer", args.resources.sortBufferValues);
cmd.DispatchCompute(resources.computeAsset, 0, args.workGroupCount, 1, 1);
Expand Down
17 changes: 11 additions & 6 deletions Packages/com.unity.render-pipelines.core/ShaderLibrary/ACES.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,22 @@ half ACES_to_ACEScc(half x)
return (log2(x) + 9.72) / 17.52;
}

half ACES_to_ACEScc_fast(half x)
{
// x is clamped to [0, HALF_MAX], skip the <= 0 check
return (x < 0.00003051757) ? (log2(0.00001525878 + x * 0.5) + 9.72) / 17.52 : (log2(x) + 9.72) / 17.52;
}

half3 ACES_to_ACEScc(half3 x)
{
x = clamp(x, 0.0, HALF_MAX);

// x is clamped to [0, HALF_MAX], skip the <= 0 check
return (x < 0.00003051757) ? (log2(0.00001525878 + x * 0.5) + 9.72) / 17.52 : (log2(x) + 9.72) / 17.52;
return half3(
ACES_to_ACEScc_fast(x.r),
ACES_to_ACEScc_fast(x.g),
ACES_to_ACEScc_fast(x.b)
);

/*
return half3(
Expand Down Expand Up @@ -782,11 +792,6 @@ half roll_white_fwd(
return o;
}

half3 linear_to_sRGB(half3 x)
{
return (x <= 0.0031308 ? (x * 12.9232102) : 1.055 * pow(x, 1.0 / 2.4) - 0.055);
}

half3 linear_to_bt1886(half3 x, half gamma, half Lw, half Lb)
{
// Good enough approximation for now, may consider using the exact formula instead
Expand Down
18 changes: 15 additions & 3 deletions Packages/com.unity.render-pipelines.core/ShaderLibrary/BC6H.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,25 @@ void EncodeMode11( inout uint4 block, inout float blockMSLE, float3 texels[ 16 ]
blockMax = max( blockMax, texels[ i ] );
}

// refine endpoints in log2 RGB space
// refine endpoints in log2 RGB space - find the second mix and max value
float3 refinedBlockMin = blockMax;
float3 refinedBlockMax = blockMin;
for (i = 0; i < 16; ++i )
{
refinedBlockMin = min( refinedBlockMin, texels[ i ] == blockMin ? refinedBlockMin : texels[ i ] );
refinedBlockMax = max( refinedBlockMax, texels[ i ] == blockMax ? refinedBlockMax : texels[ i ] );
float3 minTexel = float3(
(texels[i].x == blockMin.x) ? refinedBlockMin.x : texels[i].x,
(texels[i].y == blockMin.y) ? refinedBlockMin.y : texels[i].y,
(texels[i].z == blockMin.z) ? refinedBlockMin.z : texels[i].z
);

float3 maxTexel = float3(
(texels[i].x == blockMax.x) ? refinedBlockMax.x : texels[i].x,
(texels[i].y == blockMax.y) ? refinedBlockMax.y : texels[i].y,
(texels[i].z == blockMax.z) ? refinedBlockMax.z : texels[i].z
);

refinedBlockMin = min(refinedBlockMin, minTexel);
refinedBlockMax = max(refinedBlockMax, maxTexel);
}

float3 logBlockMax = log2( blockMax + 1.0 );
Expand Down
35 changes: 7 additions & 28 deletions Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -87,58 +87,37 @@ real SRGBToLinear(real c)

real2 SRGBToLinear(real2 c)
{
#if defined(UNITY_COLORSPACE_GAMMA) && REAL_IS_HALF
c = min(c, 100.0); // Make sure not to exceed HALF_MAX after the pow() below
#endif
real2 linearRGBLo = c / 12.92;
real2 linearRGBHi = PositivePow((c + 0.055) / 1.055, real2(2.4, 2.4));
real2 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi;
return linearRGB;
return real2(SRGBToLinear(c.r), SRGBToLinear(c.g));
}

real3 SRGBToLinear(real3 c)
{
#if defined(UNITY_COLORSPACE_GAMMA) && REAL_IS_HALF
c = min(c, 100.0); // Make sure not to exceed HALF_MAX after the pow() below
#endif
real3 linearRGBLo = c / 12.92;
real3 linearRGBHi = PositivePow((c + 0.055) / 1.055, real3(2.4, 2.4, 2.4));
real3 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi;
return linearRGB;
return real3(SRGBToLinear(c.r), SRGBToLinear(c.g), SRGBToLinear(c.b));
}

real4 SRGBToLinear(real4 c)
{
return real4(SRGBToLinear(c.rgb), c.a);
return real4(SRGBToLinear(c.r), SRGBToLinear(c.g), SRGBToLinear(c.b), c.a);
}

real LinearToSRGB(real c)
{
real sRGBLo = c * 12.92;
real sRGBHi = (PositivePow(c, real(1.0/2.4)) * 1.055) - 0.055;
real sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;
return sRGB;
return (c <= 0.0031308) ? (c * 12.9232102) : 1.055 * PositivePow(c, 1.0 / 2.4) - 0.055;
}

real2 LinearToSRGB(real2 c)
{
real2 sRGBLo = c * 12.92;
real2 sRGBHi = (PositivePow(c, real2(1.0/2.4, 1.0/2.4)) * 1.055) - 0.055;
real2 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;
return sRGB;
return real2(LinearToSRGB(c.r), LinearToSRGB(c.g));
}

real3 LinearToSRGB(real3 c)
{
real3 sRGBLo = c * 12.92;
real3 sRGBHi = (PositivePow(c, real3(1.0/2.4, 1.0/2.4, 1.0/2.4)) * 1.055) - 0.055;
real3 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;
return sRGB;
return real3(LinearToSRGB(c.r), LinearToSRGB(c.g), LinearToSRGB(c.b));
}

real4 LinearToSRGB(real4 c)
{
return real4(LinearToSRGB(c.rgb), c.a);
return real4(LinearToSRGB(c.r), LinearToSRGB(c.g), LinearToSRGB(c.b), c.a);
}

// TODO: Seb - To verify and refit!
Expand Down
Loading

0 comments on commit e2f5fc6

Please sign in to comment.