Skip to content

Commit 9ae6727

Browse files
[HDRP] Add custom pass buffer scaling functions (#5809)
* Add functions to sample/load custom buffer for custom pass * Updated changelog * Updated changelog * Fix scaling issues with dynamic res * Update CHANGELOG.md * Fix custom pass sampling functions * Fix after post scaling * Update CHANGELOG.md Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 3f9a96b commit 9ae6727

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
### Added
1010
- Added support for orthographic camera in path tracing.
1111
- Added public API to edit materials from script at runtime.
12-
13-
### Changed
14-
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
15-
- Changed the max distance for Light Anchors to avoid unstability with high values (case 1362802).
16-
- 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.
12+
- Added new functions that sample the custom buffer in custom passes (CustomPassSampleCustomColor and CustomPassLoadCustomColor) to handle the RTHandleScale automatically.
1713

1814
### Fixed
1915
- Fixed decal position when created from context menu. (case 1368987)
@@ -27,13 +23,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2723
- Fixed depth pyramid being incorrect when having multiple cameras (scene view and gameview) and when hardware DRS was activated.
2824
- Fixed the cloudlayer not using depth buffer.
2925
- Fixed crossfade not working on the HD ST8 ShaderGraph [case 1369586](https://fogbugz.unity3d.com/f/cases/1369586/)
30-
3126
- Fixed range compression factor being clamped. (case 1365707)
3227
- Fixed tooltip not showing on labels in ShaderGraphs (1358483).
3328
- Fix API warnings in Matcap mode on Metal.
3429
- Fix D3D validation layer errors w.r.t shadow textures when an atlas is not used.
3530
- Fixed anchor position offset property for the Light Anchor component. (case 1362809)
3631
- Fixed minor performance issues in SSGI (case 1367144).
32+
- Fixed scaling issues with dynamic resolution and the CustomPassSampleCameraColor function.
33+
34+
### Changed
35+
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
36+
- Changed the max distance for Light Anchors to avoid unstability with high values (case 1362802).
37+
- 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.
3738

3839
## [13.1.0] - 2021-09-24
3940

com.unity.render-pipelines.high-definition/Documentation~/Custom-Pass-Creating.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ You can also load custom buffers using the following functions:
463463
- `LoadCustomColor(uint2 pixelCoords)`
464464
- `LoadCustomDepth(uint2 pixelCoords)`
465465

466+
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:
467+
468+
- `CustomPassSampleCustomColor(float2 uv)`
469+
- `CustomPassLoadCustomColor(uint2 pixelCoords)`
470+
466471
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.
467472

468473
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:

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/CustomPassFullScreenShader.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Shader "FullScreen/#SCRIPTNAME#"
2323
// To sample custom buffers, you have access to these functions:
2424
// But be careful, on most platforms you can't sample to the bound color buffer. It means that you
2525
// can't use the SampleCustomColor when the pass color buffer is set to custom (and same for camera the buffer).
26-
// float4 SampleCustomColor(float2 uv);
27-
// float4 LoadCustomColor(uint2 pixelCoords);
26+
// float4 CustomPassSampleCustomColor(float2 uv);
27+
// float4 CustomPassLoadCustomColor(uint2 pixelCoords);
2828
// float LoadCustomDepth(uint2 pixelCoords);
2929
// float SampleCustomDepth(float2 uv);
3030

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
2424
case CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING: return float3(0, 0, 0);
2525
// there is no color pyramid yet for before transparent so we can't sample with mips.
2626
// 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
27-
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT:
28-
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
29-
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return SAMPLE_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
27+
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScaleHistory.xy, 0).rgb;
28+
case CUSTOMPASSINJECTIONPOINT_BEFORE_POST_PROCESS:
29+
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, uv * _RTHandleScale.xy, 0).rgb;
30+
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return SAMPLE_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, s_trilinear_clamp_sampler, uv * _RTHandleScale.zw, 0).rgb;
3031
default: return SampleCameraColor(uv, lod);
3132
}
3233
}
@@ -44,6 +45,20 @@ float3 CustomPassLoadCameraColor(uint2 pixelCoords, float lod)
4445
}
4546
}
4647

48+
float4 CustomPassSampleCustomColor(float2 uv)
49+
{
50+
switch ((int)_CustomPassInjectionPoint)
51+
{
52+
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return LOAD_TEXTURE2D_X_LOD(_CustomColorTexture, uv * _ScreenSize.xy, 0);
53+
default: return SampleCustomColor(uv);
54+
}
55+
}
56+
57+
float4 CustomPassLoadCustomColor(uint2 pixelCoords)
58+
{
59+
return LoadCustomColor(pixelCoords);
60+
}
61+
4762
struct Attributes
4863
{
4964
uint vertexID : SV_VertexID;

0 commit comments

Comments
 (0)