Predicting the compactness of the invasion front and the amount of trapped fluid left behind is of crucial importance to applications ranging from microfluidics and fuel cells to subsurface storage of carbon and hydrogen. We examine the interplay of wettability, macro- and pore scale heterogeneity (pore angularity and pore wall roughness), and its influence on flow patterns formation and trapping efficiency in porous media by a combination of 3D micro-CT imaging with 2D direct visualization of micromodels. We observe various phase transitions between the following capillary flow regimes (phases): (a) compact advance, (b) wetting and drainage Invasion percolation, (c) Ordinary percolation. The study of phase transitions in flow patterns that depend on the heterogeneity, wettability, and surface roughness of the pore space and their classification in phase diagrams is one of the challenges in recent multiphase flow physics. We study the dynamics of thick film and corner flows by visualization experiments with micromodels. Both flow types are characteristic of geologically representative porous media (sands, sandstones) and control the displacement and trapping process. The 2D micromodels accurately reproduce the characteristic geometric, morphological, and topological properties of 3D porous media. All microstructures were derived from mu-CT images. We fabricated identical microstructures by both DRIE-ICP etching of silicon wafers and anisotropic chemical etching of glass ceramics to vary the degree of surface roughness. The results are in excellent agreement with previous mu-CT experiments. We observe various phase transitions between the following flow regimes (phases): (a) frontal/compact advance, (b) Ordinary percolation, and (c) Invasion percolation. We show that they can be classified according to Blunt's "heterogeneity versus wettability" phase diagram. Interplay of pore-scale heterogeneity, wettability, and surface roughness controls displacement patterns and capillary trapping efficiencyThe invasion flow pattern for capillary flow were visualized by micro-CT- and micromodel experiments and classified in a new phase diagramFour generic flow regimes (phases) were observed: frontal advance, wetting and drainage invasion percolation, and ordinary percolation