Strange behaviour with texture mapping

Started by
10 comments, last by unbird 10 years, 11 months ago

Hey everyone here's an image of a problem I am having:

uv_issues.png

Hopefully this alone will demonstrate my problem, I am creating sphere like geometry using projected quads. The problem is for some reason even though the quads never overlap, and have UV's of either 0 or 1, the texture seems to get more and more distorted the closer it gets to the poles.

At first I thought it was a problem with my coordinate generator, but then I tried to draw a straight forward quad, it draws fine if all edges are at right angles to one another, however if I add a tilt like the image below, I get the distortion again so I am fairly confident there is nothing wrong with the coordinates.

uv_issues1.png

Thanks in advance for any help.

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Advertisement

How are you drawing the sphere? It looks like perspective correction isn't happening.

Your post is tagged with XNA, so I guess it's a regular 3D object drawn with a shader... maybe you can post your vertex shader code in case there's something odd going on?

In your 2D quad test, the 'distortion' across the diagonal is the correct result that should be expected to happen. When the deformation of the quad is due to depth differences though, perspective correction should ensure that the distortion doesn't occur.

Ahh that sounds like what's happening, though for this test I was just using XNA 4's BasicEffect not my own shader, this proves that every day is a school day. This still seems a bit odd to me as wikipedia says that this should be supported by Direct3D, and I have tried this on two computers. Also I've just tried it with MonoGame (OpenGL) and the same thing happens with.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Are your vertices in 3D space and the shader is projecting them to the screen as usual, or are you projecting them to 2D by yourself?

Well it's just the generic BasicEffect that is bundled with XNA 4 using the VertexPositionNormalTexture description for vertices. As far as I am aware the vertex shader it uses is near identical to implementing it myself, projecting position via World * View * Projection matrices. Surely if Direct3D supports this sort of feature then even if a custom shader was written (HLSL DX9) I would not have the ability to influence weather perspective correction features were enabled (going off what I've researched this morning), if that is the case then I may just have to cope with it.

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

As far as I am aware the vertex shader it uses is near identical to implementing it myself, projecting position via World * View * Projection matrices.

The result of that projecting is a four-dimensional vector, with important perspective data in the w component, which is how perspective correction works.

If you're projecting points yourself, you need to ensure that the whole 4D xyzw vector makes it to the rasterizer.

Ok finally found the answer and it's one of those where I feel like happily slapping myself lol, NewToXNA answered it in this post here: http://xboxforums.create.msdn.com/forums/p/108248/638080.aspx
Turns out I was just forgetting to remember I am drawing two triangles not just a quad, and the distortion of either of the triangles does not effect the other, what a great reminder that I should sleep more :P
Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

As far as I am aware the vertex shader it uses is near identical to implementing it myself, projecting position via World * View * Projection matrices.

The result of that projecting is a four-dimensional vector, with important perspective data in the w component, which is how perspective correction works.

If you're projecting points yourself, you need to ensure that the whole 4D xyzw vector makes it to the rasterizer.

thanks, I'll keep a note of that.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Turns out I was just forgetting to remember I am drawing two triangles not just a quad, and the distortion of either of the triangles does not effect the other, what a great reminder that I should sleep more

So have you managed to fix this? If you perform proper perspective projection post-VS as Hodgman mentioned, there is no distortion on a tessellated quad.

If I stick with the BasicEffect I don't think I'll be able to fix it, however I am going to be writing a replacement shader so taking Hodgman's insight into mind it should sort things out. Will report back with an update.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

This topic is closed to new replies.

Advertisement