Skip to content

Commit

Permalink
Merge pull request #7976 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 Oct 16, 2023
2 parents 5fe6edc + ffbc4ff commit f6422d8
Show file tree
Hide file tree
Showing 43 changed files with 228 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ private ResourceHandle UseResource(in ResourceHandle handle, IBaseRenderGraphBui

public BufferHandle UseBuffer(in BufferHandle input, IBaseRenderGraphBuilder.AccessFlags flags)
{
if ((flags & IBaseRenderGraphBuilder.AccessFlags.GrabRead) != 0)
if ((flags & IBaseRenderGraphBuilder.AccessFlags.AllowGrab) != 0)
{
throw new ArgumentException("GrabRead is only valid on UseTexture");
throw new ArgumentException("AllowGrab is only valid on UseTexture");
}
return new BufferHandle(UseResource(input.handle, flags).index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ static const half DIM_SURROUND_GAMMA = 0.9811;

half3 darkSurround_to_dimSurround(half3 linearCV)
{
half3 XYZ = mul(AP1_2_XYZ_MAT, linearCV);
// Extra conversions to float3/half3 are required to avoid floating-point precision issues on some platforms.
half3 XYZ = (half3)mul(AP1_2_XYZ_MAT, (float3)linearCV);

half3 xyY = XYZ_2_xyY(XYZ);
xyY.z = clamp(xyY.z, 0.0, HALF_MAX);
Expand Down
20 changes: 10 additions & 10 deletions Packages/com.unity.render-pipelines.core/ShaderLibrary/Hashes.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ void Hash_Tchou_2_1_float(float2 i, out float o)
uint r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_1_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_2_1_half(half2 i, out half o)
{
uint r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_1_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_2_3_uint(uint2 q, out uint3 o)
Expand All @@ -45,15 +45,15 @@ void Hash_Tchou_2_3_float(float2 i, out float3 o)
uint3 r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_3_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_2_3_half(half2 i, out half3 o)
{
uint3 r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_3_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_2_2_uint(uint2 v, out uint2 o)
Expand All @@ -73,15 +73,15 @@ void Hash_Tchou_2_2_float(float2 i, out float2 o)
uint2 r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_2_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_2_2_half(half2 i, out half2 o)
{
uint2 r;
uint2 v = (uint2) (int2) round(i);
Hash_Tchou_2_2_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_3_1_uint(uint3 v, out uint o)
Expand All @@ -102,15 +102,15 @@ void Hash_Tchou_3_1_float(float3 i, out float o)
uint r;
uint3 v = (uint3) (int3) round(i);
Hash_Tchou_3_1_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_3_1_half(half3 i, out half o)
{
uint r;
uint3 v = (uint3) (int3) round(i);
Hash_Tchou_3_1_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_3_3_uint(uint3 v, out uint3 o)
Expand All @@ -132,14 +132,14 @@ void Hash_Tchou_3_3_float(float3 i, out float3 o)
{
uint3 r, v = (uint3) (int3) round(i);
Hash_Tchou_3_3_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_Tchou_3_3_half(half3 i, out half3 o)
{
uint3 r, v = (uint3) (int3) round(i);
Hash_Tchou_3_3_uint(v, r);
o = r * (1.0 / float(0xffffffff));
o = (r >> 8) * (1.0 / float(0x00ffffff));
}

void Hash_LegacySine_2_1_float(float2 i, out float o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ internal enum FPTLMaxLightSizes
Ultra = 255
}

internal enum PathTracingLightListSizes
{
Low = 8,
Medium = 16,
High = 32,
Ultra = 64
}


/// <summary>
/// Project-wide shader configuration options.
/// </summary>
Expand Down Expand Up @@ -53,7 +62,18 @@ public enum ShaderOptions
/// Lower count will mean some memory savings.
/// Note: For any rendering bigger than 4k (in native) it is recommended to use Low count per tile, to avoid possible artifacts.
/// </summary>
FPTLMaxLightCount = FPTLMaxLightSizes.High
FPTLMaxLightCount = FPTLMaxLightSizes.High,

/// <summary>
/// The upper limit for the maximum amount of elements per cell in the light cluster. The maximum can be set in the project settings. This value caps the maximum.
/// </summary>
LightClusterMaxCellElementCount = 24,

/// <summary>
/// Maximum number of lights used in the path tracer light list. This number can be one of the prespecified possibilities in PathTracingLightListSizes, or can be chosen manually.
/// Lower count will mean some memory savings.
/// </summary>
PathTracingMaxLightCount = PathTracingLightListSizes.Medium
};

// Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl
Expand Down Expand Up @@ -94,6 +114,12 @@ public class ShaderConfig
/// <summary>Indicates the maximum number of lights available for Fine Prunning Tile Lighting.</summary>
/// <seealso cref="ShaderOptions.FPTLMaxLightCount"/>
public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount;
/// <summary>Indicates the cap on the maximum number of elements per cell in the light cluster.</summary>
/// <seealso cref="ShaderOptions.LightClusterMaxCellElementCount"/>
public const int LightClusterMaxCellElementCount = (int)ShaderOptions.LightClusterMaxCellElementCount;
/// <summary>Indicates the maximum number of lights in the path tracing light list.</summary>
/// <seealso cref="ShaderOptions.PathTracingMaxLightCount"/>
public static int PathTracingMaxLightCount = (int)ShaderOptions.PathTracingMaxLightCount;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define SHADEROPTIONS_BARN_DOOR (0)
#define SHADEROPTIONS_GLOBAL_MIP_BIAS (1)
#define SHADEROPTIONS_FPTLMAX_LIGHT_COUNT (63)
#define SHADEROPTIONS_PATH_TRACING_MAX_LIGHT_COUNT (16)

//
// UnityEngine.Rendering.HighDefinition.InternalLightCullingDefs: static fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ For example, you can use it to:
* Disable Area Light.
* Disable Pre-exposition.
* Enable [camera-relative rendering](Camera-Relative-Rendering.md).
* Increase the size of the tile and cluster light list for rasterization.
* Increase the size of [the Path Tracing light list](Ray-Tracing-Path-Tracing.md).

## Using the HDRP Config package

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ If there is any noise that affects the exposure in the final converged frame, ad

* **Limit Max**

## Path tracing and Light sources

Due to the fundamentally different nature of Path Tracing, light sources are queried differently. To support this, the path tracer needs to build some additional data structures that contain light source information. These data structures limit the maximum number of lights that can be evaluated in local neighborhoods. In the current implementation, there are two such data structures.

The first one is the [Ray Tracing Light Cluster](Ray-Tracing-Light-Cluster.md). It is used to resolve the lights and Decals (see below) around a specific point. The maximum number of lights per cell in this cluster can be increased if necessary.

The second one is the Path Tracing light list and internal data structure used to capture all light sources relevant to a specific path segment. If too many light sources are close to each other, they might not all fit in the light list. This might result in artifacts. To remove these artifacts, you can change the `PathTracingMaxLightCount` setting through the [HDRP Config mechanism](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/HDRP-Config-Package.html).

## Path tracing and Decals

In order to efficiently support the path tracing of decals, Decal Projectors are added to the [Ray Tracing Light Cluster](Ray-Tracing-Light-Cluster.md). In the case of many decals in a small volume, it might be necessary to increase the maximum number of lights per cell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ protected override bool showSection
if (materials[0].IsShaderGraph())
{
var shader = materials[0].shader;
var defaultRefractionModel = shader.GetPropertyDefaultFloatValue(shader.FindPropertyIndex(kRefractionModel));

var propertyIndex = shader.FindPropertyIndex(kRefractionModel);
if (propertyIndex == -1)
return false;

var defaultRefractionModel = shader.GetPropertyDefaultFloatValue(propertyIndex);
if (defaultRefractionModel == 0)
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public VFXShaderGraphGUILit()
{
uiBlocks.Clear();
uiBlocks.Add(new SurfaceOptionUIBlock(MaterialUIBlock.ExpandableBit.Base, features: vfxSurfaceOptionFeatures));
//VFX inspector UI is taking a shortcut here:
//We aren't doing distinction between LightingShaderGraphGUI & LitShaderGUI
//Only refraction has to be added to cover all settings cases
uiBlocks.Add(new TransparencyUIBlock(MaterialUIBlock.ExpandableBit.Transparency, TransparencyUIBlock.Features.Refraction));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public partial class HDRenderPipeline
internal const int k_MaxDecalsOnScreen = 2048;
internal const int k_MaxPlanarReflectionsOnScreen = 16;
internal const int k_MaxCubeReflectionsOnScreen = 64;
internal const int k_MaxLightsPerClusterCell = 24;
internal const int k_MaxLightsPerClusterCell = ShaderConfig.LightClusterMaxCellElementCount;
internal static readonly Vector3 k_BoxCullingExtentThreshold = Vector3.one * 0.01f;

#if UNITY_SWITCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ static public void SetupBaseLitKeywords(Material material)

bool enableDisplacement = material.HasProperty(kDisplacementMode) && (GetFilteredDisplacementMode(material) != DisplacementMode.None);

// Displacement mapping requires a height map.
if (enableDisplacement)
{
int layerCount = material.HasProperty(kLayerCount) ? material.GetInt(kLayerCount) : 1;

// If the layerCount is 1, then it means that the property we're fetching is not from a layered material
// thus it doesn't have a postfix
string[] postfixes = (layerCount > 1) ? new[] { "0", "1", "2", "3" } : new[] { "" };

for (int i = 0; i < layerCount; i++)
{
string kHeightMapN = string.Format("{0}{1}", kHeightMap, postfixes[i]);

enableDisplacement = enableDisplacement && material.HasProperty(kHeightMapN) && (material.GetTexture(kHeightMapN) != null);
}
}

if (enableDisplacement)
{
var displacementMode = GetFilteredDisplacementMode(material);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// How many lights (at most) do we support at one given shading point
// FIXME: hardcoded limits are evil, this LightList should instead be put together in C#
#define MAX_LOCAL_LIGHT_COUNT 16
#define MAX_LOCAL_LIGHT_COUNT SHADEROPTIONS_PATH_TRACING_MAX_LIGHT_COUNT
#define MAX_DISTANT_LIGHT_COUNT 4

#define DELTA_PDF 1000000.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,10 @@ public void Setup(ref RenderingData renderingData,
this.GbufferAttachments[this.GBufferLightingIndex] = colorAttachment;
this.DepthAttachment = depthAttachment;

if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 3)
var inputCount = 4 + (UseShadowMask ? 1 : 0);
if (this.DeferredInputAttachments == null && this.UseRenderPass && this.GbufferAttachments.Length >= 3 ||
(this.DeferredInputAttachments != null && inputCount != this.DeferredInputAttachments.Length))
{
var inputCount = 4 + (UseShadowMask ? 1 : 0);
this.DeferredInputAttachments = new RTHandle[inputCount];
this.DeferredInputIsTransient = new bool[inputCount];
int i, j = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ To open the Default VFX Graph Templates window:
3. In the Create new VFX Asset window, select a Default VFX Graph template.
4. Double-click the Template asset, or select **Create**

**Note**: Select the Add (**+**) button to repeat the last action you selected in the dropdown. For example, if you select **Insert Template**, the **Add** (**+**) button opens the **Insert Template** window.
>- The Add **[+]** button opens the templates window to insert a template in the current VFX.
>- If you hold the **CTRL** key while clicking on **[+]** button the templates window will open to create a new VFX asset.
## Create a custom VFX Graph template

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ protected void CreateGUI()
VFXManagerEditor.CheckVFXManager();

graphView = new VFXView();
graphView.StretchToParentSize();
SetupFramingShortcutHandler(graphView);

rootVisualElement.Add(graphView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ protected virtual void OnOpenPopup() { }
protected virtual void OnMainButton() { }
protected abstract Vector2 GetPopupSize();

protected void SetMainButtonTooltip(string newTooltip)
{
m_MainButton.tooltip = newTooltip;
}

protected void ClosePopup()
{
m_CurrentPopup?.Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ public VFXView()
toggleComponentBoard.value = componentBoardVisible;
#endif

Add(m_Toolbar);
Add(m_LockedElement);
Add(m_NoAssetElement);
SetToolbarEnabled(false);
Expand Down Expand Up @@ -861,8 +860,7 @@ private void ClearAllErrors(VFXModel model, VFXErrorOrigin errorOrigin)

public void SetBoardToFront(GraphElement board)
{
board.SendToBack();
board.PlaceBehind(m_Toolbar);
board.BringToFront();
}

public bool TryAttachTo(VisualEffect visualEffect, bool showNotification)
Expand Down Expand Up @@ -2465,6 +2463,7 @@ bool canGroupSelection

void OnEnterPanel(AttachToPanelEvent e)
{
parent.Insert(0, m_Toolbar);
Undo.undoRedoPerformed += OnUndoPerformed;
}

Expand Down
Loading

0 comments on commit f6422d8

Please sign in to comment.