Skip to content

Commit

Permalink
Probe Volumes: Lots of bugfixes and improvements to bilateral filteri…
Browse files Browse the repository at this point in the history
…ng 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. Still a WIP
  • Loading branch information
pastasfuture committed Mar 25, 2021
1 parent 91a403a commit 3c3b091
Show file tree
Hide file tree
Showing 23 changed files with 1,007 additions and 350 deletions.
Expand Up @@ -49,6 +49,19 @@ public enum ProbeVolumesBilateralFilteringModes
OctahedralDepth = 2
}

/// <summary>
/// Options for the mode HDRP uses for probe volume bilateral filtering.
/// </summary>
///<seealso cref="ShaderOptions"/>
[GenerateHLSL(PackingRules.Exact)]
public enum ProbeVolumesBilateralFilteringSampleModes
{
/// <summary>Bilateral filtering blends weighted texture coordinates, and then takes a single hardware filtered sample from the atlas. Reduces texture sample bandwidth at the cost of inexact bilateral filter reconstruction, and hardware interpolation precision banding.</summary>
ApproximateSample = 0,
/// <summary>Bilateral filtering loads 8x taps from the atlas, and weights these results. Reconstructs precise bilateral filter results at the potential cost of bandwidth.</summary>
PreciseLoad = 1
}

/// <summary>
/// Project-wide shader configuration options.
/// </summary>
Expand Down Expand Up @@ -85,15 +98,18 @@ public enum ShaderOptions

/// <summary>The probe volume evaluation mode.</summary>
/// <seealso cref = "ProbeVolumesEvaluationModes " />
ProbeVolumesEvaluationMode = ProbeVolumesEvaluationModes.Disabled,
ProbeVolumesEvaluationMode = ProbeVolumesEvaluationModes.LightLoop,
/// <summary>Probe volume supports additive blending.</summary>
ProbeVolumesAdditiveBlending = 1,
/// <summary>The probe volume filtering mode.</summary>
/// <seealso cref="ProbeVolumesBilateralFilteringModes"/>
ProbeVolumesBilateralFilteringMode = ProbeVolumesBilateralFilteringModes.Validity,
ProbeVolumesBilateralFilteringMode = ProbeVolumesBilateralFilteringModes.OctahedralDepth,
/// <summary>The probe volume bilateral filtering sample mode.</summary>
/// <seealso cref="ProbeVolumesBilateralFilteringSampleModes"/>
ProbeVolumesBilateralFilteringSampleMode = ProbeVolumesBilateralFilteringSampleModes.PreciseLoad,
/// <summary>The probe volume encoding method.</summary>
/// /// <seealso cref="ProbeVolumesEncodingModes"/>
ProbeVolumesEncodingMode = ProbeVolumesEncodingModes.SphericalHarmonicsL1,
/// <seealso cref="ProbeVolumesEncodingModes"/>
ProbeVolumesEncodingMode = ProbeVolumesEncodingModes.SphericalHarmonicsL2,

/// <summary>Support for area lights.</summary>
AreaLights = 1,
Expand Down Expand Up @@ -136,6 +152,9 @@ public class ShaderConfig
/// <summary>Specifies the probe volume filtering mode.</summary>
///<seealso cref="ShaderOptions.ProbeVolumesBilateralFilteringMode"/>
public static ProbeVolumesBilateralFilteringModes s_ProbeVolumesBilateralFilteringMode = (ProbeVolumesBilateralFilteringModes)ShaderOptions.ProbeVolumesBilateralFilteringMode;
/// <summary>Specifies the probe volume filtering mode.</summary>
///<seealso cref="ShaderOptions.ProbeVolumesBilateralFilteringMode"/>
public static ProbeVolumesBilateralFilteringSampleModes s_ProbeVolumesBilateralFilteringSampleMode = (ProbeVolumesBilateralFilteringSampleModes)ShaderOptions.ProbeVolumesBilateralFilteringSampleMode;
/// <summary>Specifies the probe volume encoding method.</summary>
///<seealso cref="ShaderOptions.ProbeVolumesEncodingMode"/>
public static ProbeVolumesEncodingModes s_ProbeVolumesEncodingMode = (ProbeVolumesEncodingModes)ShaderOptions.ProbeVolumesEncodingMode;
Expand Down
Expand Up @@ -25,6 +25,12 @@
#define PROBEVOLUMESBILATERALFILTERINGMODES_VALIDITY (1)
#define PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH (2)

//
// UnityEngine.Rendering.HighDefinition.ProbeVolumesBilateralFilteringModes: static fields
//
#define PROBEVOLUMESBILATERALFILTERINGSAMPLEMODES_APPROXIMATE_SAMPLE (0)
#define PROBEVOLUMESBILATERALFILTERINGSAMPLEMODES_PRECISE_LOAD (1)

//
// UnityEngine.Rendering.HighDefinition.ShaderOptions: static fields
//
Expand All @@ -33,10 +39,11 @@
#define SHADEROPTIONS_PRE_EXPOSITION (1)
#define SHADEROPTIONS_PRECOMPUTED_ATMOSPHERIC_ATTENUATION (0)
#define SHADEROPTIONS_XR_MAX_VIEWS (2)
#define SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE (0)
#define SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE (1)
#define SHADEROPTIONS_PROBE_VOLUMES_ADDITIVE_BLENDING (1)
#define SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_MODE (1)
#define SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE (1)
#define SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_MODE (2)
#define SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING_SAMPLE_MODE (1)
#define SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE (2)
#define SHADEROPTIONS_AREA_LIGHTS (1)
#define SHADEROPTIONS_BARN_DOOR (0)

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
@@ -1,3 +1,4 @@
#pragma enable_d3d11_debug_symbols
#pragma kernel Deferred_Direct_Fptl SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl
#pragma kernel Deferred_Direct_Fptl_DebugDisplay SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl_DebugDisplay DEBUG_DISPLAY

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 3c3b091

Please sign in to comment.