Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Perspective distortion issue [Solved]  (Read 2421 times)

0 Members and 1 Guest are viewing this topic.

Krechet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Perspective distortion issue [Solved]
« 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 )
« Last Edit: February 16, 2024, 11:31:28 am by Krechet »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Perspective distortion issue
« Reply #1 on: February 15, 2024, 07:36:49 pm »
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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Perspective distortion issue
« Reply #2 on: February 16, 2024, 12:09:33 am »
Waiting for Hapax to mention Elastic Sprite that "fixes" exactly this issue ;)

https://github.com/Hapaxia/SelbaWard/wiki/Elastic-Sprite
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Krechet

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Perspective distortion issue
« Reply #3 on: February 16, 2024, 11:30:57 am »
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!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Perspective distortion issue [Solved]
« Reply #4 on: March 06, 2024, 05:55:04 pm »
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
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything