Recently I have discovered a great tool for creating 3D models, it is called Magica Voxel. Basically, you build models using 3D blocks, which in geeky terms are voxels (volumetric pixels). Apart from a lot of tools for editing your voxels creations, Magica Voxel also offers a really powerful rendering engine which has various rendering effects such as drawing each voxel as a sphere or as a cylinder and doing a marching cubes effect on the voxel mesh. In my opinion, the most interesting effect is the one which draws each voxel as a Lego block.

This shader represents my effort to reproduce this effect in Unity without having to store the voxels separately. You simply import a mesh and the shader will draw the Lego cylinders on top of the geometry.  To achieve this effect, my shader is using an extra step in the rendering pipeline which was introduced since DirectX 10 and OpenGL 3.2. This extra step called the geometry stage is executed after the vertex stage and after the computations for the primitives. Therefore, the input for the geometry shader are geometry primitives (such as lines, triangles or point) and the output is a triangle stream. As a result, this specific stage gives the programmer the ability to create extra geometry and I have used this particular technique achieve the Lego effect.

[UPDATE, January 2017] I have attached multi pass rendering in order to support multiple lights, I have added PBR properties to the shader (metal and gloss) and used Unity’s PBL functions for creating light computations.  Moreover, I have added support for deferred rendering path. The shader set now comes with different shaders so that you can successfully achieve various effects: Transparent, Vertex Lit, PBL, Diffuse. The shader pack was sent to AssetStore and I am waiting for the review team’s approval. Once it will be hopefully accepted, it will appear under the name of “Modular Bricks Shader”. The decision of giving this name to the set is owed to the fact that the shader is able to create cubes and pipes and also in order to avoid any legal issues.

[UPDATE, February 2017] The assets was approved and now is available on AssetStore.

Feel free to check the gallery and the videos below.

https://www.youtube.com/watch?v=10OU_VqxAeA&t

Music visualiser with Lego bricks and a custom sound processing technology.