Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Porting unity-frosted-glass effect to LWRP

Discussion in 'Universal Render Pipeline' started by Shin_S, Jul 18, 2019.

  1. Shin_S

    Shin_S

    Joined:
    Jan 22, 2015
    Posts:
    14
    Hello guys,

    I saw that wonderful effect unity-frosted-glass (github.com/andydbc/unity-frosted-glass) from @andydbc after some research on how to do a nice frosted blur effect on Unity.

    Unfortunately I'm struggling to port this effect on LWRP because I'm not well versed in the rendering pipeline.
    The hard task seems to be porting the work done by the CommandBufferBlur.cs and I'm completely lost in converting the core of this script using the new Custom Forward Renderer feature of the SRP as it seems to be the only efficient way to get that precious camera render texture I need to blur what's behind my object :(

    I hoped the LWRPRenderPass example library (github.com/UnityTechnologies/LWRPScriptableRenderPass_ExampleLibrary) from @Andy-Touch would help, but it's broken since 2019.1 as things changed and some interfaces disapeared.

    I've also watched the really cool Introduction to the LWRP from the GDC 2019, but the last version of the LWRP package some of the scripts used in the video were still missing (like the Blit renderer feature).
    I've found it in this thread about supporting grabpass in LWRP, and that post (forum.unity.com/threads/the-scriptable-render-pipeline-how-to-support-grabpass.521473/#post-4584883) from @phil_lira left me pretty confused as he says that it can be achieved quite easily with the tools that unity already provides but I can't figure out how to use them the right way...

    Can someone help me with this?

    Thanks you in advance :)

    PS: Unity version 2019.1+ and it must work on mobiles and VR
    PS2: Links make my post being blocked for spam :/
     
    Last edited: Jul 18, 2019
  2. Shin_S

    Shin_S

    Joined:
    Jan 22, 2015
    Posts:
    14
    ...or, if it's a bit too much asking, if someone knows how I can retrieve the camera render texture using on the LWRP with the ScriptableRendererFeature and ScriptableRenderPass and pass it to a shader that will render it on a plane, it would be enough for me (i hope) to implement the blur after.

    Thank you for your time :)
     
  3. Shin_S

    Shin_S

    Joined:
    Jan 22, 2015
    Posts:
    14
    In case someone's facing the same issue, I discovered a usefull Shader Graph node called Scene Color that, if you enable the Opaque Texture checkbox into your LWRP asset, will give you the camera image (as colors) and allow you to apply whatever effect you can make on it.
    I'm not done yet in reproducing the frosted glass effect from the initial @andydbc project, and I don't know if it will be efficient enough to work on mobile, but I'll try my best :D

    Note : Seems like the scene color node is here for quite a long time now (several months) and I don't know why it's so hard to find its existence as it appears to be an amazing and "must know" tool.
     
    Last edited: Jul 22, 2019
  4. Discipol

    Discipol

    Joined:
    May 6, 2015
    Posts:
    83
    Hi Shin_S ! Did you manage to get that shader working? I tried multiple things and only screenshooting the screen before enabling the "blurred layer" + blur shader over a texture, which prevents me from having things moving in the background; Looking for a dynamic solution and I found your post; Any luck?
     
  5. Shin_S

    Shin_S

    Joined:
    Jan 22, 2015
    Posts:
    14
    I finally managed to achieve an equivalent to the GrabPass in URP. This method helped me to reproduce the frosted glass effect in UniveralRP but I'll stick with a simple project here to demonstrate how to retrieve the camera rendertexture in a RendererFeature, then expose this texture globally for it to be accessible from any shader. This way you can prepare the texture to do many things like downscale it then use it inside a smoothing shader to achieve a blur effect.

    To test this, you just need to :
    1. Create a new Unity 2019.3.x - 3D project
    2. Then install the Universal RP package from the Package Manager
    3. Next open and extract this UnityPackage joined with this post.
    4. Finally go to Edit > Project Settings > Graphics, and set the UniversaleRenderPipeline_Asset you imported from the package in the "Scriptable Render Pipeline Settings" field.
    Now you can open the GrabSampleScene to watch a simple quad receive the render texture of the camera and twirling. This quad has a GrabReceiver material on it.

    You can also look into the GrabReceiver shader graph and notice that the GrabTexture property is referencing _GrabTexture like the ShaderProperty we exposed from the GrabRendererFeature, is used and processed to achieve a uv twirl effect.

    Extract of the interesting code of the GrabRendererFeature:
    Code (CSharp):
    1. // Create a temporary RenderTexture with the size of the screen
    2. int screenCopyId = Shader.PropertyToID("_ScreenCopy");
    3. cmd.GetTemporaryRT(screenCopyId, (int)Screen.width, (int)Screen.height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);
    4.  
    5. // Blit the currently active RenderTexture into the temporary one we created above
    6. cmd.Blit(BuiltinRenderTextureType.CameraTarget, screenCopyId);
    7.  
    8. // Set the ScreenCopy texture accessible globally in shaders from the GrabTexture ID
    9. cmd.SetGlobalTexture(Shader.PropertyToID("_GrabTexture"), screenCopyId);
    I hope this will help.
     

    Attached Files:

    Discipol likes this.
  6. TyroByte

    TyroByte

    Joined:
    Mar 16, 2017
    Posts:
    25
    Do you mind sharing how this was incorporated into the blur shader from the github repo? I used this effect back in unity 2017.4 LTS and now that I upgraded my project to unity 2019.4 LTS, I'm having trouble seeing as to how this could be used for the frosted glass shader itself.

    Thanks a bunch!
     
  7. etiennepinchon

    etiennepinchon

    Joined:
    May 16, 2018
    Posts:
    8
    Up, same here :(