Skip to content

[HDRP] Fix issue with compositor related custom passes #3055

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 10 commits into from
Jan 15, 2021
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
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed spacing of UI widgets in the Graphics Compositor (case 1305638).
- Fixed undo-redo on layered lit editor.
- Fixed tesselation culling, big triangles using lit tesselation shader would dissapear when camera is too close to them (case 1299116)
- Fixed issue with compositor related custom passes still active after disabling the compositor (case 1305330)

### Changed
- Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public override void Setup()
var hdrpAsset = HDRenderPipeline.defaultAsset;
if (hdrpAsset != null)
m_Material = CoreUtils.CreateEngineMaterial(hdrpAsset.renderPipelineResources.shaders.alphaInjectionPS);

name = "AlphaInjection"; // Needed to get a scope name in RenderDoc captures
}

public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public override void Setup()
var hdrpAsset = HDRenderPipeline.defaultAsset;
if (hdrpAsset != null)
m_Material = CoreUtils.CreateEngineMaterial(hdrpAsset.renderPipelineResources.shaders.chromaKeyingPS);

name = "ChromaKeying"; // Needed to get a scope name in RenderDoc captures
}

public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public bool enableOutput
{
m_OutputCamera.enabled = value;

// also change the layers
// Aside from the output compositor camera, we also have to change the cameras of the layers
foreach (var layer in m_InputLayers)
{
if (layer.camera && layer.isUsingACameraClone)
Expand All @@ -72,11 +72,22 @@ public bool enableOutput
}
else
{
// The target texture was managed by the compositor, reset it so the user can se the camera output
// The target texture was managed by the compositor, reset it so the user can see the camera output
if (layer.camera && value == false)
layer.camera.targetTexture = null;
}
}

// Toggle the compositor-related custom passes
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (value)
{
RegisterCustomPasses(hdPipeline);
}
else
{
UnRegisterCustomPasses(hdPipeline);
}
}
}
}
Expand Down Expand Up @@ -186,19 +197,7 @@ bool ValidatePipeline()
m_AlphaSupport = AlphaChannelSupport.Rendering;
}

int indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(ChromaKeying).AssemblyQualifiedName);
if (indx < 0)
{
//Debug.Log("Registering chroma keying pass for the HDRP pipeline");
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(ChromaKeying).AssemblyQualifiedName);
}

indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(AlphaInjection).AssemblyQualifiedName);
if (indx < 0)
{
//Debug.Log("Registering alpha injection pass for the HDRP pipeline");
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(AlphaInjection).AssemblyQualifiedName);
}
RegisterCustomPasses(hdPipeline);
return true;
}
return false;
Expand Down Expand Up @@ -920,5 +919,48 @@ static internal RenderTexture GetClearDepthForStackedCamera(HDCamera hdCamera)
}
return null;
}

// Register the custom pp passes used by the compositor
static internal void RegisterCustomPasses(HDRenderPipeline hdPipeline)
{
if (hdPipeline == null)
{
return;
}

// If custom post processes are not registered in the HDRP asset, they are never executed so we have to add them manually
int indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(ChromaKeying).AssemblyQualifiedName);
if (indx < 0)
{
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(ChromaKeying).AssemblyQualifiedName);
}

indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(AlphaInjection).AssemblyQualifiedName);
if (indx < 0)
{
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(AlphaInjection).AssemblyQualifiedName);
}
}

// Unregister the custom pp passes used by the compositor
static internal void UnRegisterCustomPasses(HDRenderPipeline hdPipeline)
{
if (hdPipeline == null)
{
return;
}

int indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(ChromaKeying).AssemblyQualifiedName);
if (indx >= 0)
{
hdPipeline.asset.beforePostProcessCustomPostProcesses.Remove(typeof(ChromaKeying).AssemblyQualifiedName);
}

indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(AlphaInjection).AssemblyQualifiedName);
if (indx >= 0)
{
hdPipeline.asset.beforePostProcessCustomPostProcesses.Remove(typeof(AlphaInjection).AssemblyQualifiedName);
}
}
}
}