Weird bug when accessing the texture inside the for loop. Unrolling the for
solved the problem