Search Unity

reveal a texture

Discussion in 'Shaders' started by bumba, Aug 26, 2010.

  1. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    The best way to do this on iPhone is to move the vertices and UV coordinates of your mesh so that they only cover the part of the texture you want shown. Doing this with shaders means more materials, which means more draw calls. That's really bad on the iPhone.
     
  3. Battle Angel Alita

    Battle Angel Alita

    Joined:
    Mar 29, 2010
    Posts:
    44
    Fill alpha channel with black-to-white gradient, and then just change Cutoff value in standart "Transparent/Cutout" shader.
     
  4. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    if a move vertices the texture will be only scaled.

    If i move UVs then i can not reveal only a part of the texture. I will see always the top of the arrow
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I made a post about this a couple days ago but decided I didn't like the look of my suggestion in practice, so I deleted the post.


    I agree with this, but the problem comes from the fact that the arrow can fade in and out. So, it requires a different material than everything else I see on screen.

    That's what I thought at first, but I don't think it plays nicely with blending. The edge of the meter flickered in and out on my MacBook Pro when using a combination of alpha testing and blending, so I imagine it would look as bad or worse on an iOS device.

    That's why he used the word "and". It must be both.


    Here's my solution. It's got blending, power meter level changing, and the ability to switch to a different-looking texture when you can't use the arrow (greyed out); it's all done in a single pass. You can play with the custom Inspector for the script to test it out. Go into play mode and you can trigger the opacity-changing function with a button in the Inspector.
     

    Attached Files:

  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    alpha blending and cutout is actually one of those areas where the powerVR gpu is worlds different from desktop gpus
    so always test ideas on the real device instead of assuming things basing on the desktop as there is no guarantee that it will be the same in any way actually (that rule though applies to anything: if being sure costs you 5mins, better invest those 2 mins as early as possible instead of assume things. You don't lose much but can gain a lot from it)