The author of AmiCraftNova recently released a new demo called StarBoxDemo. While everyone has been posting new fps benchmarks with it, how it uses shaders should be of greater interest to aspiring developers. So download the demo (if you haven't already), and take a look in the Shaders directory.

The big advantage of shaders is that you can choose exactly the lighting model you need/want. CharasGhant has used three different sets of shaders for StarBoxDemo. Each handles the rendering of different types of objects.

The shaders are as follows:

  • planet*.txt - for rendering planets & moons
  • sun*.txt - for rendering the sun
  • texture*.txt - renders unlit objects such as the star field you see in the background (the star-box)

Let's go through these in reverse order. First up, texture*.txt. These shaders do zero lighting at all; they simply render a texture-mapped model to screen as-is. This is perfect for the background star field because no lighting calculations are needed.

Next are the sun shaders. The sun emits light and is so bright that other objects don't affect its colour. So, the sunFrag.txt fragment shader outputs a constant colour.

Planets and moons are lit by the sun, so its shaders (planet*.txt) are more interesting. The shaders implement a diffuse lighting model on a per-pixel basis. PlanetVert.txt projects the model and calculates the surface normal and light directions in camera space. Next, planetFrag.txt calculates the diffuse light reflecting off the surface at every pixel.

So each object is rendered to screen using shaders written specifically for that object's type. Combined, they generate images such as the screenshot at the top of this blog post.

Which shaders should you use for your projects? That depends entirely on what you're trying to achieve. For example, if you're going for a cartoon look, then you'll need very different shaders from someone going for photorealism. There are many different techniques to choose from, and you can also create something brand new yourself. I recommend keeping things simple early on, though, because it's easy to get lost in the sea of possibilities.