Arvtesh / UnityFx.Outline

Screen-space outlines for Unity3d.
MIT License
1.26k stars 90 forks source link

[URP] OutlinePass doesn't restore default render targets which break further rendering #54

Open STARasGAMES opened 2 years ago

STARasGAMES commented 2 years ago

To fix this I modified OutlinePass.cs at line ~106

cmd.SetRenderTarget(_renderer.cameraColorTarget, _renderer.cameraDepthTarget); // added line
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

For such a small fix, I don't want to make a pull request, please forgive my laziness :)

P.S. Most likely this line should be placed in a few more places to cover all setting combinations, but for my situation it solves the issue.

Thanks again for your excellent work on this project. It's a blessing to read well-structured code

Arvtesh commented 2 years ago

Thanks for the report!

Arvtesh commented 2 years ago

Hm, I'm actually not sure if this is something worth doing. Standard URP render features don't seem to have any code that restores default render target. Instead, each render pass sets its own render target. @STARasGAMES could you share details of your use-case please?

STARasGAMES commented 2 years ago

Hi @Arvtesh Yes, sure. So, I have Outline as a first feature, then goes URP's built-in Render Objects feature image

This is how it looks without outline: image

And that's how it looks with: image

Notice broken gun rendering. This happens because there is no depth target currently active which leads to completely ignoring ZTest: image (at least frame debugger indicates that there is no depth target)

But if there is no outline pass before rendering the gun, then we can see the depth target and image renders correctly. image

Adding the line, that reverts to default render targets fixes this issue.