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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Strange alpha transparency behavior based on sprite texture

Discussion in 'Shader Graph' started by bruce_c, Nov 10, 2022.

  1. bruce_c

    bruce_c

    Joined:
    Oct 22, 2022
    Posts:
    2
    Hello, I'm observing something I don't quite understand and was hoping someone could tell what's going on and why (and potentially how to resolve it if possible). I am using Unity 2021.3.11f1.

    Following is my setup:

    Project assets:
    Key assets in the project.
    1. Pen.png (attached)
    2. Pen_Base.png (not attached; similar to Pen.png just does not include the curvy tip at the end)
    3. Pen_Base_Mask.png (not attached; similar to Pen.png just uses black and white instead of color and does not include the curvy tip at the end)
    4. Pen_Tip_Mask.png (not attached; similar to Pen.png just uses black and white instead of color and does not include the base of the pen--only the curvy tip)
    5. Pen shader
    6. Pen material with shader applied
    Scene setup:
    • I have a sprite renderer on scene with an attached texture (Pen.png).
    • Pen.png sprite has properties: sRGB (Color Texture)=checked; Alpha Source=Input Texture Alpha; Alpha Is Transparency=checked
    • Sprite has the pen shader/material applied
    Shader graph settings:
    • Surface Type=Transparent
    • Blending Mode=Alpha
    I am using the shader to generate a mask from two mask textures (Pen_Base_Mask.png and Pen_Tip_Mask.png), then adding them together for the complete mask (see attached shader graph). I get the following rendered scene results under the respective circumstances:

    The final rendered result in the scene using alpha from the Pen.png texture.
    Pen_Using_GeneratedMask.png

    The final rendered result in the scene using the generated mask from the shader (which is created using two mask PNG files that I couldn't attach here).
    Pen_Using_MainTex.png

    The preview looks correct in the shader for both cases, though, no matter which alpha mask I use.
    Pen_Preview.png

    My question is: what are all of the black pixels being rendered here when using the shader-generated mask? Why do they occur when using a generated mask that looks identical to the alpha mask from the main texture in the shader, but not when using the alpha channel from the main pen texture on the sprite? As can be seen from the shader graph PNG, it looks like the alpha/mask is the same between the generated and the texture alpha mask. So why is the rendered result different?

    Complete Shader Graph attached: Pen_Shader.png

    Thank you!
     

    Attached Files:

    Last edited: Nov 10, 2022
  2. bruce_c

    bruce_c

    Joined:
    Oct 22, 2022
    Posts:
    2
    I actually figured out what my issue was. One of the input textures for the mask was exposed but not set so I can only assume that was somehow confusing the shader. I removed the exposed property and simply defined a Texture 2D asset with the reference properly set. Once I did that, the mask seemed to work correctly.