0
Not a bug

Transparency inside texture problem

Mad Ks 6 years ago updated 6 years ago 5

Hello,

I haven't found any topics with a similar problem to mine so here it is :

- I have tiles in a 2D world. They can contain decorations (resources, placeables...) and some overlay (selection indicator). I'm trying to make a shader that takes a MainTex and 2 optional textures with 2 switches allowing to apply the secondary textures on the main texture.

 - The problem i'm having is that secondary textures have transparency and ShaderForge doesn't seem to be confortable with it. 

As shown in the image, circled in red shows some bleeding in the images with transparency. Also, one of the texture seem to completely remove transparency (the one with black color around it). I checked inside Unity and with an Image Editor to be sure that transparency is present at places where bleeding can be seen. I also checked that the visual result in ShaderForge is the same when the game is launched.

- I'm not sure why it happens but the only possibilities I can see is that it's either a bug, or i'm using ShaderForge wrong.


Am I doing something wrong?

Answer

Answer
Not a bug

Keep in mind that transparency is in the alpha channel, so in this case the transparency isn't applied at all. You'll need to blend based on the alpha channel. The common case is to use a lerp node, with the background in A and the foreground in B, with the foreground alpha channel in the T input of the lerp node.

Answer
Not a bug

Keep in mind that transparency is in the alpha channel, so in this case the transparency isn't applied at all. You'll need to blend based on the alpha channel. The common case is to use a lerp node, with the background in A and the foreground in B, with the foreground alpha channel in the T input of the lerp node.

Sorry, it seems there was a misunderstanding : what i'm saying is that there is no transparency in the alpha channel. I already tried Lerp with plugging Alpha channel in T, but all I got is only the secondary texture painted. Whether I select the secondary texture as Texture Asset or Texture 2D, it deletes the transparency.


When I use the secondary texture as a sprite object inside a Unity scene, it correctly shows transparency, but that does not show properly inside ShaderForge. I imported the image trough drag and drop. All I changed was the PixelPerUnit, everything else was left as is, and was correctly selected by Unity.

Here is another simplified example of what i'm saying :

And below the result, on the right, with, on the left, a simple sprite with a Sprites/Default shader :


You have to connect the alpha channel to either Opacity or Opacity clip to make this work. If you want to get as close to Unity's sprites as possible, start with the 2D/Sprite preset in SF, and then hook it up the way you want it to be.

Thank you for the answer, however I still think there is a bug. After trying to make a simple Lerp, the way I intended to do it, I got a weird result : The shader works as intended, but the nodes don't. This is why I posted this.

Below is the screenshot from ShaderForge showing the problem


As you can see in the image :

 - The mainTex is Lerped with Decoration texture.

 - Decoration texture is transparent around the center but is shown as black with bleeding colors (bug)

 - The Lerp node shows only MainTex although it's T input is plugged inside Alpha channel of Decoration node (bug)

 - The result is as I want it, but the node tree doesn't show the same things. (bug)


I can't think of this as anything but a bug.