Gerstner waves in the fragment shader
posted by teodron
The given height function that takes a point (x,y) on the water's surface and associates a given height to it can be used to compute the normal at a certain point.

Since we're in the fragment shader, we cannot use the position for anything but computing the normal. We have to compute the two main directional derivatives and the cross product of the two gives the direction of our normal. Here's how a point on the surface looks like
 (x,y, H(x,y,t))

We derive with respect to the x and y directions (spatial derivatives, we ignore time):
 \frac{\partial}{\partial x} (x,y,H(x,y,t)) = (1,0, \partial_x H(x,y,t))

and
 \frac{\partial}{\partial y} (x,y, H(x,y,t)) = (0,1, \partial_y H(x,y,t))

You can use the formulae given in the gem article to compute the derivatives of the H function (H is actually a sume of functions whose derivatives can be also analitacally computed with some Calculus knowledge at hand).

In the end, you get the normal:
 N(x,y) = (-\partial_x H(x,y,t), -\partial_y H(x,y,t), 1)


For any per fragment lighting computations, you can use this normal (preferably normalized beforehand :) ).
Reply to this post

Replies

Gerstner waves in the fragment shader
posted by Anonymous
[IEQ][B][I]\frac{}{}[/I][/B][/IEQ]
The given height function that takes a point (x,y) on the water's surface and associates a given height to it can be used to compute the normal at a certain point.

Since we're in the fragment shader, we cannot use the position for anything but computing the normal. We have to compute the two main directional derivatives and the cross product of the two gives the direction of our normal. Here's how a point on the surface looks like
 (x,y, H(x,y,t))

We derive with respect to the x and y directions (spatial derivatives, we ignore time):
 \frac{\partial}{\partial x} (x,y,H(x,y,t)) = (1,0, \partial_x H(x,y,t))

and
 \frac{\partial}{\partial y} (x,y, H(x,y,t)) = (0,1, \partial_y H(x,y,t))

You can use the formulae given in the gem article to compute the derivatives of the H function (H is actually a sume of functions whose derivatives can be also analitacally computed with some Calculus knowledge at hand).

In the end, you get the normal:
 N(x,y) = (-\partial_x H(x,y,t), -\partial_y H(x,y,t), 1)


For any per fragment lighting computations, you can use this normal (preferably normalized beforehand :) ).
Use this to start your reply
Submit Reply
Title: Your Name:
Wrap equations in [EQ]equation here[/EQ] tags, and inline equations in [IEQ][/IEQ] tags.