How to get correct pixel position ?

hi
i am trying to create a material that split screen from center and draw the red color if current pixel is right else green;

it work fine when i am on immersive mode. but does not work correctly on viewport.

https://i.imgsafe.org/b22725b.jpg

That exact example is explained in this video: