Thursday, February 27, 2014

Something from last semester.

Learning the material editor last semester was a lot of fun. I applied most of the things I learned to this lantern shader.
















One of the most interesting things I learned about last semester was gradient mapping, which I used here. It allowed me to store the diffuse in one channel of a texture and use a second, very small texture to color it. With only one channel dedicated to the diffuse I could pack everything else I needed in the same texture: flicker clouds, a hot spot, and the internal wires / paper folds.
People used this asset all over their levels, often hanging in a line on ropes. Because of this I had to offset the flicker using Object World Position so that they didn't all dim and glow at the same time.
The most complicated part of this asset was getting the hot center. After experimenting with less elegant solutions I came across a technique used by several people, but one which none of them could explain to me; that is, masking a Camera Vector that has had 0.5 multiplied and added to it. After reading the entire Material Compendium I figured out that this is to bias the output of the camera vector (which goes from -1 to 1) to positive numbers. This can also be done with a Constant Bias Scale (which I left floating in there as a reminder) but it's more expensive. The mask simply allows the X and Y channels of the Camera Vector to be used as texture coordinates.

If I had to change one thing I might make the Divide by 8 into a Multiply by 0.125 because computers can multiply faster than they can divide. The difference may or may not be negligible but I'm sure if you talked to a real programmer they'd tell you to use Multiply, especially since you won't get any rounding errors representing 0.125 as binary, though that's getting awfully anal over the part of my shader nobody even used.

This semester we're going into custom lighting, which is an extremely powerful tool. I especially like having a lot of control over my specular highlight.