I have recently published a gizmo on Nukepedia by the name G_Ripple. You can download it from here.
If you want to know more about this tool then go ahead and read this blog. I have mentioned everything that I referenced while developing the tool.
You will get to know about the mathematical equation that makes this gizmo do what it does.

Concept
The thought behind this tool was to generate a map which can be used to simulate ripple like effect on images and on 3d geometries as well, inside of nuke.
I wanted the process to be mostly driven by some mathematical function /equation so that it can be more automated and accurate. So I went on to doing some research on the equation of ripple waves, and I came around one video which you can find here.
Ian Hoover has shared an equation which he used to generate the ripple like effect which is clearly visible in the video. I used the same equation with a little bit of modifications to make it work in nuke and to give user more controls on the equation so that one can tweak the values to achieve the desired result.
Understanding the ripple equation
Before we begin our setup in nuke, let’s just get clear on the equation first. Ian Hoover has mentioned the following equation that he used to create water ripple
Z = (cos ( 0.5sqrt(x^2+y^2)-6n)/(0.5(x^2+y^2)+1+2n), n={0...10}
where x and y are map coordinates and n is a variable changing with time.
If we break the equation then we will see that there are two main functions inside it. First one is a “cos” function and the other is a quadratic function.
Let’s have a look on the “cos” function first. The function is as follows:
cos(0.5sqrt(x^2+y^2)-6n)
or if we write it slightly more clearly and elaborately it will be:
cos(0.5 * sqrt((x-x’)^2 + (y-y’)^2) – 6 * n) …(eq1)
where x’ and y’ are the center coordinates of the ripple.
Before understanding the different parts inside of this cos function, let us first get ourselves familiar with what the cos function does. Cos is basically a trigonometric function which generates a wave when graphed. The type of wave generated depends completely on the equation used inside cos function. To read more about it follow this link.
From above information it is clear that whatever algorithm is inside the cos, its finally going to generate a wave. Now let’s break the function even more. So if you look closely there are three separate parts
0.5 – wavelength …(eq1_1)
sqrt((x-x’)^2 + (y-y’)^2) – equation of a circle with center x’ and y’ …(eq1_2)
6*n – a variable multiplied with a constant 6 …(eq1_3)
So from eq1_2, it is clear that the cos function is generating a circular wave with its center at (x', y'). And the wavelength / wave numbers can be controlled by the value used in eq1_1. But still with these two equation inside a cos function we only get a static wave. In order to animate the wave generated, we need to offset it with some variable which changes over time and that’s exactly what the eq1_3 does. The variable n in eq1_3 changes overtime and as a result it offsets the wave as well, which in turn gives an inwardly or outwardly animated waves. After trial and error, I came on a conclusion that, in our case, the constant multiplied with n should be 7 and not 6. As it gives, more accurate speed and the right direction of ripple movement.
So our eq1 changes to following:
cos (0.5 * sqrt((x-x’)^2 + (y-y’)^2) – 7 * n) ..(eq2)
Now, we have our wave, but there is still a problem which needs to be solved.
Since the wave generated is going to have the same amplitude all over the map. But as we are familiar with water ripples, it dissipates as it moves further away from the origin, in real world and finally dissolves overtime. So we also need to dissipate our ripple waves as it moves away from the center. In order to achieve this result, we have our second equation for this purpose.
The second part of our wave ripple expression is as follows:
(0.5(x^2+y^2)+1+2n)
Above equation can also be written as:
(m * ((x-x’)^2+(y-y’)^2) + c + 2 * n) …(eq3)
where;
m – Multiplier to increase or decrease the output
((x-x’) ^2 + (y-y’) ^2) – a circular gradient with lowest value at center (x’, y’)
c – a constant to offset the overall value
2*n – a variable that changes the final value overtime
In conclusion, eq3 generates a radial gradient with the center at (x’, y’) and its value keeps on increasing as it goes farther away from the center. Also a variable is added later on so that the overall value keeps on increasing overtime.
All these above factors in eq3 give exactly the result we require. The values generated in eq3 are used to divide the values in eq2. Because of these gradually increasing values we get a map which dissipates as it moves away from the origin. And because of the variable added in eq3 our ripple gets dissolved as well, after some time.
So, basically the above two equations gives us a map that can be used to drive a ripple like simulation in Nuke or in any other software which supports such system.
Applying the equation in Nuke
Now that we know how the ripple wave expression works, it’s time we look into how to use the expression in Nuke.
To begin with, we will create a constant and an expression node. Connect the expression node with constant, and our starting setup is done. Constant is used to set the format of our ripple map and also to set a starting value for the expression node of (0.0, 0.0, 0.0).
Follow the below instructions as mentioned, and you will get a working ripple map:
· Set the format in constant to 2048x2048
· Double click expression node and set the following three expression in the temp_expr space
1. a = cos(0.05*hypot(x-1024, y-1024)-7 *frame)
2. b = (0.005*(pow2(x-1024)+pow2(y-1024))+20+0.01*frame)
3. c = (a/b)*10’
· Go to expr0 and write c in it
And that’s it; we are done setting our expressions in Nuke. All the values in above mentioned expressions are tested to provide a ripple wave of good frequency and wavelength. You can obviously try substituting your own values and generate the ripple that suits your purpose or you can go to Nukepedia and download G_Ripple gizmo to get even more control and accuracy.
In case you have any further queries or suggestions, you can comment here or you can write a mail to me from my contact page.
Go ahead! Download and test the G_Ripple gizmo here.
Comments