Skip to content

Commit

Permalink
Probe Volume Improvements
Browse files Browse the repository at this point in the history
Probe Volumes: Force the lightmapper to free old additionalbakedata jobs in a few cases, such as when probe volumes are disabled, or when probe volumes are hidden. Previously, it looks like the lightmapper could hang onto this data until you quit. (#19)

Probe Volumes: Lots of bugfixes and improvements to bilateral filtering modes. Octahedral Depth data now working (requires changes on the C++ side). Added support for comparing filtering the texel coordinates and then taking a single sample, vs taking 8x samples and then filtering the results. Ported over from unity graphics repo 3c3b091

Probe Volumes: Lots of bugfixes around baking. Reflection Probes and Density Volumes: now respect scene visibility toggles in regards to their contribution to the scene. TODO: Remove debug logging that was added! Backing up WIP work.

SceneObjectIDMap: Fix bug where index from gameobject dictionary would get out of sync from entries after an insertion occurred to fill a hole. This resulted in a nasty bug where reflection probes would occasionally generate the same filename as eachother, would overwrite eachothers textures, and would point to the same texture after the bake completed.

Probe Volume: Comment out log spam. Planning to clean it out completely in a follow up commit

Probe Volume: Remove log spam from ProbeVolumeManager

Added HDRP_STRIP_LEGACY_AMBIENT_PROBE_BAKING define for enabling legacy ambient probe bake feature stripping - requires custom build with backport of https://ono.unity3d.com/unity/unity/pull-request/123092/_/lighting/SRP-opt-out-skymanager

Make HDBakedReflectionSystem public for baking API

Co-authored-by: pastasfuture <nickb@bonfirestudios.com>
  • Loading branch information
pastasfuture and pastasfuture committed Sep 14, 2021
1 parent 12be7d6 commit a131403
Show file tree
Hide file tree
Showing 23 changed files with 1,097 additions and 365 deletions.
Expand Up @@ -84,13 +84,13 @@ static void Drawer_BakeToolBar(SerializedProbeVolume serialized, Editor owner)
var asset = serialized.probeVolumeAsset.objectReferenceValue as ProbeVolumeAsset;

if (ShaderConfig.s_ProbeVolumesBilateralFilteringMode == ProbeVolumesBilateralFilteringModes.OctahedralDepth
&& asset != null && asset.payload.dataOctahedralDepth == null)
&& asset != null && (asset.payload.dataOctahedralDepth == null || asset.payload.dataOctahedralDepth.Length == 0))
{
EditorGUILayout.HelpBox(Styles.k_FeatureOctahedralDepthEnabledNoData, MessageType.Error);
}

if (ShaderConfig.s_ProbeVolumesBilateralFilteringMode != ProbeVolumesBilateralFilteringModes.OctahedralDepth
&& asset != null && asset.payload.dataOctahedralDepth != null)
&& asset != null && (asset.payload.dataOctahedralDepth != null && asset.payload.dataOctahedralDepth.Length > 0))
{
EditorGUILayout.HelpBox(Styles.k_FeatureOctahedralDepthDisableYesData, MessageType.Error);
}
Expand Down Expand Up @@ -130,6 +130,20 @@ static void Drawer_ToolBar(SerializedProbeVolume serialized, Editor owner)
static void Drawer_PrimarySettings(SerializedProbeVolume serialized, Editor owner)
{
EditorGUILayout.PropertyField(serialized.drawProbes, Styles.s_DrawProbesLabel);
EditorGUILayout.PropertyField(serialized.drawOctahedralDepthRays, Styles.s_DrawOctahedralDepthRays);
if (serialized.drawOctahedralDepthRays.boolValue)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.DelayedIntField(serialized.drawOctahedralDepthRayIndexX, Styles.s_DrawOctahedralDepthRayIndexX);
EditorGUILayout.DelayedIntField(serialized.drawOctahedralDepthRayIndexY, Styles.s_DrawOctahedralDepthRayIndexY);
EditorGUILayout.DelayedIntField(serialized.drawOctahedralDepthRayIndexZ, Styles.s_DrawOctahedralDepthRayIndexZ);
if (EditorGUI.EndChangeCheck())
{
serialized.drawOctahedralDepthRayIndexX.intValue = Mathf.Clamp(serialized.drawOctahedralDepthRayIndexX.intValue, 0, serialized.resolutionX.intValue - 1);
serialized.drawOctahedralDepthRayIndexY.intValue = Mathf.Clamp(serialized.drawOctahedralDepthRayIndexY.intValue, 0, serialized.resolutionY.intValue - 1);
serialized.drawOctahedralDepthRayIndexZ.intValue = Mathf.Clamp(serialized.drawOctahedralDepthRayIndexZ.intValue, 0, serialized.resolutionZ.intValue - 1);
}
}
EditorGUILayout.PropertyField(serialized.probeSpacingMode, Styles.s_ProbeSpacingModeLabel);
switch ((ProbeSpacingMode)serialized.probeSpacingMode.enumValueIndex)
{
Expand Down
Expand Up @@ -25,6 +25,11 @@ internal static class Styles
internal static readonly GUIContent s_Size = new GUIContent("Size", "Modify the size of this Probe Volume. This is independent of the Transform's Scale.");
internal static readonly GUIContent s_DebugColorLabel = new GUIContent("Debug Color", "This color is used to visualize per-pixel probe volume weights in the render pipeline debugger.");
internal static readonly GUIContent s_DrawProbesLabel = new GUIContent("Draw Probes", "Enable or disable drawing probes.");
internal static readonly GUIContent s_DrawOctahedralDepthRays = new GUIContent("Draw Octahedral Depth Rays", "Enable or disable drawing rays to visualize to the octahedral depth data.");
internal static readonly GUIContent s_DrawOctahedralDepthRayIndexX = new GUIContent("Octahedral Depth Rays Probe X", "Specifies the x index of the probe to visualize octahedral depth rays for.");
internal static readonly GUIContent s_DrawOctahedralDepthRayIndexY = new GUIContent("Octahedral Depth Rays Probe Y", "Specifies the y index of the probe to visualize octahedral depth rays for.");
internal static readonly GUIContent s_DrawOctahedralDepthRayIndexZ = new GUIContent("Octahedral Depth Rays Probe Z", "Specifies the z index of the probe to visualize octahedral depth rays for.");

internal static readonly GUIContent s_BlendLabel = new GUIContent("Blend Distance", "Interior distance from the Size where the contribution fades in completely.");
internal static readonly GUIContent s_NormalModeContent = new GUIContent("Normal", "Exposes standard parameters.");
internal static readonly GUIContent s_AdvancedModeContent = new GUIContent("Advanced", "Exposes advanced parameters.");
Expand Down
Expand Up @@ -6,6 +6,10 @@ class SerializedProbeVolume
internal SerializedProperty probeVolumeAsset;
internal SerializedProperty debugColor;
internal SerializedProperty drawProbes;
internal SerializedProperty drawOctahedralDepthRays;
internal SerializedProperty drawOctahedralDepthRayIndexX;
internal SerializedProperty drawOctahedralDepthRayIndexY;
internal SerializedProperty drawOctahedralDepthRayIndexZ;

internal SerializedProperty probeSpacingMode;

Expand Down Expand Up @@ -48,6 +52,11 @@ internal SerializedProbeVolume(SerializedObject serializedObject)
debugColor = probeVolumeParams.FindPropertyRelative("debugColor");
drawProbes = probeVolumeParams.FindPropertyRelative("drawProbes");

drawOctahedralDepthRays = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRays");
drawOctahedralDepthRayIndexX = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRayIndexX");
drawOctahedralDepthRayIndexY = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRayIndexY");
drawOctahedralDepthRayIndexZ = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRayIndexZ");

probeSpacingMode = probeVolumeParams.FindPropertyRelative("probeSpacingMode");

resolutionX = probeVolumeParams.FindPropertyRelative("resolutionX");
Expand Down
Expand Up @@ -15,6 +15,9 @@

namespace UnityEditor.Rendering.HighDefinition
{
// custom-begin
public
// custom-end
unsafe class HDBakedReflectionSystem : ScriptableBakedReflectionSystem
{
struct HDProbeBakingState
Expand Down
Expand Up @@ -2615,6 +2615,14 @@ bool TrivialRejectProbe(in ProcessedProbeData processedProbe, HDCamera hdCamera)
if (processedProbe.hdProbe.texture == null)
return true;

// custom-begin:
#if UNITY_EDITOR
// Skip reflection probes that are hidden by the scene visibility toggle.
if (UnityEditor.SceneVisibilityManager.instance.IsHidden(processedProbe.hdProbe.gameObject))
return true;
#endif
// custom-end

return false;
}

Expand Down
Expand Up @@ -19,6 +19,7 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"
float3 _TextureViewResolution;
float2 _ValidRange;
int _ProbeVolumeAtlasSliceMode;
float4 _AtlasTextureOctahedralDepthScaleBias;
// float _RcpGlobalScaleFactor;
SamplerState ltc_linear_clamp_sampler;

Expand Down Expand Up @@ -105,8 +106,9 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"

float valueValidity = saturate((ProbeVolumeSampleValidity(uvw) - _ValidRange.x) * _ValidRange.y);

#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
float2 valueOctahedralDepthMeanAndVariance = saturate((SAMPLE_TEXTURE2D_LOD(_AtlasTextureOctahedralDepth, ltc_linear_clamp_sampler, input.texcoord * _AtlasTextureOctahedralDepthScaleBias.xy + _AtlasTextureOctahedralDepthScaleBias.zw, 0).xy - _ValidRange.x) * _ValidRange.y);
#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_MODE == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
float4 scaleBias = _AtlasTextureOctahedralDepthScaleBias;
float2 valueOctahedralDepthMeanAndMeanSquared = saturate((SAMPLE_TEXTURE2D_LOD(_ProbeVolumeAtlasOctahedralDepth, ltc_linear_clamp_sampler, input.texcoord * scaleBias.xy + scaleBias.zw, 0).xy - _ValidRange.x) * _ValidRange.y);
#endif

switch (_ProbeVolumeAtlasSliceMode)
Expand Down Expand Up @@ -164,11 +166,13 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"

case PROBEVOLUMEATLASSLICEMODE_OCTAHEDRAL_DEPTH:
{
#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
// Tonemap variance with sqrt() to bring it into a more similar scale to mean to make it more readable.
#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_MODE == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
float mean = valueOctahedralDepthMeanAndMeanSquared.x;
float meanSquared = valueOctahedralDepthMeanAndMeanSquared.y;
float variance = meanSquared - mean * mean;
return float4(
valueOctahedralDepthMeanAndVariance.x,
(valueOctahedralDepthMeanAndVariance.y > 0.0f) ? sqrt(valueOctahedralDepthMeanAndVariance.y) : 0.0f,
mean,
variance,
0.0f,
1.0f
);
Expand Down

0 comments on commit a131403

Please sign in to comment.