Category: Code

Kindle Fire HDX and Unity

Unity and the Kindle Fire HDX… a Christmas story!

As most of you know, I have been working on my wife’s game, Notespace, for the last year. It has been an epic adventure filled with joy and peril but treacherous waters of publishing on Android. You can avoid a lot of the problems by publishing multiple builds per texture compression but every now and then you get those sharp rocks that come out of no where. And that, for me, was the mysterious crashing on Kindle Fire HDX devices.

Now before I move on, for those that don’t already know, Android devices use an array of GPU’s where as iOS devices only use one (Power VR). This generally does not affect you in anyway except when it comes to texture compression that has alpha. Unity’s default Android compression setting is ETC 1/ RGBA16. What that means is that it will compress power of 2 textures with no alpha as ETC 1 (an older OpenGL format) and will set compressed textures with alpha to RGBA 16. On average, RGBA16 will be at least double the size as your compressed texture so it has the ability of sending your GPU memory usage over the edge. That being said, I have not actually seen that happen on a device but that kinda means nothing on Android with a gazillion devices on the market. Whats more important is that 16 bit textures can look really bad, especially if you have a lot of gradient work. So there is 2 ways around it. 1) Build a custom shader for your compressed images with alpha…




Adding the Dolby API to your Unity Project

While developing Notespace with Amorse Inc, we decided to implement the Dolby API into our tablet based game. The game is a interactive musical activity book for girls so it makes a whole bunch of sense. As of the date of this post, the Dolby API is integrated into the following:

Acer Iconia Tab 10 2014
Amazon Kindle Fire HDX 7 2012
Amazon Kindle Fire HDX 8.9 2012
Amazon Kindle Fire HD 7 2013
Amazon Kindle Fire HDX 7 2013
Amazon Kindle Fire HDX 8.9 2013
Amazon Fire HDX 7 2014
Amazon Fire HDX 8.9 2014
Amazon Fire HD 6 2014
Fujitsu Arrow F-06E
Lenovo Yoga 8 2013
Lenovo Yoga 10 2013
Lenovo Yoga Tablet 2 8” 2014
Lenovo Yoga Tablet 2 10” 2014
Lenovo Yoga Tablet 2 Pro 2014
Samsung Galaxy Tab 3 8.0 2013
Samsung Galaxy Tab 3 10.1 2013
Tesco Hudle2 Tablet
ZTE Grand S Flex
ZTE Grand S
ZTE Grand Memo LTE
ZTE Grand Memo N5S
ZTE Nubia Z5S
ZTE Nubia Z5S Mini
ZTE V975
ZTE N5S
ZTE Geek U988S
ZTE Boost Max
ZTE ZMax
ZTE BladeBox

As you can see, we know that its not on iOS devices (boo) but is on every Kindle Fire device past first gen. Thats a sizable market to optimize our experience for! We also know, for development down the road, that every Windows 8 device will have Dolby hardware. This is not necessarily true for Windows 8 mobile though, so don’t get them mixed up.

First, we are…




Unite 2014 Presentation: BUILDING A SOLID FOUNDATION

Video recording of my session

Presentation slides




Resizing Textures In Unity

It sounds silly but its true! Unity does not have any methods for resizing textures. Experienced readers might object, “what about Texture2D.Resize?” you say. Well, turns out that Texture2D.Resize only resizes the texture container, like trimming an array. Unlike trimming an array, Texture2D.Resize also sets the pixels to undefined. So really, all its doing is changing the amount of memory allocated. Thats all a bit disappointing, especially when you might be wanting to build a multi resolution pipeline for mobile. The weird thing is that Unity does this already when generating mip maps. So, lets roll up the old sleeves and figure this out.

We can get pixel data from texture, check! We can alter the pixel data, check! We can put pixel data into a texture, check! So whats left? The algorithm to resample pixel data. Resample is really the operative word because we are going to sample the source texture from the destination texture, pixel by pixel. This is exactly how pixel shaders work. So, We have our source texture at 1024×1024 and a destination texture at 512×512. What we are going to do is iterate through that 512×512 grid, find the corresponding color from the source texture and fill out destination pixel. Now we get to words you might have heard but never have known what they meant. Bilinear sampling is most common in games and gives a good understanding of how to sample but we are going to start with a technique called Nearest Neighbor. Resampling is mapping one set of coordinates onto another. So…




Lists and Linq in Unity, do it!

I have been using C# for many years now in game dev and I love it. Most hardcore C++ guys have always given me grief but I still think the language is beautiful! Yes yes, its memory managed but thats a whole beast unto its self. At least I don’t have to spend a week looking for an illusive overwrite or leak. But each unto their own, we all make games and in todays world, fast to market is a big deal, especially with little to no budget.

One of the great things in C# is Lists. For those of you who don’t know them, they are basically dynamic arrays with a whole host of special functions. They are wonderful things, especially for inventory systems. There is a lot of debate about if they are significantly slower than arrays but the general rule is don’t add to them in a critical update loop. Besides being able to add and remove items dynamically, you can also just bake the list to an array using ToArray(). This way you can have a list that you use to manage your stack and once you are done, you can just bake it out.

So what I want to chat about here is Linq, which is C#’s look up language for lists. I always stayed away from it, erring and my years for “Doing things the right way” but Linq used in the right way can save you a lot of time. I have started using it for my data structure look…