A 20 sided die is commonly called a "d20" by gamers and an "icosahedron" by mathematicians. This blog post will illustrate how I use these angular shapes to create nice soft lights in the Pantheon engine.
We start with a dark hallway, then we fill it with a giant d20. No, not just big. Not large. Not even huge. GIANT. It's taller than the room, so it sticks through both the floor and the ceiling.
Now just like that, it's obviously not very useful. However, as a programmer I've got a number of tricks up my sleeve. Instead having the graphic card draw the visible part, we're going to reverse that and only draw the portion behind the walls, floors, ceiling, etc. In other words, we're only going to draw the portion that's embedded in something else. It looks like this:
Better, it now highlights surfaces in the world instead of blocking visibility, but it's still very hard and edgy. Now I'll round it off in the shader. A shader is code that runs on your graphics card -- it decides which pixels to draw and what color to draw them. In this case we're going to measure the distance from each pixel to the center of the d20. We'll use that to prevent pixels outside a certain radius from getting drawn. The result is that we only draw the pixels inside a sphere.
Much better, though still a bit harsh on the eyes. We'll add additional checks to fade out the light based on distance from the center. We'll also fade out the light for surfaces that aren't facing the light very well.
Yay! Looks good right? Well almost. One problem. It shines right through the wall! It has no bounds and shines right though everything! To fix this, we use the surfaces of the walls, ceiling, and floor to "cut" the mesh so that it never protrudes through geometry. Now the walls will cast a shadow. Subtle, but very necessary
And finally, in motion: