Tuesday, November 20, 2012

Volume Materials in Unity4.

Some quick experiments with volume textures (Texture3D assets) with Unity4 yielded the below results.


This ship is using volume materials only, no UV unwrapping is required.

Tuesday, October 16, 2012

Unity4 and Texture3D

The new Texture3D support in Unity4 is an absolute gift when it comes to planet shaders! It's not documented very well (at all!) so it took some trial and error to get working.


Friday, September 21, 2012

A Football Game

Ive been working on a small yet ambitious game over the last 3 months.

It's almost baked, so we're starting up the Hype Machine.

You can see a small preview here.

It follows my usual MO, with a Python backend and a Unity3D client. More coming soon! :-)

Wednesday, September 12, 2012

Spacecraft shading cont...

Today I discovered that Unity3D will let you apply multiple materials to a single mesh. So I used a bump mapped triplanar material, an image based lighting material and a triplanar emissive material on the one ship. I had to adjust the shaders so they would work together, Eg. the IBL shader only uses the emissive channel and blends on top of the previous material.


Monday, September 10, 2012

Spacecraft Shading

After revamping my Spacebox tool I implemented a little shader which uses the spacebox cubemap to apply image based lighting to a model. Realistic lighting in space adds a lot of immersion factor to a scene.


I really want to texture this ship procedurally. I've played with some tri-planar shaders, but am not super happy with the results. Who can tell me a good idea on how to approach this? :-)





Tuesday, September 04, 2012

UniWeb, WWW and crossdomain.xml explained.

I get many confused emails from people trying to get UniWeb to work in the Unity WebPlayer. It works, but you have to set things up correctly, as described in the manual. I'll explain it again here, maybe it will reduce the influx of support emails!


Situation #1.
You want to use the builtin WWW class to fetch stuff from a HTTP server.

In this case, you MUST have a crossdomain.xml file that is hosted by that SAME HTTP server,

This will allow, and ONLY allow Unity's builtin WWW class to work. It has no effect on the usage of .NET sockets within Unity.

This particular setup will NEVER help you get .NET sockets (and by
extension UniWeb) working within Unity WebPlayer.


Situation #2.
You want to use UniWeb to fetch stuff from a HTTP server.

In this case, you MUST have a server process running on a port on the SAME host, which follows the behaviour specified in the manual.

This will allow .NET sockets (and therefore UniWeb) to work within a Unity WebPlayer. The Security.PrefetchSocketPolicy MUST be called before .NET sockets will successfully connect to a host on ANY port.

Particularly note this section from the manual:
Specifically the server expects to receive a zero-terminated string
that contains . It only sends to the client the socket policy xml document when this string (and exactly this string) has been received. Further, it is required that the xml header and xml body are sent with a single socket write.

Also note:
Note: Whilst the crossdomain.xml and socket policy files are both xml
documents and are broadly similar, the way that these documents are served are very different. Crossdomain.xml (which applied to http requests) is fetched using http on port 80, where-as the socket policy is fetched from port 843 using a trivial server that implements the <policy-file-request/>. You cannot use an http server to issue the socket policy file, nor set up a server that simply sends the socket policy file in response to a socket connection on port 843. Note also that each server you connect to requires its own socket policy server.

Monday, September 03, 2012

JS Games

I'm clearly not under enough pressure so I've decided to have a go at the 13K Javascript Game Competition.

I spent some time looking at existing libraries, and it seems clear that very few were designed for tiny 13k games! Obviously I must therefore write my own engine. Chortle. It will be fashioned after the superb design of Unity3D.

Code is on github, and I'm happy to say my base framework weighs in at 612 bytes compressed. Next up, adding things that draw stuff.


Wednesday, August 29, 2012

Really Really Easy Multithreading in Unity3D.

When you start working with threads in your Unity3D project, you will discover that many things need to be done in the main loop. For example, if you try and do a Physics.Raycast call from a thread, you'll come across this error.

INTERNAL_CALL_Internal_RaycastTest  can only be called from the main thread.

This can be really frustrating, so, what to do? We need some Magic Threads!

The below example shows how the latest version of UnityExtender allows you to make a coroutine jump back and forth between a background thread and the foreground main loop. It doesn't get much easier than this, and it integrates perfectly with Unity coroutines. This new version of UnityExtender should be available in a few days.

    void Start () {
        MagicThread.Start(ThisIsAMagicalThread());
    }
 
    IEnumerator ThisIsAMagicalThread() {

        Debug.Log("I am running in the background.");
        //This will raise an error
        Physics.Raycast(new Ray(Vector3.zero, Vector3.forward));

        yield return new ForegroundTask();
 
        Debug.Log("I am now running in the Unity main loop.");
        //This will work!
        Physics.Raycast(new Ray(Vector3.zero, Vector3.forward));
  
        yield return new WaitForSeconds(2);

        Debug.Log("About to re-enter the background...");
        yield return new BackgroundTask();
        Debug.Log("I am running in the background again.");

    }

Tuesday, August 28, 2012

Unity3D + Pusher.com

Pusher.com is one of these new fangled web services things aimed to reduce the amount of work us developers need to do to get large scale applications and games up and running. In a sentence, it's a big pub-sub service that uses Web Sockets.

I've made a Unity3D API for it, and it's available on GitHub.

Friday, August 17, 2012

The Secret Project

This is the complete schema for my current project. Of course, deliberately downscaled so you can't exactly see what is going on... :-)


I'm building most of the game server within PostgreSQL itself, using the plpython extension language. The game interface will be HTML, with a tiny bit of Unity3D visualisation. Having been out of the web dev game for some years now, I'm not sure of the best tech for exposing my database as a Web API, and I'm double unsure about what client side tech to use. Shouldn't we have a one click develop and deploy solution by now? :-)

Sunday, August 05, 2012

Controlling an IP Camera from Unity3D.

I recently bought an IP camera, which I discovered has a HTTP interface which lets me pan, tilt, take pictures etc. Of course, I had to use this from within Unity, so I wrote a small class which lets me stream the camera's image down into a Texture2D instance.

Code available on github.

Friday, August 03, 2012

Augmented Reality #2

This time, a stadium and city scape on my lounge room floor. Therei s actually a game playing in that stadium... but you can't see it from here.

Saturday, July 28, 2012

Augmented Reality

I've been experimenting with the Vuforia Augmented Reality plugin for Unity3D. It works very well! In the below image, I have a teeny little animated character which appears whenever I view my business card. And those little blue things buzzing around are butterflies! Next thing to do... give her a can of bug spray and a fly swat! :-)


Thursday, July 12, 2012

UnityGUI: Tip and Tricks

I suspect I am alone when it comes to praising UnityGUI. I was rather pleased to hear that more work has gone into UnityGUI in the Unity3D 4 Release. I know that most people don't like it for one reason or another, but I believe there are a few reasons to LIKE it that most people don't consider.

1. Text Editing. Have you tried to implement a reasonable text field widget using other toolkits? UnityGUI already does it perfectly, on all platforms. No third party GUI toolkits have the same capability. If you want your home and end keys to work, or allow the user to use a mouse to select text... UnityGUI is the best (and only?) solution.

2. Customisation. It is trivial for a programmer to create compound widgets which can be reused all over the place. Eg, grids, table views, validated text fields, etc.

3. Skinning. It is so simple to apply a different skin to your GUI, and to get artists to build a custom skin for you.

4. It's standard. You know you can use it anywhere and it will work the same. You know you can take someone else's GUI code and make it work for you without major changes. We need a standard to allow interoperability.

There are still some valid issues with UnityGUI.

It's hard for non-programmers to use, and it's hard for programmers to make nice looking interfaces. This is primarily a tool and workflow issue, and solvable. To get started with your own solution, make your GUI scripts run at edit time using [ExecuteInEditMode], so you can visualize changes. Expose all your variables in the inspector so they can be tweaked and visualised.

The performance issue is harder to solve, but I would posit that if you're experiencing major performance problems and you blame UnityGUI, then you're just Doing It Wrong. The path to UnityGUI enlightenment starts with using only one OnGUI call per scene. Next, remove your GUILayout calls, and write some layout manager code which can size and position your widgets just once, or when needed at runtime. Set your GUI.skin variable once, and don't use GUIStyle instances, just refer to a custom style in your skin. This will help you get the best performance out of your GUI code. It also helps to remember that while people are staring at your GUI, they're probably not worried about dropping to 60 instead of the usual 200 or more! :)

Finally, do yourself a big favour and learn how the event system in Unity3D works. You can get the current event using Event.current. Once you have that information, your code can make smart decisions about which methods to call and which events can be short-circuited.

Tuesday, June 05, 2012

A new startup...

If all things align, I'm about to start work on a new venture.

For the last two years I've been building something epic, and I've now handed that project over to a new team in Singapore. It is time for something new!

Of course, I can't say exactly what I'll be doing, but it will all be made public in about 3 months. What I can say, is that the project is at least an order of magnitude more complex than any system I have yet built. It will run on Unity3D and Python. It's a niche market game, but there is a dedicated and unusual audience waiting to play it. And I have a stake in the new company. I think that is important. I think it guarantees a success, or at least a spectacular disaster! :-)

Monday, June 04, 2012

Complexity

I'm building a new game for a new client. The specification of the game rules is very detailed, and well structured. To help visualise the task, I built a parser which generated a JSON structure of the rules, and also a directed graph. These were the results, scaled down to 2.5% of the original size.



Wow, this is going to be fun.

Tuesday, May 29, 2012

Monday, May 28, 2012

Kroolz

As recently promised, "Krool Joolz" has made a comeback on the iOS platform as "Kroolz". Get it here, it's Free!

Monday, May 07, 2012

Micro Optimisation in Unity3D

NGUI caches the transform component in a member variable called mTrans, to optimise speed of access. I think this is UGLY, so I decided to do some benchmarks to see if the ugliness is worth the performance increase.

In short, the answer is NO.

My tests showed that using a local variable is always as fast as using a member variable, and usually faster.

Here are some typical results.

Cached: Time elapsed: 00:00:04.8086550
Uncached: Time elapsed: 00:00:09.1058490
Local: Time elapsed: 00:00:04.7870590

They show that caching and accessing the target reference is twice as fast as just using the reference. They also show that assigning to a local variable and using that variable for access is usually even faster than a member variable.

This is the code I used for benchmarking.

using UnityEngine;
using System.Collections;

public class Benchmark : MonoBehaviour
{
    Transform cachedTransform;
    
    void Start () {
        cachedTransform = transform;
        TestCached();    
        TestUncached();
        TestLocal();
    }
    
    void TestUncached()
    {
        var stopwatch = new System.Diagnostics.Stopwatch ();
        stopwatch.Start ();
        for (int i = 0; i < 100000000; i++) {
            var p = transform.position;
        }
        stopwatch.Stop ();
        Debug.Log (string.Format("Uncached: Time elapsed: {0}", stopwatch.Elapsed));
    }
    
    void TestCached()
    {
        var stopwatch = new System.Diagnostics.Stopwatch ();
        stopwatch.Start ();
        for (int i = 0; i < 100000000; i++) {
            var p = cachedTransform.position;
        }
        stopwatch.Stop ();
        Debug.Log (string.Format("Cached: Time elapsed: {0}", stopwatch.Elapsed));
    }
    
    void TestLocal()
    {
        var stopwatch = new System.Diagnostics.Stopwatch ();
        stopwatch.Start ();
        var t = transform;
        for (int i = 0; i < 100000000; i++) {
            var p = t.position;
        }
        stopwatch.Stop ();
        Debug.Log (string.Format("Local: Time elapsed: {0}", stopwatch.Elapsed));
    }
}

Saturday, May 05, 2012

Rendering HTML

Rendering HTML in Unity3D sure is... tricky.
It would seem simple enough, but page/text layout algorithms can certainly be challenging, even when supporting only a subset of HTML.

Monday, April 23, 2012

Tuesday, April 17, 2012

How not to spend your kickstarter funds...

Having just read What the Hell These Game Developers Did with Your Kickstarter Money I have to respond to this particular point:
In a recent update post on their Kickstarter, War Balloon breaks down where all that money's gone and it's a revealing portrait of what kinds of costs an indie dev team can face.

The revealing costs in question?

After that, we had $22,000 remaining. From there:

Music - $6,000
Attorneys, startup fees, CPA - $4000
Poster art - $2000
iPads - $1000
PAX East - $3000

TOTAL: $16,000

Now, I don't RANT often (LOL), but here comes my squinty-eyed-viewpoint from 30000 feet...

$6000 on music! Woah, thats a terrible waste. Instead, buy a bunch of sample packs from the interweb and write a procedural background music manager. $100 for loops, 2 days labour, awesome sound filler.

$4000 on legal fees... I could be wrong, but that seems to be a really dumb move at this point. If you really need a legal entity in order to develop your game (!?!@?) instead of ramen noodles to feed your programmer army, then register something in the Cayman Islands or somewhere similar. Seriously, I don't think you need to this Right Now.

Poster Art, $2000. Are you kidding me? You spend 2k on Posters? For your office or for promotion? If these posters are for your garage wall, then I need say no more. If they're for promotion... then you don't need them right now. If they're for PAX East, then you spent way too much. You could buy an A3 colour inkjet printer, design your own and print a dozen copies, laminate and frame them for far less than 2k. In fact, you could just enlarge some of your awesome pixel art for some awesome retro posters. LOL.

iPads, $1000. This is the only cost that makes sense, but only if you are developing for iOS.

PAX East, $3000. This almost sounds like a Corporate Junket. These events are rarely worth going to for if you're looking for return on investment. Better to save the cash and go next year, when you have a product ready to go and you can hunt down some partners to help promote your game.

</rant>

Thursday, April 12, 2012

(Python + Unity3D) == MMO

This is something I've been helping build for quite some time now, and it is almost done.



It is an educational MMOG. It is powered by Python out the back, and Unity3D at the front. The Python server(s) are running Python 2.7, with Greenlets :-) and ZeroMQ for IPC. We had to design our own ORM, because SQLAlchemy (our first choice) didn't play well with the asynchronous Psycopg2 extension. The backend is loosely based on an Entity Component architecture, which is quite elegant and a joy to work with. It has been so easy to modify and extend, that I think I'll be using this architecture for most of my new projects.

Soon, the whole system will be battle tested by hordes of screaming children. I am confident it will weather the storm, and more. :-)

Tuesday, April 03, 2012

Wednesday, March 28, 2012

Adobe charging royalties for new Flash content.


Adobe is going to charge you royalties if you want to make games in Flash when using "premium" features.

Yuck, this smells rather greedy to me. Yet another reason to stay away from Flash.



Wednesday, March 21, 2012

Unity3D: kCGErrorInvalidConnection

If your Unity3D editor starts showing a blank, grey screen, check your Editor.log.

If you see this error:
kCGErrorInvalidConnection: CGSGetWindowBounds: Invalid connection
we found that the fix is to change your resolution to something lower, open the Unity3D project, then change your resolution back.

Update:Hmm, fix was only temporary, the problem persists.

Tuesday, March 20, 2012

Unity3D Pro Tip: Singletons

If you're using DontDestroyOnLoad to preserve a game object across levels, you might find that you get duplicated instances of that object when you reload that level. How do you solve this simply?
public class MyComponent : MonoBehaviour {
    
    static MyComponent _instance;
    
    void Awake() {
        if(_instance != null) Destroy(gameObject);
        _instance = this;
        DontDestroyOnLoad(gameObject);
    }
}
If you want to reuse this behaviour, make it a base class and inherit from it in any components you need to persist but not multiply!

Things I like about PyPy...

The fact that PyPy needs to use scientific notation to print the results of a pystone benchmark... :-)


Pystone(1.1) time for 50000 passes = 0.016978
This machine benchmarks at 2.94499e+06 pystones/second

Saturday, March 17, 2012

Tuesday, March 13, 2012

Bzzzzt!

Sometimes Ball Lightning is the only way to cook your goose...


Burninating the Chickens!


Unity3D Pro Tip: Finger Gestures

The Finger Gestures library is an essential component of my Unity3D toolbox. It is used in almost every project I am working on. If you don't have it yet, you really should get it and learn it! Why?

Getting consistent input schemes working across multiple platforms is hard to get right, and I bet you have much better things to worry about that writing touch and mouse input routines for your game! So, skip the drudgery and instantly enable every kind of mouse and touch gesture you might need, from a simple tap, to a two finger swipe, to pinch and rotate. Finger Gestures will save you many hours of development, it is well worth the investment.

Tuesday, March 06, 2012

Mutton, Pork and Near Light Speed Projectiles.


Quido von Killnhurtz...

... is well prepared to stem the tide of Mutant Sheep!


Monday, March 05, 2012

Quido von Killnhurtz...

... returns in the Mushroom Incident!


Wednesday, February 29, 2012

Master of Orion on your iPad

It is not an official port, but a very good replica. This is one of my favorite games, and I don't have many. It's deep, difficult, actively developed and infinitely replayable. Definitely worth your time if you like 4x games.

Starbase Orion

Javascript in Unity3D


Thursday, February 09, 2012

Game Development: It has never been easier.

Some time ago I came across an excellent product, which let me make great looking games in a snap. The product is Unity3D, and it has grown to become a very strong development platform. Unity3D is a particularly good solution for Indie Developers, because it allows you to think about building games, instead of building tools to make games (which was my particular curse). This is part of what Unity Technologies call the "democratisation of game development".

A few weeks ago I came across another excellent and perhaps revolutionary product. What Unity3D does for game development, Parse does for backend development. Parse essentially gives you a zero configuration, no setup, zero to low cost, instant backend for your application. In the context of Unity3D, we now have instant game backends.

This is why we are building a tool to allow Unity3D developers to use Parse with zero effort. It's called UniParse, it will be free, and it is almost baked. Stay tuned.

Thursday, January 26, 2012

No GGJ For Me.

I'm flying from London to Singapore over the 2012 GGJ weekend. Sad to miss this one, but I'm looking forward to seeing what my fellow Perth peeps get done!

Friday, January 13, 2012

Best app @ BETT show in London?

IMHO, it's Skoolbo. Skoolbo is developed using Unity3D. Oh, and I run the company that built it! So I guess I am a little biased. :-)

Wednesday, January 11, 2012

We're building a library!

Would you like to help build a library for a school in Thailand?

It is easy to help out, all you need is to send a FB like, and you're sending a brick for the library!

Skoolbo is funding (and even helping with the brick laying!) the project.

Skoolbo is a project I've been working for almost two years. The backend is a beautiful piece of Python, and the front end is a similar quality piece of Unity3d, which will be released Real Soon Now.

Popular Posts