Messaging apps haven't been pure SMS for a long time. If you've sent photos/images, it's using MMS, which basically uploads the picture to a HTTP server hosted by your carrier and sends the URL in a SMS message that the receiving app knows to automatically download and display the image, provided you have a data connection.
iMessage is proprietary to Apple, so of course it goes through Apple's servers. When you set up your iPhone, it registers your phone number with Apple's iMessage server so that whenever someone tries to send a message to your number, it sends it to the iMessage cloud instead of SMS. This can actually cause problems when you switch from an iPhone to Android because other Apple users trying to send you text messages might still get routed to iMessage instead of SMS, and there's no iMessage available for Android. You may have to use a website that Apple provides to manually deregister the phone number from iMessage in that case.
I'm not all that familiar with how RCS works but presumably there's a similar registration process so that other phones know that your phone is RCS capable, except decentralized since it's not controlled by a single company.