This page looks best with JavaScript enabled

A World Space Grid Snapped Shader

 ·   ·  ☕ 2 min read

Expanding upon our exploration of a shader that snaps vertices to a grid. This time we’re moving things into world space!

By moving the grid snapping into world space positions we actually gain a few fun things! For example it means that multiple different objects with the shader applied will actually merge together cleanly in world space (in essence, all objects will share a global grid space in our scene). This makes the results a lot more consistent and prevents things like rotating or scaling an object from skewing the results. This also means that we get pretty interesting results when we apply the effect to more complex objects like a particle system, in this case we can create a series of flowing snapped cubes with particles.

Compared to the previous grid snapped shader we need to add two lines. One to move our vertices into World Space and another to move back into Object Space after our operations have been applied.

  void vert(inout appdata_full v) {
+    v.vertex = mul(unity_ObjectToWorld, v.vertex);
     v.vertex /= _GridSize;
     v.vertex = round(v.vertex);
     v.vertex *= _GridSize;
+    v.vertex = mul(unity_WorldToObject, v.vertex);

You can view the entire playlist of implementing this effect here:

The variables I use (unity_ObjectToWorld and unity_WorldToObject) are documented here along with a number of other useful built-in shader variables:
You can find a collection of other Visual Effects we’ve explored on the channel here:
The animated model is from the “Mecanim Warrior Anim Free” package on the asset store - this effect should work on any object that you can apply the material to though.
Join the World of Zero Discord Server:

Sam Wronski
Sam Wronski
Maker of things and professional software engineer. Lets make something awesome together!