Skip to content

[HDRP] Add custom pass buffer scaling functions #5809

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 11 commits into from
Oct 18, 2021
Merged
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
- Added a SG node to get the main directional light direction.
- Added new functions that sample the custom buffer in custom passes (CustomPassSampleCustomColor and CustomPassLoadCustomColor) to handle the RTHandleScale automatically.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add it to what's new


### Changed
- MaterialReimporter.ReimportAllMaterials and MaterialReimporter.ReimportAllHDShaderGraphs now batch the asset database changes to improve performance.
Expand All @@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed overwriting of preview camera background color. [case 1357004](https://issuetracker.unity3d.com/product/unity/issues/guid/1361557/)
- Fixed selection of light types (point, area, directional) for path-traced Unlit shadow mattes.
- Fixed precision issues with the scene voxelization for APV, especially with geometry at the origin.
- Fixed scaling issues with dynamic resolution and the CustomPassSampleCameraColor function.

## [13.0.0] - 2021-09-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ You can also load custom buffers using the following functions:
- `LoadCustomColor(uint2 pixelCoords)`
- `LoadCustomDepth(uint2 pixelCoords)`

Note that depending on the injection point used for the Fullscreen custom pass, sampling the custom buffer can result in incorrect scaling. Thus it's recommended to use these functions instead:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which injection points cause incorrect scaling? I think it would be helpful to the user to be specific here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These injection points were causing scaling issues:

  • BeforePreRefraction
  • BeforePostProcess
  • AfterPostProcess


- `CustomPassSampleCustomColor(float2 uv)`
- `CustomPassLoadCustomColor(uint2 pixelCoords)`

HDRP sets the custom pass target buffers to the Camera buffers by default. However, you can select a custom buffer in the UI of the Custom Pass. To do this, go to your Custom Pass component and change the **Target Color Buffer** or **Target Depth Buffer** properties.

To change the buffer format of the Custom Pass component in your HDRP asset, go to **Rendering > Custom Pass > Custom Buffer Format** and select one of the following formats from the drop down menu:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Shader "FullScreen/#SCRIPTNAME#"
// To sample custom buffers, you have access to these functions:
// But be careful, on most platforms you can't sample to the bound color buffer. It means that you
// can't use the SampleCustomColor when the pass color buffer is set to custom (and same for camera the buffer).
// float4 SampleCustomColor(float2 uv);
// float4 LoadCustomColor(uint2 pixelCoords);
// float4 CustomPassSampleCustomColor(float2 uv);
// float4 CustomPassLoadCustomColor(uint2 pixelCoords);
// float LoadCustomDepth(uint2 pixelCoords);
// float SampleCustomDepth(float2 uv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
case CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING: return float3(0, 0, 0);
// there is no color pyramid yet for before transparent so we can't sample with mips.
// Also, we don't use _RTHandleScaleHistory to sample because the color pyramid bound is the actual camera color buffer which is at the resolution of the camera
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT:
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return SAMPLE_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
case CUSTOMPASSINJECTIONPOINT_BEFORE_POST_PROCESS:
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScale.xy, 0).rgb;
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return SAMPLE_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, s_trilinear_clamp_sampler, uv * _RTHandleScale.zw, 0).rgb;
default: return SampleCameraColor(uv, lod);
}
}
Expand All @@ -44,6 +45,20 @@ float3 CustomPassLoadCameraColor(uint2 pixelCoords, float lod)
}
}

float4 CustomPassSampleCustomColor(float2 uv)
{
switch ((int)_CustomPassInjectionPoint)
{
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return LOAD_TEXTURE2D_X_LOD(_CustomColorTexture, uv * _ScreenSize.xy, 0);
default: return SampleCustomColor(uv);
}
}

float4 CustomPassLoadCustomColor(uint2 pixelCoords)
{
return LoadCustomColor(pixelCoords);
}

struct Attributes
{
uint vertexID : SV_VertexID;
Expand Down