Alternatively you can do this in the shader itself, just find the distance and branch out.