Jump to content
  • Advertisement
Sign in to follow this  
AmzBee

Strange behaviour with texture mapping

This topic is 2038 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!