Gerstner waves in the fragment shader
posted by Anonymous
posted 32d 13h ago
The given height function that takes a point
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
We derive with respect to the x and y directions (spatial derivatives, we ignore time):
and
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:
For any per fragment lighting computations, you can use this normal (preferably normalized beforehand :) ).
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
We derive with respect to the x and y directions (spatial derivatives, we ignore time):
and
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:
For any per fragment lighting computations, you can use this normal (preferably normalized beforehand :) ).





![[IEQ][B][I]\frac{}{}[/I][/B][/IEQ] [IEQ][B][I]\frac{}{}[/I][/B][/IEQ]](equations/163975_0.png)



