Skip to content

Commit

Permalink
Merge pull request #8043 from Unity-Technologies/internal/2022.3/staging
Browse files Browse the repository at this point in the history
Internal/2022.3/staging
  • Loading branch information
UnityAljosha authored Mar 13, 2024
2 parents 3cf3552 + 541de32 commit 6552c80
Show file tree
Hide file tree
Showing 48 changed files with 8,326 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public static TType instance
if (s_Instance == null)
{
GameObject go = new GameObject("Default " + typeof(TType).Name) { hideFlags = HideFlags.HideAndDontSave };

#if !UNITY_EDITOR
GameObject.DontDestroyOnLoad(go);
#endif

go.SetActive(false);
s_Instance = go.AddComponent<TType>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,23 @@ public Vector2Int GetLastScaledSize()
/// This allows the caller to directly compare the float result safely with the floating point target resolution.
/// </param>
/// <returns>Returns the resolved low res multiplier based on the low transparency threshold settings.</returns>
public float GetLowResMultiplier(float targetLowRes)
public float GetLowResMultiplier(float targetLowRes) => GetLowResMultiplier(targetLowRes, m_CachedSettings.lowResTransparencyMinimumThreshold );

/// <summary>
/// Returns the resolved low res multiplier based on the a low res threshold.
/// </summary>
/// <param name="targetLowRes"> the target low resolution.
/// If by any chance thresholding is disabled or clamped, the exact same resolution is returned.
/// This allows the caller to directly compare the float result safely with the floating point target resolution.
/// </param>
/// <param name="minimumThreshold"> The custom threshold used to clamp the effect's resolution. </param>
/// <returns>Returns the resolved low res multiplier based on the minimumThreshold threshold settings.</returns>
public float GetLowResMultiplier(float targetLowRes, float minimumThreshold)
{
if (!m_Enabled)
return targetLowRes;

float thresholdPercentage = Math.Min(m_CachedSettings.lowResTransparencyMinimumThreshold / 100.0f, targetLowRes);
float thresholdPercentage = Math.Min(minimumThreshold / 100.0f, targetLowRes);
float targetPercentage = targetLowRes * m_CurrentFraction;
if (targetPercentage >= thresholdPercentage)
return targetLowRes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,8 @@ public struct GlobalDynamicResolutionSettings

/// <summary>The minimum percentage threshold allowed to render ray tracing effects at half resolution. When the resolution percentage falls below this threshold, HDRP will render ray tracing effects at full resolution.</summary>
public float rayTracingHalfResThreshold;

/// <summary>The minimum percentage threshold allowed to clamp low resolution for SSGI (Screen Space Global Illumination). When the resolution percentage falls below this threshold, HDRP will clamp the low resolution to this percentage.</summary>
public float lowResSSGIMinimumThreshold;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public class Styles
public static readonly GUIContent forceScreenPercentage = EditorGUIUtility.TrTextContent("Force Screen Percentage", "When enabled, HDRP uses the Forced Screen Percentage value as the screen percentage.");
public static readonly GUIContent forcedScreenPercentage = EditorGUIUtility.TrTextContent("Forced Screen Percentage", "Sets a specific screen percentage value. HDRP forces this screen percentage for dynamic resolution.");
public static readonly GUIContent lowResTransparencyMinimumThreshold = EditorGUIUtility.TrTextContent("Low Res Transparency Min Threshold", "The minimum percentage threshold allowed to clamp low resolution transparency. When the resolution percentage falls below this threshold, HDRP will clamp the low resolution to this percentage.");
public static readonly GUIContent lowResSSGIMinimumThreshold = EditorGUIUtility.TrTextContent("Low Res Screen Space GI Min Threshold", "The minimum percentage threshold allowed to clamp low resolution Screen Space Global Illumination. When the resolution percentage falls below this threshold, HDRP will clamp the low resolution to this percentage.");
public const string lowResTransparencyThresholdDisabledMsg = "Low res transparency is currently disabled in the quality settings. \"Low Res Transparency Min Threshold\" will be ignored.";
public static readonly GUIContent rayTracingHalfResThreshold = EditorGUIUtility.TrTextContent("Ray Tracing Half Res Threshold", "The minimum percentage threshold allowed to render ray tracing effects at half resolution. When the resolution percentage falls below this threshold, HDRP will render ray tracing effects at full resolution.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ static void Drawer_SectionDynamicResolutionSettings(SerializedHDRenderPipelineAs
EditorGUILayout.HelpBox(Styles.lowResTransparencyThresholdDisabledMsg, MessageType.Info);
}

{
EditorGUI.showMixedValue = serialized.renderPipelineSettings.dynamicResolutionSettings.lowResTransparencyMinimumThreshold.hasMultipleDifferentValues;
float lowResSSGIMinimumThreshold = serialized.renderPipelineSettings.dynamicResolutionSettings.lowResSSGIMinimumThreshold.floatValue;
EditorGUI.BeginChangeCheck();
lowResSSGIMinimumThreshold = EditorGUILayout.DelayedFloatField(Styles.lowResSSGIMinimumThreshold, lowResSSGIMinimumThreshold);
if (EditorGUI.EndChangeCheck())
serialized.renderPipelineSettings.dynamicResolutionSettings.lowResSSGIMinimumThreshold.floatValue = Mathf.Clamp(lowResSSGIMinimumThreshold, 0.0f, 50.0f);
}

{
float rayTracingHalfResThreshold = serialized.renderPipelineSettings.dynamicResolutionSettings.rayTracingHalfResThreshold.floatValue;
EditorGUI.BeginChangeCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SerializedDynamicResolutionSettings
public SerializedProperty forcedPercentage;
public SerializedProperty lowResTransparencyMinimumThreshold;
public SerializedProperty rayTracingHalfResThreshold;
public SerializedProperty lowResSSGIMinimumThreshold;

public SerializedDynamicResolutionSettings(SerializedProperty root)
{
Expand All @@ -46,6 +47,7 @@ public SerializedDynamicResolutionSettings(SerializedProperty root)
forcedPercentage = root.Find((GlobalDynamicResolutionSettings s) => s.forcedPercentage);
lowResTransparencyMinimumThreshold = root.Find((GlobalDynamicResolutionSettings s) => s.lowResTransparencyMinimumThreshold);
rayTracingHalfResThreshold = root.Find((GlobalDynamicResolutionSettings s) => s.rayTracingHalfResThreshold);
lowResSSGIMinimumThreshold = root.Find((GlobalDynamicResolutionSettings s) => s.lowResSSGIMinimumThreshold);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma kernel BilateralUpSampleColor BILATERAL_UPSAMPLE=BilateralUpSampleColor
#pragma kernel BilateralUpSampleColorHalf
#pragma kernel BilateralUpSampleColor

//#pragma enable_d3d11_debug_symbols

Expand All @@ -22,6 +23,8 @@ TEXTURE2D_X(_LowResolutionTexture);
groupshared float3 gs_cacheLighting[36];
groupshared float gs_cacheDepth[36];

float _RayMarchingLowResPercentage;

void FillUpsampleDataLDS(uint groupIndex, uint2 groupOrigin)
{
// Define which value we will be acessing with this worker thread
Expand Down Expand Up @@ -79,7 +82,7 @@ void FillUpsampleNeighborhoodData_2x2(int2 groupThreadId, int subRegionIdx, out
RW_TEXTURE2D_X(float3, _OutputUpscaledTexture);

[numthreads(BILATERAL_UPSAMPLE_TILE_SIZE, BILATERAL_UPSAMPLE_TILE_SIZE, 1)]
void BILATERAL_UPSAMPLE(uint3 currentCoord : SV_DispatchThreadID,
void BilateralUpSampleColorHalf(uint3 currentCoord : SV_DispatchThreadID,
int groupIndex : SV_GroupIndex,
uint2 groupThreadId : SV_GroupThreadID,
uint2 groupId : SV_GroupID)
Expand Down Expand Up @@ -111,3 +114,54 @@ void BILATERAL_UPSAMPLE(uint3 currentCoord : SV_DispatchThreadID,
// Upscale and return the result
_OutputUpscaledTexture[COORD_TEXTURE2D_X(currentCoord.xy)] = BilUpColor2x2_RGB(hiResDepth, upsampleData);
}

SAMPLER(sampler_LinearClamp);
SAMPLER(sampler_PointClamp);

[numthreads(BILATERAL_UPSAMPLE_TILE_SIZE, BILATERAL_UPSAMPLE_TILE_SIZE, 1)]
void BilateralUpSampleColor(uint3 currentCoord : SV_DispatchThreadID)
{
UNITY_XR_ASSIGN_VIEW_INDEX(currentCoord.z);

// Only 36 workers of the 64 region do the pre-fetching
// If out of bounds, discard
if (any(currentCoord.xy >= uint2(_ScreenSize.xy)))
return;

// Read the depth value as early as possible and use it as late as possible
// TODO: do a gather here.
float4 depthNeighborhood = float4(
LOAD_TEXTURE2D_X(_DepthTexture, currentCoord.xy + uint2(0,1)).x,
LOAD_TEXTURE2D_X(_DepthTexture, currentCoord.xy + uint2(1,1)).x,
LOAD_TEXTURE2D_X(_DepthTexture, currentCoord.xy + uint2(1,0)).x,
LOAD_TEXTURE2D_X(_DepthTexture, currentCoord.xy + uint2(0,0)).x);

float closestDepth = max(depthNeighborhood.x, max(depthNeighborhood.y, max(depthNeighborhood.z, depthNeighborhood.w)));

float2 uvAtLowRes = min((currentCoord.xy) * _RayMarchingLowResPercentage + 0.5, _HalfScreenSize.xy - 1) * _ScreenSize.zw;
float2 sampleUV = ClampAndScaleUVForBilinear(uvAtLowRes);

float2 samplePixel = sampleUV * _ScreenSize.xy;
float2 bottomRight = frac(samplePixel + 0.5);
float2 topLeft = 1.0 - bottomRight;
float4 linearWeights = float4(
topLeft.x * bottomRight.y,
bottomRight.x * bottomRight.y,
bottomRight.x * topLeft.y,
topLeft.x * topLeft.y);

float4 reds = GATHER_RED_TEXTURE2D_X(_LowResolutionTexture, sampler_LinearClamp, sampleUV);
float4 greens = GATHER_GREEN_TEXTURE2D_X(_LowResolutionTexture, sampler_LinearClamp, sampleUV);
float4 blues = GATHER_BLUE_TEXTURE2D_X(_LowResolutionTexture, sampler_LinearClamp, sampleUV);

float3 trueCol = SAMPLE_TEXTURE2D_X_LOD(_LowResolutionTexture, sampler_LinearClamp, sampleUV, 0.0).rgb;
float3 s0 = float3(reds.x, greens.x, blues.x);
float3 s1 = float3(reds.y, greens.y, blues.y);
float3 s2 = float3(reds.z, greens.z, blues.z);
float3 s3 = float3(reds.w, greens.w, blues.w);

float3 bilCol = BilUpColor3WithWeight(closestDepth, depthNeighborhood, s0, s1, s2, s3, linearWeights);

// Upscale and return the result
_OutputUpscaledTexture[COORD_TEXTURE2D_X(currentCoord.xy)] = bilCol;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ float3 BilUpColor3(float HiDepth, float4 LowDepths, float3 lowValue0, float3 low
return WeightedSum / TotalWeight;
}

// THe bilateral upscale function (2x2 neighborhood, color3 version)
float3 BilUpColor3WithWeight(float HiDepth, float4 LowDepths, float3 lowValue0, float3 lowValue1, float3 lowValue2, float3 lowValue3, float4 initialWeight)
{
float4 weights = initialWeight * float4(9, 3, 1, 3) / (abs(HiDepth - LowDepths) + _UpsampleTolerance);
float TotalWeight = dot(weights, 1) + _NoiseFilterStrength;
float3 WeightedSum = lowValue0 * weights.x
+ lowValue1 * weights.y
+ lowValue2 * weights.z
+ lowValue3 * weights.w
+ _NoiseFilterStrength;
return WeightedSum / TotalWeight;
}

// The bilateral upscale function (2x2 neighborhood, color4 version)
float4 BilUpColor(float HiDepth, float4 LowDepths, float4 lowValue0, float4 lowValue1, float4 lowValue2, float4 lowValue3)
{
Expand Down
Loading

0 comments on commit 6552c80

Please sign in to comment.