Jump to content

  • Log In with Google      Sign In   
  • Create Account


Strange behaviour with texture mapping


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 16 May 2013 - 10:45 PM

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


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27643

Like
1Likes
Like

Posted 16 May 2013 - 10:51 PM

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.



#3 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 16 May 2013 - 11:59 PM

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


#4 Hodgman   Moderators   -  Reputation: 27643

Like
0Likes
Like

Posted 17 May 2013 - 12:36 AM

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?



#5 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 17 May 2013 - 01:24 AM

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


#6 Hodgman   Moderators   -  Reputation: 27643

Like
1Likes
Like

Posted 17 May 2013 - 01:29 AM

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.



#7 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 17 May 2013 - 01:37 AM

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


#8 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 17 May 2013 - 01:44 AM

 

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


#9 eppo   Crossbones+   -  Reputation: 2311

Like
0Likes
Like

Posted 17 May 2013 - 04:36 AM

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.



#10 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 18 May 2013 - 12:29 AM

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


#11 phil_t   Crossbones+   -  Reputation: 3202

Like
0Likes
Like

Posted 18 May 2013 - 03:24 PM

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.

 

As for VertexPositionNormalTexture not supporting the W component - you can easily create your own vertex declaration that does include it. Have you tried this?

 

Alternately, why can't you perform your transformations on the GPU instead of on the CPU (or maybe in addition to on the CPU, if you require the projected coordinates for calculations in your code). Then you wouldn't run into this problem. 



#12 unbird   Crossbones+   -  Reputation: 4829

Like
0Likes
Like

Posted 20 May 2013 - 09:58 PM

You unlikely get rid of those artifacts on such a low tesselated sphere. The faces are trapezoids which - as you've seen yourself in the 2D case - don't map niceley to rectangular tex-coords.

You could UV unwrap your sphere like in the following picture, but then you still have the problem of painting said texture.

f16f1c255519575.jpg

The 2D problem turns up regularly here and elsewhere. There are two solutions: One is a bilinear inverse, the other is the perspective approach. The former is more involved, for the latter one can (ab)use the graphics hardware.

I once found the solution myself using a bit a convoluted approach here. More elegantly one can use homogenous 2D coords, derived here by (of course) Alvaro. IIRC this is the same approach Blinn showed in his Notation3 book.

I think this is also possible for 3D. Since this is a sphere (all faces are symmetric trapezoids) it will likely simplify the calculation.

Edit: Proof of concept.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS