Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added an option to extend the camera culling for skinned mesh animation in ray tracing effects (1258547).
- Added decal layer system similar to light layer. Mesh will receive a decal when both decal layer mask matches.
- Added shader graph nodes for rendering a complex eye shader.
- Added more controls to contact shadows and increased quality in some parts.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Only one Light can cast Contact Shadows at a time. This means that, if you have
| __Fade Out Distance__ | The distance, in meters, over which HDRP fades Contact Shadows out when at the __Max Distance__. |
| __Sample Count__ | Use the slider to set the number of samples HDRP uses for ray casting. Increasing this increases quality at the cost of performance. |
| __Opacity__ | Use the slider to set the opacity of the Contact Shadows. Lower values result in softer, less prominent shadows. |
| **Ray Bias** | Controls the bias applied to the screen space ray cast to get contact shadows. Higher values can reduce self shadowing, however too high values might lead to peter-panning that can be especially undesirable with contact shadows. |
| **Thickness** | Controls the thickness of the objects found along the ray, essentially thickening the contact shadows. It can be used to fill holes in the shadows, however might also lead to overly wide shadows. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ HDRP now stores OnEnable and OnDemand shadows in a separate atlas and more API i

The shader function `SampleShadow_PCSS` now requires you to pass in an additional float2 parameter which contains the shadow atlas resolution in x and the inverse of the atlas resolution in y.

Ray bias and thickness parameters have been added to contact shadows. These might lead to small changes to the visual impact of contact shadows with the default parameters. Please consider tuning those values to fit the needs of your project.

## Shader config file

From Unity 2020.2, due to the change of the shadow map, HDRP moved the HDShadowFilteringQuality enum to HDShadowManager.cs. HDRP also removed ShaderConfig.s_DeferredShadowFiltering and ShaderOptions.DeferredShadowFiltering from the source code because they have no effect anymore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ You can now control the texture mapping mode for all textures in the [AxF Shader

For more information about this improvement, see [AxF Shader](AxF-Shader.md).

### Contact Shadows Improvements

More control is given for contact shadows, in particular now a bias can be set to avoid self intersection issues and a new thickness parameter is introduced to fill gaps that can be left by contact shadows.

### Exposure

#### Exposure curve mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ContactShadowsEditor : VolumeComponentWithQualityEditor
SerializedDataParameter m_FadeInDistance;
SerializedDataParameter m_SampleCount;
SerializedDataParameter m_Opacity;
SerializedDataParameter m_Bias;
SerializedDataParameter m_Thickness;

public override void OnEnable()
{
Expand All @@ -32,6 +34,8 @@ public override void OnEnable()
m_FadeInDistance = Unpack(o.Find(x => x.fadeInDistance));
m_SampleCount = Unpack(o.Find(x => x.sampleCount));
m_Opacity = Unpack(o.Find(x => x.opacity));
m_Bias = Unpack(o.Find(x => x.rayBias));
m_Thickness = Unpack(o.Find(x => x.thicknessScale));
}

public override void OnInspectorGUI()
Expand All @@ -49,6 +53,9 @@ public override void OnInspectorGUI()
PropertyField(m_FadeInDistance, EditorGUIUtility.TrTextContent("Fade In Distance", "Sets the distance over which HDRP fades Contact Shadows in when past the Min Distance. Uses meters."));
PropertyField(m_FadeDistance, EditorGUIUtility.TrTextContent("Fade Out Distance", "Sets the distance over which HDRP fades Contact Shadows out when at the Max Distance. Uses meters."));
PropertyField(m_Opacity, EditorGUIUtility.TrTextContent("Opacity", "Controls the opacity of the Contact Shadow."));
PropertyField(m_Bias, EditorGUIUtility.TrTextContent("Bias", "Controls the bias applied to the screen space ray cast to get contact shadows."));
PropertyField(m_Thickness, EditorGUIUtility.TrTextContent("Thickness", "Controls the thickness of the objects found along the ray, essentially thickening the contact shadows."));

base.OnInspectorGUI();
GUI.enabled = useCustomValue;
PropertyField(m_SampleCount, EditorGUIUtility.TrTextContent("Sample Count", "Controls the number of samples HDRP uses for ray casting."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,7 @@ struct ContactShadowsParameters

public Vector4 params1;
public Vector4 params2;
public int sampleCount;
public Vector4 params3;

public int numTilesX;
public int numTilesY;
Expand Down Expand Up @@ -3762,8 +3762,8 @@ ContactShadowsParameters PrepareContactShadowsParameters(HDCamera hdCamera, floa
float contactShadowFadeIn = Mathf.Clamp(m_ContactShadows.fadeInDistance.value, 1e-6f, contactShadowFadeEnd);

parameters.params1 = new Vector4(m_ContactShadows.length.value, m_ContactShadows.distanceScaleFactor.value, contactShadowFadeEnd, contactShadowOneOverFadeRange);
parameters.params2 = new Vector4(firstMipOffsetY, contactShadowMinDist, contactShadowFadeIn, 0.0f);
parameters.sampleCount = m_ContactShadows.sampleCount;
parameters.params2 = new Vector4(firstMipOffsetY, contactShadowMinDist, contactShadowFadeIn, m_ContactShadows.rayBias.value * 0.01f);
parameters.params3 = new Vector4(m_ContactShadows.sampleCount, m_ContactShadows.thicknessScale.value * 10.0f , 0.0f, 0.0f);

int deferredShadowTileSize = 16; // Must match DeferreDirectionalShadow.compute
parameters.numTilesX = (hdCamera.actualWidth + (deferredShadowTileSize - 1)) / deferredShadowTileSize;
Expand All @@ -3786,7 +3786,7 @@ static void RenderContactShadows( in ContactShadowsParameters parameters,

cmd.SetComputeVectorParam(parameters.contactShadowsCS, HDShaderIDs._ContactShadowParamsParameters, parameters.params1);
cmd.SetComputeVectorParam(parameters.contactShadowsCS, HDShaderIDs._ContactShadowParamsParameters2, parameters.params2);
cmd.SetComputeIntParam(parameters.contactShadowsCS, HDShaderIDs._DirectionalContactShadowSampleCount, parameters.sampleCount);
cmd.SetComputeVectorParam(parameters.contactShadowsCS, HDShaderIDs._ContactShadowParamsParameters3, parameters.params3);
cmd.SetComputeBufferParam(parameters.contactShadowsCS, parameters.kernel, HDShaderIDs._DirectionalLightDatas, lightLoopLightData.directionalLightData);

// Send light list to the compute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ float SampleDepth(float2 UV, bool HalfRes)
return LoadCameraDepth(pixelCoord);
}

float GetDepthCompareThreshold(float step, float rayStartZ, float rayOrthoZ)
{
return abs(rayOrthoZ - rayStartZ) * _ContactShadowThickness * max(0.07, step);
}

bool CompareDepth(float depthDiff, float compareThreshold)
{
return abs(compareThreshold - depthDiff) < compareThreshold;
}


bool ScreenSpaceShadowRayCast(float3 positionWS, float3 rayDirWS, float rayLength, uint2 positionSS, out float fade)
{
Expand All @@ -50,7 +60,7 @@ bool ScreenSpaceShadowRayCast(float3 positionWS, float3 rayDirWS, float rayLengt
uint taaEnabled = _TaaFrameInfo.w;
float dither = InterleavedGradientNoise(positionSS, (_FrameCount % 8u) * taaEnabled) - ditherBias;

float3 rayStartWS = positionWS;
float3 rayStartWS = positionWS - positionWS * _ContactShadowBias;
float3 rayEndWS = rayStartWS + rayDirWS * rayLength;

float4 rayStartCS = TransformWorldToHClip(rayStartWS);
Expand All @@ -68,7 +78,7 @@ bool ScreenSpaceShadowRayCast(float3 positionWS, float3 rayDirWS, float rayLengt
float3 rayDirCS = rayEndCS.xyz - rayStartCS.xyz;

float step = 1.0f / _SampleCount;
float compareThreshold = abs(rayOrthoViewSpace.z - rayStartCS.z) * max(0.07f, step);
float compareThreshold = GetDepthCompareThreshold(step, rayStartCS.z, rayOrthoViewSpace.z);

float occluded = 0.0f;

Expand Down Expand Up @@ -107,7 +117,7 @@ bool ScreenSpaceShadowRayCast(float3 positionWS, float3 rayDirWS, float rayLengt

float depthDiff = sampleDepth - sampleAlongRay.z;

if (depthDiff > 0.0f && depthDiff < compareThreshold && sampleAlongRay.z > 0)
if (depthDiff > 0.0f && CompareDepth(depthDiff, compareThreshold) && sampleAlongRay.z > 0)
{
if (tracingHalfRes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ public class ContactShadows : VolumeComponentWithQuality
/// </summary>
public MinFloatParameter fadeInDistance = new MinFloatParameter(0.0f, 0.0f);
/// <summary>
/// Controls the number of samples HDRP takes along each contact shadow ray. Increasing this value can lead to higher quality.
/// Controls the bias applied to the screen space ray cast to get contact shadows.
/// </summary>
public ClampedFloatParameter rayBias = new ClampedFloatParameter(0.2f, 0.0f, 1.0f);
/// <summary>
/// Controls the thickness of the objects found along the ray, essentially thickening the contact shadows.
/// </summary>
public ClampedFloatParameter thicknessScale = new ClampedFloatParameter(0.15f, 0.02f, 1.0f);



public int sampleCount
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ RW_TEXTURE2D_X(uint, _ContactShadowTextureUAV);
CBUFFER_START(DeferredShadowParameters)
float4 _ContactShadowParamsParameters;
float4 _ContactShadowParamsParameters2;
float4 _ContactShadowParamsParameters3;
int _SampleCount;
CBUFFER_END

Expand All @@ -13,3 +14,6 @@ CBUFFER_END
#define _RenderTargetHeight _ContactShadowParamsParameters2.x
#define _ContactShadowMinDistance _ContactShadowParamsParameters2.y
#define _ContactShadowFadeInEnd _ContactShadowParamsParameters2.z
#define _ContactShadowBias _ContactShadowParamsParameters2.w
#define _SampleCount (int)_ContactShadowParamsParameters3.x
#define _ContactShadowThickness _ContactShadowParamsParameters3.y
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static class HDShaderIDs
public static readonly int _ContactShadowTextureUAV = Shader.PropertyToID("_ContactShadowTextureUAV");
public static readonly int _ContactShadowParamsParameters = Shader.PropertyToID("_ContactShadowParamsParameters");
public static readonly int _ContactShadowParamsParameters2 = Shader.PropertyToID("_ContactShadowParamsParameters2");
public static readonly int _ContactShadowParamsParameters3 = Shader.PropertyToID("_ContactShadowParamsParameters3");
public static readonly int _DirectionalContactShadowSampleCount = Shader.PropertyToID("_SampleCount");
public static readonly int _ShadowFrustumPlanes = Shader.PropertyToID("_ShadowFrustumPlanes");

Expand Down