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

Question URP full window partial transparency

Discussion in 'Universal Render Pipeline' started by polerin, Sep 3, 2020.

  1. polerin

    polerin

    Joined:
    Apr 11, 2013
    Posts:
    11
    ( tl;dr ) Can you correctly access pixel alpha values in URP shaders in order to render correct transparency in a win10 transparent window. (I guess? Unless there's a better way to handle this?)

    I'm working on a unity obs integration for twitch streaming, and I'm running into a bit of a frustrating limitation. I want to be able to render a window with transparency, so I can capture it and compose the shot using obs. Ideally, this requires both fully transparent backgrounds and partial transparency for things like particle effects and aliased edges around the edges where foreground items meet the background.

    I've seen two basic solutions that gives me fully "transparent" backgrounds, but nothing that would handle partial transparency. I put transparent in scare quotes because one of them is basically just setting a solid color for the background and using chroma keying to remove it in obs. This works, but doesn't allow for partial shading, and means that no effects can have any kind of gradient or aliased edges as it will have visual defects. The second version of that is basically doing the same thing in unity itself using a shader to compare a the pixel RGB delta to the chroma key color and if it falls under a value rendering rgba(0,0,0,0).

    In other places in the forums and documentation, it seems that the HDRP (and later the URP) do not respect the value of the alpha channel, reserving it as a pathway for other kinds of information. This seems like it will make any kind of nuanced transparency impossible using the URP.

    Hopefully I'm wrong?

    halp.
     
  2. polerin

    polerin

    Joined:
    Apr 11, 2013
    Posts:
    11
    Bump?

    Any leads at all on this would be helpful
     
  3. Megalon2D

    Megalon2D

    Joined:
    Nov 29, 2015
    Posts:
    8
    Were you able to figure this out?

    I am having the same problem.

    I have a similar overlay project that uses the builtin pipeline with the camera background set to a solid color with the alpha set to zero. This worked fine with OBS by using a Game Capture and enabling the "Allow Transparency" option. I am now trying to update to URP, and the previous method does not work anymore. The background is completely opaque.
     
  4. cw6394

    cw6394

    Joined:
    Jan 23, 2017
    Posts:
    2
    I'm having the same problem too.
    Seems the URP ForwardRenderer writes 1s to alpha channel regardless of background color's alpha value.
     

    Attached Files:

    Last edited: Jul 5, 2021
  5. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    191
    The ForwardRenderer writes 1 to alpha channel if you are rendering to the framebuffer. If you are rendering to a renderTexture, the alpha gets saved in the renderTexture. URP utilizes heavily on renderTextures for effects (and fixing AA). You might want to try and output the renderTexture for capture instead of the framebuffer.
     
  6. BennyKokMusic

    BennyKokMusic

    Joined:
    Dec 22, 2016
    Posts:
    33
    Was also trying to get URP working with a transparent window, looking at the frame debugger, seems like turning off HDR, AA etc, will preserve the alpha value.

    upload_2021-8-15_18-43-44.png
     
  7. FinleyOderSo

    FinleyOderSo

    Joined:
    Mar 31, 2019
    Posts:
    5
    It works for me when I disable HDR. If anyone knows a way that doesn't come with this drawback, please share it.
     
  8. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    313
  9. sureacd

    sureacd

    Joined:
    Jun 7, 2022
    Posts:
    6
  10. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    313
  11. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hey, you can already achieve transparent shadows in custom shader graphs by clipping pixels (link dither node to the alpha cutout output) only in the shadow caster pass. You may refer to this thread (doing the opposite things).
     
  12. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    313
    Dithered was mentioned in this thread of mine aswel... https://forum.unity.com/threads/urp...-even-supported-anymore.1045252/#post-8253321

    still a whole of bunch of extra steps just to try and get subpar dithered shadows that aren't even smoothed... its a bit lame for 2023 URP.. when Built In atleast had smooth transparent shadows and none of those extra steps required to achieve it, still no sign of it on the roadmap.... surprised developers are making games with such basic shadows or they have some graphics people on the team to improve it.. but shaders is the lowest priority for me ..I still find it to be an overcomplicated mess URP/HDRP and wish they'd just merge them into one again with better scaling for pc/mobile..
     
    wwWwwwW1 likes this.