Post categories



Recommended Wordpress Hosting from WPEngine

  • I use these guys for some of my clients; absolutely rock solid and blazingly fast - check them out!





Here are a couple of ads whose clicks and views help me pay for my server hosting











A raytracer for Google Chrome Native Client

A couple of months ago, I applied for a job. I’d been working for the previous 6 years in Java, and the job was a C++ post so I needed to learn C++ quickly – as a good project to get me going, I wrote a raytracer. I got the job, and I’m about 5 months in – looking back at the code I’d written for this starter project, it’s not great – I’ve already learnt a lot in that time, so I’ve rewritten it – and this time I targeted only standard, portable C++ so it compiled nicely (at least the core of the raytracer does) under GCC 4 with no libraries on any platform I fancied.

Then I found out about NaCl – Native Client – Google’s system for building extensions for Chrome using native code – and noticed the requirements for building things in it are that it compiles in GCC 4. Sounded like a good test-case…

I’ve built a NaCl version of the simple raytracer – it’s not fast (it’s only single threaded) and because it’s compiled for NaCl, that’s got a small performance hit too, but it works.

It’s pretty slow at the moment, single threaded, no acceleration structures (kd-trees et al), no ray averaging, etc but now it has triangles (!) so next step is .obj loading or at least simple scene graph editing in the page it’s loaded into… Once I’ve figured out pthreads in Pepper and made them work in NaCl, that should speed it up a bit on multicore processors anyway.

It’s about 4mb for the NaCl .nexe (unfortunately, most of that is 0’s added as padding by the modified gcc) so takes a little while to download but if you’d like to try it, you need a recent(ish) version of Chrome and you can find it in the Chrome store (with a rather daft name too):

https://chrome.google.com/webstore/detail/keikppoeceeaceabgdiommjljipfjmng

Depending on the speed of your PC, it may be unuseably slow, but on my work I7 it’s responsive enough… (drag the bits around x and y; hold ctrl to drag around x and z).

For reference, here’s a native (Windows) version compiled using VC++ (I said it was portable C++!) – on my PC, it runs considerably faster – I’m not 100% convinced where the major slowdowns are, but that’s something to look into.

Future

Eventually (when I get time – something I don’t seem to have much of at the moment) I’ll expand on it, and add some features to it.

  • add some kind of scene description support
  • acceleration structure for the scene description (kd-tree, octree perhaps)
  • multi-threading

Changelog

2012/03/08 – v 0.0.2
first build in NaCl, first build of Chrome extension, and upload to Chrome store. Woo!