Skip to content

Fix slope scale depth bias when depth offset is ON #5466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2021
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 @@ -378,6 +378,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed case where the SceneView don't refresh when using LightExplorer with a running and Paused game (1354129)
- Fixed wrong ordering in FrameSettings (Normalize Reflection Probes)
- Fixed a null ref exception when no opaque objects are rendered.
- Fixed issue with depth slope scale depth bias when a material uses depth offset.

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ TextureHandle RenderShadowMaps(RenderGraph renderGraph, CullingResults cullResul
data.globalCBData._InvProjMatrix = shadowRequest.deviceProjectionYFlip.inverse;
data.globalCBData._ViewProjMatrix = viewProjection;
data.globalCBData._InvViewProjMatrix = viewProjection.inverse;
data.globalCBData._SlopeScaleDepthBias = -shadowRequest.slopeBias;

data.globalCB.PushGlobal(ctx.cmd, data.globalCBData, HDShaderIDs._ShaderVariablesGlobal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ void Frag( PackedVaryingsToPS packedInput

#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
outputDepth = posInput.deviceDepth;


#if SHADERPASS == SHADERPASS_SHADOWS
// If we are using the depth offset and manually outputting depth, the slope-scale depth bias is not properly applied
// we need to manually apply.
float bias = max(abs(ddx(posInput.deviceDepth)), abs(ddy(posInput.deviceDepth))) * _SlopeScaleDepthBias;
outputDepth += bias;
#endif

#endif

#ifdef SCENESELECTIONPASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ unsafe struct ShaderVariablesGlobal
public float _MicroShadowOpacity;
public uint _EnableProbeVolumes;
public uint _ProbeVolumeCount;
public float _Pad6;
public float _SlopeScaleDepthBias;

public Vector4 _CookieAtlasSize;
public Vector4 _CookieAtlasData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0)
float _MicroShadowOpacity;
uint _EnableProbeVolumes;
uint _ProbeVolumeCount;
float _Pad6;
float _SlopeScaleDepthBias;
float4 _CookieAtlasSize;
float4 _CookieAtlasData;
float4 _PlanarAtlasData;
Expand Down