Skip to content

Fix custom pass after post process buffer #1072

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
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
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an error when clearing the SSGI history texture at creation time (1259930).
- Fixed alpha to mask reset when toggling alpha test in the material UI.
- Fixed an issue where opening the look dev window with the light theme would make the window blink and eventually crash unity.
- Fixed fallback for ray tracing and light layers (1258837).
- Fixed Sorting Priority not displayed correctly in the DrawRenderers custom pass UI.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down Expand Up @@ -862,6 +864,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Renamed the debug name from SSAO to ScreenSpaceAmbientOcclusion (1254974).
- Added missing tooltips and improved the UI of the aperture control (case 1254916).
- Fixed wrong tooltips in the Dof Volume (case 1256641).
- 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).

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ float4 FullScreenPass(Varyings varyings) : SV_Target

// Load the camera color buffer at the mip 0 if we're not at the before rendering injection point
if (_CustomPassInjectionPoint != CUSTOMPASSINJECTIONPOINT_BEFORE_RENDERING)
color = float4(CustomPassSampleCameraColor(posInput.positionNDC.xy, 0), 1);
color = float4(CustomPassLoadCameraColor(varyings.positionCS.xy, 0), 1);

// Add your custom pass code here

Expand All @@ -98,6 +98,7 @@ In this snippet, we fetch a lot of useful input data that you might need in your
| **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. |
| **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). |
| **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. |
| **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. |

### DrawRenderers Custom Pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
#endif

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

EditorGUI.indentLevel--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static class HDShaderIDs
public static readonly int _CustomDepthTexture = Shader.PropertyToID("_CustomDepthTexture");
public static readonly int _CustomColorTexture = Shader.PropertyToID("_CustomColorTexture");
public static readonly int _CustomPassInjectionPoint = Shader.PropertyToID("_CustomPassInjectionPoint");
public static readonly int _AfterPostProcessColorBuffer = Shader.PropertyToID("_AfterPostProcessColorBuffer");

public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap");
public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
float _CustomPassInjectionPoint;
float _FadeValue;

// This texture is only available in after post process and contains the result of post processing effects.
// While SampleCameraColor still returns the color pyramid without post processes
TEXTURE2D_X(_AfterPostProcessColorBuffer);

float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
{
if (uvGuards)
Expand All @@ -22,6 +26,7 @@ float3 CustomPassSampleCameraColor(float2 uv, float lod, bool uvGuards = true)
// 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;
default: return SampleCameraColor(uv, lod);
}
}
Expand All @@ -34,6 +39,7 @@ float3 CustomPassLoadCameraColor(uint2 pixelCoords, float lod)
// there is no color pyramid yet for before transparent so we can't sample with mips.
case CUSTOMPASSINJECTIONPOINT_BEFORE_TRANSPARENT:
case CUSTOMPASSINJECTIONPOINT_BEFORE_PRE_REFRACTION: return LOAD_TEXTURE2D_X_LOD(_ColorPyramidTexture, pixelCoords, 0).rgb;
case CUSTOMPASSINJECTIONPOINT_AFTER_POST_PROCESS: return LOAD_TEXTURE2D_X_LOD(_AfterPostProcessColorBuffer, pixelCoords, 0).rgb;
default: return LoadCameraColor(pixelCoords, lod);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ internal bool Execute(ScriptableRenderContext renderContext, CommandBuffer cmd,
return false;

Shader.SetGlobalFloat(HDShaderIDs._CustomPassInjectionPoint, (float)injectionPoint);
if (injectionPoint == CustomPassInjectionPoint.AfterPostProcess)
Shader.SetGlobalTexture(HDShaderIDs._AfterPostProcessColorBuffer, targets.cameraColorBuffer);

foreach (var pass in customPasses)
{
Expand Down