Tuesday, December 18, 2012

Syntactic sugar for Unity3D binding

Recently, we've updated the Unity3D version of our product. Along with various fixes and improvements, we've added a feature that allows you to bind JavaScript methods even easier than before. The feature is called "Automatic binding" and it was suggested by one of our beta testers (thanks, Tyler!).

Using the current pattern, you have to wait until Coherent UI fires the ReadyForBindings event, and register your handlers. That would look something like this:
The essence of the new feature is decorating the method in .Net that you want to bind with an attribute, specifying the name of the corresponding JavaScript function. Using the attribute simplifies the code above to the following:
Easy, right? The second argument of the attribute defines whether the JavaScript event should be treated as single or multicast. You can check out the binding sample in our new version, along with detailed explanation in the Coherent UI guide for Unity3D.

We're always striving to improve our product, so if you have an idea for a cool feature don't hesitate and drop us a line :).

Thursday, December 6, 2012

Far Cry 3 Review: UI & Gameplay

Far Cry 3, the long waited role-playing shooter game, has just been released in the US for consoles and PC. Critics describe it as “something like Skyrim but with guns” and many say that this is the best game UbiSoft has released since Assassin's Creed: Brotherhood.

We don’t know if this is true yet, however when there is so much buzz around an AAA title the team of Coherent Labs is always curious to find out more about it. Since we believed that many of you will be interested to learn more as well we decided to share with you some screenshots of Far Cry 3 introducing you to the game’s UI and gameplay.




As you can see on the picture there are different kind of troops in Far Cry 3: skulls are the normal guys, the shields are the heavies, and be careful from the lightning guys - they are fast, suicidal and probably the most dangerous NPCs. There are also 2 types of animals - herbivores and predators. With so many enemies the good news is that you are able to see people through the walls which allows you to prepare a stealth attack instead of getting killed in the melee. You’re also able to spot others on your mini map.



This beautiful HUD represents the camera that you use to zoom in and get a closer look before you decide to explore certain location. It has a nice legend explaining about the types of NPCs you might see and it also allows you to take pictures which you’re able to review later in your gallery.



This is how the map looks like in Far Cry 3. The red bits represent the enemy controlled territory which you need to conquer. You are allowed to fast travel to your camps marked on the map and, last but not least, you can see different kind of animal territories - bears, deer, pigs, etc.The map also displays cursor’s coordinates and has a legend explaining the meaning of each icon.



This is one of the RPG elements in the game allowing you to take quests for which you get small rewards and xp. The fun part is that you’re supposed to kill the target with a specific weapon in order for the mission to be successful.



In the game inventory you are allowed to carry and use different kind of potions which you prepare by yourself using ingredients that you find on the island. This is why the player in Far Cry 3 needs to pay close attention to the wildlife or he’s going to have a tough in the game.



There is the place in every camp where you are allowed to buy weapons and ammo, to customize them by changing their skin or to improve their performance.



You are also allowed to learn lots of skills in Far Cry 3, mainly divided in 3 category:
  1. The heron - these are long range takedowns and mobility skills
  2. The shark - assault takedowns and healing skills
  3. Spider - stealth takedowns and survival skills


This is how the Handbook looks like. Here you can check out your progress of the game: number of missions, quests, skills learned and more useful things.

If these screenshots are not enough for you to get a feeling about the game’s UI and gameplay, you might want to check out this video review of Far Cry 3 done by the Official Playstation magazine.



Far Cry 3 is one of these games that impresses with great UI and gameplay. You will be surprised how big is the world in the game and that it has a life of its own with NPCs attacking each other on island regardless of your presence.

Tuesday, December 4, 2012

A high level shader construction syntax - Part III

This article is part of the a series of posts, the first ones can be found here: 

A high level shader construction syntax - Part I
A high level shader construction syntax - Part II

Compile-time conditions

Although the proposed shader syntax minimizes compile-time code branching, it is still needed. Sometimes it is required to perform a calculation only if a specified previous step has been selected by the polymorphic decision system. Such cases should be rare.

To address the issue two new keywords are introduced: CONTEXT_IF and CONTEXT_IFNOT. The syntax for using them is: 


The usage is:
CONTEXT_IF(context.some_semantic) {
...
}

When the CONTEXT_IF is parsed, the translator splats the code in the curly braces if (or not if) the semantic is currently present in the context.

For instance in the snippet above if specular_color has not been calculated (i.e. GetSpecularColor()) was None, then the semantic will be missing from the context. In that case the CONTEXT_IFNOT will be true and the code will be added to the final shader. Keep in mind that all those conditions are evaluated at shader translation time and at the moment the translator reaches the line with the context conditional. If the tested semantic appears after the test in code, it won't influence it.

The implementation supports condition nesting as well as polymorphics in conditions. However conditions can currently appear only in the main body of the shader and not in expanded polymorphics.

Implementation

A sample implementation of a translator that implements the enhanced syntax can be found on GitHub:
http://github.com/stoyannk/ShaderTranslator.
The sample can easily be modified to become a stand-alone library.

The major components are the ShaderTranslationUniverse and the ShaderTranslator. The universe is a holder for all the atoms, combinators and polymorphics. It is highly likely that all shaders in a product share a library of those components but it might not always be the case.

The ShaderTranslator performs the translation itself given a universe and the initial source code. It outputs valid HLSL SM4 code.

The translation process itself is heavily based on regular expression and performs a lot of string operations. To speed things up and reduce memory fragmentation, the temporary strings used during the translation process use a linear scratch allocator. It takes a big chunk of memory and always returns new blocks from it without ever freeing it. At the end of the translation the whole memory region is freed all at once. This scratch allocator is accessed as a thread-local variable. I wouldn't recommend however using the translator at runtime - it is best suited as a step in the build process of the final product.

I wasn't too pedantic at fixing allocations during the translation process so some containers used still access the default allocator. It would be trivial to change those too.
The main program comes with two sample shaders used for testing.

Monday, December 3, 2012

What can Unity 4 and DirectX 11 do together?

With the new version Unity 4 introduces support for DirectX 11 which can really take your graphics to the next level. The company released a video explaining a bit about the new features, however we believe it was not enough for the game developers to learn even slightly for all the possibilities.

Using DirectX 11 with Unity 4 means taking full advantage of features like:

Shader model 5

The main purpose of this feature is to solve a common problem in current game engines: the upsurge in the number of shaders due to the large number of permutations. In other words, for each kind of material and light the game developers must include a shader in order to handle all cases.  


DirectX 11 offers an elegant solution through dynamic shader linkage.
 
Tessellation

Tessellation is one of the biggest features around DirectX 11 and Unity 4. It is simply breaking down polygons into finer pieces which brings profound improvements to 3D graphics. For example, game developers can cut a square across its diagonal to make 2 triangles and use them to depict new information. You can see the difference in the images below.



Without Tessellation



With Tessellation

Compute shaders

Compute shaders provide high-speed general purpose computing and takes advantage of the large numbers of parallel processors on GPU. They provide with memory sharing and thread synchronization features to allow more effective parallel programming methods.

A great example is this demo made by Nvidia showing a real-time simulated ocean under twilight lighting condition.



Unity 4, DirectX 11 and UI

As you may already know, Coherent UI have been recently integrated with Unity. Coherent UI natively supports DirectX 11 rendering and we are really happy that in Unity 4 it is supported too so users will be able to use its features to create better game UI. Inspired by this we integrated one of the Unity 4 samples with Coherent UI components and we made this demo to show you what Coherent UI, Unity 4 and DirectX 11 can do together.



As you can see there is a HUD on the main camera and two more Coherent UI Views on the paintings. You are allowed to scroll and select the paintings, interact with the UI and even play a game within the game. At the same time the performance has improved up to 50% compared to using Unity 3.5 version and DirectX 9.

If you’re interested in using Coherent UI with Unity 4, you’re welcomed to request a public beta of our integration with the game engine from our download page.