Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Post processing "truns off" camera's solid color alpha

Discussion in 'Shaders' started by S_Thibault, May 31, 2017.

  1. S_Thibault

    S_Thibault

    Joined:
    May 31, 2017
    Posts:
    7
    Hello all !
    I'm having and issue with my render texture and post processing asset from Unity (and also with the camera).

    So, I have 2 Cameras in my game, and one is only rendering my characters. And I want this camera to have post process effect on it. I set up like this:
    My camera's Clear flag is Solid color and is (0,0,0,0)
    It renders into a Render texture
    I apply this render texture to a raw image on my canvas

    it works perfectly, with only my character showing until I had post process behavior and select things like Bloom, Anti-Alliasing and Color Grading. If I activate one of these, it's like there is no more transparency in my solid color, it's always there !

    How can I have Solid Color transparency AND post process at the same time ?

    Thanks a lot !

    Thibault
     
    Inkfish_2017 and Print3d like this.
  2. Print3d

    Print3d

    Joined:
    Oct 22, 2017
    Posts:
    35
    Dannycopo likes this.
  3. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    818
    Hiya, i know its an old thread but there is a fix for this in the Post Processing Stack V1.

    At the end of the PostFX Uber shader it simply returns 1 for alpha, we can sample the original alpha and return that instead. This is the original:

    https://github.com/Unity-Technologi...Processing/Resources/Shaders/Uber.shader#L310

    Just replace it with:

    Code (csharp):
    1. return half4(color, tex2D(_MainTex, uv).a);
    However Anti Aliassing wont work, for FXAA it will clear the alpha again and for TAA it wont render at all. Perhaps you can simply upscale the rendertexture.

    I believe the v2 stack has a fix for this, there are some defines regarding AA and alpha.
     
  4. jake_vr

    jake_vr

    Joined:
    May 21, 2017
    Posts:
    6

    I rarely post here but this was a lifesaver, thanks!
     
    TJHeuvel-net likes this.
  5. FL53

    FL53

    Joined:
    Nov 28, 2018
    Posts:
    14
    It seems there are some configs which enable to get the alpha with PostProcess Stack 2 but I cannot find them.
    I have got a project in which alpha is used (to apply the render texture with Bloom on it to a RawImage/canvas rendered by a non post process camera) and everything works well.
    I did another project with the same configuration for player and quality settings (I hope, I checked and did not see differences but I may have forgotten something) with the elements imported from the previous project. This projects fails to render the texture with alpha on my UI. Have you got any idea to fix that (Uniyt 2019.2 + Post Process Stack 2.1.7) ?
     
  6. Romaleks360

    Romaleks360

    Joined:
    Sep 9, 2017
    Posts:
    69
    yeah i'm also interested
     
  7. FL53

    FL53

    Joined:
    Nov 28, 2018
    Posts:
    14
    Disabling HDR fixed it for me ! Hope this will help.
     
    Romaleks360 likes this.
  8. Romaleks360

    Romaleks360

    Joined:
    Sep 9, 2017
    Posts:
    69
    Can't believe this actually worked, thank you!
    It is also important to set anti-aliasing on Post Process Layer to FXAA and toggle the "Keep Alpha" button.
     
    Last edited: Jan 29, 2020
  9. ycanatilgan

    ycanatilgan

    Joined:
    Aug 23, 2017
    Posts:
    30
    Perfect, thanks!
     
  10. dtaddis

    dtaddis

    Joined:
    Oct 17, 2019
    Posts:
    20
    Thanks so much for this! In URP 10.4.0, the syntax has changed, you'll now want:

    Code (csharp):
    1. return half4(color, SAMPLE_TEXTURE2D_X(_SourceTex, sampler_LinearClamp, uv).a);
     
    pertsi and TJHeuvel-net like this.
  11. yyysukiii

    yyysukiii

    Joined:
    Jun 13, 2020
    Posts:
    8
    It works, thx!
     
    dtaddis likes this.
  12. Jacker

    Jacker

    Joined:
    Jul 16, 2013
    Posts:
    4
    Is there anyone know how can I fix this on v2?
    It looks like all of the solutions are not affectable.
     
  13. RINNUXEI

    RINNUXEI

    Joined:
    Sep 3, 2015
    Posts:
    32
    Hello, I have a similar problem but with v2.
    On v2, and if the platform is iOS or Android, my render texture's alpha lost when post-process layer is enabled. However, if the platform is PC, the alpha just works well.
    Is there any setting we can adjust to make alpha work also in iOS and Android platforms?
     
    dman8723 likes this.
  14. pertsi

    pertsi

    Joined:
    Mar 27, 2015
    Posts:
    1
    This is absolute gold! Thanks so much for this
     
  15. ShowMeMore

    ShowMeMore

    Joined:
    May 20, 2021
    Posts:
    1
    For urp, change PostFX Uber shader works,
    you can do the follow, to force UniversalRendererData use new Uber shader.
    1. create new shader, copy and change Uber shader
    2. cretae new Custom PostProcessData, open it with any text Editor
    3. find " uberPostPS: {fileID: 4800000, guid: .......}", replace guid with your new shader's guid
    3. remember change UniversalRenderData's PostProcessData to your new Custom PostProcessData