Tsunami texture mapping at long last

I added texture mapping and blend mapping to Tsunami. The textures aren’t mine, they’re from a book and it’s associated tutorial. It looks much better now than the bland triangles from before. There isn’t a whole lot else to say about this except that I still need to add in the material system, which is next on the list.

I was able to add in a blend mapping. It just takes 3 different textures and blends them together based on what is defined in the blend map. These textures were also taken from a book’s tutorials because I don’t really care to make the textures or the blend map for that matter.

Lighting for Tsunami

I managed to get some lighting into Tsunami in the form of point lights, spot lights, and directional lights. Currently it only supports one light, but that will change. The next step I need to do is create a material system because, as of right now, there isn’t one and it’s a serious pain to pass stuff into the shaders manually.

The lighting in this image is vertex shaded lighting with ambient, diffuse, and specularity. The image is just a single spot light emanating from the camera in the direction of the camera, so it acts like a flash light. Wherever I point the camera, the light shines in that direction.

I’m not really sure if this is considered phong lighting/shading. I don’t really care that much since I’ll probably implement it later, but it seems that when people refer to phong lighting, they mean it’s per pixel, and the normals are interpolated and then renormalized on a per-pixel basis. These normals aren’t renormalized, but they are interpolated, since it’s a vertex shader that’s doing the work, but that’s about all. I’ve mentioned before that I planned on implementing a bunch of different lighting algorithms in the vertex shader and then doing the same for pixel shaders and then place them side by side to compare them, so eventually I’ll implement phong.

The next step on this ridiculous quest is to add texture mapping and the material system. For texture mapping, I’m just talking about basic diffuse texture mapping to at least make the ground plane look decent. I want crates too.

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.

Engine Update 001

I’m in the process of redoing my “testing” engine. I hope to make it robust, scalable, modular, while supporting a lot of other different technologies. This is the start of it using D3D9, but don’t worry, I’ll eventually port it over to d3d11. I’m going to skip 10 though. I have lots of things in the works for it too!

As you can see here, I have a few simple cubes and a triangle grid. Most likely the grid will turn into terrain. I haven’t decided what I wanted to name the engine yet. I’m leaning towards “Tornado.” I remember looking into a physics engine a while ago named “Cyclone” and I thought the name was interesting.