Lecture: Atoms

How to 3D

Chapter 10: Texture Effects

Lecture: Atoms

Dear students:

Textures are not just for colors. They effectively provide any kind of per-fragment data that we might need, with the understanding that we don't exactly know how many fragments are going to be rendered. This fragment data will necessarily be stretched across a surface. Today we'll use textures to achieve several effects: masking, billboards, and normal maps.

Billboard

To develop a visceral feel for what we're about to do in code, design your own billboard with a partner. Follow these steps:

  1. Draw two identical instances of a simple shape with a solid base, like a tree, saguaro cactus, fire hydrant, and so on.
  2. Cut out the shapes.
  3. Make a vertical cut at the bottom of one.
  4. Make a vertical cut at the top of the other.
  5. Interlock the two shapes along the cuts.

As you move your head to the side of one shape, the other is still fully visible.

Many Atoms

Let's now try rendering many atoms. We could create full sphere geometry and either draw it many times or pack the many vertices together into one VAO. Either way is expensive. An alternative is to use billboards. Let's try them by following these steps:

Generate an image containing a sphere. Let's put the distance from the center in the alpha channel.
Discard any fragment beyond some threshold distance.
Turn the quadrilateral into a billboard.
Put the sphere's normal in the red-green-blue channels of the image.
Add diffuse lighting to the flat billboard.
Render many atoms.
Adjust the fragments' depth based on their distance.

TODO

Here's your list of things to do before we meet next:

There are no more quizzes.
Keep working on your projects and games.

See you next time.

Sincerely,

P.S. It's time for a haiku!

The artist did some But the vertices are mine Yes, all four of them
← Projective TexturingLab: Game Step →