Tuesday, September 09, 2014

Getting Started with Game Programming Using Unity

I have been starting out with Game Deveopment recently, specifically using Unity Game Engine. It’s been an interesting experience so far but also an overwhelming one. There are a lot of aspect in game development that trying to ship something quickly requires you to have a good focus in both the learning and working process. Below is the list of starting guidelines that I find could save you a lot of time but at the same time give you most benefit :

  • Use tutorials and videos as  your main learning tools. Unlike what I experienced with learning many development platform before, manual and documentation of Unity (version 4.5 as of this writing) does not give you much foundation to start being productive. Instead, their tutorials, videos and samples on the site are the most useful ones to get you started and learning the concept and practices. You can refer more to manual and documentation later on when you have more context and the relevance of it’s contents
  • Read this two books : "Game Coding Complete” and “Game Engine Architecture”. It will give you valuable shortcut to game programming world that could probably take you months or even years figuring it our yourself from various sources.  Surprisingly, it gives you more insights and contexts on why Unity do things the way it does compare to Unity-specific books. Also as an added bonus you get also the concepts of game development and engine in general too, not just Unity
There are a lot of other materials to advance further, of course, but so far I find the two above is what I wish someone had told me when I got started before wasting too much time to build something by reading the manuals or reading Unity-specific books :)

Friday, June 06, 2014

HEVC support on Android

HEVC is the new video coding standard which even on the Desktop it is still basically under development. So, having a support for it on mobile device at this moment is even more interesting.

For library , it seems there is two major hevc decoding support currently, that is openhevc (part of libav library) and libde265. Both seems to be usable, at least for low resolution samples. However, their use require you to integrate them to media framework or pipeline like gstreamer.

If you want to just have quick look of hevc playing, right now you can just try Vitamio SDK. It already support hevc through its use of ffmpeg underneath it. It also mimic the API of Media part of Android SDK so it will be straightforward to use compare to using third party media pipeline like gstreamer as mentioned above.

Thursday, June 05, 2014

Conversion and Playing of HEVC on Desktop and Web

HEVC (H.265)  is the new emerging video coding standard. It is made as a success for the widely used H.264. It's implementation and adoption progress is quite fast. It probably because the 4k display has been out for someitme and the video streaming is  currently booming, both of which are being handled nicely by HEVC.

At the moment of this writing you can actually able to convert material to HEVC and playing it. The implementations are mostly still in beta stage and some are not avaiable through the more common publicized channel, but it's quite usable from my tests so far. The quality is quite good too in term of visual quality and compression ratio. So, you can already play around with the technology at this stage.

Conversion :  x265 and Handbrake Nightly Build

x265 project probably is the most used HEVC converter right now. It has progressed quite far, below is the quote from the author on one of the forum :
x265 development is going well.  x265 is often able to exceed the HM reference encoder in quality, with performance that is orders of magnitude faster.  The x265 HEVC encoder is easily able to encode with quality / compression efficiency that far exceeds the best H.264 encoder available, x264.  We've just passed the 0.7 milestone.  Although we have more algorithmic improvement and performance optimization on the development roadmap ahead, x265 is quite usable today, and it includes many advanced features.

So, it is quite a safe bet to choose x265 project for HEVC encoding purpose. However, using it directly means using CLI which is cumbersome and would require manual demuxing and remuxing, so it’s better to use proper video conversion application.

There is no official release version of full-featured video converter that uses x265 yet. However, Handbrake-nightly-build already integrate x265 whitin. The developer said that they won’t be  releasing it until HEVC standard more widely used which probably will still a while. So, you just have to use the nightly-build if you want to have access to HEVC conversion on Handbrake for sometime ahead.

Unfortunately, currently it only exist on Windows version of Handbrake. So, no support for other platform for now.

Now, about the playing.

VLC Nightly Build and Playing on Browser

The latest release version of VLC (2.1.4) can not play HEVC output in container (muxed) yet.  It will complain when you try to play the file you encoded with Handbrake above.  However, hevc playing support is currently progress and can be tested on VLC-nightly-build version (2.2.x). It works well playing output from Handbrake when tested.

Also, the good thing about VLC is that it has browser plugin support for Mozilla and Activex(IE) so it can be used to play HEVC content on the browser. It currently only support Windows though but the plan is to have it on other platforms when 2.2.x finally released. This would be interesting since it means you can now start streaming HEVC stream to wide range of targets.

Another alternative for the web/browser support for HEVC is DivX Web Player whichs seems to be free although not open source.

Monday, April 14, 2014

Better way of combining path in C#

You could do string operation to construct path as below :

string path = path1 + "\\" + path2;

However, more portable and cleaner way would be to use Path.Combine as below :

Path.Combine(path1, path2);

The above avoid you to make manually ensuring the correctness of path separators.

Monday, March 24, 2014

Choosing Logging Library for .Net : NLog

When it comes to logging, printing it out yourself to console or file probably the most straightforward way. However, if you want to get more structured in your log, with level and flexible on/of switching you'll need a more dedicated logging library. However, like any library, choosing the sweet spot where you get the feature you want but with the least complexity and learning curve can be challenging.

As for logging, when I research around the two that pop up most is log4net and NLog. The choise is pretty simple though, log4net is good but pretty outdated now while NLog is quite active, well-supported has rich feature. So, the choice goes to NLog.

Quick Usage :

After you link the library (using NuGet or manually). Declare the logger in your class :

private static Logger logger = LogManager.GetCurrentClassLogger();

and call at the place that needed it :

logger.Debug("log message");

You can add a lot of additional details to your log with its predefined variables. You can consult the manual to see what is available. Also, since you declare logger on each class, it can automatically  print in which class and the point where the log is called. It is quite useful for debugging.

Monday, March 10, 2014

Lesson about delegation from OpenCL

Using OpenCL and the complexities / benefits that comes with it reminds me of an issue of trade-off in delegation. You can always do things the simple straightforward, serial way but there is a limit of how much and how fast it can finish the tasks. We can scale things better by utilizing more external agents and manage it. However using additional agents means delegating tasks to those agents and manage the overhead and unpredictability that comes with it. This is why the code to achieve the same thing using OpenCL can be quite complex since you need to manage the data and logic that comes to and from those computing units and get them to work together properly.

It's not just cost that is increased though, the risk is also higher. When you delegate, you add another factor with its own set of quirkiness to your system. Each agent you add, you add another risk of it fail in some way and effect the overall system. In OpenCL, certain GPU might not behave as it should, your calculation might fail in certain configuration. So, you will need to add more activities to manage the risk. How it can be anticipated, localized and how the system can cope gracefully when it happen.

So, since delegation is not free it is important that the scale of the problem would need to justify the use of delegation.  You can add more things, method, people to your system, but when it does not fit your scale, it will become a burden since your output, what you get, is lower than what you need to expense. In term of OpenCL, the low complexity or low number of calculation probably not worth the trouble. For example, even when you ding the formula is complex and can be paralellize but if your expected data to be processd is not much, it probably better to just code it the traditional way.

Delegation can be costly and risky, but if you need your solution to scale better, the return can be very much worth it.

Friday, February 28, 2014

Translating Traditional Program Logic to OpenCL

If you just started to look at OpenCL and see the example of the code, it can be quite confusing on how it got that way from its traditional program logic counterpart. Take a look at an example of comparison below taken from PDF Overview on OpenCL site :

You can see that the calculation is intact but you can't seem to find where the for loop counterpart is.

It is because, the logic has been separated between host (your main program) and kernel (that will be sent to device). So, you need to look at both of them to get the whole picture. There is some data partitioning done that you can take a look at the code at the host. Together with the batch processing happen in kernel code you can start to see the implied loop there.

Due to its parallelism and batch processing nature, the logic in OpenCL can look more declarative and more separated compare to traditional one. So, the logic that you expect to find will probably be implied somewhere in host and kernel code. This could help if you try to read the existing code.