Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

In-House 2D Support with Unity 4.3

Discussion in 'General Discussion' started by BTStone, Aug 28, 2013.

  1. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
  2. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    Wow, that makes my TP question obsolete :)
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    While we're on the subject of 2D, we come to a problem I've been facing recently.

    Namely, shuriken is the fastest way to get a lot of "sprites" moving around programatically, but currently it's not very useful for 2D because you cannot change the cell shuriken is displaying in code. I would like support for shuriken changing which cell is currently being displayed in the Particle class if possible please.

    Otherwise we're forced to use our own mesh class, which isn't as fast as shuriken afaik.
     
  4. krakov

    krakov

    Joined:
    Jul 23, 2012
    Posts:
    11
    I vote the 2d tool team should spend some more time with the shuriken team too, shotgun wedding if necessary. I'm currently a bit miffed with shuriken as it applies to 2d games right now:

    Default billboards have no normals/tangents forcing use of mesh particles in many situations (well, mine atleast).

    Mesh particles default axis of rotation seems to get changed with unity versions also changes itself when you switch between world/local simulation so in many situations (mainly 2d) you cannot orient particles to face camera in XY plane have rotation.

    Recently exposed axisofrotation parameter does not change the default - forcing you to update every particle every frame...this is just...well, c'mon!

    Question: Are there any more pro only features for the 2d stuff not yet mentioned? Misery loves company :cool:

    $misery4.gif
     
  5. MikaelTroc

    MikaelTroc

    Joined:
    Nov 2, 2012
    Posts:
    33
    Are you talking about the Texture Sheet Animation module ? In that case you should be able to use the lifetime variable to set which cell shuriken is using for each particle.
     
  6. blacksp1der

    blacksp1der

    Joined:
    Dec 11, 2007
    Posts:
    76
    I was resisting to upgrade to 4.3 since they are going to remove support for old devices and now they are going to support 2D?. No sense…

    Deprecation heads-up. In the next release (4.3), we plan to drop:
    OpenGL ES 1.1 support on mobile
    Pre-DX9 GPU support on PC
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    1) how much of your mobile population can't run OpenGL ES 2.0? Really, are you supporting iPhone 2G ?!
    2) how much of your PC population has GPUs older than 10 years? Does your game still run on them (i.e. do you do QA and performance testing)?
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    I just have to say that I'm so happy about 2D implementation :) Who cares about the new GUI now, as long as we can make it ourselves :D
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    On the topic of SetPixels() etc... it is definitely a lot slower than it could be. a) Alpha8 images have to be stored in floats in order to upload them instead of bytes, big waste. b) Conversion from Color() or Color32() formats is slow.. like was mentioned, it should be byte arrays. c) SetPixels/32 with a less-than-full texture rect still has to upload the entire texture to the GPU when you do the Apply(). There is no dirtyrects algorithm or only uploading of the part that actually changed. d) Using SetPixel(s) to change texture pixels is much slower than just setting some bytes in an array. e) Unity seems to store an internal copy of the texture in an internal main memory buffer, in addition to the memory buffer/byte array you're using to modify the pixels from script, meaning you have to upload main-memory to main-memory and then on to the GPU which is a totally unnecessary step - our byte array should go immediately to the GPU texture and ONLY the part of the texture that needs to change, as in glTexSubImage2D instead of glTexImage2D.

    Unity's texture uploads are thus *several times slower* than they could be. Tests done in BlitzMax for example show way better performance - ability to upload much bigger textures every frame and much more efficient uploading when you only want to change a small part of a texture.

    Anyway..

    Keely you said texture packing to a spritesheet is pro only? .... is there ANY atlas support for Free users, like rectangle based?
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I've tried that multiple times, it never actually works (per particle) - they all appear to change in one go.
     
    Last edited: Aug 29, 2013
  11. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Depends on what is your definition of atlas support. There are now two separate features regarding atlases:

    1. Sprite Packer (pro)
    2. Sprite Editor (free)

    They do different things. Actually they kinda do the opposite things of each other.

    Sprite Editor (free) is in the import pipeline. It takes texture as input and has sprite assets as output. Say you have ten sprites all on a single texture, Sprite Editor allows you to visually define where those sprites are (UV rects basically) and then import pipeline will spit out ten sprite sub-assets. You can then use these sprite assets in your game. We also offer something called automatic slicing or grid slicing in the editor, so that it is very fast operation workflow-wise. You can define these rects via the texture importer APIs too.

    Sprite Packer (pro) however does the opposite. It takes sprite assets as input and texture sheet as output. When you have pro, it doesn't really matter how you import your sprites (as singles or sheets), they will get repacked (unless you tell Unity you don't want to) when you build or when you go into the playmode. The result will be tighter than typical rect packing. Sprite Packer has no script APIs at the moment.

    So if you only have free, you need to have your sprites already in an texture atlas. You then use Sprite Editor to slice. If you happen to already have the metadata where the UV rects are, you can also create your own importer that spits out the sprite assets automatically.

    I think the bottom line is that with free version, you can import atlases, and it's easy to slice them to assets. For 1 sprite = 1 texture, you can make the packing yourself, but you need to operate on rects. With pro, you get automatic packing that doesn't really require any effort on your part and has the tightest packing evar.

    To clarify: Sprite assets are always sub-assets of a texture asset.
     
    Last edited: Aug 29, 2013
  12. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Absolutely, fricking fantastic!!!! This'll significantly cut down the number of texture atlases I need and ease the pressure of the 50 Mb barrier.

    Questions:
    * Please support variable resolutions texture atlases at runtime. The diff between 3GS and iPad 3 is ... not small. At a minimum, the Texture packer (TP) should allow mip-mapping of the assets, where you can tell it easily what size asset to push to the GPU, BEFORE it tries to shove a 2048x2048 texture to the 3GS.
    * Can you expose the Shuriken API in code? So we can use it's awesomeness, programatically. Yes, this is an aside.
    * Can you explore BMFonts (or other font packers) in your 2D features? That'll be a huge hole if not supported.
    * Will the TP be integrated closely with the eventual GUI tools? I'd like the TP to feel uniform between the 2D sprites and GUI elements.

    Gigi.
     
  13. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Nothing like this on the first release, but it makes a lot of sense. We just need to figure out the "Unity-way".

    Don't have much info on these, sorry.

    I'd rather not speculate too much on what the GUI will do, because so many things might still change. The new GUI will use the same import/packing/asset pipeline than the 2D with very very high probability, though. The current build already does this.
     
  14. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    950
    Will we be able to render images through script in a fast way, such as through the GL class?
     
  15. Sirithang

    Sirithang

    Joined:
    Nov 29, 2010
    Posts:
    28
    How the thing is working for the camera? Is there some "2D Camera" that setup the ortho cam with the right projection matrix for a WxH screen, to allow pixel perfect rendering?

    Also so kind of autosnap of sprite position at render time to avoid bad rasterization?
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Regarding texture packing, for example 2D tiles and such - please offer padding to defeat artefacts with point filtering games etc. While we will be moving away from 2D later, we still think its a good thing to be aware of for unity.
     
  17. JonathanCzeck

    JonathanCzeck

    Joined:
    Mar 21, 2013
    Posts:
    12
    In case you're not aware, there's "Texture Quality" in the QualitySettings. Can change to half-res. Might be enough for you.

    Ahh, I see.

    Cheers,
    -Jon
     
  18. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Nothing for the camera for the 4.3. We might still do some last minute tweak, but more likely not.

    4.3 ships with a shader that snaps to pixels.
     
  19. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    You can set the "extrude edges" value on the advanced texture import settings. This is "I want x pixels of padding on the mesh around my sprite, please".
     
  20. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    Lotta good suggestions in this thread. In particular, I'm interested in padding for the texture packing, BMFont support (bitmapped fonts, created with the BMFont program) and a smart 2D camera to make things easy.
     
  21. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Do you have any information on performance, not including physics? Like if we have 1000 2d objects in the new system, will it possibly perform x% faster than any other third party solution due to faster internal code etc?
     
  22. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Will it support existing sprite sheet definitions? For example, our pipeline uses TP already. Will it parse an existing sprite sheet and xml/plist?
     
  23. Sirithang

    Sirithang

    Joined:
    Nov 29, 2010
    Posts:
    28
    He already answered that no, no particular import from metadata from 3rd party software, but there is a hook in the AssetImporter API, and that you can set subRect through script, so easy to wrote an editor script that do it when you import your spritesheet.

    My two cents : tons of free script on the net will do it two day after release. So much love in the Unity community.
     
  24. dingosmoov

    dingosmoov

    Joined:
    Jul 12, 2005
    Posts:
    559
    +1 for Vectors
     
  25. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    Vectors are a dicey proposition, and not necessarily the best way to handle things for an engine designed around 3D rendering.

    The current rendering pipeline is built around using textures to define colors stretched across polygons. Adding vector support would be a low-level operation that would have to replace that functionality with vector graphics. It's possible, but it isn't easy, and it wouldn't blend very well with texture definitions.

    Personally I love vectors, and regularly use Inkscape for finishing illustrations. But to properly take advantage of vector graphics, you would have to build the rendering engine around them. Shoehorning support into an existing system wouldn't be enough.
     
  26. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I'm not sure you know what you're talking about re vectors... they can be rendered either by breaking them up into triangles, which is the standard rendering unit of all graphics cards, or by rendering a single triangle with a special `curve` shader. True the GPU doesn't really generate vector shapes in their most native format (although perhaps that could be done with a DX11 tesselation shader), but they definitely can be rendered FAST in Unity without any low-level modification, and in support of texturing.

    In the new 2D unity tools, a sprite which has a custom mesh cutting out its shape is essentially a vector object with a texture applied, is it not?
     
  27. keithsoulasa

    keithsoulasa

    Joined:
    Feb 15, 2012
    Posts:
    2,126
    I'd like to see if I could somehow use 3d models in 2D mode . I'm working on what is basically a 2d game with 3d models , but I'd really like better hit detection .
     
  28. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    The new 2D system isn't exclusive. You will still be able to integrate 3D models. If you watch the Unite Keynote you can see that everything is still taking place in 3D, it's just the tools that are being streamlined for 2D functionality (and of course a lot of optimizations). But a mix of 2D/3D is still totally possible.
     
  29. BlackRain

    BlackRain

    Joined:
    Jun 26, 2012
    Posts:
    76
    Well S***...There go my Simple Sprite sales :(
     
  30. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    So.. Unity will get more Uni2D Features xD

    Will there be a way to animate sprites via bones too?
     
  31. Deleted User

    Deleted User

    Guest

    @keely do you plan support for skeletal/bones animation in 4.x releases?

    Thank you.
     
  32. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,246
    Hmm, interesting so if I understand correctly you use much more complex meshes vs Quads but without the need for an alpha shader? Or just to save on fill rate?
    And that is faster on all systems?
     
    Last edited: Aug 30, 2013
  33. Craig_OZ

    Craig_OZ

    Joined:
    Jun 12, 2012
    Posts:
    30
    Does the Texture Atlas auto creation tool work with 3d scenes as well as 2d scenes?

    Thanks
    Craig
     
  34. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    You still need alpha shader. We do it to save fillrate. It may or may not be faster on all systems, but the long term vision is that user doesn't need to actually care about the mesh at all and we will do the Right Thing(tm) in all circumstances for the user.
     
  35. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    There is no such thing as 2D scene. It's always 3D.

    Texture auto atlasing only covers textures that have sprites in them.
     
  36. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    No skeletal support for 4.3. We are researching it.
     
  37. Deleted User

    Deleted User

    Guest

    Good to know, thank you.
     
  38. Durayel

    Durayel

    Joined:
    Aug 30, 2013
    Posts:
    5
    Thanks Keely! I've got two quick questions regarding sorting layers:
    1. What will happen if two sprites in the same sorting layer overlap? Will z-fighting occur or does the sprite renderer disable the depth-buffer?
    2. Can sorting layers be dynamically inserted and removed at runtime?
     
  39. RichardKain

    RichardKain

    Joined:
    Oct 1, 2012
    Posts:
    1,261
    You can never get faster on ALL systems. Systems are just so diverse. But depending on the complexity of the sprite atlas, it should allow things to run faster on most systems. With modern GPUs, polygon limits are usually not the rendering performance bottleneck.
     
  40. kenaochreous

    kenaochreous

    Joined:
    Sep 7, 2012
    Posts:
    395
    There is an article on The Escapist talking about this.

     
  41. keithsoulasa

    keithsoulasa

    Joined:
    Feb 15, 2012
    Posts:
    2,126
    Awesome , anyway to switch a scene to 2D mode after developing it in the traditional 3d mode . I'm working on 2D ish game now and I don't want to wait( and for some reason I code best from 12am to 4am #life)

    Thanks again for doing this .
     
  42. McMurphy

    McMurphy

    Joined:
    Jul 16, 2012
    Posts:
    1
    I have a question for keely: in Will Goldstone video presentation of the native 2d tools, it's clearly shown that the main character has a Animator Controller attached to it. Does this means that in 4.3 it will be possibile to use the Animator Controller also for sprites and meshes without a skeleton?

    thanks
     
  43. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
  44. Deleted User

    Deleted User

    Guest

    I have some question too. I noticed that most of the sprite stuff is on the import settings of the textures, what I would like to know if it will be possible to create a sprite with sliced sprites and everything at runtime.

    I'm working on a fps hexen/heretic style, with sprites for monsters etc... and planning to wait a little for this update as it will sped up the whole process, but also I'm adding modding support through an ingame editor and would like to let the user be able to create new sprites using resources from external files from the build. I can understand if the animations won't be possible to do at runtime, but I can handle it in a different way, I'm only worried on the ability to create the sprites components at runtime.

    Another thing I would ask is about the batching. I will have billboarded sprites (by script) so they keep rotating toward the player view, in this case the sprite renderers will be still batched?

    Thanks.
     
  45. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Yes.
     
  46. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Yes. Although you can't access the automatic tight packing stuff from runtime and have to resort to your own rect packing if you want to atlas user generated stuff, but I think you can live with that.

    Yes.
     
  47. Deleted User

    Deleted User

    Guest

    Fair enough. There is also another thing I noticed on the keynote demonstration, the pixel by unit field. It is basicly the scale of the sprite? Eg: I put 32 there, so every 32 pixel is 1 unity unit.

    Also it will definable at runtime this too, or I have to convert unit myself then?

    Thanks for the patience.
     
  48. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  49. primaerfunktion

    primaerfunktion

    Joined:
    Jan 16, 2012
    Posts:
    98
    Would make sense... But I feel like this could be kinda bad for my current projects progression.
     
  50. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    I hope it's soon. I also wish we had some kinda vague timeline for 4.3. If proper mecanim events are just around the corner I'll work around my crappy event hack code until it is released. If it's months away I probably need to go ahead and improve my own system.