Skip to content

Commit c01d193

Browse files
Antoine Lelievresebastienlagarde
authored andcommitted
Fix custom pass after post process buffer #1072
1 parent c650892 commit c01d193

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
### Fixed
1010
- Pre-warm the RTHandle system to reduce the amount of memory allocations and the total memory needed at all points.
1111
- Appropriately constraint blend distance of reflection probe while editing with the inspector (case 1248931)
12+
- Fixed fallback for ray tracing and light layers (1258837).
13+
- Fixed Sorting Priority not displayed correctly in the DrawRenderers custom pass UI.
14+
15+
### Changed
16+
- The `CustomPassLoadCameraColor` and `CustomPassSampleCameraColor` functions now returns the correct color buffer when used in after post process instead of the color pyramid (which didn't had post processes).
1217

1318
## [7.4.3] - 2020-08-06
1419

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ float4 FullScreenPass(Varyings varyings) : SV_Target
7979
8080
// Load the camera color buffer at the mip 0 if we're not at the before rendering injection point
8181
if (_CustomPassInjectionPoint != CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING)
82-
color = float4(CustomPassSampleCameraColor(posInput.positionNDC.xy, 0), 1);
82+
color = float4(CustomPassLoadCameraColor(varyings.positionCS.xy, 0), 1);
8383
8484
// Add your custom pass code here
8585
@@ -98,6 +98,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your
9898
| **Sampling the camera color with lods is only available in after and before post process passes**. Calling `CustomPassSampleCameraColor` at before rendering will only return black. |
9999
| **DrawRenderers Pass chained with FullScreen Pass**: In multi-pass setups where you draw objects in the camera color buffer and then read it from a fullscreen custom pass, you'll not see the objects you've drawn in the passes before your fullscreen pass (unless you are in Before Transparent). |
100100
| **MSAA**: When dealing with MSAA, you must check that the `Fetch color buffer` boolean is correctly setup because it will determine whether or not you'll be able to fetch the color buffer in this pass or not. |
101+
| **Before Pre-Refraction and After post-process**: On these injection points, the camera color buffer set as the target for the fullscreen pass is the same as the one you can access inside the shader. Because the camera color buffer is the target, and because of read/write restrictions on certain platforms, you cannot directly sample from the camera color buffer inside the shader. Instead, you need to split your effect into two passes and use the custom color buffer as an intermediate buffer. This avoids reading and writing simultaneously to the same buffer. |
101102

102103
### DrawRenderers Custom Pass
103104

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/CustomPass/DrawRenderersCustomPassDrawer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
161161
#endif
162162

163163
// TODO: remove all this code when the fix for SerializedReference lands
164+
m_SortingCriteria.intValue = (int)(SortingCriteria)EditorGUI.EnumFlagsField(rect, Styles.sortingCriteria, (SortingCriteria)m_SortingCriteria.intValue);
164165
// EditorGUI.PropertyField(rect, m_SortingCriteria, Styles.sortingCriteria);
165166
m_SortingCriteria.intValue = (int)(SortingCriteria)EditorGUI.EnumPopup(rect, Styles.sortingCriteria, (SortingCriteria)m_SortingCriteria.intValue);
166167
rect.y += Styles.defaultLineSpace;

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ static class HDShaderIDs
445445
public static readonly int _CustomDepthTexture = Shader.PropertyToID("_CustomDepthTexture");
446446
public static readonly int _CustomColorTexture = Shader.PropertyToID("_CustomColorTexture");
447447
public static readonly int _CustomPassInjectionPoint = Shader.PropertyToID("_CustomPassInjectionPoint");
448+
public static readonly int _AfterPostProcessColorBuffer = Shader.PropertyToID("_AfterPostProcessColorBuffer");
448449

449450
public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap");
450451
public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap");

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
float _CustomPassInjectionPoint;
1111
float _FadeValue;
1212

13+
// This texture is only available in after post process and contains the result of post processing effects.
14+
// While SampleCameraColor still returns the color pyramid without post processes
15+
TEXTURE2D_X(_AfterPostProcessColorBuffer);
16+
1317
float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
1418
{
1519
if (uvGuards)
@@ -22,6 +26,7 @@ float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
2226
// 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
2327
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT:
2428
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;
2530
default: return SampleCameraColor(uv, lod);
2631
}
2732
}
@@ -34,6 +39,7 @@ float3 CustomPassLoadCameraColor(uint2 pixelCoords, float lod)
3439
// there is no color pyramid yet for before transparent so we can't sample with mips.
3540
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT:
3641
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return LOAD_TEXTURE2D_X_LOD(_ColorPyramidTexture, pixelCoords, 0).rgb;
42+
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return LOAD_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, pixelCoords, 0).rgb;
3743
default: return LoadCameraColor(pixelCoords, lod);
3844
}
3945
}

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassVolume.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd,
8888
return false;
8989

9090
Shader.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)injectionPoint);
91+
if (injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
92+
Shader.SetGlobalTexture(HDShaderIDs._AfterPostProcessColorBuffer, targets.cameraColorBuffer);
9193

9294
foreach (var pass in customPasses)
9395
{

0 commit comments

Comments
 (0)