OS X Localisation: incremental genstrings and UTF-8 files

Development, OS X No Comments

I came across a couple of interesting issues when I came to do the first pass of writing the text for the user-visible strings I’d been setting up for a Cocoa app I’m writing (painfully slowly as I learn the nuances of the environment), and I thought I’d share them. Full details are after the jump, since I’ve embedded a large script in the post.

The basic principle for text localisation on OS X is that, like most systems, you externalise your user-visible strings in string tables and reference them by keyed aliases in code – in this case using NSLocalizedString. Apple provide a tool called ‘genstrings’ which extracts all these into a template strings file called Localizable.strings which you can then populate per language – localised files are kept in folders called en.lproj, fr.lproj etc and helpfully they’re picked up by default like this.  So far, so good.

Read the rest of this entry »

Taking a bite of the Apple

Development, OS X, Personal 13 Comments

Giving up the leadership of OGRE was a sad moment for me, but in hindsight it has also been rather liberating. For 10 years I’d spent most of my energy on OGRE or on projects that were related to OGRE. There was an implicit understanding both from the community and from myself that everything I embarked on would in some way tie into OGRE – and indeed my business has always been based on a constant balancing act between how I can make a living while also promoting and advancing OGRE. I’d tended to major on the latter rather than the former most of the time as it happens, because I had an emotional attachment to the project and a feeling of responsibility and custodianship that I took very seriously. So when I finally admitted to myself that my back couldn’t take the ongoing demands of being an open source leader as well as making a living, the big question was: what next?

Over the years I’ve learned a couple of things about choosing what projects to work on – follow your gut, and work on things you’d do even if there was no money in it. Yes, you need to do a business case and convince yourself that there’s a viable market for what you have in mind, but all that’s irrelevant if you don’t feel strongly about what you’re doing, because it’s passion and enthusiasm that will get you through the difficult times. So I sat down and gave some thought to what really excited me these days, what I liked using and what technical directions piqued my interest. I still find 3D and games fascinating, but they’re far from my only interests.

So, I realised that one area that I’ve been dying to get my teeth into properly for ages but had never found the time before, was coding specifically for Mac OS X. In 3 years I’ve gone from a total newcomer to the platform, to a staunch advocate of it. However until now I’d never really had time to play with developing on it, beyond porting cross-platform C++ code and providing / using intermediate libraries. One thing I learned in those 3 years as a user was how much better applications designed for OS X felt to use compared to those that were just ported via a common UI layer (like wxWidgets / Qt), and I’m convinced now that while cross-platform infrastructural code is great, user experiences are far better when designed with the specific platform in mind – increasingly that means OS and physical device now of course. Sure, cross-platform UIs save the developer time, but the result is often a watered-down experience – early on I liked OS X applications that felt like Windows, or ran the same on both platforms – now I  do not. Such carbon-copying applications were helpful while I was unfamiliar with the platform, but now it’s just glaring to me how basic their compatibility with the OS typically is, and how the UI styles clash with the expected standards.

So, I decided I wanted to learn how to target OS X specifically, and had a couple of ideas for projects I could do with it, which meant learning Objective-C. At first, I hated it and tried to escape via more familiar technologies like Objective-C++ and PyObjC. Ultimately I found shortcomings and limitations of those routes and returned to Objective-C, and the more I used it, the more my animosity toward it diminished. In the end I realised the problem was that I needed to adapt to the environment, rather than try to adapt it to my previously learned styles and behaviours. Sure, missing elements like namespaces might still nag me, but on balance the blend of static and dynamic language elements works very well for the intended use. And besides, I really didn’t want to be ‘that guy’ – the programmer that having decided one language / tech is ‘the best’, then tries to apply it everywhere, regardless of suitability; I like to think I’m a bit more flexible & multicultural than that.

I’ve also learned that Cocoa is a very, very smart system. Mad as a bison if you’re used to other systems beforehand, but persevere with it and resist the urge to hide it under some vanilla layer that you’re already familiar with, and you discover it’s really very powerful. Not to mention the Core Animation and Core Graphics frameworks are a lot of fun.

It’s funny, I’ve spent so many years concerning myself with providing compatibility across multiple OS’s, multiple GPUs, multiple render APIs, and multiple drivers, it’s a genuine joy to actually forget all that for a while, and concentrate on an end goal with a finite number of permutations for a change – and not to shy away from using platform-specific features.

While I’m still very much an advocate of open systems, I look at things slightly differently now – that data & protocols should be open, and that we should all re-use & collaborate on common, preferably open source infrastructure (like OGRE), but that the ‘last mile’ to the user is the least suitable for generalisation, because the more specific you can make that interface to what the user expects on their OS & device, the better that experience will be. And at the end of the day to the user, that experience is the application, and thus all that really matters – and I feel that Apple gets that, in a way that very few others do.

So, I’m having a great time learning to be an Apple developer so far, I’m going to see where this takes me for a while. My gut says it feels right, and I’ve learned to listen to my gut :) I love the platform, it’s a total change of pace and technology, it’s something I’ve had an interest in for a while, and the Mac has quite a thriving community of quality independent app developers that I can try to join – what’s not to like?

Monsieur, you are really spoiling us

Games, OGRE, OS X 4 Comments

Yesterday saw a triple-whammy of sugary Apple gaming goodness:

  1. Steam for Mac was released, meaning all the games you own on Steam that are ported to the Mac can also be played there, free.
  2. Torchlight was a day-1 release on the service, meaning Ogre (and therefore code written by me) was among the very first on the service.
  3. Portal became free (for Mac and PC)

Wow. A great day for Mac gaming. I noticed that World Of Goo was up on day 1 too, and since I’d bought it on Steam I could play it right away on my MBP too. Yummy.

Curiously, considering it’s based on Ogre, I don’t actually own Torchlight on Steam – I had a free Windows-only copy from Runic, I bought a physical (Windows-only) copy for my shelf, and I bought copies for both my wife and Diablo-obsessed brother in law on Steam but I never got a copy there myself, so I haven’t tried it on the Mac yet. I need to ask my wife to log in on the MBP so I can try it! :)

VMWare Fusion 3 impressions

OS X, Tech, Windows 3 Comments

vmware_fusion3As soon as Macs started running on Intel, they became infinitely more attractive just because suddenly you had the option of using Windows on them too if you needed to. Because let’s face it, as lovely to use as OS X is, and as much as its popularity has grown, the majority of the world still runs Windows. Boot Camp is a great little tool provided by Apple which makes setting up a dual-boot into Windows generally a breeze, barring a few small niggles such as the slightly ropey support for the extended functions of the track pad (two-finger right-clicking and scrolling is very flaky).

I have Vista installed as a secondary boot on my 2007 MacBook Pro, something I’ve come to regret as it’s regularly far more hassle than XP would have been. In practice, I’ve found that I hardly use it, with weeks passing without me bothering to boot up Vista (which makes it worse, because when I do boot it up its intrusive and wholly unstoppable update process starts kicking in in the background, making me grind my teeth at the CPU / RAM loss). Nevertheless, it’s useful at times.

I’ve dallied with virtualisation occasionally, from Parallels to VMWare to VirtualBox, but have been generally disappointed – my day-to-day work and most of my recreation involves 3D acceleration in one form or another, and virtualisation has historically been pretty bad at supporting it, making it an impractical option. VMWare Fusion 3, however, claims support for Shader Model 3, which is good enough for the vast majority of the work that I do (Dx10+ is still a tiny, tiny niche that is still rarely in demand), so I thought I’d give it a shot.

One of the nice things about Fusion 3 is that it lets you boot your existing Boot Camp partitions in a VM, which meant I could test it quickly. Parallels supported this too but I found it didn’t work that well in practice when I tried it. Fusion 3’s support is excellent – just a few minutes of adaptation and the requisite install of VMWare Tools on the Windows partition and it was up and running. The main problem I initially encountered is that the default 1GB memory allocation is, of course, absolutely no use for running the sweating hunk of lard that is Vista. This is the OS that is capable of getting up to 1.2GB on my machine after first boot with only Explorer open, if you’re unlucky enough that it feels it needs to run update processes in the background. I only (only??) have 2GB on my laptop so I had limits, but a quick tweak of the VM to 1.6GB (and also letting it use multiple CPUs) made it run OK and still let me jump back to OS X, albeit a bit slower than usual (but show me a post-millennium Windows OS that can stay usable on 400MB!).

For general non-specialist use, Fusion 3 is as awesome as other virtualisation tools. Either in a window, full screen, or in ‘Unity’ mode, where Windows apps look like first-party OS X windows in your task list (a bizarre feeling to have Explorer and Visual Studio show up in Exposé), it works great. They even fix the track pad issues, it works much better than in Boot Camp natively. I’d definitely want to upgrade the RAM on my machine if I did this regularly, but it’s certainly solid. But, for me, it’s all about the 3D, so let’s get to that.

I ran through a few GPU tests, after having to wait an hour or so for Vista to go through its background update processes so that it stopped sucking CPU and RAM, distorting my performance sampling (grr), and sure enough all the OGRE demos ran ok. They did, however, run pretty slowly; simple fixed-function demos that usually run at 2000fps on this machine ran at about 300fps, and moderately complex SM2 demos usually pegged at 250fps here ran at about 40fps. Highly complex SM3 demos (e.g. OgreSpeedTree) were unfortunately almost unusable. So, you can expect a pretty steep performance penalty of at least a factor of 6 times running virtualised 3D in my experience. Clearly, at this performance degradation, this would be no good for me as a sole Windows option on this machine. But, it still is valuable, since it’s using the Boot Camp partition, I can use this to quickly test things for compile & run-time behaviour, albeit at unrealistic performance levels, and reboot ‘properly’ into Windows for the times where I want to performance test or demo something.

That is, I would be able to if it wasn’t for Windows Activation. As we all know, this is Microsoft’s anti-piracy strategy and involves requiring you to re-activate your copy of Windows within 3 days if a ’significant’ hardware change is detected. Since a VM basically emulates all of the core system processes, inevitably Windows sees that as a ’significant’ change and requires you to reactivate. You can do this online, but only 5 times, after which you have to phone someone every time you want to do it. If I used my Boot Camp partition in both modes, as is useful to me, I’d have to reactivate way too often.

There are some threads and articles about this issue on the VMWare site; they claim that provided you follow this article, then the Windows activation monster will be sated and leave you alone when switching between Boot Camp and Fusion 3. No such luck for me, I’ve rebooted many times between Boot Camp and VMWare and have had the VMWare Tools installed since the first boot, and all I continuously get is an activated product when I use Boot Camp, and a ‘2 days to activation expiry’ message in VMWare. I’m not the only one: people are reporting this issue in the forums, including with Windows 7.

If they can’t get the activation issue fixed, so that I can choose to use Boot Camp and VMWare interchangeably, this effectively kills the product stone dead for me, as with every other virtualisation product before it. Which is a shame, because apart from this,  it works great. It’s Windows fault of course, rather than VMWare’s, but regardless the effect is the same. This is a perfect example of bad, customer-unfriendly DRM – it’s especially galling to have MS accuse me of stealing when in fact I’ve paid through the nose for many, many copies of Windows before, and am set to do so again with their expensive Windows 7 (Pro+) pricing – where they still seem to stick to this ridiculous principle. Another option would be to free up a spare Windows license from my collection and have separate Boot Camp and VMWare partitions, but I’d really prefer not to burn the time & disk space on maintaining two installs.

Fix the activation issue and I’ll be buying a copy of this plus a 4GB RAM upgrade immediately. Until then, it’s another nice product that’s scuppered by one small, but nevertheless major issue.

Edit: Ok, I’ve resolved this issue. Actually the original KB article on the VMWare site was correct, I just didn’t follow it correctly. In my defence, the key to success is in the small print at the bottom of the article rather than the ordered steps: you have to make sure that you’ve booted once into Boot Camp with the VMWare Tools installed, then afterwards to start the VM under OS X and reactivate Windows. Having done this, both my hosted VM and Boot Camp configuration show up as ‘activated’, which is precisely what I need.

So, now to buy a copy of this puppy and get 2 new sticks of RAM to shove in the laptop. :)

Accented characters on OS X

OS X, Tech 4 Comments

I can’t believe this is the first time I’ve needed this on OS X, but it came about from needing to write a document for a European customer and suddenly realising I didn’t know how to make an umlaut on my Macbook Pro’s British keyboard. On Windows I might fire up the Character Map, but I didn’t know how to do it on OS X. Here’s what I discovered:

  1. OS X friendly apps like Mail, Safari, iCal and even Firefox have a ‘Special Characters’ entry on the Edit menu which brings up an equivalent of Character Map.
  2. For less OS X friendly apps (like Open Office), you can add a menu bar item to do the same everywhere under System Preferences, Language & Text, Input Sources – check the Keyboard and Character Viewer option and make sure the Show Input On Menu Bar is enabled. Then you just click the new icon on the menu bar every time you need the character browser.
  3. The most common ones have keyboard shortcuts which modify the next character you type afterward – Option-e puts an acute accent on the next character you type, Option-` is a grave accent, Option-u is an umlaut, Option-i a circumflex, Option-n that weird Spanish squiggle ;) While experimenting I found the ® and © symbols too (Option-r and Option-g respectively, Option-c is the cedilla)

So there you go – useful stuff if you’re on a British (or presumably US) keyboard and need to deal with non-English names from time to time. If you already knew this, great – this is just for people in my position who have to use these characters rarely and haven’t encountered it on a Mac yet.

Apple owns the US premium retail PC market

OS X, Tech, hardware 18 Comments

apple_logoThis was pretty interesting; CNet reports that according to NPD stats, Apple has 91% of the retail PC sales in the US above $1,000.

Now, let’s add the caveats here:

  • That’s retail PCs. Of course, loads of people build their (desktop) PCs from OEM parts rather than buying a prebuilt machine, so it’s safe to say that these sales are almost all going to be laptops, where Apple particularly shines.
  • Also, these are primarily going to be consumer purchases, because businesses tend to buy in bulk and not at retail (excluding the smaller businesses) – again Apple is far more popular in the consumer space than in business (barring the iPhone).
  • The above $1,000 range is a minority of all sales; a majority of people buy cheap rubbish ;)
  • This is only the US, where Apple seems more popular

So, the headline isn’t quite as accurate in its crushing assessment as the wholesome reality, but even so it’s pretty impressive. When it comes to laptops, I always buy quality because I’ve been disappointed many times by machines that looked good on paper but turned out to be poorly constructed, poorly designed, and had all kinds of heat / battery life / general robustness issues, which led me to always buy from the ‘premium’ range in the last 6 years or so. At first that was the likes of the top-end Sonys, but after being convinced to try a MacBook Pro, I’ve been so pleased with the overall construction / design and the ability to use OS X as well as Windows that I’m very unlikely to buy anything else next time (my next hardware revision will be 2010, I generally switch every 3 years, which is reasonable if you buy something decent to begin with).

The talk now is about whether Apple will start making a netbook, to compete at the cheaper end of the market. Personally I don’t care – I quit buying cheap laptops ages ago, I don’t think it really ends up being cheaper in the long run. Powerful and cheap machines tend to be poorly built – I’ve burned through (literally in a couple of cases!) far too many laptops that couldn’t handle their power actually being used regularly, or which developed problems because the build quality was naff. Cheap machines with decent construction but lower spec (e.g. netbooks) just need upgrading faster if you have my sort of needs, or are just a supplement to a ‘real’ machine, either of which costs more in aggregate, and the resale value when you do upgrade is usually not even worth considering. In the round, buying a premium laptop relatively infrequently works far better for me, and as such Apple already provide what I want. YMMV :)

WWDC 09 – Apple gets aggressive, in a fairly relaxed way

OS X, Tech 6 Comments

In the grand scheme of things, nothing really very surprising was announced at the WWDC 09 keynote; sure, we got a few hardware revisions and some more specific details on the next version of OS X, but there wasn’t anything singularly shattering about it. And yet, when taken as a whole, I think it was one of the most important WWDC’s yet.

iPhone 3GS

A speed increase, more memory, better battery life, better camera, addition of a compass so it can know which direction you’re facing as well as where you are. All fairly minor but no doubt welcome changes. But, in my view perhaps the more important fact is that following the release, the previous standard 3G revisions are being sold off for $99; I think that’s going to make a big difference in the number of people taking up the iPhone. I didn’t pick one up because of the price (especially because we get screwed on it over here, since we have no O2 to subsidise it), but had it been a $99 base price – well, that’s a lot easier. Being able to offer an iPhone to a wider range of buyers is certain to give more steam to the iPhone popularity train.

MacBook Pro

More speed & RAM, FireWire 800 is back (no use to me, but some people missed it), SD card slots are in, and perhaps more importantly, Lithium-polymer battery tech is in, for up to 7 hours on the go. Sweet. Interestingly, the entry-level MacBook is now replaced by the 13-inch MacBook Pro, with the same overall design but just lower specs. This allowed Apple to claim that the MacBook Pros now start cheaper, but really they don’t – the 15 inch (the one you’d really want to start at as a power user) is exactly the same price as before. [edit]Actually, it has dropped in price, but back to the same price as the 15″ MBP was in 2007, when I last bought one. 2008’s unibody design came with a price increase, so this decrease puts it back to how it was, hence my confusion.[/edit] But still, a faster chip, double the memory and bigger HD are welcome for the same price; I’m glad I didn’t buy a unibody yet, but I’ll definitely be tempted by the new ones.

The MacBook Air however did get a set of serious price cuts; they’re impractical for me still, despite being sexy as hell, but I’m sure people that don’t need so much local power and who desire sleek looks will be very happy.

OS X

We already knew that Snow Leopard would be basically a leaner, meaner version of Leopard with go-faster stripes and a few feature tweaks. The big announcement was that Apple would be releasing the upgrade for a mere $29 (or $49 for the multi-machine family pack), which was very well received. That basically makes it a no-brainer for all users, I know I’ll be upgrading soon after launch.

Most importantly, it’s a big contrast to the price that Microsoft want to charge for the Windows 7 upgrade, which contains roughly the same degree of change over Vista as Snow Leopard has over Leopard (although Leopard is a more efficient base than Vista is – does that make W7 worth more as an upgrade?). It’s rumoured that a Home Premium upgrade for W7 will be around $50, and a Professional upgrade about $100. Of course, OS X has no ‘graduations’ like Windows has, where you don’t get everything in the OS unless you buy an expensive ‘Ultimate’ version – OS X is just OS X (personally, that lack of fannying about with variable feature sets is attractive to me as a customer).  This is an obvious attempt to undermine Microsoft’s claim to be the ‘value’ player in the OS market, and frankly, it’s a good argument. Of course, you still can’t buy cheap-and-cheerful hardware to run OS X on like you can with Windows, but when I shell out $100 per machine for my Windows 7 Pro upgrade but only $29, or $49 for up to 5 Snow Leopard upgrades, hell yeah I’m going to notice the difference.

So, I think despite the lack of shattering announcements, this was an important WWDC for Apple, a consolidation move which in many ways is more important. Despite the often fiercely held opinions of people who haven’t even used them, Apple products are generally pretty damn good, and earn brand loyalty for a reason. Making them more accessible can only lead to more people trying them, and perhaps coming to conclusions for themselves, rather than just writing them off based on what they’ve heard from other people who haven’t used them either.  ;)

Homeless Frank & Laptop Hunters

OS X, Personal, Tech, Windows 10 Comments

It’s always fun to watch Apple and Microsoft slug it out in the advertising space – here in the UK we mostly have to do this via YouTube, since apart from a short stint of amusing Mitchell and Webb Apple ads and those pretty bland “I’m A PC” ripostes, we don’t really see the front-line assaults which take place on US TV screens.

So I hear that MS have a new set of ads out, where “regular” people go and look for a laptop, whereby they look at the Mac and say “whoah, far too expensive!” and then go and buy a Dell instead. Fair enough, the 3rd party PC market certainly gives you a wider choice of blending specifications than Apple does – in practice, Macs aren’t actually much different in price to a similarly specced PC, it’s just that all the components are generally of similar ‘grade’ – so you can’t cut corners to save money like buying something with a big screen but a crappy GPU, or a large HD with a slow motherboard, or a fast CPU but crappy battery life.  Of course, many people don’t realise they’re making these sacrifices and just look at the price – but if you do know what you’re doing, you can tailor a machine closer to your needs. Anyway, I enjoyed the “Homeless Frank” spoof of these new ads:

A couple of years ago I would have made the same arguments against the Mac that MS makes with it’s Laptop Hunter series; and indeed I did, when a Mac-owning friend tried to convince me to buy one, despite being a .Net guru (who now works for Microsoft!). However, now that I’ve owned a Mac for almost 2 years, I feel completely different – in a laptop at least, I’m very willing to sacrifice a little configuration flexibility in favour of having a device that is of uniformly good quality, and is nice to use. After all, laptops are always compromised in terms of upgradability once you’ve bought them, so it’s generally better to buy something decent from the outset anyway.

I know that buying a Mac laptop is going to encourage me to spend a little more money than I otherwise might get away with. But, what I get for that is a really nice device, that has the added bonus of being able to run OS X as well as Windows. I still use Windows every day, almost exclusively because of Visual Studio these days (and some games) since everything else I use runs on the Mac too anyway, but running both Windows and OS X on the same machine merely serves to make me love OS X more, despite still being a newbie with it in many ways. Windows is fine to use and all, but there’s something about the way OS X just gets out of the way, doesn’t pester me with stupid warnings all the time, doesn’t need a virus scanner to slow it down, allows me to unmount my USB drives without hunting down every Explorer window that is using it first, and countless other little things that have slowly endeared me to it despite being a total skeptic to begin with. I’m a technical guy by nature, but even I can appreciate technology that doesn’t waste my time with trivial stuff I don’t want to care about – and at the end of the day Windows (and Linux) still feels like it’s designed for “PC users”, whilst OS X feels like it’s designed for people, specifically people with stuff to do other than worrying about keeping the computer happy. The day that XCode equals Visual Studio in functionality (it’s not far off, but it’s not there yet), and I can run Steam on OS X, is the day I might seriously consider not using Windows on a daily basis anymore. But, we’ll see whether Windows 7 changes that view.

Milestones

Business, OS X, Personal, Travel 7 Comments

I’m the kind of person who likes to keep busy; not in a ‘mad about DIY / the garden’ kind of way that tends to be the most socially acceptable form of being a ‘project oriented person’, but I always have a bunch of things on the go and never seem to have enough time to do them all. I’m always ‘working’ evenings & weekends, but a lot of the time I really don’t think of it as work, because a large portion of the time I’m doing exactly what I want to do.

If you’re anything like me you’ve had difficulty explaining to your wife / significant other that in our kind of world, there’s really no discrete black-and-white transition between ‘work’ and ‘not work’ that starts at 9am and ends at 5pm every day like clockwork. In fact there are a multitude of subtle levels ranging from ‘definitely work’ (e.g. something I don’t particularly want to do but someone has paid me to do it), to ‘not really work at all’ (e.g. having fun with technology that as a spin-off might help make a living now or later). Unfortunately these subtle graduations are invisible to the casual observer, often leading to discussions which begin with ‘You’re working again!’, ‘Not really…’, and from then on get complicated.

In the end, it’s probably not a solvable problem, but one thing that does help is taking the odd break, where you at least pretend not to think about what others would deem ‘work’ for a while. Holidays are obvious candidates, but also a good trigger for maybe taking a weekend off or something is recognising a milestone, or a cluster of milestones.

OgreSpeedTree and OgreSpeedGrass emerged from beta this morning, with official 1.0 versions being released. I’m pretty damn pleased with the result, and that’s a fairly unusual situation; I normally have a list of things as long as my arm that I consider ‘unfinished’, but in this case I’m very content with stamping a 1.0 badge on them. My attention can now switch to finalising Ogre 1.6, which is currently at the Release Candidate stage.

It’s also 2 years since I made the decision to give up having a regular day job and try my luck as a free agent / start-up. My initial measure of success was not to go broke (either personally or bankrupting the company) in the first 2 years, and I’m pleased to say that hasn’t happened. It’s certainly had ups and downs, and probably given my prior senior tech position I’ve undoubtedly earned less personally as a result, but the company has still grown, I’m still paying myself a wage that isn’t too insulting, and the benefits have easily compensated for that. Besides the flexibility and the satisfaction of knowing I’ve found and earned every penny I’ve made (which somehow makes the money feel more valuable than a guaranteed monthly paycheck), it’s been good for my personal development to mix it up a bit. And most importantly, I’m not bored :)

It’s also almost 8 years ago that I wrote this fateful message in my (very old, very manual) blog:

18th October 2000: Exam done! Work on OGRE will restart soon. First, web site revamp to be done.”

Inauspicious, but that was the seed – the time when OGRE as we know it swung into full development and started this whole crazy sequence of events off; if I’d known the significance of it at the time, I wonder whether it would have affected how I did things?

Laozi was right when he said “A journey of a thousand miles begins with a single step.”. Those words motivate me to this day – that no matter how big or challenging something looks, the most important thing is to start. My experience certainly tells me that genius and raw talent / ability is often not the most important factor when it comes to achieving things, it’s usually more about taking that first step, and having the tenacity or pure bloody-mindedness to keep going for as long as it takes. That’s particularly good for me since even if I might not be as smart as some, I’m probably more stubborn. :) And that in turn feeds back into what I was talking about at the start of this post.

But, stopping occasionally to admire the view is good too :) Maybe I’ll do that this weekend.

Parallel-split Shadow Maps are cool

Development, OGRE, OS X, Uncategorized 3 Comments

OgreSpeedTree with PSSMWe’re on the final home straight for Ogre 1.6 (aka Shoggoth), which should hit RC1 next week. One of the final features I wanted to squeeze in was support for Parallel-split Shadow Maps (PSSM), which uses multiple shadow maps per light in a hierarchical fashion to improve the quality while keeping the size down, particularly in outdoor scenes using global directional light. If you’ve played Assassin’s Creed, you will have seen this technique in action already.

For example, the screenshot on the right there is using 3 shadow maps for the single directional light, the closest one being 1024×1024, and the other two being 512×512 – together they are 38% of the size of a single 2048×2048 shadow map and yet provide greater detail. The 3 shadow textures are displayed for debug purposes on the right – notice that all 3 are using LiSPSM projection to bias the texture precision toward the camera which also helps. If you look really closely on the full resolution shot, you can see the transition from the highest resolution shadow map to the second shadow map about halfway up the screen, it changes near the top of the closest tree shadow. It’s quite hard to see though, which is kinda the point :)

One of the challenges with supporting PSSM is that Ogre had previously assumed that there is a 1:1 mapping between lights and shadow maps, which clearly had to be overcome – this limitation also prevented easy use of dual parabaloid and full cubic shadow maps for point lights of course. It was one of those things that had been languishing on my TODO for a while, begging me to find some time for it, and that’s where it still was until Pang Lih-Hern (aka lf3thn4d) from Malaysia came along and did it for me :) What a star! His initial patch allowed multiple shadow textures per light in a very sensible way, and he then implemented a PSSM facility on top of that, via our pluggable ShadowCameraSetup system (which he also extended in the patch to be aware of shadow map iteration). I adapted the PSSM code from his demo to be a little more flexible (it now handles any number of splits, and a more flexible split configuration) , so that setting it up goes something like this (simple projected shadows here, depth shadowmaps are also possible of course but let’s not overcomplicate it):


float shadowFarDistance = 3000;
mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
mSceneMgr->setShadowTextureCountPerLightType(Light::LT_DIRECTIONAL, 3);
mSceneMgr->setShadowTextureCount(3);
mSceneMgr->setShadowTextureConfig(0, 1024, 1024, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(1, 512, 512, PF_X8R8G8B8);
mSceneMgr->setShadowTextureConfig(2, 512, 512, PF_X8R8G8B8);
PSSMShadowCameraSetup* pssm = new PSSMShadowCameraSetup();
pssm->calculateSplitPoints(3, mCamera->getNearClipDistance(), shadowFarDistance);
pssm->setSplitPadding(mCamera->getNearClipDistance());
pssm->setOptimalAdjustFactor(0, 2);
pssm->setOptimalAdjustFactor(1, 1);
pssm->setOptimalAdjustFactor(2, 0.5);
mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(pssm));
mSceneMgr->setShadowFarDistance(shadowFarDistance);

Notice that I used Integrated Shadows, this is a requirement of PSSM since only shaders with integrated shadow support can decide on the fly which shadowmap to sample from.

My sincere thanks to lf3thn4d for helping us get this feature in to Ogre 1.6 (and to all those who send us patches in fact). If you want to see it and OgreSpeedTree in motion, there is a video available; that’s the low-quality streamed version but you can also download the higher resolution version if you want.