Jump to content
• Advertisement

# Weird perspective warping.

This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

So as some of you may know, I've been developing a 2D graphics library for DirectX called Gorgon. I don't use the ID3DXSprite interface, but instead use my own custom rectangle for sprites and I use an Orthographic projection matrix to project into 2D space. That said, I'm experiencing a big ol' brain fart and I should know this, but I can't recall why this is:
Notice how when I bring the two top corners of the sprite together I get a warping effect along the seam of the rectangle? But this is what I was hoping to get (this was modified in a paint program):
Is there something I'm missing? Does DirectX do something funky when an orthographic matrix is active? Am I missing sometime stupid simple (this is most likely), like some render state or something? Sorry if this is a trivial question, but for the life of me I can't seem to think of why I'm getting this output.

#### Share this post

##### Share on other sites
Advertisement
What are your texture coordinates like? And I'm not quite sure how you want to map the texture onto that region.

You have a rectangular texture, with the four corners as so:
A----------B|          ||          ||          |C----------D

When that texture is mapped onto your shape, do you want it to map like so:
A---+--+---B|  +    +  || +      + ||+        +|C----------D

I.e. without any distortion, so 1 pixel will equal 1 texel, or like this:
+---A--B---+|  +    +  || +      + ||+        +|C----------D

I.e. warp the texture so that points A and B on the texture map to the top two corners of the region?

#### Share this post

##### Share on other sites
Warp the texture such that corner A has a texture index of (0,0) and corner B has a texture index of (1.0, 0), so I think your second ascii drawing is what I'm trying to accomplish. That is, when corner A of the polygon moves, its texture coordinate index will remain at (0,0), and when B moves the texture coordinate index will remain at (1.0, 0). And that's currently how it's set up, and in theory I thought I should end up with an image like my second picture, but instead I got my first picture as my output.

I want the output to be like the old SNES Mode 7 effect.

#### Share this post

##### Share on other sites
If you want it to be drawn with perspective, draw it with perspective. Making it a trapezoid in an orthographic projection, as you've tried here, isn't going to work.

#### Share this post

##### Share on other sites
Sneftel is correct. Here's a fuller explanation:

What you see is the simplest interpolation, and is correct and easy to understand. Think about it this way: Take a rectangle, and divide it into two triangles. Now leave one of them as is, and shrink the other. You will get an effect similar to what you see in your first image. What reason would it have to look like your second image?

When you use an orthographic projection, what you're basically saying is "all my triangles are on the screen plane". In this case, they will be interpolated simply, as described above. On the other hand, when a rectangle looks like yours because of perspective, the graphics card has a good idea that it needs to interpolate the texture coordinates differently, taking depth into consideration.

You should be able to get the card to interpolate like you want by setting z or w on your vertices. However, as Sneftel said, the easier way to go to produce a perspective effect is to use a perspective projection, and not try to simulate it.

#### Share this post

##### Share on other sites
Quote:
 Original post by ET3DSneftel is correct. Here's a fuller explanation:What you see is the simplest interpolation, and is correct and easy to understand. Think about it this way: Take a rectangle, and divide it into two triangles. Now leave one of them as is, and shrink the other. You will get an effect similar to what you see in your first image. What reason would it have to look like your second image?When you use an orthographic projection, what you're basically saying is "all my triangles are on the screen plane". In this case, they will be interpolated simply, as described above. On the other hand, when a rectangle looks like yours because of perspective, the graphics card has a good idea that it needs to interpolate the texture coordinates differently, taking depth into consideration.You should be able to get the card to interpolate like you want by setting z or w on your vertices. However, as Sneftel said, the easier way to go to produce a perspective effect is to use a perspective projection, and not try to simulate it.

Yeah I realized that after I whipped up a test this morning (which I have to admit was incredibly dumb of me not to have done before then). Like I said, it's something I should have known, but my brain failed me. I've got it all sorted now, thanks.

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Now

• 23
• 10
• 19
• 15
• 14
• Advertisement
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!