using System;
using System.Diagnostics;
using UnityEngine.Serialization;
namespace UnityEngine.Rendering.HighDefinition
{
///
/// Screen Space Reflection Algorithm
///
public enum ScreenSpaceReflectionAlgorithm
{
/// Legacy SSR approximation.
Approximation,
/// Screen Space Reflection, Physically Based with Accumulation through multiple frame.
PBRAccumulation
}
///
/// Screen Space Reflection Algorithm Type volume parameter.
///
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class SSRAlgoParameter : VolumeParameter
{
///
/// Screen Space Reflection Algorithm Type volume parameter constructor.
///
/// SSR Algo Type parameter.
/// Initial override state.
public SSRAlgoParameter(ScreenSpaceReflectionAlgorithm value, bool overrideState = false)
: base(value, overrideState) {}
}
///
/// A volume component that holds settings for screen space reflection and ray traced reflections.
///
[Serializable, VolumeComponentMenu("Lighting/Screen Space Reflection")]
[HelpURL(Documentation.baseURL + Documentation.version + Documentation.subURL + "Override-Screen-Space-Reflection" + Documentation.endURL)]
public class ScreenSpaceReflection : VolumeComponentWithQuality
{
bool UsesRayTracingQualityMode()
{
// The default value is set to quality. So we should be in quality if not overriden or we have an override set to quality
return !mode.overrideState || mode == RayTracingMode.Quality;
}
bool UsesRayTracing()
{
var hdAsset = HDRenderPipeline.currentAsset;
return hdAsset != null && hdAsset.currentPlatformRenderPipelineSettings.supportRayTracing && rayTracing.overrideState && rayTracing.value;
}
/// Enable Screen Space Reflections.
[Tooltip("Enable Screen Space Reflections.")]
public BoolParameter enabled = new BoolParameter(true);
/// Screen Space Reflections Algorithm used.
public SSRAlgoParameter usedAlgorithm = new SSRAlgoParameter(ScreenSpaceReflectionAlgorithm.Approximation);
///
/// Enable ray traced reflections.
///
public BoolParameter rayTracing = new BoolParameter(false);
// Shared Data
///
/// Controls the smoothness value at which HDRP activates SSR and the smoothness-controlled fade out stops.
///
public float minSmoothness
{
get
{
if ((UsesRayTracing() && (UsesRayTracingQualityMode() || !UsesQualitySettings())) || !UsesRayTracing())
return m_MinSmoothness.value;
else
return GetLightingQualitySettings().RTRMinSmoothness[(int)quality.value];
}
set { m_MinSmoothness.value = value; }
}
///
/// Controls the smoothness value at which the smoothness-controlled fade out starts. The fade is in the range [Min Smoothness, Smoothness Fade Start]
///
public float smoothnessFadeStart
{
get
{
if ((UsesRayTracing() && (UsesRayTracingQualityMode() || !UsesQualitySettings())) || !UsesRayTracing())
return m_SmoothnessFadeStart.value;
else
return GetLightingQualitySettings().RTRSmoothnessFadeStart[(int)quality.value];
}
set { m_SmoothnessFadeStart.value = value; }
}
///
/// When enabled, SSR handles sky reflection.
///
public BoolParameter reflectSky = new BoolParameter(true);
// SSR Data
///
/// Controls the distance at which HDRP fades out SSR near the edge of the screen.
///
public ClampedFloatParameter depthBufferThickness = new ClampedFloatParameter(0.01f, 0, 1);
///
/// Controls the typical thickness of objects the reflection rays may pass behind.
///
public ClampedFloatParameter screenFadeDistance = new ClampedFloatParameter(0.1f, 0.0f, 1.0f);
///
/// Controls the amount of accumulation (0 no accumulation, 1 just accumulate)
///
public ClampedFloatParameter accumulationFactor = new ClampedFloatParameter(0.75f, 0.0f, 1.0f);
///
/// Layer mask used to include the objects for screen space reflection.
///
public LayerMaskParameter layerMask = new LayerMaskParameter(-1);
///
/// Controls the length of reflection rays.
///
public float rayLength
{
get
{
if (!UsesQualitySettings() || UsesRayTracingQualityMode())
return m_RayLength.value;
else
return GetLightingQualitySettings().RTRRayLength[(int)quality.value];
}
set { m_RayLength.value = value; }
}
///
/// Clamps the exposed intensity.
///
public float clampValue
{
get
{
if (!UsesQualitySettings() || UsesRayTracingQualityMode())
return m_ClampValue.value;
else
return GetLightingQualitySettings().RTRClampValue[(int)quality.value];
}
set { m_ClampValue.value = value; }
}
///
/// Enable denoising on the ray traced reflections.
///
public bool denoise
{
get
{
if (!UsesQualitySettings() || UsesRayTracingQualityMode())
return m_Denoise.value;
else
return GetLightingQualitySettings().RTRDenoise[(int)quality.value];
}
set { m_Denoise.value = value; }
}
///
/// Controls the radius of reflection denoiser.
///
public int denoiserRadius
{
get
{
if (!UsesQualitySettings() || UsesRayTracingQualityMode())
return m_DenoiserRadius.value;
else
return GetLightingQualitySettings().RTRDenoiserRadius[(int)quality.value];
}
set { m_DenoiserRadius.value = value; }
}
///
/// Controls if the denoising should affect pefectly smooth surfaces
///
public bool affectSmoothSurfaces
{
get
{
if (!UsesQualitySettings() || UsesRayTracingQualityMode())
return m_AffectSmoothSurfaces.value;
else
return GetLightingQualitySettings().RTRSmoothDenoising[(int)quality.value];
}
set { m_AffectSmoothSurfaces.value = value; }
}
///
/// Controls which version of the effect should be used.
///
public RayTracingModeParameter mode = new RayTracingModeParameter(RayTracingMode.Quality);
///
/// Defines if the effect should be evaluated at full resolution.
///
public bool fullResolution
{
get
{
if (!UsesQualitySettings())
return m_FullResolution.value;
else
return GetLightingQualitySettings().RTRFullResolution[(int)quality.value];
}
set { m_FullResolution.value = value; }
}
// Quality
///
/// Number of samples for reflections.
///
public ClampedIntParameter sampleCount = new ClampedIntParameter(1, 1, 32);
///
/// Number of bounces for reflection rays.
///
public ClampedIntParameter bounceCount = new ClampedIntParameter(1, 1, 8);
///
/// Sets the maximum number of steps HDRP uses for raytracing. Affects both correctness and performance.
///
public int rayMaxIterations
{
get
{
if (!UsesQualitySettings())
return m_RayMaxIterations.value;
else
return GetLightingQualitySettings().SSRMaxRaySteps[(int)quality.value];
}
set { m_RayMaxIterations.value = value; }
}
[SerializeField, FormerlySerializedAs("minSmoothness")]
private ClampedFloatParameter m_MinSmoothness = new ClampedFloatParameter(0.9f, 0.0f, 1.0f);
[SerializeField, FormerlySerializedAs("smoothnessFadeStart")]
private ClampedFloatParameter m_SmoothnessFadeStart = new ClampedFloatParameter(0.9f, 0.0f, 1.0f);
[SerializeField, FormerlySerializedAs("rayMaxIterations")]
private IntParameter m_RayMaxIterations = new IntParameter(32);
[SerializeField, FormerlySerializedAs("rayLength")]
private MinFloatParameter m_RayLength = new MinFloatParameter(50.0f, 0.01f);
[SerializeField, FormerlySerializedAs("clampValue")]
[Tooltip("Controls the clamp of intensity.")]
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
[SerializeField, FormerlySerializedAs("fullResolution")]
[Tooltip("Full Resolution")]
private BoolParameter m_FullResolution = new BoolParameter(false);
[SerializeField, FormerlySerializedAs("denoise")]
[Tooltip("Denoise the ray-traced reflection.")]
private BoolParameter m_Denoise = new BoolParameter(true);
[SerializeField, FormerlySerializedAs("denoiserRadius")]
[Tooltip("Controls the radius of the ray traced reflection denoiser.")]
private ClampedIntParameter m_DenoiserRadius = new ClampedIntParameter(8, 1, 32);
[SerializeField]
[Tooltip("Denoiser affects smooth surfaces.")]
private BoolParameter m_AffectSmoothSurfaces = new BoolParameter(false);
}
}