SFML community forums
Help => Graphics => Topic started by: Krechet on February 15, 2024, 07:06:29 pm
-
Hi all. I'm trying to draw a distorted square to simulate perspective. I use rendering through an array of vertices. And as a result I get a strange picture. I tried using different vertices modes (PrimitiveType.Quads and PrimitiveType.Triangles), the result was the same.
I would be very grateful if anyone could suggest a solution on how to get the correct picture.
(Sample in attach (https://i.postimg.cc/wjzchMZs/Shapes-Sample.png))
-
What you're getting is Affine Texture Mapping - caused by the vertex stage interpolating the UV coordinates in 2D space. (It's actually what the PS One did).
For Perspective Texture Mapping you'll need to supply some sort of depth value. This article explains more: https://mtrebi.github.io/2017/03/15/texture-mapping-affine-perspective.html as does wikipedia: https://en.wikipedia.org/wiki/Texture_mapping#Affine_texture_mapping
-
Waiting for Hapax to mention Elastic Sprite that "fixes" exactly this issue ;)
https://github.com/Hapaxia/SelbaWard/wiki/Elastic-Sprite
-
For Perspective Texture Mapping you'll need to supply some sort of depth value. This article explains more: https://mtrebi.github.io/2017/03/15/texture-mapping-affine-perspective.html
Magic! But its working)) Thanks a lot!
-
Just in case you hadn't seen the cause of the issue, it's because - in 2D - both of the triangles have no idea about the other triangles so one doesn't realise it's supposed to be a part of a pair to make a quad (and then have to share some of its texture with another one).
Waiting for Hapax to mention Elastic Sprite that "fixes" exactly this issue ;)
https://github.com/Hapaxia/SelbaWard/wiki/Elastic-Sprite
Haha! It exists because it solves the issue! :)
Elastic Sprite is entirely 2D and automatically 'solves' perspective (in the same way apps like Photoshop create perspective when given 2D corners).
It's also therefore compatible with SFML's 2D vertices (since z cannot be used with those).
I have long considered a more involved solution allowing multiple faces but if that much 3D is needed, it's likely that going raw OpenGL/Vulcan is the better option. Maybe in the future... ;D