Rockpapershotgun, and Horace, the endless tech.

http://www.rockpapershotgun.com

RPS is down. Or maybe replaced. Instead, there is a text adventure game there:

503 – Service Unavailable
An Interactive Fiction by Horace The Endless Server Technician
Release 1 / Serial number 110707 / Inform 7 build 6E72 (I6/v6.31 lib 6/12N)

HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>refresh
That’s not a verb I recognise.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>go north
You can’t go that way.

>go south
You can’t go that way.

>go s
You can’t go that way.

>go up
You can’t go that way.

>sleep
You aren’t feeling especially drowsy.

>eat
What do you want to eat?

>eat shoes
You can’t see any such thing.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>eat cast,e
You can’t see any such thing.

>eat jim
(first taking Jim)
I don’t suppose Jim would care for that.

>eat John
(first taking John)
I don’t suppose John would care for that.

>eat Tim
(first taking Tim)
I don’t suppose Tim would care for that.

>eat Alec
(first taking Alec)
I don’t suppose Alec would care for that.

>look at Alec
On closer inspection, Alec appears to be gluing bits of Warhammer 40k model armour to his shoulders and chest.

He picks up a plastic lascannon and tries it out on his left nipple.

>look Jim
His top hat and procedurally-generated facial hair gives him away in a second – this is Jim Rossignol, wordsmith and crazed steampunk inventor.

Jim is hunched over an opening in the Castle Shotgun walls, from which various wires are trailing. There is the occasional spark and fizz as he rummages around.

>look John
John sits hunched over on a stone at the foot of Castle Shotgun’s walls, head in hands groaning to himself. There are several empty rum bottles nearby, one of which appears to have an Asda logo on it.

>drink rum
You can’t see any such thing.

>look Tim
Tim is standing on a small outcrop, binoculars in one hand, looking out eastwards. Unfortunately, east of here is just the M4 corridor, but east is the direction heroes look in, as evidenced by his stony glare.
He takes a deep breath. “I love the smell of Bath in the morning.”

>talk Tim
I didn’t understand that sentence.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>pickup Tim
That’s not a verb I recognise.

>pick up tim
I don’t suppose Tim would care for that.

>talk alec
I didn’t understand that sentence.

>look alec
On closer inspection, Alec appears to be gluing bits of Warhammer 40k model armour to his shoulders and chest.

Alec clears his throat and tests out his Librarian imitation. It’s not bad.

>help
That’s not a verb I recognise.

>die
That’s not a verb I recognise.

>kill
What do you want to kill?

>kill Alec
Violence isn’t the answer to this one.

>kill Jim
Violence isn’t the answer to this one.

>Kill seld
You can’t see any such thing.

>Kill self
Violence isn’t the answer to this one.

>kill me
Violence isn’t the answer to this one.

>talk me
I didn’t understand that sentence.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>talk to jim
Jim doesn’t take his head out of the hole in the wall. You hear him muttering to himself.

“Yes, it must be the… no, unless it’s the… Hmm.”

>talk to john
John looks up. “Hmm? No, I didn’t lock us out. We’re just having a bit of trouble with Horace. We’ll have it working again in a tick.”

He resumes nursing his headache.

>talk horace
I didn’t understand that sentence.

>talk jogn
I didn’t understand that sentence.

>talk to john
John looks up. “Hmm? No, I didn’t lock us out. We’re just having a bit of trouble with Horace. We’ll have it working again in a tick.”

He resumes nursing his headache.

>talk to tim
You don’t feel like talking tactics right now, and Tim is looking rather intense at the moment.

>look tim
Tim is standing on a small outcrop, binoculars in one hand, looking out eastwards. Unfortunately, east of here is just the M4 corridor, but east is the direction heroes look in, as evidenced by his stony glare.
He pulls out a script from “Patton” and flicks through it, mouthing a few lines to himself.

>talk to alec
Alec seems a bit involved with sticking plastic armour to himself to reply. It’s probably best to leave him alone when he’s arming up, anyway.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>pick up magazines
They’re not yours to take, really. I’m sure no-one would mind you looking at them though.

>look at magazines
You grab a magazine at random. It’s the latest issue of Your Cat magazine! You’ve read this issue at least four times though, so you put it back.
You notice an old copy of Amiga Power in the pile.

>look at amiga power
An old copy of some obscure, arcane tome. The glyphs on the front are mysterious, and appealing.

>look at glyphs
You can’t see any such thing.

>read glyphs
You can’t see any such thing.

>read amiga power
An old copy of some obscure, arcane tome. The glyphs on the front are mysterious, and appealing.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>look at wall
You peek at the hole in the wall. There is a mess of wiring and tubes, and what appears to be the midriff of a particularly long animal. You peer down the inside of the wall in both directions, but see no evidence of legs or a head. Weird.

>look at wires
You can’t see any such thing.

>look at mess
You can’t see any such thing.

>look at tubes
You can’t see any such thing.

>look at animal
You can’t see any such thing.

>look at midriff
You can’t see any such thing.

>look at wall
You peek at the hole in the wall. There is a mess of wiring and tubes, and what appears to be the midriff of a particularly long animal. You peer down the inside of the wall in both directions, but see no evidence of legs or a head. Weird.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Jim, John, Tim, Alec and a Refresh Button here.

>open gates
You can’t see any such thing.

>look at castle
You can’t see any such thing.

>look castle
You can’t see any such thing.

>look magazines
You pick up one of the magazines. It’s the latest issue of Guns And Conversation, John and Jim’s fanzine that they distribute around Bath. The cover story promises “Semi-autos and small talk” and an interview with a man who has invented a talking gun.
You notice an old copy of Amiga Power in the pile.

>pick up amiga power
You reach for the magazine, but as you touch it it disintegrates in front of your eyes. In its place are the feet of a man. That man is Kieron Gillen. He smiles down at you.

>talk kieron
I didn’t understand that sentence.

>look kieron
Kieron’s figure is hard to make out, as his very flesh appears to emanate a glowing white light. He floats approximately two inches off the ground, and is wearing glasses which, when peered into, appear to reflect visions of the future and past.
He still looks a bit like Jason Statham though.

>talk kieron
I didn’t understand that sentence.

>talk to kieron
You open your mouth but the words fail to come. Without speaking, Kieron’s voice echoes inside of your head. He mentions something about Thief. Everything is right with the world.

>look
HTTP Error
You are standing at the entrance to Castle Shotgun. The gates are securely locked, with an unappealing sign on the front. The sign reads “Whoops! RPS is having a bit of a wobbly. Don’t worry, we’ll be back soon!”

To the left of the gates is a large opening in the wall, which Jim is leaning into. John is perched on a small rock nearby, while Alec and Tim are standing on the other side of the gates. A pile of magazines is scattered in a corner.

You can see Kieron, Jim, John, Tim, Alec and a Refresh Button here.

This is the most fun I’ve ever had on a 404 page.

A new beginning.

When I tried to start writing posts on Raytracing, the idea was to document my steps. The problem was, that when I started,  I’d already finished the project.

When I say finished the project, what I actually mean is ” I got too bored, stuck, or distracted to continue.”

I hadn’t planned the code out very well, and as I added new things I had to break old things, and it turned in to a stack of kludges built on kludges. It was kludges all the way down. It may as well have been held together with gaffa tape.

So I’m going to start again, and this time plan it a bit better, and I’m also switching languages. And I’ll post on my progress, because even though no one is reading this, I can still refer back to it.

In memory of this occasion, here are some snapshots of what I achieved. They’re not all very good, and some of them are downright weird.

Early code, with bad lighting and only one type of object. Orthographic camera.

Can’t remember what the hell happened here. Early plane intersection code, I think

A cock up, but an attractive one, as they go.

Plane intersection code still making things difficult.

Yeah. Not sure about this. Lighting problem? Plane seems to work though.

Plane intersection working, with some randomisation of the “up” vector,

Showing only the phong exponent of the scene.

Polygon intersection test. Weird bug if two polygons lie on the same plane.

Fixed bug. Can’t actually remember what it was.

With polygon intersection tests working ( or so I thought ), I turned my attention to loading an OBJ.

After a long struggle with weird bugs, ta-fucking-da. Also, transparency.

Rabbit model without any normals calculated.

Also, persitent shadow bugs. These eventually turned out to be the plane intersection code playing up. Again.No ordinary rabbit! Normals calculated.Glass onion.

Wizards!

So there we have it, a long line of bugs, and some pretty pictures.

The next version will have all kinds of cool optimisation! (I hope.)

What I want to achieve:

  • Faster OBJ loading
  • BVH tree for scene divisions. Should dramatically speed up rendering.
  • Distributed ray tracing:  soft shadows, depth of field, etc.
  • An easier to steer camera, and possibly some animation, to produce videos. Not in real time.
  • Photon mapping. This can be bolted on top, I think.

Raytracing Part 1: First Steps

Ray tracing theory is simple, but I’ll explain it anyway. Ray tracing is a generic technique, that can be applied to a lot of different things. I’m applying it to one thing- graphics.
(If you want a better overview than this, look elsewhere. Look at wikipedia. Ask someone.)
Simulating light is far too complex to be done “properly”. If you think about the sheer number of photons that are output by a light source (the sun), and the number of bounces each photon goes through, depositing energy each time it does, before finally arriving at your eye, or camera, you’d see why it’s not possible. At least, not at the moment. If instead, you ignore light being emitted from the sun, and instead trace the photons backwards- from your eye, into the world, you are faced with a much easier challenge.
**Some notation. I’ll be using the word eye and camera interchangeably. When I use the word “scene” I’m refering to the environment that the ray’s interact with.**
If you know you wish to render an image of 800 by 600 pixels, that’s 800*600 rays you have to trace.
  1. For each pixel, shoot a ray into the scene.
  2. Test the ray for intersections with every object in the scene.
  3. Find the closest intersection.
  4. Find the colour of that pixel.
  5. Rinse and repeat, until each pixel has been done.
Object Intersections.
The simplest kind of object to test a ray against is a sphere. This is nice, because real-time applications running in OpenGL or DirectX fail miserably at perfect spheres. They have to be rendered as a flat sided object, with lots and lots of sides.
Ah yes – some maths.
A ray can be defined as two vectors: an origin and a direction vector. The direction vector should be a unit vector.
ray = origin + direction
A sphere can be defined as position vector (which describes the pos of the centre) and a radius. That’s all:
sphere = centre + radius
A sphere with centre (x0, y0, z0) and radius r is the locus of all points (x, y, z) such that
\, (x - x_0 )^2 + (y - y_0 )^2 + ( z - z_0 )^2 = r^2.
Finding the Intersection:
A set of points on a ray can be defined by:
Ray(t) = ray(origin) + ray(direction) * t
Where t is the distance from the ray origin.
The ray equation can be substituted into the sphere equation, and solved to find t.
This takes the form of a quadratic equation. If you don’t remember quadratic equations from whatever secondary school maths equation, they take this form:
ax^2+bx+c=0,\,
So, substitution for ray:
X = X(ray(origin)) + X(ray(direction)) * t
Y = Y(ray(origin)) + Y(ray(direction)) * t
Z = Z(ray(origin)) + Z(ray(direction)) * t
Insert X, Y, Z into sphere equation:
(X)2 + (Y)2 + (Z)2 = R2
Solve this quadratically, to find t.

There. That was easy.
So, the first thing I did was to define a scene composed of a single sphere, no lights, and shot rays at it through an orthographic camera. All this accomplished was a sense of self satisfaction, as I watched some text in my console, proving that some pixels came back as “hit”, and some came back “miss”. At this point I had no way to show the results on screen.
I could show you the results of this…..but why?
The second thing I did was start hunting around for a way to display my output. Image libraries were out- I thought they might be too complex to learn to use. I simply wanted to define a window of the correct size, and use something like “setPixel”. I eventually, after much google-fu, gave up and used the windows API instead. This felt like a small betrayal (I’m mostly a linux user for coding). It did however allow me to produce this:
Ah. A black screen.
After some more fiddling, this happened:
Hurrah! I had ray-traced my first scene.
Admittedly, is has no lighting, no shading, no support for more than a single sphere, no support for anything other than spheres……The list of things it doesn’t do goes on.
It DOES get better.

Ray Tracer Part 0: Introduction

Everyone and their dog, and their dog’s mum, has built a raytracer. This is not surprising: I mean, seriously, it’s not that hard, and it looks REALLY SHINY. So, despite the fact that everyone has already done this, and in many cases done it better, now it’s MY turn.

I started this project in my final year at Univeristy, during an Advanced Graphics module. I did this because the module was theory, and theory only.Now I like building stuff, but not everyone else does, so I was probably alone in wishing for more brain melting coursework. Also, the theory was hard. Very hard.

So, in order to understand it better, I built it. This may not have been wise, and their were a number of decidedly non-wise decisions in this project (I’ll get to those).

For your enjoyment, and my own, I will be posting here, as regularly as I can manage, until this blog has caught up with me in reality.

-Anorak