Disfunctional 100 Report post Posted November 5, 2009 Hello, I have a rather noob question, but how do I get UV coordinates of a plane defined by a normal and by an offset? Thanks! 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 5, 2009 Strictly seen: Not at all. The plane as is given is infinite with no special point or direction.If you want to have u,v you need an origin and one direction (then the other direction can be computed from the first and the normal). Since the plane doesn't have those features, you need to either pick them more or less randomly or else abstain from u,v. 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 Wel let's say I've origin O(x, y, z) and direction D(x, y, z). How will I be able to calculate UV? 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 5, 2009 The (u,v) tuple is nothing more than 2 co-ordinates in the 2D u,v co-ordinate system. A co-ordinate system needs an origin and as many non co-linear directions as dimensions are there. The plane has 2 dimensions but is given in 3D space. So, although the origin and u,v directions are given as 3D vectors, they need to be constrained to lie within the plane:For the origin oo . n - D == 0(dependent on the definition of D you may need to use plus instead of minus above), and for the directionsu . n == 0v . n == 0where n denotes the plane's normal, and D the distance.Usually u and v are choosen to be orthonormal (i.e. orthogonal and of unit length)u . v == 0so thatu := v x n can be used to compute u if v is already chosen.Then any point p on the plane can be expressed by the (u,v) co-ordinate tuple because ofo + u * u + v * v == pso that for any p the (u,v) tuple can be computed. 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 Thank you! But I've still a small question, how can I get a good origin? Just by randomly getting a point from the plane? 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 5, 2009 There is in fact no single definition of "good" in this case, at least not until knowing what the purpose of finding (u,v) on an infinite plane is.Mathematically simple is the point closest to the world origin, likeo := n * D(maybe you need to use -D here).Or do you prefer a point that is within the view frustum of a camera? I don't know. 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 A small question, does this equation that you gave me results in tiles? So if my image is small does this results in tiles? 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 5, 2009 The given equations have nothing to do with tiles by itself. If you've implemented it and observe tiling, then you probably see the effect of how you've set-up texturing. By definition the entire texture is mapped in the range [0,1]x[0,1]. Now, the plane you use has infinite extension, so that the above range occurs infinitely often. For example, if you see (u,v) from (-1,-2) up to (3,4) then there are 3--1==4 tilings in u direction and 4--2==6 tilings in v direction.You can influence this by choosing another scaling in (u,v). 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 So I have p and I would like for example calculate the v (coordinate).o (origin coordinates) + u (coordinate) * u + v (coordinate) * v = pNow I've a problem, I get a vector division? So can you show me how I can express u into p? (I am a little bit confused)I assume p is the coordinate that I get when a ray from my raytracer hits the plane. 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 5, 2009 Quote:Original post by DisfunctionalSo I have p and I would like for example calculate the v (coordinate).o (origin coordinates) + u (coordinate) * u + v (coordinate) * v = pNow I've a problem, I get a vector division? So can you show me how I can express u into p? (I am a little bit confused)What you have here is a linear equation system with 3 equations:o_{x} + u * u_{x} + v * v_{x} = p_{x}o_{y} + u * u_{y} + v * v_{y} = p_{y}o_{z} + u * u_{z} + v * v_{z} = p_{z}where u and v are the unknown variables. So you have to apply a method os solving this system.Quote:Original post by DisfunctionalI assume p is the coordinate that I get when a ray from my raytracer hits the plane.p means any point on the plane. So a hit of a ray is absolutely a valid example. I've mentioned the formula to show you the correspondence between (u,v) and the belonging 3D point p due to the co-ordinate system build using o, u, and v. You can use it in the case that you need to compute (u,v) for a given point. Maybe you don't have the need at all. 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 So if I got this straight, I need to solve that system to get my formulas for u and v and I can just plug them into my ray tracer? 0 Share this post Link to post Share on other sites
Disfunctional 100 Report post Posted November 5, 2009 Okay my very last question. Can I thank you using a "Thanks" button? You really helped me a lot today and I solved the equation and generalized it.Thank you very much! 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted November 6, 2009 Quote:Original post by DisfunctionalSo if I got this straight, I need to solve that system to get my formulas for u and v and I can just plug them into my ray tracer?Exactly. As already mentioned above, you may consider some scaling. 0 Share this post Link to post Share on other sites