Search Unity

Camera to RenderTexture dont remove background

Discussion in 'High Definition Render Pipeline' started by Benmaster, Jan 26, 2020.

  1. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    Im trying to reproduce the same effect for a character portrait, that allow me the Default render pipeline, but in HDRP I cant get it working correctly.

    In the old render system, I Create a camera, parent with the model, "Clear Flags"=Solid Color, "Background"=0,0,0,0,0, "Culling Mask"=Default, and set the camera to see only what you want, this allow me to see the character without background (well with black, and later apply a mask to remove)
    In this case the "Clear Flags" do the trick.

    But with HDRP i dont get this working. I play many combination with the Culling Mask and Volume Mask layer, but I only get 2 wrong cases:
    - My camera render only the character, AND render the background (the HDRR Sky or whatever I have in scene background)
    - My camera render a black background, but the character is "white" like is masked incorrectly.

    I try with Camera Background "None" but this cause the superior part of the render image to be half transparent and see trought the UI the part full transparent (weird effect)

    maybe is there a hidden option to remove the scene sky from the camera?

    EDIT: More details, the issue is the "Sky and fog volume" if I do this:
    - Set the "Sky and Fog Volume" Layer to "Sky"
    - Culling Mask: Player layer
    - Volume Layer Mask: All except "Sky"
    - Set the layer in the Culling Mask and Volume Layer Mask in the main camera.

    This make the main camera continue render the effects correctly, but the portrait render is incorrect, appear a black background, but the character in white, with many bloom, maybe the issue is somethin in the HDRP options.
     
    Last edited: Jan 28, 2020
  2. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    After many research and time lost I get already the black background image, the trick is the Post Procesing Volume.
    - Create a new empty gameobject, add a new Volume and create a new empty post processing volume inside.
    - Set this volume near the character portraits and cameras.
    - Set a boxCollider to this volume, and maximize the collider to cover all portrair elements (lights, character models, cameras, etc), set the Volume as "local" to use the box collider to apply that effects to only object inside the collider.
    - Set all this in separated Layer (create one specific and change for all element inside this Volume collider.

    Now I have the character with black background, but now im unable to remov that background from the render texture.
    For regular RenderPipeline, yo can add a Mask, set to 255.255.255.1, and put the renderTexture as children of this mask, and the background is removed, now with HDRP this dont work...

    WORKING:
    After many many crawling over internet, and read many many fixed that dont work with HDRP and unity 2019.3.x i found how to get the transparent background.

    - Check if HDRP is over 7.1.1 and Unity 2019.3.4b
    - Check if now the rendertexture have some "A" alpha options to select.
    - Set HDRP asset "Color Buffer Format" to use "R16G16B16A16" Everything works now. (Project Setting -> Quality -> HDRP)
    - Set the render texture to R16G116B16A16_UNIFORM
    - Are you using a RenderPipelineAsset? Check if the "Opaque texture" checkbox is checked. If you want to keep it on its ok, yoo can override that configuration per camera. Make sure that the camera that is rendering the cube has that optin set to "Off".

    The main trick was change the "Color Buffer Format" to get rgbA renderTexture
    Hope this help people in the future.
     
    Last edited: Feb 5, 2020
  3. Krzysztof_Poros

    Krzysztof_Poros

    Joined:
    Feb 13, 2020
    Posts:
    4
    You just saved my day :)
     
  4. Elsiehar

    Elsiehar

    Joined:
    Mar 2, 2021
    Posts:
    3
    OMG, thank you. :) Your pain was definitely my gain. This has been driving me nuts!
     
  5. projectorgames_unity

    projectorgames_unity

    Joined:
    Oct 15, 2018
    Posts:
    107
    +1 for this. I couldn't work out why my UI Camera was causing such weirdness when stacked above the main camera.
     
  6. WalnutBat

    WalnutBat

    Joined:
    Dec 5, 2021
    Posts:
    1
    Not all heroes wear capes