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
13 changes: 7 additions & 6 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Added support for orthographic camera in path tracing.
- Added public API to edit materials from script at runtime.

### Changed
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
- Changed the max distance for Light Anchors to avoid unstability with high values (case 1362802).
- PrepareLightsForGPU CPU Light loop performance improvement (40% to 70% faster), utilizing burst and optimized. Utilizing better sorting, distributing work in jobs and improving cache access of light data.
- Added new functions that sample the custom buffer in custom passes (CustomPassSampleCustomColor and CustomPassLoadCustomColor) to handle the RTHandleScale automatically.

### Fixed
- Fixed decal position when created from context menu. (case 1368987)
Expand All @@ -27,13 +23,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed depth pyramid being incorrect when having multiple cameras (scene view and gameview) and when hardware DRS was activated.
- Fixed the cloudlayer not using depth buffer.
- Fixed crossfade not working on the HD ST8 ShaderGraph [case 1369586](https://fogbugz.unity3d.com/f/cases/1369586/)

- Fixed range compression factor being clamped. (case 1365707)
- Fixed tooltip not showing on labels in ShaderGraphs (1358483).
- Fix API warnings in Matcap mode on Metal.
- Fix D3D validation layer errors w.r.t shadow textures when an atlas is not used.
- Fixed anchor position offset property for the Light Anchor component. (case 1362809)
- Fixed minor performance issues in SSGI (case 1367144).
- Fixed scaling issues with dynamic resolution and the CustomPassSampleCameraColor function.

### Changed
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
- Changed the max distance for Light Anchors to avoid unstability with high values (case 1362802).
- PrepareLightsForGPU CPU Light loop performance improvement (40% to 70% faster), utilizing burst and optimized. Utilizing better sorting, distributing work in jobs and improving cache access of light data.

## [13.1.0] - 2021-09-24

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