Skip to content

[HDRP][Compositor] Fix errors when resizing the compositor's output #2118

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 1 commit into from
Oct 7, 2020
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 @@ -137,6 +137,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix decal being applied twice with LOD Crossfade.
- Fixed camera stacking for AOVs in the graphics compositor (case 1273223).
- Disable quad overdraw on ps4.
- Fixed error when resizing the graphics compositor's output and when re-adding a compositor in the scene

### Changed
- Preparation pass for RTSSShadows to be supported by render graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ static public void RemoveAudioListeners(Camera camera)

static public void SetDefaultCamera(CompositionManager compositor)
{
var camera = CompositionManager.GetSceceCamera();
if (camera != null)
// Create a new camera for the compositor's output
var newCameraGameObject = new GameObject(k_DefaultCameraName);
var camera = newCameraGameObject.AddComponent<Camera>();
{
var outputCamera = Object.Instantiate(camera);
RemoveAudioListeners(outputCamera);
outputCamera.name = k_DefaultCameraName;
outputCamera.tag = "Untagged";
outputCamera.cullingMask = 0; // we don't want to render any 3D objects on the compositor camera
compositor.outputCamera = outputCamera;
camera.tag = "Untagged";
camera.cullingMask = 0; // we don't want to render any 3D objects on the compositor camera
}
newCameraGameObject.AddComponent<HDAdditionalCameraData>();
compositor.outputCamera = camera;
}

static public void SetDefaultLayers(CompositionManager compositor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public float aspectRatio
[SerializeField] Camera m_LayerCamera;

// Returns true if this layer is using a camera that was cloned internally for drawing
bool isUsingACameraClone => !m_LayerCamera.Equals(m_Camera);
internal bool isUsingACameraClone => !m_LayerCamera.Equals(m_Camera);

// The input alpha will be mapped between the min and max range when blending between the post-processed and plain image regions. This way the user can controls how steep is the transition.
[SerializeField] float m_AlphaMin = 0.0f;
Expand Down Expand Up @@ -266,7 +266,11 @@ public void Init(string layerID = "")

if (m_OutputTarget != OutputTarget.CameraStack && m_RenderTarget == null)
{
m_RenderTarget = new RenderTexture(pixelWidth, pixelHeight, 24, (GraphicsFormat)m_ColorBufferFormat);
// If we don't have a valid camera (zero width or height) avoid creating the RT
if (pixelWidth > 0 && pixelHeight > 0)
{
m_RenderTarget = new RenderTexture(pixelWidth, pixelHeight, 24, (GraphicsFormat)m_ColorBufferFormat);
}
}

// check and fix RT handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public bool enableOutput
// also change the layers
foreach(var layer in m_InputLayers)
{
if (layer.camera)
if (layer.camera && layer.isUsingACameraClone)
{
layer.camera.enabled = value;
}
Expand Down Expand Up @@ -351,10 +351,25 @@ public void OnEnable()

public void DeleteLayerRTs()
{
int numRTReferences = 0;

// delete the layer from last to first, in order to release first the camera and then the associated RT
for (int i = m_InputLayers.Count - 1; i >= 0; --i)
{
m_InputLayers[i].DestroyRT();
// Since some layers are not useing cloned cameras, we have to count the number of references in a RT and only delete if it is zero
if (numRTReferences == 0)
{
m_InputLayers[i].DestroyRT();
}

if (m_InputLayers[i].outputTarget == CompositorLayer.OutputTarget.CompositorLayer)
{
numRTReferences = 0;
}
else
{
numRTReferences += (m_InputLayers[i].camera != null) ? 1 : 0;
}
}
}

Expand Down Expand Up @@ -522,11 +537,7 @@ void Update()

void OnDestroy()
{
// We need to destroy the layers from last to first, to avoid releasing a RT that is used by a camera
for (int i = m_InputLayers.Count - 1; i >= 0; --i)
{
m_InputLayers[i].Destroy();
}
DeleteLayerRTs();

if (m_CompositorGameObject != null)
{
Expand Down Expand Up @@ -804,6 +815,11 @@ void CustomRender(ScriptableRenderContext context, HDCamera camera)
/// <returns>Returns true if this camera is used to render in more than one layer</returns>
internal bool IsThisCameraShared(Camera camera)
{
if (camera == null)
{
return false;
}

int count = 0;
foreach (var layer in m_InputLayers)
{
Expand Down