• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AmzBee

Strange behaviour with texture mapping

11 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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.

1

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.

0

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

0

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.

1

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
0

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.

0

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.

0

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.

0

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.

 

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. 

0

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0