Set text color based on color of another element in the same spot

I want my fixed text change its color depending on the exact background color that’s currently behind it, pixel-by-pixel. Is it possible?In the given example, part of the text on the blue background would be white
Is it possible to do if the shape on which the text is displayed has different edges than horizontal/vertical?

I tried using JQuery to target specific elements on the page, knowing that the scroll function will only let me target scroll position, so only horizontal elements, and the text will change color in its entirety, not pixel-by-pixel, which would be my goal, as I’m planning to add custom-shaped backgrounds, and it would make the text readable also in transitional positions, as per the example. However, even this didn’t work, possibly due to some CSS issues. Is here a way to do it in CSS?

$(window).scroll(function() {
    var scroll = $(window).scrollTop();
    if (scroll <= $('.fp-container-1').offset().bottom) {
      $('nav-button').css('color', 'black');
    }
    if (scroll >= $('.fp-container-2').offset().top) {
      $('nav-button').css('color', 'white');
    }
  });
.fp-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
}

.fp-container-1 {
    background-color: rgb(255, 255, 255);
}

.fp-container-2 {
    display: block;
    background-color: rgb(70, 67, 226);
    height: 150vh;
}