User Manual

Table Of Contents
Using the n1 slider for the angle theta, and a sample function, we get (for the red
channel):
getr1b(x * cos(n1) - y * sin(n1), x * sin(n1) + y * cos(n1))
This calculates the current pixel’s (x,y) position rotated around the origin at (0,0) (the
bottom-left corner), and then fetches the red component from the source pixel at this
rotated position. For centered rotation, we need to subtract 0.5 from our x and y
coordinates before we rotate them, and add 0.5 back to them afterward:
getr1b((x-.5) * cos(n1) - (y-.5) * sin(n1) + .5, (x-.5) * sin(n1) + (y-.5)
* cos(n1) + .5)
Which brings us to the next lesson: Setup and Intermediate Expressions. These are
useful for speeding things up by minimizing the work that gets done in the Channel
expressions. The Setup expressions are executed only once, and their results don‘t
change for any pixel, so you can use these for s1 and s2, respectively.
cos(n1) sin(n1)
Intermediate expressions are executed once for each pixel, so you can use these for
i1 and i2:
(x-.5) * s1 - (y-.5) * s2 + .5
(x-.5) * s2 + (y-.5) * s1 + .5
These are the x and y parameters for the getr1b() function from above, but with the
Setup results, s1 and s2, substituted so that the trig functions are executed only once
per frame, not every pixel. Now you can use these intermediate results in your Channel
expressions:
getr1b(i1, i2)
getg1b(i1, i2)
getb1b(i1, i2)
geta1b(i1, i2)
With the Intermediate expressions substituted in, we only have to do all the additions,
subtractions, and multiplications once per pixel, instead of four times. As a rule of
thumb, if it doesn‘t change, do it only once.
This is a simple rotation that doesn’t take into account the image aspect at all. It is left
as an exercise for you to include this (sorry). Another improvement could be to allow
rotation around points other than the center.
Filtering
Our second example duplicates the functionality of a 3 x 3 Custom Filter node set to
average the current pixel together with the eight pixels surrounding it. To duplicate it
with a Custom Tool node, add a Custom Tool node to the node tree, and enter the
following expressions into the Setup tab.
(Leave the node disconnected to prevent it from updating until we are ready.)
S1
1.0/w1
S2
1.0/h1
Chapter – 100 Miscellaneous Nodes 2217