Search Unity

2D Alpha Build Leaked!

Discussion in '2D' started by Kuan, Apr 24, 2015.

  1. LiberLogic969

    LiberLogic969

    Joined:
    Jun 29, 2014
    Posts:
    138
    Sorry I misunderstood... I'm pretty sure it looks for sprites in sheets that are all the same size... it sounds like a bug.
     
  2. pioj

    pioj

    Joined:
    Nov 5, 2012
    Posts:
    15
    I can't wait to get these new additions included in the next version!

    This could mean a significant point into 2D game development for sceptic users that still defend frameworks like UbiArt or GameMaker.
     
  3. Greenwar

    Greenwar

    Joined:
    Oct 11, 2014
    Posts:
    43

    So I decided to play around with the masking a bit. I'd like to emphasize the 'bit' part since it was only for ten minutes or so, so I'm probably doing something wrong - but the masking seems really weird.

    Tried several different sprites as masks and they all churn out unexpected results, such as; not actually masking what they are supposed to mask.

    Above gif uses a circle primitive as a mask. Simple Enough.
    Also some sort of z-fighting/tearing seems to appear quite frequently on maskable (and outside of??) sprites.
     
  4. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    @Greenwar: Masking is based on the stencil, and not alpha. If you go to Shaded-Wireframe mode, you will be able to see the mesh that is generated for the mask, and this mesh is used for masking.
     
  5. Greenwar

    Greenwar

    Joined:
    Oct 11, 2014
    Posts:
    43
    I see, thank you.

    Any plans on implementing alpha texture based masking?
     
  6. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    @Greenwar
    We are currently looking at improving stencil based masking and its workflow.
    No plans materialised yet for alpha masking.

    But if it is a must, I've come across some solutions on the asset store that can get you alpha masking right now.
     
  7. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    682
    i think i got it (2d sprite alpha mask) working with these shaders
    if i remove the 'discard' line it looks like the gif above

    Code (CSharp):
    1. Shader "Custom/Mask"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Tags
    13.         {
    14.             "Queue"="Transparent-1"
    15.             "IgnoreProjector"="True"
    16.             "RenderType"="Transparent"
    17.             "PreviewType"="Plane"
    18.             "CanUseSpriteAtlas"="True"
    19.         }
    20.  
    21.         Cull Off
    22.         Lighting Off
    23.         ColorMask 0
    24.         ZWrite Off
    25.         Blend One OneMinusSrcAlpha
    26.  
    27.         Stencil
    28.         {
    29.             Ref 1
    30.             Comp always
    31.             Pass replace
    32.         }
    33.  
    34.         Pass
    35.         {
    36.         CGPROGRAM
    37.             #pragma vertex vert
    38.             #pragma fragment frag
    39.             #pragma multi_compile _ PIXELSNAP_ON
    40.             #include "UnityCG.cginc"
    41.  
    42.             struct appdata_t
    43.             {
    44.                 float4 vertex   : POSITION;
    45.                 float4 color    : COLOR;
    46.                 float2 texcoord : TEXCOORD0;
    47.             };
    48.  
    49.             struct v2f
    50.             {
    51.                 float4 vertex   : SV_POSITION;
    52.                 fixed4 color    : COLOR;
    53.                 half2 texcoord  : TEXCOORD0;
    54.             };
    55.  
    56.             fixed4 _Color;
    57.  
    58.             v2f vert(appdata_t IN)
    59.             {
    60.                 v2f OUT;
    61.                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    62.                 OUT.texcoord = IN.texcoord;
    63.                 OUT.color = IN.color * _Color;
    64.                 #ifdef PIXELSNAP_ON
    65.                 OUT.vertex = UnityPixelSnap (OUT.vertex);
    66.                 #endif
    67.  
    68.                 return OUT;
    69.             }
    70.  
    71.             sampler2D _MainTex;
    72.  
    73.             fixed4 frag(v2f IN) : SV_Target
    74.             {
    75.                 fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
    76.                 if (c.a < 0.1) discard;
    77.                 c.rgb *= c.a;
    78.                 return c;
    79.             }
    80.         ENDCG
    81.         }
    82.     }
    83. }
    84.  
    Code (CSharp):
    1. Shader "Custom/Masked"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Tags
    13.         {
    14.             "Queue"="Transparent"
    15.             "IgnoreProjector"="True"
    16.             "RenderType"="Transparent"
    17.             "PreviewType"="Plane"
    18.             "CanUseSpriteAtlas"="True"
    19.         }
    20.  
    21.         Cull Off
    22.         Lighting Off
    23.         ZWrite Off
    24.         Blend One OneMinusSrcAlpha
    25.  
    26.         Stencil
    27.         {
    28.             Ref 1
    29.             Comp notequal
    30.             Pass keep
    31.         }
    32.  
    33.         Pass
    34.         {
    35.         CGPROGRAM
    36.             #pragma vertex vert
    37.             #pragma fragment frag
    38.             #pragma multi_compile _ PIXELSNAP_ON
    39.             #include "UnityCG.cginc"
    40.  
    41.             struct appdata_t
    42.             {
    43.                 float4 vertex   : POSITION;
    44.                 float4 color    : COLOR;
    45.                 float2 texcoord : TEXCOORD0;
    46.             };
    47.  
    48.             struct v2f
    49.             {
    50.                 float4 vertex   : SV_POSITION;
    51.                 fixed4 color    : COLOR;
    52.                 half2 texcoord  : TEXCOORD0;
    53.             };
    54.  
    55.             fixed4 _Color;
    56.  
    57.             v2f vert(appdata_t IN)
    58.             {
    59.                 v2f OUT;
    60.                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    61.                 OUT.texcoord = IN.texcoord;
    62.                 OUT.color = IN.color * _Color;
    63.                 #ifdef PIXELSNAP_ON
    64.                 OUT.vertex = UnityPixelSnap (OUT.vertex);
    65.                 #endif
    66.  
    67.                 return OUT;
    68.             }
    69.  
    70.             sampler2D _MainTex;
    71.  
    72.             fixed4 frag(v2f IN) : SV_Target
    73.             {
    74.                 fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
    75.                 c.rgb *= c.a;
    76.                 return c;
    77.             }
    78.         ENDCG
    79.         }
    80.     }
    81. }
    82.  
     
  8. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    Yes... this should work for ON/OFF alpha based on a cut-off threshold.
    Although Alpha masks cover gradients also which could prove to be costly.
     
  9. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    A shader that multiplies with the texture's screen space alpha with the mask's screen space alpha would be more efficient as alpha testing, branching, and discarding pixels are costly for the GPU.

    Unfortunately, I'm still in the process of learning shader language, so I'm not prepared to write a proper alpha masking shader yet as I still need to learn the syntax.

    In general though, alpha would more useful than stencil for 2D as the stencil requires the manual editing of polygonal shapes for all textures to approximate the shape. Alpha can be set to go with any shape.
     
  10. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    Alpha masking is certainly more fancy; but there are pros and cons to each approach.
    Stencil based masking is the starting point, but not the end.
     
  11. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    259
    Will the unity 2d build be updated to include the new bugfixes and features in the current 5.1 release?
     
  12. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    682
    Will the unity 5.1 build be updated to include the new bugfixes and features in the current 2d build?
     
  13. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    @Xelnath. It depends. If the next update to the 2D preview build is based on 5.1, then it will includes everything in 5.1 official release + 2D preview features. Stay tuned!

    @rakkarage. Bugfixes are generally push directly to the official Unity 5.x release, unless it is a specific bug fixes for the 2D preview build's feature set. We will push the features in 2D preview build into official release when the feature is ready, this is why we need your help in testing and giving us feedback on the previewing feature!
     
  14. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    475
    Would have to humbly have to shout for alpha channel here. Alpha channel masking is the only route that makes any sense to artists, it's been in Flash and Photoshop for eons. Telling artists that the mask can only be made with polygons which are crudely (from an art asset point of view) generated - not delicately crafted alpha channels - is like asking them to perform origami with chainsaws.

    At the most there will probably only be a few of these onscreen, modern computers can probably handle this overhead easily.
     
    Last edited: Jun 22, 2015
  15. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    @hawken:
    Your point noted. Some improvements to SpriteMasking were made in the new preview release today.
    More will be on the way. Stay tuned :)
     
    the_motionblur and hawken like this.
  16. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    301
    Repost:

    Dear Beloved Users...

    We are sharing with you our latest progress on the in-development tools.

    Quick Highlights
    • Animated Tiles in TileMap
    • Spline support in SmartSprites
    • Massive Physics 2D updates
    • Masking, New Demos, etc etc...

    Get it here: https://bitbucket.org/Unity-Technologies/2ddemos/wiki/Home
    Full Details here: https://bitbucket.org/Unity-Technologies/2ddemos/wiki/Alpha Release 2
    Submit your issues here: https://bitbucket.org/Unity-Technologies/2ddemos/issues

    (Submit alpha related issues at BitBucket to prevent clutter and confusion in this forum).

    Thank you and hope you will try it out!
     
    the_motionblur, blizzy and mh114 like this.
  17. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    Guys ... this is all sorts of awesome!
    The only thing I'm hoping for is that NavMesh 2D will be here rather sooner than later.
    But other than that these toolsets are all looking so super-sweet. Awesome! :)

    I'll give it a try as soon as I can. Thanks for the early sharing.
     
  18. cecilcruxis

    cecilcruxis

    Joined:
    Sep 17, 2013
    Posts:
    92
    Unity as usual you guys are beyond amazing when coming up with new features that will make everyone's job easier when it comes to development workflow. I must say the thing I like most might be the buoyancy effector. Keep up the good work.
     
  19. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    Where can I find some infos on how to use the new features?
    I feel a bit lost on BitBucket...
     
  20. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    301
    @the_motionblur

    We do have some videos and demo projects on the new features found here:
    https://bitbucket.org/Unity-Technologies/2ddemos/wiki/Alpha_Release_2
    Video links are at the side and demo projects are at the bottom.

    For scripting, the scripting reference that comes with the preview build is updated with the information for the new APIs.

    If you need more help with any features, do let us know and we will improve our documentation and tutorials. We plan to add information on these features to the Unity Manual too.
     
    blizzy and the_motionblur like this.
  21. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    Cool - thanks a lot :)
     
  22. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    I have to say ... as awesome as the smart tiles are I think I love the 2D tile editor even more.
    Please don't scrap this one in the long run. Using sprite tiles on a grid is so much fun and so fast ..... it's awesome!
     
  23. v2-Ton-Studios

    v2-Ton-Studios

    Joined:
    Jul 18, 2012
    Posts:
    181
    Just wanted to +1 your animation thots.

    A 2D animator would be greatly appreciated. On that note...

    Aside from specialized support for classic sprite based animation (which is definitely needed), I'd personally benefit from more support for 2D pseudo rigged animation (basically a hierarchy of sprites which create a rig of sorts, chest owns shoulders, which own arms, which own hands, etc).

    Concepts like "feet" that understand where the ground is, and land on it rather than go through it.

    Much better support for creating transitions between animations (not the auto transitions we have today), but systems for managing hand created chains of transitions Idle --> IdleToRun --> Run --> RunEnd. Today if I update Run, I have to go through this very painful copy-paste dance, syncing the properties of each component from one animation to the others just to get the start and end frames of IdleToRun and EndRun to be the same.

    Better support for creating looped animations which use proper weight and delay techniques. For instance, when doing a run I want the hands to be delayed a bit, so that the motion has a nice fluid arc to it and the proper weight, getting this to work while having the start and end of the animation in sync and not "drag" as the animation restarts is a pain in the butt.

    Ability to preview chains of animations, Idle --> Run --> Jump, rather than having to always test them in-game, stop, tweak, test, etc. It wastes a ton of time.

    Ability to have non-looped animations just play once in the timeline, rather than always loop. It's a pain to get a sense of say an attack animation when it is always looped. I hack this by adding a empty event and dragging it way out to the right, but that can lead to little bugs e.g. if I forget the event is there :).

    Ability to force a code adjustment of an animated element to "win". Today, if I adjust something in code, that is also animated, the animation always wins. For instance, if I want to have my hero disarm his weapons, in code I might deactivate them, but if I have any animations that just so happen to turn them on (or off actually, I think the animator just totally owns things) my code won't deactivate them. In some cases this is desirable, but I'd like to have some kind of a way to forces a code operation to win, something like HeroSword.SetActive (false, AnimatorMode.Force);

    Refactoring improvements i.e. way better coupling / visibility between the animator and code. I'd love it if I could do a Find All References through code and see which animations call it as an event. Similarly, if I rename an event, it would be great if all the animations that call it have their event references update, today I have to manually hunt through each animation -- in a system where a single character has dozens of animations this gets very tedious. Rather than string names for parameters, can we get generated enums? It's currently a very bug prone system... I update a parameter name through the editor, then I have to go trolling through my code to find all uses of that name changing both the name and the Get / Set calls to it.

    The ability to rename elements in the hierarchy and have the animation update would be awesome. Ability to reorder things without animations breaking would be better still. Can't animations key off an internal ID, rather than the GameObject's name?

    Huge +1 on swap spritesheet at runtime :).

    BTW, the new alpha updates seem fantastic (I'm guessing I need a dedicated machine to test them on, no side-by-side right?) I love that you guys are pushing things out early and gathering feedback, bodes very well for the future of 2D in Unity!
     
    Last edited: Jun 27, 2015
  24. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    168
    Thanks for the feedback. 2D Skeletal characters with IK is definitely on our minds. Once we have a solid plan we will announce it here! Stay tuned
     
    v2-Ton-Studios likes this.
  25. Xemenas

    Xemenas

    Joined:
    Sep 10, 2012
    Posts:
    28
    Are 2D primitives still in development? For one of my projects, I was hoping to be able to render complex graphs such as the attached image. I've looked into using canvas render, but it seems like that can only render quads, so I won't be able to use it.

    Thanks for any info!

    P.S. I use GraphMaker for simpler line/bar graphs, but it unfortunately doesn't support this type of behavior yet.
     

    Attached Files:

  26. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
  27. Deleted User

    Deleted User

    Guest

    Seems cool. Any release date?
     
  28. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    Stay tuned™ :D
     
  29. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    Haha, so specific. I'm really looking forward to testing this stuff out too. It's going to make a big difference in how many features I create by hand or not.

    It's a bit harder to find motivation to work on features I know Unity is already working on, knowing there is a good chance your implementation may suffice or mine might be downright ignorant and inferior.

    But I do understand when it's done it's done. Depending on how flexible and performent your solutions are, it's going to make a big difference in how deep I choose to go for a 2D game rendering wise, cause in a way, it would be nice to focus on art and game design.
     
  30. NormaNeal

    NormaNeal

    Joined:
    Sep 10, 2015
    Posts:
    1
    Awesome
     
  31. BytesOfChicken

    BytesOfChicken

    Joined:
    Jan 12, 2013
    Posts:
    34
    Can anyone point me in the right direction to figure out how we create brushes for the tile maps?
     
  32. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    301
    There are two things you need to make to create a new brush, the brush painting script and the brush asset. The brush painting script contains the logic to paint and erase tiles, while the brush asset contains customised information for painting specific sprites.

    To create the brush painting script, you will need to extend from the GridBrush class, overriding the Paint, Erase and GetPreviewSprite functions. You will also need to have a way to create the brush asset/s itself; in the sample, we added a function CreateBrush to each brush painting script to create the brush asset. Anytime a brush asset is created, the Tilemap Palette will pick it up and make it available for selection.

    You can check out the samples to jump-start your way to creating brushes! This would be the latest version.
     
    Samich, holliebuckets and blizzy like this.
  33. ImAldu

    ImAldu

    Joined:
    Mar 6, 2015
    Posts:
    63
    Wow. This is awesome. One of the things I'm most excited for is the tile map features. Thanks, Unity.
     
  34. QuaintShanty

    QuaintShanty

    Joined:
    Mar 4, 2014
    Posts:
    46
    Is this still ongoing? I recently just found out about this after nearly finishing my own tile mapping system. This would definitely save me a lot of time on my next project. I hope it's not dead. Several months have passed and I can't download the alpha, nor can I find any updates about the progress on this.

    Edit: I see there are some updates here. I'm still not sure if this is in 5.4 though. I'm currently reading the release notes.
     
    Last edited: Jun 4, 2016
  35. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,099
  36. QuaintShanty

    QuaintShanty

    Joined:
    Mar 4, 2014
    Posts:
    46
    Thanks, that's a big help. :)
     
  37. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,736
    Last thing I've heared is that it's not in 5.4 because some things had to be rolled back for now.
    I'm pretty sure it still is in development seeing how far it has come but it will probably take some time longer.
     
  38. QuaintShanty

    QuaintShanty

    Joined:
    Mar 4, 2014
    Posts:
    46
    Yeah, looks like it's only in Unity 5.5. I'll just play with 5.5 for now until it comes out. If something goes wrong, I'll just make it again.
     
  39. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    222