Author Topic: Beautify on rarely changing scenes  (Read 157 times)

KorbenDallasMultiPassport

  • Guest
Beautify on rarely changing scenes
« on: February 24, 2021, 07:52:12 AM »
Hi. My question is:
is it possible to re-use precomputed Beatify image effects from previous frame if nothing has changed in the scene? Like, imagine that you decorating a table with different food items and have a stationary camera. So I'd want to re-draw Beautify effects only if something got changed in the scene or while camera is in transition between defined point of views. Or what would you suggest to improve performance? We have Beautify + HBAO now with URP and currently FPS on my Android device is about 7. I've started thinking what if I render entire game to texture and then use it if scene is the same as frame before, but maybe there is a better way to do it?

Thank you! 
« Last Edit: February 24, 2021, 10:20:55 AM by Kronnect »

KorbenDallasMultiPassport

  • Guest
Re: Beautify on rarely changing scenes
« Reply #1 on: February 24, 2021, 09:11:16 AM »
sorry.. should've posted this into Beautify category. ::)

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #2 on: February 24, 2021, 10:27:23 AM »
Hello,

Yes, it's possible although in URP it could be a bit trickier:

1) Create an alternate URP forward renderer which doesn't have the render features.

2) Use a second camera that renders to a render texture to capture the screen. Enable it for just one frame so it captures it and stores that screen to your render texture.

3) Assign the URP forward renderer to the Graphics piipeline setting so no HBAO/Beautify executes.

4) Use the render texture from step 2) as the background of your UI or assign it to the material of a quad that fills the screen.

When you want to restore HBAO/Beautify, just reassign the URP asset with those features.

KorbenDallas

  • Guest
Re: Beautify on rarely changing scenes
« Reply #3 on: March 05, 2021, 10:15:44 AM »
Thank you. It worked!

I also have another question. I want to make an imposter render textures for 3d individual objects in my scene to bake all post processing effects into a texture and then use it as sprite. My current problem is that, when post-processing is enabled on the camera that renders to that texture, the background is not clear. I'm guessing I have to go to render features and custom render passes that are currently used in my project, but I'm not sure what exactly I should look for. I've never did it before. So, to clarify, I want to render just my object + shadow + post-processing effect, but with clear background. Now it's always a solid color whenever I turning a post-processing on. Could you please point me to the right direction if it's possible what I want to do.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #4 on: March 05, 2021, 10:57:03 AM »
I guess it's possible, at least when using cameras that're not "base", but renders on top of the stack (overlay camera). You could ask in the URP public forum of Unity site.
Alternatively, you could write a "chroma key" render feature that basically restores the transparent alpha channel on green or specific colors...

KorbenDallas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #5 on: March 25, 2021, 06:46:04 PM »
Thank you. That worked as well. I've found a Chromakey shader. What I'm doing now to take imposter render textures is I make the camera that is taking this images only see the object that is currently taking with ground object that is using shadow only material at the time the image is being taken. So I'm getting images with shadow with background color which is solid color from camera settings. Then I'm using those textures in RawImages with Chromakey material which removes solid color background. But I'm guessing it runs this chromakey stuff every frame if chromakey material is assigned to RawImage.
I've tried to implement my own ChromakeyFeature with RenderPass that is using that material. It worked, but it looked like it didn't took previous Beautify and HBAO passes into account.
Here is my Execute method:
       
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            _source = _renderer.cameraColorTarget;
            var cmd = CommandBufferPool.Get("Chromakey");
            Blit(cmd, _source, BuiltinRenderTextureType.RenderTexture, _chromakeyMaterial);
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }

I'm not sure if I'm doing the Blit correctly. Never did it before. I've looked at examples in Beautify and came up with this code so far. So the question is how to run this Blit on the result of post-processing, so Beautify and HBAO is already processed?
Aslo, I've got another question about HBAO. Now when I'm taking those imposter render textures when there is nothing behind except ground that is using ShadowOnly shader I'm not getting that HBAO 'soft dark outline' around the object. Is there a way to still make it work even when there nothing visible for the camera in the background?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #6 on: March 26, 2021, 10:06:31 AM »
If you take a look at the render feature script of Beautify, you will find a renderPassEvent property which specifies the injection point of the command buffer. You should specify in your render feature script an injection point which runs after both HBAO and Beautify.
Check renderPassEvent property of the ScriptableRenderPass class:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/api/UnityEngine.Rendering.Universal.ScriptableRenderPass.html

KorbenDallas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #7 on: March 27, 2021, 09:24:05 AM »
Thank you. That worked, but it only looks beautiful in Editor. When I'm playing this on Android the transparent background of RenderTexture which is assigned to RawImage is solid black. Do you happened to know what could possibly causing it?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6869
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #8 on: March 27, 2021, 10:09:15 AM »
Maybe URP is scrapping the alpha channel to reduce bandwidth on mobile and improve performance by using a render texture format that donít use alpha. You should ask in the URP forums or submit a bug report to Unity.

KorbenDallas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Beautify on rarely changing scenes
« Reply #9 on: April 02, 2021, 02:34:38 AM »
I think I could use depth texture to get rid of the solid color as well. So, first take a depth texture, then on render texture, which comes after post processing, make all pixels transparent where corresponding pixel on depth texture is black. Because if it is not black, then it means, that you see geometry and you should leave this pixel on render texture as is. But I donít know how to do that. Is it possible? Sorry it is getting a bit off topic, but really want to solve this.