# 运算节点¶

## 范例¶

### 自定义Z深度通道节点设置¶

“使用最小值”功能是依据靠近摄影机的像素将Z深度值选择出来；也可以选择矩形部分的平面Z深度值。背景有个初始的Z深度值，值限定为1.0（显示为白色）。在“使用最大值”范例中，矩形的Z深度值比图像平面要大，因此更靠近左侧，但是图像平面(FlyCam)渲染层Z值初始在右侧（对应于1.0），因此他们被选择。

### 使用正弦功能得到不断循环的变化数¶

This example has a Time node putting out a linear sequence from 0 to 1 over the course of 101 frames. At frame 25, the output value is 0.25. That value is multiplied by 2 × pi (6.28) and converted to 1.0 by the Sine function, since we all know that $$sin(2 × pi/ 4) = sin(pi/ 2) = +1.0$$.

Since the sine function can put out values between (-1.0 to 1.0), the Map Value node scales that to 0.0 to 1.0 by taking the input (-1 to 1), adding 1 (making 0 to 2), and multiplying the result by one-half (thus scaling the output between 0 to 1). The default Color Ramp converts those values to a gray-scale. Thus, medium gray corresponds to a 0.0 output by the sine, black to -1.0, and white to 1.0. As you can see, $$sin(pi/ 2) = 1.0$$. Like having your own visual color calculator! Animating this node setup provides a smooth cyclic sequence through the range of grays.

### Restrict Color Selection (Posterization)¶

In this example, we restrict the color values to be one of the six values: 0, 0.2, 0.4, 0.6, 0.8, 1.

To split up a continuous range of values between 0 and 1 to certain set of values, the following function is used: $$round(x × n - 0.5) / (n - 1)$$, where "n" is the number of possible output values, and "x" is the input pixel color. Read more about this function.

To implement this function in Blender, consider the node setup above. We string the math nodes into a function that takes each color (values from 0 to 1), multiplies it up by six, the desired number of divisions (values become from 0 to 6), offsets it by 0.5 (-0.5 to 5.5), rounds the value to the nearest whole number (produces 0, 1, 2, 3, 4, 5), and then divides the image pixel color by five (0.0, 0.2, 0.4, 0.6, 0.8, 1.0).

In the case of a color image, you need split it into separate RGB channels using Separate/Combine RGBA nodes and perform this operation on each channel independently.