Normals and Lighting


So one problem with my game that I wasn't able to fix before the jam closed really annoyed me no end. Was it the lack of an intro? The lack of credits? The lack of anything playable past the first two scenes? No, none of those. It's a jam, these things happen. 

What annoyed me was that I had specifically placed some posters on the wall of Elektra's bedroom/workshop and they were not showing up.

I mean they would be hard to see (since everything was rendering as gray at that point), but they should have shown up. That was frustrating, because one of the story points for that introductory scene was that she would see the poster for the Steam Science Faire. Instead, people who played the game only saw (maybe) a random message pop up with no motivation for it. That's obviously why I came  in 19th place.

So, today, I finally figured it out. 

A piece of paper (a flat rectangle) in a 3D program is a little different from a sheet of paper from your notebook or printer tray. If you turn the real paper around front to back, you can still see it. Depending on your 3D engine, the same might not happen for your flat rectangle.

Of all the ghods held dear by the real time rendering community, there is one greater than all the others, casting its dire shadow over even innocents trying to write adventure games. Its name is Efficiency, and all must acknowledge (if not worship) it.

If you're familiar with 3D computations, you know that one of the major ones is figuring out how much light falls on an object. There are all sorts of clever tricks, many as far beyond me as quantum physics is an ant (OK, quantum physics is beyond me too, but let's run with it...). However, one of the basic ones is to figure out which way a light is pointing, and which way the surface (or more properly, the surface normal -- a vector perpendicular to surface (think of a pencil, standing on its eraser in the middle of the piece of paper)) is pointing and multiplying them together to get the dot product, which is a number describing how parallel the two vectors are.

The idea is that if they're very parallel (dot product of two normalized vectors is close to or equal to 1.0), then the light is turned full face on the object. As the light is turned away, the number drops. If it's zero, then the surface isn't getting any light at all ('cause the light isn't pointing at it, right?).

Now at some point, some bright spark realized that if we had to keep track of the points that define the surface, could we interpret them in such a way that we knew if the surface wasn't facing the viewer at all, and thus we wouldn't even have to do the minimal math to do the dot product? And the answer was yes, we could certainly do that, and most of the time nobody would notice (because objects (like, say, a sphere) generally have volume and faces all around that define that volume) and the great ghod Efficiency would be pleased because we avoided a matrix operation and so on.

Left gasping on the bloody altar of Efficiency was the fact that something thin, like a piece of paper, would effectively have only a single side. Even if it was hanging in mid air (from a string) and you walked around it, it would suddenly disappear as soon as it's defining points were being wound counter-clockwise from your viewpoint.

And that was what had happened to my posters. Because they had no depth and they were turned facing the wall, they no longer existed according to my OpenGL card. So, I went into Blender, selected them and instructed Blender to "flip the normals" so they were facing outward. And, lo and behold, I could finally see my posters. Now, they don't have texture, so you can't tell what they're a poster of, but at least you can see that there's some papers stuck to the wall.

Oh, and I played around a bit with the lights to try to brighten things up. I cheated by screwing up the ambient term, which is why things are brighter, but there's no shading on the walls, but at least it doesn't look like you're stuck in a cave now. Lighting is hard...

Files

steamy-v1.0.3.zip 17 MB
May 01, 2020

Get Steam+SPARK

Leave a comment

Log in with itch.io to leave a comment.