Question

I'm trying to implement a simple water simulation, with theory from GPU Gems 1 chapter 1.

if you imagine a 3D plane (flat in the xz plane, with y denoting height at any point), the height field function is given as:

heightfield function

where: Wavelength (w): the crest-to-crest distance between waves in world space.

Amplitude (A): the height from the water plane to the wave crest.

Speed (S): the distance the crest moves forward per second.

Direction (D): the horizontal vector perpendicular to the wave front along which the crest travels.

This is straightforward to implement.

Please note the article in GPUGems uses the z direction for height, but this isn't standard for graphics (normally, x is width, y is height, z is depth). So I'll refer to the xz direction meaning the flat/horizontal plane directions.

So, having computed the height (y) value at any given point, I need to compute the bitangent and tangent vectors to that point, in order that I can compute a normal vector, which I need for lighting equations.

The bitangent and tangent vectors are partial derivatives in the x and z directions (y is the heightfield value).

So my question is, how can I take a partial derivative in the x and then the z directions for the height field function?

The article says that the partial derivative for the x direction is given by

partial derivative in the x direction

partial derivative in the x direction2

I understand the concept of taking a partial derivative from this video:, but I don't know how to take the partial derivative of my heightfield function.

Can someone explain it (like I'm 5) - My grasp of maths isn't great!

Était-ce utile?

La solution

You want to derive the following equation:

W(x) = A * sin(w * (D.x * x + D.y * z) + t * phi)
     = A * sin(w * D.x * x + w * D.y * z + t * phi)

which is the above formula with the expanded dot product. Because we want to find the derivative with respect to x, all other variables (except x) are considered constant. So we can substitute the constants:

c1 = A
c2 = w * D.x
c3 = w * D.y * z + t * phi
W(x) = c1 * sin(c2 * x + c3)

The derivative is:

W'(x) = c1 * c2 * cos(c2 * x + c3)

Reverting the substitution we get:

W'(x) = A * w * D.x * cos(w * D.x * x + w * D.y * z + t * phi)

which describes the y-component of the tangent at a given position.

Similarly, the bitangent (derivative with respect to z) can be described by

W'(z) = A * w * D.y * cos(w * D.y * z + w * D.x * x + t * phi)

Therefore:

tangent   = (1, W'(x), 0)
          = (1, A * w * D.x * cos(w * D.x * x + w * D.y * z + t * phi), 0)
bitangent = (0, W'(z), 1)
          = (0, A * w * D.y * cos(w * D.y * z + w * D.x * x + t * phi), 1)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top