Search Unity

Single object, varying transparencies

Discussion in 'Editor & General Support' started by renman3000, Jul 25, 2012.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    How can I have an object that's image is partially, as in a portion, say the bottom third 70% transparent. The middle third 30% and the top 90%?


    Or am I going to have to use compleltey separate objects, pieced together?
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Anybody?
     
  3. fransh

    fransh

    Joined:
    Sep 15, 2010
    Posts:
    92
    Simply add an alpha channel to the uv?
     
  4. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    Use a transparent shader of some kind and have the alpha channel in the texture. Black is 0% visible and white is 100% visible, shades of gray are the transparency levels.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Right,
    But can I have a section of the mesh, material be more transparent than another section? Or do I need separate objects for that?
     
  6. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    I don't understand, the material covers your mesh, if a section of the material is transparent, than a section of the mesh will be transparent.
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    You can use a single object with separate subobjects. The crucial thing is that you have separate materials.
     
  8. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    or just use a material that has varying levels of transparency? What am I missing here?
     
  9. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Try it. You'll see the problem.
     
  10. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    ok, I was not aware you could do that. Can you point me in the right direction?

    Also, just of note, I am currently using a material with only 2 vertices, that should probably be changed? Also, can I for instance make the transparency levels different for a full circumference around the edges of the plane? Then repeat that again closer to the center?


    Thanks


    edit: @ superpig. different materials method is best?
     
  11. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    If this is just for a plane and you're asking about varying levels of transparency then you need to do some basic research on alpha blended transparency. If you figured out how to make your character cut out with a transparent background then you can figure this one out too, it's not that tricky.
     
  12. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    I understand how to use transparency via shaders as well as using alpha to adjust. But if you read the original post you would know what I mean.

    Thanks.
     
  13. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Yes, I read your post and I'm saying you need to learn how to create alpha channels for your textures with varying levels of transparency.
     
  14. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    What I am asking is do I need multiple materials for this? Or can multiple alpha adjustments be made on the same material at the same time on the same object?
     
  15. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Alpha channels are 8-bit channels with 256 levels. So no, you do not need multiple materials for varying levels of transparency on a single mesh.

    Superpig was possibly referring to sorting issues, but that doesn't apply to your question when dealing with single planes being used as billboards.

    If you're talking about changing these values dynamically at runtime, then you either need to split it up into multiple materials, use a shader that takes vertex colors into account and dynamically change the vertex colors on the mesh, or split the alpha channel from the diffuse texture in the shader and feed the material different alpha channel textures at runtime (or use a texture sheet and offset the coordinates to map to different sections of the alpha texture).
     
  16. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Ok great thank you.

    I looked up "alpha blended transparency" but nothing lept out. I think this may be a little beyond me at the moment. As I have not touched UV adjustment or anything. I know how to adjust a single level alpha, but am failing to grasp how an object could have more than 1 alpha.

    You say an Alpha has 8 channels so I looked up this..
    http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=alpha+channel


    Sorry for not researching more, but I am out the door for a bit.
    Thanks! Your help is appreciated.
     
  17. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    You only need one alpha channel



    Like this would provide every level of transparency needed for the image.
     
  18. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    I am sorry, I just dont follow.

    How can a single material with alpha set to x, have another area set to != 12?


    Do you understand that I have an image, lets just say it takes up the entire mesh, material. So there is zero transparency. Now, I want the bottom third to be 50% transparent and the top half to be fully opaque.

    How do I do this|?
     
  19. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Do a search for creating alpha channels in Photoshop (or whatever image editing app you use).
     
  20. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    In photoshop click the channels tab in the bottom right of the application (it's next to layers) there is a small button below called create alpha channel or something, click it and it makes an alpha channel, there you put the grey scale image that controls the transparency. Such as:



    For what you asked specifically you would want the top to be all white (opaque) and the bottom grey.
     
    Last edited: Jul 25, 2012
  21. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Oh, so how you import from photoshop plays a roll! Great. I had just been importing solid png fils.

    Thanks you!
     
  22. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    You should be fine now.
     
  23. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    I was actually thinking runtime-varied percentages, but sorting issues too, sure. But yeah for a billboard it doesn't matter much.

    Instead of taking the alpha value from the material's tint (which is the same across the whole material) you take it on a per-pixel basis from the texture. As Khyrid and antenna tree have explained, you set up the value as an extra per-pixel 'alpha' channel in Photoshop, save it to a format like PNG, and then Unity should preserve the alpha value on import. You can check by clicking the texture, looking in the Inspector, and looking just above the preview of the texture - there should be a little button you can click to toggle between 'color' and 'alpha' display modes.