This project was made with the aim to replicate the pixel art style when rendering 3D meshes. By customizing Unity's rendering pipeline and using a series of postprocessing techniques, the effect is achieved and, from crude simple 3D models, we can produce a stable pixelization effect that gives a stylized look to our rendererd scene.
Pixelization Effect
Pixelization is achieved by rendering the initial image to a small render target and then upscaling it to the final screen resolution with Nearest texture filtering. However, this approach alone will cause some terrible artifacts arround the edge of objects when we move the camera arround:
Stable Camera
In order to stabilize the camera, we must make sure that it only moves at discrete steps of 1 pixel. This can be done by converting the the camera target position into view space coordinates. Then, using the total amout of pixels per unit, we can convert from view space to pixel coordinates and snap to the closest integer:
This results in stable pixels but we can still see the camera snapping, causing a slight stuttering effect:
The final stable and smooth result can be obtained by rendering the previous result into a quad and then setting up a secondary camera to render that quad with one pixel of extra margin and then offset this camera by the difference between original and snapped coordinate:
Outlines
The outlines are a final touch that gives life to the pixel art style. In this case, I simply sampled the depth and normal textures at the center and at the 4 neighboring pixels and calculating the gradients. The total sum of the gradient components is used as the outline strength: