VS with diffuse and ambient lighting

This is just an update, not really meant to show how awesome it is or anything.  I managed to implement diffuse and ambient lighting (which I’ve done like 1000 times but can’t seem to locate the shaders for). I’ll get in specularity after a while with both vertex and pixel shaders. I’m also debating on implementing specular maps. There is an obvious tradeoff. If I eventually get my material system up and running, the object will be able to specify whether or not to use spec maps or have spec calculated.

Did implement a cool little pyramid object in the background though. I’m planning on working in lots of different lighting algorithms as well. Phong is popular, but the interesting thing is that they can all be per-vertex or per-pixel. So I will be implementing both so you can see side by side comparisons.

Sine wave with Tsunami

Sine wave

Sine wave using a vertex shader

Look kids, math.  Done using sine wave where the distance from the center is passed into the sine function (along with some other stuff). It animates with time too, but I didn’t feel like putting up a youtube video. I’ve wanted to make this for quite some time but I’ve just never gotten around to doing it. I always thought this looked cool though. May build off of this for a water scene in the future, but we’ll see. It used to have color associated with the height of each vertex, but I removed the colors and just made the height get darker. You can see the valleys get lighter in color.

On a side note, I’ve decided to keep posting the progress of my engine (which I’ve decided to call Tsunami). Mainly for myself to see where I’ve been because it’s kind of nice to see the progress I’ve made.

Good vertex buffers gone bad

I encountered a particularly interesting bug, I thought I’d post it here. It’s actually fairly easy to reproduce. As you can see from the screenshot, my scene is all screwed up. I’m attempting to draw a triangle grid. I know it’s being generated correctly because it was displaying earlier, but as you can see, it’s interesting because I’m drawing in wireframe. The real reason is because I have a memcpy() going on that is copying a vertex from 1 array to another (for various reasons). When I did this, I was copying only 3 vertices ( and forgetting about the 4th color), and overwriting the 4th element (the color) with the next vertex component (x value).  Note the vertex positions are capped along the x,y, & z. This is because I am giving (what I thought), each vertex a red color. This red color stomps all over the vertex positions in the array. The reason it caps the x,y,z is because the red has a max value of 255.

Besides that, I finally got my camera operational. I’ve done cameras in the past, but I had a bit of trouble with this one because I was hazy on my transforms.. After brushing up, I was trying different things such as using Quaternions, giving the camera a model world matrix and just inverting that for the view transform. Calculating the view transform myself by using only cross products or by using the Grahm Schmidt rule. For the mean time, I opted not to go with Quaternions even though I wanted to because I don’t have my quaternion library fully operational yet. So I decided to use spherical coordinates.

This worked better than expected, but there are a few corner cases. Looking straight up or straight down results in a division by zero so the screen goes blank. Also, you can flip the camera completely around so the controls are backwards. For example, if you were to look up, and then keep rotating your head so that you’re head is upside down and you were looking behind you (don’t try this at home, or anywhere else for that matter, you might scare people). This was really irritating for me, but clamping the latitude value between 0 and pi for the camera orientation solved all 3 cases.

Where delta is some small value.