1. Render the container (and anything else that is fully or partially immersed in the water) to an offscreen texture (same size/format as the back buffer - basically a copy of what you see on the screen). This is the refraction map, which you later apply to the plane of the water.
2. Render the plane using normal mapping, and apply the texture you previously stored to it. The refraction is simply determined by how you sample the texture - to create the effect I add on the xz components of the normal vector to the texture coordinates. This way, you sample from the texture based on the curvature of the water at that point in the pixel shader.
It's not 'true' refraction (it doesn't use raytracing) but it creates exactly the same effect as you'd see, with small differences.
I might give that a try, thanks! I was thinking of finding the distance of the point from the plane, but I didn't know about the clip() function. I actually tried without clipping, and you're right - it works just fine. I guess it makes sense since you only sample from the part of the image which shows the underwater stuff anyway. For some reason the Rastertek tutorial on refraction mapping uses clipping - maybe it's slightly faster to not render the whole scene to the refraction map? Anyway, here's how it looks:
Well, I've been practicing a lot with HLSL lately, and I've always wanted to make some decent water. I tried the usual technique of animated normal maps, and it's awesome! I'm using the same normal map tiled twice, with different texture coordinates each time, which removes the need for two different normal maps.
Anyway, just thought I'd make this post because I'm pretty pleased with the results.
It draws the detail texture for pixels within a certain distance of my camera, and since this 'sand' texture is quite subtle, it's not possible to see the boundary between the detail texture and the main texture. It works for now!
OK, I applied a slightly better texture (an old sand texture converted to greyscale) and I'm beginning to see large improvements:
This one doesn't look too bad from a distance either! I'm thinking that it would be a good idea to only apply the detail texture to pixels which are a certain distance from the camera - does anyone know how to find the depth of a pixel in HLSL? I know how to do it by rendering to a shadow map and then sampling from that, but is there a simple way without needing to do this?
At the moment I've got basic shadow maps, but I'd like to try and remove the blocky pixel edges by adding some antialiasing. I'm not looking for soft shadows - I want to keep them hard, but I'd like to try and make the edges smoother.
Hmm, I am liking all the articles that people are posting! Most are genuinely useful or interesting to read (not just space fillers!). I'd love to do one myself - I did make some article-style posts on smooth/sliding collision handling with cylinders and walls, so maybe I should do an article about that!
I've found it. I was using the dxcpl.exe from the x64 folder instead of the x86. I did some debugging and while I haven't solved the reset device issue yet, I have managed to get through a good amount of other errors/exceptions, and I've cleaned up every memory leak in the game, so that's one good thing!
The format of my SM texture is D3DFMT_R32F and then I use GetSurfaceLevel(0, &shadowMapSurface) to get the surface. I saved it as a PNG using D3DXSaveSurfaceToFile, and then just uploaded the PNG file as it was. I guess because it's not an RGB format that it only has a red channel.