Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question 2DRenderer with lit shaders seems to give alpha/transparency issues in Render Textures

Discussion in '2D Experimental Preview' started by HuldaGnodima, Dec 2, 2021.

  1. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Hi!

    I'm currently using the 2D-experimental Renderer together with a character animated with the awesome 2DAnimation.

    What I'm trying to achieve: My character has a custom Lit Shader material. I wanted to capture my character with a Render Texture + a Camera to use her as a poritrait in UI, to do this someone suggested I use a Render Texture on a camera. I have done so and it works nicely.

    The Issue: However, there seems to be a strange bug going on with Lit Shaders. When I'm using the Render Texture to capture my 2DAnimated character, areas around her sprite-parts get dark lines. There seems to be some kind of transparency-issue. You can see what's happening here:



    What I tried: Wondering what could be causing this I tried changing her shader. First I tried the "Sprite-Lit-Default" materials (her colors are beige, ignore that, it's her default color) she still has these artefacts, see here:


    But if I give all her parts the "Sprite-Default" they more or less dissappear (she does have pink that shines through around her lips/Eyes though)


    Note how she looks mostly fine it the "Default-Sprite" material (transparency artefacts gone?)

    Could it be something with the 2DExperimental renderer I'm using? Could it be caused by the Lit-shader-functionality together with a Render Texture? Outside the Render Texture she looks perfect!
    Does anyone know how to fix this? Any help is greatly appreciated!

    Thanks so much in advance!
     
  2. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    To anyone who finds this thread in the future, I think I found a solution! At least, it looks perfect now
    I went into the Render Texture I'm using to render my 2d character on a camera and chose Color Format "B5G5R5A1_UNORM_PACK16". This mode made all artefacts dissappear! See below:



    Imortant to note here is that I don't know at all why it works, if it's a "performance heavy" Color Format or if it has other issues. But it currently works and I'm now using it! :)

    Hope this helps someone in the future!
     
  3. TheCrackerSnacker

    TheCrackerSnacker

    Joined:
    Oct 14, 2022
    Posts:
    1
    Sorry on the necro, but to those who might view this in the future, the problem with his solution is that it removes all pixels with partial alpha, (which is why the color mode says that alpha has only one bit, on or off). So that is the main problem with his solution.