lukakldiashvili / URP-Transparent-Distortion-Example

Example Unity URP project, demonstrating distortion(heatwave) effect on opaque and transparent objects
MIT License
24 stars 3 forks source link

Issue with post-processing #2

Open rage2050a opened 1 month ago

rage2050a commented 1 month ago

Hi, I'm learning ScriptableRenderPass and this repository is a great material. I'd really like to integrate this rendering technique to my game.

But I have a problem when I turned on Volume of Post-process Volume in the Demo scene. (I also made Vignette --> Intensity to a large value so we can see the difference clearly)

image

When the distortion is used with post-process, we see the border of the distortion object, even at the position where it is not distorting its background. It looks as though the distortion object is making its background brighter.

I opened the Frame Debugger to investigate.

The 47th event, the _CameraColorTexture is as shown below: image

The 73th event, _AfterPostProcessTexture is as follows: image

The 75th event, _AfterPostProcessTexture is as follows: image

It looks like the border color of the distortion objects come from _CameraColorTexture which is before applying post-process. It is no wonder as the injection point of the feature is set to BeforeRenderingPostProcessing and the DistortionPass.cs takes cameraData.renderer.cameraColorTarget as its source.

I tried various combination of Injection Point of the Distortion Feature and Event of Distortion Render Objects, but didn't get the expected result -- I'd like (1)the transparent red cube is rendered and nicely distorted (2)color of the pixels are post-processed after distortion.

Could you please suggest something so that the distortion works well with post-processing?

lukakldiashvili commented 1 month ago

Hi, thank you for expressing your interest and opening the issue. After a little bit of tinkering, the way I got it working is by enabling "Native RenderPass" and adding new injection point for Distortion Texture (AfterRenderingTransparents).

Here is the settings:

image

I wish I could elaborate more about the solution, but I do not have time to look into it right now. Hope this helps you to continue your research and I will be happy to see and read your findings, if any.

rage2050a commented 1 month ago

Thank you for the reply. I think I've done what you suggest, but it doesn't work. The distortion objects are all painted black with the setting. (Using Unity 2023)

image

Hmm... I don't know why it doesn't work. Your setting look correct to me -- blitting the full screen texture just after rendering transparent objects, and render the distortion objects using the texture before post-processing.

Well, probably my game (https://x.com/NekoBeko2024) doesn't necessarily need post-processing that changes color. I'll keep the previous version of the distortion effect.

Anyway, thank for your time.

lukakldiashvili commented 1 month ago

No problem. Could be the issue with the version of URP, I'll try it with newer versions of Unity sometime later.