Topics

Wednesday, August 22, 2012

Another making-of

Ever wondered about the Earth image on the screen background of every new iPhone? Turns out it's another Blue Marble image and here is an article on how it's made written by the artist Robert Simmon himself: Crafting the Blue Marble.


Sunday, August 19, 2012

Iconic Earth images

While researching, I stumbled across this great article about 10 Iconic Images of the Earth from Space. Images featured include the Blue Marble and the Pale Blue Dot.

One of the most iconic photos ever is the Earthrise taken by astronaut William Anders on Dec 24, 1968 during the Apollo 8 mission. To quote Anders: "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth"

The first public image of an Earthrise from Moon orbit (Dec 24, 1968)

In 2007, JAXA (Japan Aerospace Exploration Agency) launch a lunar orbiter SELENE (nicknamed Kaguya after the moon princess from Japanese folklore) whose on-board HDTV cameras recorded high-definition video footage of a newer Earthrise:


We are indeed lucky to be living at a time when technology allows us to appreciate our home planet from a perspective that must have once been unimaginable.

Wednesday, August 15, 2012

Shader upgrades ^^

Necessity can be a great motivator. A recent freelance opportunity meant I had to create much faster shaders to get the job done in time. I dove head first into VEX code writing for the first time, and managed to adapt Sean O'Neil's real-time atmospheric scattering algorithm into my new Earth shaders.

My method uses the CPU instead of GPU and is not real-time, but is still multiple times faster than my old method while looking visually very similar. Some volumetric shadow effect is lost, but not really noticeable if you are not looking for it, and the amount of speed up is well worth tradeoff.

Naturally, the implementation is not straightforward and took me almost 3 days to get it working properly. Perhaps I'll post more details under the "making-of" label in future.

Making of a Planet - Part 3 - Shader Basics

In this post I'll be describing what I learnt about shaders when building the CG Earth, with specific examples of Houdini VEX shader networks. First off, a quick introduction to how shaders work.

What are Shaders?

Shaders can be thought of a set of program instructions that tells a renderer how to determine the color of a surface (or volume) at any given location. In 3D programs, they are also referred to as materials.

Shaders are actually program code written in a shading language. However, Houdini allows the code to be build visually as a node network (called a SHOP network, for SHader OPerators). The most famous industry shader language for rendering CGI is the RenderMan shading language. For real-time graphics (e.g. games and 3D applications) you will hear names like GLSL and HLSL. Houdini's shading language is called VEX (Vector EXpressions).

Regardless of shading language used, the simplest shader returns a constant color at every point, making the object appear uniformly flat. In the following example, a constant color blue is being fed into the surface output of a Material Shader Builder node in Houdini's SHOP network:

The constant shader instructs the renderer...
 ...to use the same color for every point on the surface

Let's consider how light may affect how the surface looks.

The following example is the basic Lambert shader (which mathematically is the dot product of the normalized surface normal vector, N, and the normalized light vector, L). It's amazingly elegant that this single dot product formula is enough to describe how the light falls off a surface depending on its angle to the light source:

A classic Lambertian shader...
...makes the teapot surface react correctly to light

Lighting Inside a Loop

In Houdini, this lighting calculation must take place inside what is called an illuminance loop. A loop in computer programming is a sequence of instructions that repeats itself until particular conditions are met. Think of it as repeatedly calculating the same lighting formula (dot product) for all the points on the surface that appears in the final image, using the corresponding N and L vectors for each point location.

So we now have a properly lit teapot, but what if we want it in blue color? All we need to do is to multiply the result of the illuminance loop with a constant (blue color) before passing it to the output:

The Lambert shading network from before is actually hidden inside the illuminance loop node above
Only one dot product and one multiplication is needed to get this blue teapot

Houdini already includes a selection of basic CG shaders (such as Lambert) as a network node so we don't really need to create our own illuminance loops. However, writing your own illuminance loop function allows specific low-level control over the look of your material. For the Earth shader, I adapted a light wrap shader inside the illuminance loop to simulate atmospheric scattering.

Building Visual Complexity

When shaders take into account various factors such as lighting and texturing, more complex looks can be achieved. Notice also how we can take the first two separately rendered images (the constant blue and the grayscale lit teapots) and combine them using a multiply blending in a 2D program to get the same results (blue lit teapot). Therein lies the flexibility and power of render passes and compositing, because we can tweak the amount of blending without having to re-render in 3D.

The example below is a slightly more complex shader including specular highlights and texture mapping, but the basic concept is the same as the previous examples. Notice that the texture map (diffuse color) is multiplied with the Lambert shading, and the specular is added to the results.

No illumination loop used here
More complex shaders will result in more realistic surface appearance

Shader writing may not be everyone's cup of tea, but with some effort anyone can write their own shader. There's a definite amount of mathematics and logical thinking involved, but with it comes the power to go beyond what is available off-the-shelf.

If you're keen to find out more, I recommend the following books:

1) Texturing and Modeling: A Procedural Approach
2) The RenderMan Companion: A Programmer's Guide to Realistic Computer Graphics
3) Advanced RenderMan: Creating CGI for Motion Pictures

That's it for today. Next post I'll elaborate more about my Earth shaders.