Technically they have the same brightness (625 nits) but if the 12 looks dimmer to you compared to the XR, then it is.
iPhone OLED screens are not consistent. Some look great and some definitely don’t.
Two iPhones of the same model can have very different looking screens (color, color shift, brightness, color banding on edges, different color shifting at low brightness levels).
Getting a great iPhone OLED screen is like buying a lottery ticket. Maybe you’ll be lucky.