Lately, I’ve been reading a lot about Custom Shaders, FX Files and HLSL (High Level Shader Language), and now after I understood their concepts I decided to implement what I though was very hard to do, Sea Waves !

I used to think it was very hard because all I could do was change the Transformation Matrices of the 3D Models or the Meshes inside the Model, and making animated waves requires me to modify the positions of the vertices of the 3D Model individually and not all together.

But now after knowing that whatever is written in the Vertex Shader method gets applied on every vertex in every model I render using this shader, making waves became as simple as writing a “sin” function !
Really! all I did was add one line in the Vertex Shader that modifies the Y component of the vertex position according to a sin function that depends on the Z component and Time :)

All what was left was to get a nice Texture and apply it on the water surface, play with the constant and add some bits of code here and there to make it look good.
One way to make this look even cooler is to apply a Bloom Effect on it, which basically extracts the bright areas of the image, blurs it both ways then combine them together, so that bright areas will seem to glow and gives you more feeling of how bright it is, but I can doo this later after I take another look at the BloomPostProcess XNA Sample and fully understand it to be able to recreate it.

You can find here a link to the XNA Project files so you can read the code, mess with it and recompile it as much as you like, and if you have any questions ask me on the Comments or by Email.
BTW if you want to learn HLSL I really recommend reading Catalin Zima’s “Crash Course in HLSL”, and take a look at the other posts and link he has there, ULTRA COOL !!!