It is a very simple question, but after a brief search and a reading of "similar questions", I have not yet found an answer.
I'm creating a 2D game with OpenGL and I came across a problem: let's say I wanted to create portals. An entity can enter a portal A and exit the corresponding portal B. Transforming coordinates and speed of the entity is easy, but it would create a "hard" texture teleportation.
Which means: although half of the entity is in Portal A, it will not be restored to the corresponding B side.
How could I create a smooth transition?
My first idea was: I define the fields "exit" and "entry" containing the transformation function (Matrix). Now, when an entity enters the exit zone, the entity is also drawn into the input area using the input zone transformation matrix. / Release. But to draw it twice would still pose the difficulty, namely that I had to cut the entity on the "back" portals. (The entity must disappear behind Portal A by entering).
So, my second thought was that there should be a solution using shader (vertex?)? But what would such a shader look like? (Code example would be nice, but not necessary, I would rather have an answer "what the shader would do"). Would I define the uniforms (exit and entry areas) that the shader would cut / transform ("move") the vertices?
What does a typical solution look like for this break? Where can I read about this type of problem? I found only 3D versions, where the view of portal B should be rendered in portal A. But that does not solve the problem of moving objects that move … I think
In my opinion, changing the order of the prints or displaying something above the back of the portals is not the right solution, as this could create strange behavior in certain situations. (Portal B is just behind Gate A. For example, one of them would be overdraft, I think.)