In open water, social fish gather to form schools, in which fish generally align with each other. In this work, we study how this social behavior evolves when perturbed by artificial obstacles. We measure the behavior of a group of zebrafish in the presence of a periodic array of pillars. When the pillar density is low, the fish regroup with a typical interdistance and a well-polarized state with parallel orientations, similarly to their behavior in open-water conditions. Above a critical density of pillars, their social interactions, which are mostly based on vision, are screened and the fish spread randomly through the aquarium, orienting themselves along the free axes of the pillar lattice. The abrupt transition from natural to artificial orientation happens when the pillar interdistance is comparable to the social distance of the fish, i.e., their most probable interdistance. We develop a stochastic model of the relative orientation between fish pairs, taking into account alignment, antialignment, and tumbling, from a distribution biased by the environment. This model provides a good description of the experimental probability distribution of the relative orientation between the fish and captures the behavioral transition. Using the model to fit the experimental data provides qualitative information on the evolution of cognitive parameters, such as the alignment or the tumbling rates, as the pillar density increases. At high pillar density, we find that the artificial environment imposes its geometrical constraints to the fish school, drastically increasing the tumbling rate.