Ok, here’s a breakdown, ebi. Hopefully you like reading.
First let’s break down the Quantize node group. This is responsible for pixelating the texture it’s fed into with some vector math. To do this, we need to work on the X and Y (UV) coordinates separately.
The nodes in blue aren’t essential to the function, but let’s start there. Our goal with this node group is to pixelate an image, and allow you to to scale the pixels up and down. When scaling in UV space, the transform happens from the origin (0,0) which is at the bottom left corner. That works fine, but I wanted the pixelation to line up to the center of the image.
See in the .gif how the pixels are perfectly centered as the pixels are scaled? The blue nodes are responsible for this. When modeling, you can move the pivot to where you want to scale from. In UV space, you can’t move the pivot to the center of the texture, but you CAN move the center of the texture to the pivot.
That said, here’s what’s happening, starting with the blue node in the top left:
- Get half of the pixel size.
- Add that value to 0.5.
- UV space is 0 - 1, so this gives us the center of the U/V vector PLUS half of one pixel (so the “pivot” is at the corner of the pixel, and not the center of it.)
- Now get the vector and subtract (translate negatively) by this center value.
- At this point, the center of the texture has moved to the bottom left corner. Now we can scale from the center.
- In the first gray node, take the vector and divide by (scale down to) the pixel size.
- The texture now tiles across the mesh. If the vector length is 1 and the pixel size is say 0.05, then 1 / 0.05 = 20 tiles (pixels) across. In other words, our vector space was scaled from 0.0 - 1.0 to 0.0 - 20.0.
- “Round” quantizes the vector space. 0.0 - 20.0 becomes 0 - 20.
- Multiply the vector by the pixel size to scale it from 0 - 20 back down to 0 - 1
- Lastly, we need to undo step 3, by adding (translate positively) back to the original UV space.
Now for the matrix node group.
It’s as simple as the quantize group when you take out the blue and red nodes. Just like before, the blue nodes have to do with changing the scale “pivot point”. The red nodes are simply there to make pixel gap and pixel squareness sliders more user friendly. That leaves you with 5 gray nodes doing all the work.
I’ll skip the blue and red this time:
- Divide the vector by the pixel size.
- Feed this into a modulo, which in most basic terms, repeats the texture
- This group is being fed into a procedural gradient texture, which doesn’t repeat like an image texture does.
- Subtract (translate) each pixel by 0.5 to re-center them. This node should have been blue.
- Multiply (scale) each pixel individually by the gap size
- Feed this into a power node with the exponent controlled by the squareness input.
- The higher the exponent, the sharper, or more “square” a curve looks.
- This node group is plugged into the gradient texture.
- The gradient is plugged into a “greater than” node to make it solid black and white. This is your mix factor for the lit and unlit pixel materials.
- The gradient texture can also be plugged (without the greater than node) into a bump map node to give the pixel grid some dimension.
That’s about it. Let me know if that clears things up for you.